From 99b25e3abb275a8491ae1dcb5b0b609f9cd5ca22 Mon Sep 17 00:00:00 2001 From: Jean-Francois Monfort Date: Thu, 4 Mar 2021 11:38:03 +0100 Subject: [PATCH 1/2] Add new field attributes to user to store data from SAML connection --- Entity/User.php | 36 +++++++++++++++++++++++++++- migrations/Version20210304085819.php | 30 +++++++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 migrations/Version20210304085819.php diff --git a/Entity/User.php b/Entity/User.php index d77883200..1a46b30a5 100644 --- a/Entity/User.php +++ b/Entity/User.php @@ -100,7 +100,14 @@ class User implements AdvancedUserInterface { * @ORM\Cache(usage="NONSTRICT_READ_WRITE") */ private $groupCenters; - + + /** + * Array where SAML attributes's data are stored + * @var array + * + * @ORM\Column(type="json_array", nullable=true) + */ + private $attributes; /** * User constructor. @@ -346,4 +353,31 @@ class User implements AdvancedUserInterface { } } + /** + * Set attributes + * + * @param array $attributes + * + * @return Report + */ + public function setAttributes($attributes) + { + $this->attributes = $attributes; + + return $this; + } + + /** + * Get attributes + * + * @return array + */ + public function getAttributes() + { + if ($this->attributes === null) { + $this->attributes = []; + } + + return $this->attributes; + } } diff --git a/migrations/Version20210304085819.php b/migrations/Version20210304085819.php new file mode 100644 index 000000000..48b54919e --- /dev/null +++ b/migrations/Version20210304085819.php @@ -0,0 +1,30 @@ +addSql('ALTER TABLE users ADD attributes JSONB DEFAULT NULL'); + $this->addSql('COMMENT ON COLUMN users.attributes IS \'(DC2Type:json_array)\''); + } + + public function down(Schema $schema) : void + { + $this->addSql('ALTER TABLE users DROP attributes'); + } +} From e91ddfae33ca7f71b51f5b00aff6db6cdd138f51 Mon Sep 17 00:00:00 2001 From: Jean-Francois Monfort Date: Thu, 4 Mar 2021 11:39:20 +0100 Subject: [PATCH 2/2] Add priority tag support For MenuBuilder --- .../CompilerPass/MenuCompilerPass.php | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/DependencyInjection/CompilerPass/MenuCompilerPass.php b/DependencyInjection/CompilerPass/MenuCompilerPass.php index b6b66a755..a8d87d950 100644 --- a/DependencyInjection/CompilerPass/MenuCompilerPass.php +++ b/DependencyInjection/CompilerPass/MenuCompilerPass.php @@ -36,13 +36,28 @@ class MenuCompilerPass implements CompilerPassInterface . "container.", MenuComposer::class)); } - $menuComposerDefinition = $container->getDefinition('chill.main.menu_composer'); - + $menuComposerDefinition = $container->getDefinition('chill.main.menu_composer'); + + $services = []; foreach ($container->findTaggedServiceIds('chill.menu_builder') as $id => $tags) { - $class = $container->getDefinition($id)->getClass(); + $services[] = [ + 'id' => $id, + 'priority' => $tags[0]['priority'] ?? 100, + ]; + } + + usort($services, function ($a, $b) { + if ($a['priority'] == $b['priority']) { + return 0; + } + return ($a['priority'] < $b['priority']) ? -1 : 1; + }); + + foreach ($services as $service) { + $class = $container->getDefinition($service['id'])->getClass(); foreach ($class::getMenuIds() as $menuId) { $menuComposerDefinition - ->addMethodCall('addLocalMenuBuilder', [new Reference($id), $menuId]); + ->addMethodCall('addLocalMenuBuilder', [new Reference($service['id']), $menuId]); } } }