Compare commits

..

1 Commits

Author SHA1 Message Date
24a66e4985 Show whether doc generation template is active or not. 2025-11-03 16:35:24 +01:00
12 changed files with 56 additions and 72 deletions

View File

@@ -1,6 +0,0 @@
kind: UX
body: Remove the label if there is only one scope and no scope picking field is displayed.
time: 2025-10-30T15:31:26.807444365+01:00
custom:
Issue: "449"
SchemaChange: No schema change

View File

@@ -0,0 +1,6 @@
kind: UX
body: Display whether doc generation template is active or not in admin and order templates alphabetically
time: 2025-11-03T16:19:10.051947925+01:00
custom:
Issue: "456"
SchemaChange: No schema change

View File

@@ -88,8 +88,8 @@ class ActivityType extends AbstractType
if (null !== $options['data']->getPerson()) {
$builder->add('scope', ScopePickerType::class, [
'role' => ActivityVoter::CREATE === (string) $options['role'] ? ActivityVoter::CREATE_PERSON : (string) $options['role'],
'center' => $options['center'],
'role' => ActivityVoter::CREATE === (string) $options['role'] ? ActivityVoter::CREATE_PERSON : (string) $options['role'],
'required' => true,
]);
}

View File

@@ -25,12 +25,24 @@
<div class="item-bloc">
<div class="item-row">
<div class="item-col" style="flex-basis:100%;">
<h2>{{ entity.name|localize_translatable_string }}</h2>
<h2>{{ entity.name|localize_translatable_string }} </h2>
<p style="margin-left: 1rem;"><span class="badge bg-chill-gray">
{% if entity.active %}
{{ 'admin.active'|trans }}
{% else %}
{{ 'admin.not active'|trans }}
{% endif %}
</span></p>
</div>
</div>
<div class="item-row">
<p><span class="badge bg-chill-green-dark">{{ contextManager.getContextByKey(entity.context).name|trans }}</span></p>
</div>
{# <div class="item-row">#}
{# <div class="item-col" style="flex-basis:100%;">#}
{##}
{# </div>#}
{# </div>#}
<div class="item-row">
<div class="item-col"></div>
<ul class="record_actions item-col flex-shrink-1">

View File

@@ -49,3 +49,7 @@ crud:
Template file: Fichier modèle
admin:
active: Actif
not active: Non-actif

View File

@@ -17,7 +17,6 @@ use Chill\DocStoreBundle\Entity\PersonDocument;
use Chill\MainBundle\Form\Type\ChillDateType;
use Chill\MainBundle\Form\Type\ChillTextareaType;
use Chill\MainBundle\Form\Type\ScopePickerType;
use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface;
use Chill\MainBundle\Security\Resolver\CenterResolverDispatcher;
use Chill\MainBundle\Security\Resolver\ScopeResolverDispatcher;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
@@ -28,11 +27,10 @@ use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Security\Core\Security;
class PersonDocumentType extends AbstractType
{
public function __construct(private readonly TranslatableStringHelperInterface $translatableStringHelper, private readonly Security $security, private readonly AuthorizationHelperInterface $authorizationHelper, private readonly ScopeResolverDispatcher $scopeResolverDispatcher, private readonly ParameterBagInterface $parameterBag, private readonly CenterResolverDispatcher $centerResolverDispatcher) {}
public function __construct(private readonly TranslatableStringHelperInterface $translatableStringHelper, private readonly ScopeResolverDispatcher $scopeResolverDispatcher, private readonly ParameterBagInterface $parameterBag, private readonly CenterResolverDispatcher $centerResolverDispatcher) {}
public function buildForm(FormBuilderInterface $builder, array $options)
{
@@ -59,8 +57,8 @@ class PersonDocumentType extends AbstractType
if ($isScopeConcerned && $this->parameterBag->get('chill_main')['acl']['form_show_scopes']) {
$builder->add('scope', ScopePickerType::class, [
'center' => $this->centerResolverDispatcher->resolveCenter($document),
'role' => $options['role'],
'subject' => $document,
]);
}
}

View File

@@ -16,7 +16,6 @@ use Chill\MainBundle\Entity\Scope;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Form\DataMapper\ScopePickerDataMapper;
use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface;
use Chill\MainBundle\Security\Resolver\CenterResolverManagerInterface;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
@@ -33,84 +32,65 @@ use Symfony\Component\Security\Core\Security;
* Allow to pick amongst available scope for the current
* user.
*
* Options:
* - `role`: string, the role to check permissions for
* - Either `subject`: object, entity to resolve centers from
* - Or `center`: Center|array|null, the center(s) to check
* options :
*
* - `center`: the center of the entity
* - `role` : the role of the user
*/
class ScopePickerType extends AbstractType
{
public function __construct(
private readonly TranslatableStringHelperInterface $translatableStringHelper,
private readonly AuthorizationHelperInterface $authorizationHelper,
private readonly Security $security,
private readonly CenterResolverManagerInterface $centerResolverManager,
private readonly TranslatableStringHelperInterface $translatableStringHelper,
) {}
public function buildForm(FormBuilderInterface $builder, array $options)
{
// Compute centers from subject
$centers = $options['center'] ?? null;
if (null === $centers && isset($options['subject'])) {
$centers = $this->centerResolverManager->resolveCenters($options['subject']);
}
if (null === $centers) {
throw new \RuntimeException('Either "center" or "subject" must be provided');
}
$reachableScopes = array_values(
$items = array_values(
array_filter(
$this->authorizationHelper->getReachableScopes(
$this->security->getUser(),
$options['role'],
$centers
$options['center']
),
static fn (Scope $s) => $s->isActive()
)
);
$builder->setAttribute('reachable_scopes_count', count($reachableScopes));
if (0 === count($reachableScopes)) {
$builder->setAttribute('has_scopes', false);
return;
if (0 === \count($items)) {
throw new \RuntimeException('no scopes are reachable. This form should not be shown to user');
}
$builder->setAttribute('has_scopes', true);
if (1 !== count($reachableScopes)) {
if (1 !== \count($items)) {
$builder->add('scope', EntityType::class, [
'class' => Scope::class,
'placeholder' => 'Choose the circle',
'choice_label' => fn (Scope $c) => $this->translatableStringHelper->localize($c->getName()),
'choices' => $reachableScopes,
'choices' => $items,
]);
$builder->setDataMapper(new ScopePickerDataMapper());
} else {
$builder->add('scope', HiddenType::class, [
'data' => $reachableScopes[0]->getId(),
'data' => $items[0]->getId(),
]);
$builder->setDataMapper(new ScopePickerDataMapper($reachableScopes[0]));
$builder->setDataMapper(new ScopePickerDataMapper($items[0]));
}
}
public function buildView(FormView $view, FormInterface $form, array $options)
{
$view->vars['fullWidth'] = true;
// display of label is handled by the EntityType
$view->vars['label'] = false;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver
// create `center` option
->setRequired('center')
->setAllowedTypes('center', [Center::class, 'array', 'null'])
// create ``role` option
->setRequired('role')
->setAllowedTypes('role', ['string'])
->setDefined('subject')
->setAllowedTypes('subject', ['object'])
->setDefined('center')
->setAllowedTypes('center', [Center::class, 'array', 'null']);
->setAllowedTypes('role', ['string']);
}
}

View File

@@ -11,11 +11,11 @@ declare(strict_types=1);
namespace Form\Type;
use Chill\MainBundle\Entity\Center;
use Chill\MainBundle\Entity\Scope;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Form\Type\ScopePickerType;
use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface;
use Chill\MainBundle\Security\Resolver\CenterResolverManagerInterface;
use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder;
@@ -39,11 +39,11 @@ final class ScopePickerTypeTest extends TypeTestCase
{
use ProphecyTrait;
public function testBuildOneScopeIsSuccessful()
public function estBuildOneScopeIsSuccessful()
{
$form = $this->factory->create(ScopePickerType::class, null, [
'center' => new Center(),
'role' => 'ONE_SCOPE',
'center' => [],
]);
$view = $form->createView();
@@ -54,8 +54,8 @@ final class ScopePickerTypeTest extends TypeTestCase
public function testBuildThreeScopesIsSuccessful()
{
$form = $this->factory->create(ScopePickerType::class, null, [
'center' => new Center(),
'role' => 'THREE_SCOPE',
'center' => [],
]);
$view = $form->createView();
@@ -66,8 +66,8 @@ final class ScopePickerTypeTest extends TypeTestCase
public function testBuildTwoScopesIsSuccessful()
{
$form = $this->factory->create(ScopePickerType::class, null, [
'center' => new Center(),
'role' => 'TWO_SCOPE',
'center' => [],
]);
$view = $form->createView();
@@ -101,13 +101,10 @@ final class ScopePickerTypeTest extends TypeTestCase
static fn ($args) => $args[0]['fr']
);
$centerResolverManager = $this->prophesize(CenterResolverManagerInterface::class);
$type = new ScopePickerType(
$translatableStringHelper->reveal(),
$authorizationHelper->reveal(),
$security->reveal(),
$centerResolverManager->reveal()
$translatableStringHelper->reveal()
);
// add the mocks for creating EntityType

View File

@@ -168,8 +168,9 @@ final readonly class PersonContext implements PersonContextInterface
if ($this->isScopeNecessary($entity)) {
$builder->add('scope', ScopePickerType::class, [
'center' => $this->centerResolverManager->resolveCenters($entity),
'role' => PersonDocumentVoter::CREATE,
'subject' => $entity,
'label' => 'Scope',
]);
}
}

View File

@@ -16,7 +16,6 @@ use Chill\MainBundle\Form\Type\ChillTextareaType;
use Chill\MainBundle\Form\Type\DateIntervalType;
use Chill\MainBundle\Form\Type\ScopePickerType;
use Chill\MainBundle\Form\Type\UserPickerType;
use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface;
use Chill\MainBundle\Security\Resolver\CenterResolverDispatcherInterface;
use Chill\MainBundle\Security\Resolver\ScopeResolverDispatcher;
use Chill\TaskBundle\Security\Authorization\TaskVoter;
@@ -25,17 +24,10 @@ use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Security\Core\Security;
class SingleTaskType extends AbstractType
{
public function __construct(
private readonly ParameterBagInterface $parameterBag,
private readonly CenterResolverDispatcherInterface $centerResolverDispatcher,
private readonly Security $security,
private readonly AuthorizationHelperInterface $authorizationHelper,
private readonly ScopeResolverDispatcher $scopeResolverDispatcher,
) {}
public function __construct(private readonly ParameterBagInterface $parameterBag, private readonly CenterResolverDispatcherInterface $centerResolverDispatcher, private readonly ScopeResolverDispatcher $scopeResolverDispatcher) {}
public function buildForm(FormBuilderInterface $builder, array $options)
{
@@ -72,8 +64,8 @@ class SingleTaskType extends AbstractType
if ($isScopeConcerned && $this->parameterBag->get('chill_main')['acl']['form_show_scopes']) {
$builder
->add('circle', ScopePickerType::class, [
'center' => $center,
'role' => $options['role'],
'subject' => $task,
'required' => true,
]);
}

View File

@@ -5,7 +5,7 @@
{% block title 'Tasks for {{ name }}'|trans({ '{{ name }}' : person|chill_entity_render_string }) %}
{% block content %}
<div class="task-list"">
<div class="col-md-10 col-xxl">
<h1>{{ block('title') }}</h1>

View File

@@ -37,7 +37,7 @@
{% endblock %}
{% else %}
{% block content %}
<div class="col-md-9 col-xxl tasks">
<div class="col-md-10 col-xxl tasks">
{% include '@ChillTask/SingleTask/AccompanyingCourse/list.html.twig' %}
</div>