diff --git a/ChillMainBundle.php b/ChillMainBundle.php index 7e6620522..6cb83ee50 100644 --- a/ChillMainBundle.php +++ b/ChillMainBundle.php @@ -12,6 +12,7 @@ use Chill\MainBundle\DependencyInjection\CompilerPass\ExportsCompilerPass; use Chill\MainBundle\DependencyInjection\CompilerPass\WidgetsCompilerPass; use Chill\MainBundle\DependencyInjection\CompilerPass\NotificationCounterCompilerPass; use Chill\MainBundle\DependencyInjection\CompilerPass\MenuCompilerPass; +use Chill\MainBundle\DependencyInjection\CompilerPass\ACLFlagsCompilerPass; class ChillMainBundle extends Bundle @@ -27,5 +28,6 @@ class ChillMainBundle extends Bundle $container->addCompilerPass(new WidgetsCompilerPass()); $container->addCompilerPass(new NotificationCounterCompilerPass()); $container->addCompilerPass(new MenuCompilerPass()); + $container->addCompilerPass(new ACLFlagsCompilerPass()); } } diff --git a/DependencyInjection/CompilerPass/ACLFlagsCompilerPass.php b/DependencyInjection/CompilerPass/ACLFlagsCompilerPass.php new file mode 100644 index 000000000..9197ddb83 --- /dev/null +++ b/DependencyInjection/CompilerPass/ACLFlagsCompilerPass.php @@ -0,0 +1,39 @@ + + */ +class ACLFlagsCompilerPass implements CompilerPassInterface +{ + public function process(ContainerBuilder $container) + { + $permissionGroupType = $container->getDefinition(PermissionsGroupType::class); + + foreach($container->findTaggedServiceIds('chill_main.flags') as $id => $tags) { + $reference = new Reference($id); + + foreach ($tags as $tag) { + switch($tag['scope']) { + case PermissionsGroupType::FLAG_SCOPE: + + $permissionGroupType->addMethodCall('addFlagProvider', [ $reference ]); + break; + default: + throw new \LogicalException(sprintf( + "This tag 'scope' is not implemented: %s, on service with id %s", $tag['scope'], $id) + ); + } + } + } + } +} diff --git a/Entity/GroupCenter.php b/Entity/GroupCenter.php index 429aac3da..d34b86475 100644 --- a/Entity/GroupCenter.php +++ b/Entity/GroupCenter.php @@ -58,7 +58,7 @@ class GroupCenter public function __construct() { - $this->permissionGroups = new ArrayCollection(); + $this->permissionsGroup = new ArrayCollection(); $this->users = new ArrayCollection(); } diff --git a/Entity/PermissionsGroup.php b/Entity/PermissionsGroup.php index d3de7e2d5..706c96d3e 100644 --- a/Entity/PermissionsGroup.php +++ b/Entity/PermissionsGroup.php @@ -43,6 +43,12 @@ class PermissionsGroup */ private $name; + /** + * + * @var string[] + */ + private $flags = []; + /** * * @var \Doctrine\Common\Collections\Collection @@ -109,6 +115,19 @@ class PermissionsGroup } } + public function getFlags() + { + return $this->flags; + } + + public function setFlags(array $flags) + { + $this->flags = $flags; + + return $this; + } + + /** * Test that a role scope is associated only once with the permission group * diff --git a/Form/PermissionsGroupType.php b/Form/PermissionsGroupType.php index 20109d095..d9b4ab730 100644 --- a/Form/PermissionsGroupType.php +++ b/Form/PermissionsGroupType.php @@ -5,9 +5,20 @@ namespace Chill\MainBundle\Form; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; +use Symfony\Component\Form\Extension\Core\Type\TextType; +use Chill\MainBundle\Form\Utils\PermissionsGroupFlagProvider; +use Symfony\Component\Form\Extension\Core\Type\ChoiceType; class PermissionsGroupType extends AbstractType { + /** + * + * @var PermissionsGroupFlagProvider[] + */ + protected $flagProviders = []; + + const FLAG_SCOPE = 'permissions_group'; + /** * @param FormBuilderInterface $builder * @param array $options @@ -15,8 +26,40 @@ class PermissionsGroupType extends AbstractType public function buildForm(FormBuilderInterface $builder, array $options) { $builder - ->add('name') + ->add('name', TextType::class) ; + + $flags = $this->getFlags(); + + if (count($flags) > 0) { + $builder + ->add('flags', ChoiceType::class, [ + 'choices' => \array_combine($flags, $flags), + 'multiple' => true, + 'expanded' => true, + 'required' => false + ]); + } + } + + /** + * + * @return array + */ + protected function getFlags(): array + { + $flags = []; + + foreach ($this->flagProviders as $flagProvider) { + $flags = \array_merge($flags, $flagProvider->getPermissionsGroupFlags()); + } + + return $flags; + } + + public function addFlagProvider(PermissionsGroupFlagProvider $provider) + { + $this->flagProviders[] = $provider; } /** diff --git a/Form/Utils/PermissionsGroupFlagProvider.php b/Form/Utils/PermissionsGroupFlagProvider.php new file mode 100644 index 000000000..39ddb62d5 --- /dev/null +++ b/Form/Utils/PermissionsGroupFlagProvider.php @@ -0,0 +1,18 @@ +addSql('ALTER TABLE permission_groups ADD flags JSONB DEFAULT \'[]\' NOT NULL'); + $this->addSql('ALTER TABLE group_centers ALTER permissionsgroup_id DROP NOT NULL'); + + } + + public function down(Schema $schema) : void + { + $this->addSql('ALTER TABLE permission_groups DROP COLUMN flags'); + $this->addSql('ALTER TABLE group_centers ALTER permissionsgroup_id SET DEFAULT NULL'); + } +} diff --git a/Resources/translations/messages.fr.yml b/Resources/translations/messages.fr.yml index 120a529d9..90baaa4dc 100644 --- a/Resources/translations/messages.fr.yml +++ b/Resources/translations/messages.fr.yml @@ -129,6 +129,7 @@ Edit password for %username%: Éditer le mot de passe de %username% Change password: Changer le mot de passe Back to the user edition: Retour au formulaire d'édition Password successfully updated!: Mot de passe mis à jour +Flags: Drapeaux #admin section for circles (old: scopes) List circles: Liste des cercles diff --git a/Resources/views/PermissionsGroup/edit.html.twig b/Resources/views/PermissionsGroup/edit.html.twig index 43ffd6a62..2d56b8602 100644 --- a/Resources/views/PermissionsGroup/edit.html.twig +++ b/Resources/views/PermissionsGroup/edit.html.twig @@ -9,6 +9,7 @@ {{ form_start(edit_form) }} {{ form_row(edit_form.name) }} + {{ form_row(edit_form.flags) }} {{ form_row(edit_form.submit, { 'attr': { 'class': 'sc-button green' } } ) }} {{ form_end(edit_form) }} diff --git a/Resources/views/PermissionsGroup/new.html.twig b/Resources/views/PermissionsGroup/new.html.twig index e28e60992..16a6fb817 100644 --- a/Resources/views/PermissionsGroup/new.html.twig +++ b/Resources/views/PermissionsGroup/new.html.twig @@ -7,6 +7,7 @@ {{ form_start(form) }} {{ form_row(form.name) }} + {{ form_row(form.flags) }} {{ form_row(form.submit, { 'attr': { 'class': 'sc-button green' } } ) }} {{ form_end(form) }}