mirror of
				https://gitlab.com/Chill-Projet/chill-bundles.git
				synced 2025-10-31 17:28:23 +00:00 
			
		
		
		
	Compare commits
	
		
			7 Commits
		
	
	
		
			v3.12.0
			...
			issue17_us
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 6f7bda9f0a | |||
| c34c8035ea | |||
| a3c5cabc9a | |||
| 0fc3c2eb1f | |||
| 3ebeda9840 | |||
| 1453fdcd18 | |||
| 0a4abe9b8d | 
| @@ -20,7 +20,7 @@ class DefaultController extends AbstractController | ||||
| { | ||||
|     public function indexAction() | ||||
|     { | ||||
|         if ($this->isGranted('ROLE_ADMIN')) { | ||||
|         if ($this->isGranted('ROLE_ADMIN') && !in_array('ROLE_USER',$this->getUser()->getRoles())) { | ||||
|             return $this->redirectToRoute('chill_main_admin_central', [], 302); | ||||
|         } | ||||
|  | ||||
|   | ||||
| @@ -112,6 +112,11 @@ class User implements AdvancedUserInterface | ||||
|      */ | ||||
|     private string $password = ''; | ||||
|  | ||||
|     /** | ||||
|      * @ORM\Column(type="json") | ||||
|      */ | ||||
|     private array $roles = ['ROLE_USER']; | ||||
|  | ||||
|     /** | ||||
|      * @internal must be set to null if we use bcrypt | ||||
|      * | ||||
| @@ -146,36 +151,24 @@ class User implements AdvancedUserInterface | ||||
|         $this->groupCenters = new ArrayCollection(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return string | ||||
|      */ | ||||
|     public function __toString() | ||||
|     public function __toString(): string | ||||
|     { | ||||
|         return $this->getLabel(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param \Chill\MainBundle\Entity\GroupCenter $groupCenter | ||||
|      * | ||||
|      * @return \Chill\MainBundle\Entity\User | ||||
|      */ | ||||
|     public function addGroupCenter(GroupCenter $groupCenter) | ||||
|     public function addGroupCenter(GroupCenter $groupCenter): self | ||||
|     { | ||||
|         $this->groupCenters->add($groupCenter); | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     // empty function... remove? | ||||
|     public function eraseCredentials() | ||||
|     { | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get attributes. | ||||
|      * | ||||
|      * @return array | ||||
|      */ | ||||
|     public function getAttributes() | ||||
|     public function getAttributes(): ?array | ||||
|     { | ||||
|         if (null === $this->attributes) { | ||||
|             $this->attributes = []; | ||||
| @@ -189,18 +182,12 @@ class User implements AdvancedUserInterface | ||||
|         return $this->currentLocation; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return string | ||||
|      */ | ||||
|     public function getEmail(): ?string | ||||
|     { | ||||
|         return $this->email; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return string | ||||
|      */ | ||||
|     public function getEmailCanonical() | ||||
|     public function getEmailCanonical(): ?string | ||||
|     { | ||||
|         return $this->emailCanonical; | ||||
|     } | ||||
| @@ -213,12 +200,7 @@ class User implements AdvancedUserInterface | ||||
|         return $this->groupCenters; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Get id. | ||||
|      * | ||||
|      * @return int | ||||
|      */ | ||||
|     public function getId() | ||||
|     public function getId(): ?int | ||||
|     { | ||||
|         return $this->id; | ||||
|     } | ||||
| @@ -243,23 +225,17 @@ class User implements AdvancedUserInterface | ||||
|         return $this->mainScope; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return string | ||||
|      */ | ||||
|     public function getPassword() | ||||
|     public function getPassword(): string | ||||
|     { | ||||
|         return $this->password; | ||||
|     } | ||||
|  | ||||
|     public function getRoles(): array | ||||
|     { | ||||
|         return ['ROLE_USER']; | ||||
|         return array_unique($this->roles); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return string|null | ||||
|      */ | ||||
|     public function getSalt() | ||||
|     public function getSalt(): ?string | ||||
|     { | ||||
|         return $this->salt; | ||||
|     } | ||||
| @@ -269,50 +245,32 @@ class User implements AdvancedUserInterface | ||||
|         return $this->userJob; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return string | ||||
|      */ | ||||
|     public function getUsername() | ||||
|     public function getUsername(): string | ||||
|     { | ||||
|         return $this->username; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return string | ||||
|      */ | ||||
|     public function getUsernameCanonical() | ||||
|     public function getUsernameCanonical(): ?string | ||||
|     { | ||||
|         return $this->usernameCanonical; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return bool | ||||
|      */ | ||||
|     public function isAccountNonExpired() | ||||
|     public function isAccountNonExpired(): bool | ||||
|     { | ||||
|         return true; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return bool | ||||
|      */ | ||||
|     public function isAccountNonLocked() | ||||
|     public function isAccountNonLocked(): bool | ||||
|     { | ||||
|         return $this->locked; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return bool | ||||
|      */ | ||||
|     public function isCredentialsNonExpired() | ||||
|     public function isCredentialsNonExpired(): bool | ||||
|     { | ||||
|         return true; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @return bool | ||||
|      */ | ||||
|     public function isEnabled() | ||||
|     public function isEnabled(): bool | ||||
|     { | ||||
|         return $this->enabled; | ||||
|     } | ||||
| @@ -363,97 +321,84 @@ class User implements AdvancedUserInterface | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function setCurrentLocation(?Location $currentLocation): User | ||||
|     public function setCurrentLocation(?Location $currentLocation): self | ||||
|     { | ||||
|         $this->currentLocation = $currentLocation; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param $email | ||||
|      * | ||||
|      * @return $this | ||||
|      */ | ||||
|     public function setEmail($email) | ||||
|     public function setEmail($email): self | ||||
|     { | ||||
|         $this->email = $email; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param $emailCanonical | ||||
|      * | ||||
|      * @return $this | ||||
|      */ | ||||
|     public function setEmailCanonical($emailCanonical) | ||||
|     public function setEmailCanonical($emailCanonical): self | ||||
|     { | ||||
|         $this->emailCanonical = $emailCanonical; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function setEnabled(bool $enabled) | ||||
|     public function setEnabled(bool $enabled): self | ||||
|     { | ||||
|         $this->enabled = $enabled; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function setLabel(string $label): User | ||||
|     public function setLabel(string $label): self | ||||
|     { | ||||
|         $this->label = $label; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function setMainCenter(?Center $mainCenter): User | ||||
|     public function setMainCenter(?Center $mainCenter): self | ||||
|     { | ||||
|         $this->mainCenter = $mainCenter; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function setMainLocation(?Location $mainLocation): User | ||||
|     public function setMainLocation(?Location $mainLocation): self | ||||
|     { | ||||
|         $this->mainLocation = $mainLocation; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function setMainScope(?Scope $mainScope): User | ||||
|     public function setMainScope(?Scope $mainScope): self | ||||
|     { | ||||
|         $this->mainScope = $mainScope; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param $password | ||||
|      * | ||||
|      * @return $this | ||||
|      */ | ||||
|     public function setPassword($password) | ||||
|     public function setPassword($password): self | ||||
|     { | ||||
|         $this->password = $password; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param $salt | ||||
|      * | ||||
|      * @return $this | ||||
|      */ | ||||
|     public function setSalt($salt) | ||||
|     public function setRoles($roles): self | ||||
|     { | ||||
|         $this->roles = $roles; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function setSalt($salt): self | ||||
|     { | ||||
|         $this->salt = $salt; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function setUserJob(?UserJob $userJob): User | ||||
|     public function setUserJob(?UserJob $userJob): self | ||||
|     { | ||||
|         $this->userJob = $userJob; | ||||
|  | ||||
| @@ -478,12 +423,7 @@ class User implements AdvancedUserInterface | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param $usernameCanonical | ||||
|      * | ||||
|      * @return $this | ||||
|      */ | ||||
|     public function setUsernameCanonical($usernameCanonical) | ||||
|     public function setUsernameCanonical($usernameCanonical): self | ||||
|     { | ||||
|         $this->usernameCanonical = $usernameCanonical; | ||||
|  | ||||
|   | ||||
| @@ -19,6 +19,7 @@ use Chill\MainBundle\Templating\TranslatableStringHelper; | ||||
| use Doctrine\ORM\EntityRepository; | ||||
| use Symfony\Bridge\Doctrine\Form\Type\EntityType; | ||||
| use Symfony\Component\Form\AbstractType; | ||||
| use Symfony\Component\Form\CallbackTransformer; | ||||
| use Symfony\Component\Form\Extension\Core\Type\ChoiceType; | ||||
| use Symfony\Component\Form\Extension\Core\Type\EmailType; | ||||
| use Symfony\Component\Form\Extension\Core\Type\PasswordType; | ||||
| @@ -59,6 +60,16 @@ class UserType extends AbstractType | ||||
|                     return $qb; | ||||
|                 }, | ||||
|             ]) | ||||
|             ->add('roles', ChoiceType::class, [ | ||||
|                 'required' => true, | ||||
|                 'multiple' => true, | ||||
|                 'expanded' => true, | ||||
|                 'label' => 'Roles', | ||||
|                 'choices' => [ | ||||
|                     'Usager' => 'ROLE_USER', | ||||
|                     'Administrateur' => 'ROLE_ADMIN', | ||||
|                 ], | ||||
|             ]) | ||||
|             ->add('mainScope', EntityType::class, [ | ||||
|                 'label' => 'Main scope', | ||||
|                 'required' => false, | ||||
| @@ -94,6 +105,18 @@ class UserType extends AbstractType | ||||
|                 }, | ||||
|             ]); | ||||
|  | ||||
|         // $builder->get('roles') | ||||
|         //     ->addModelTransformer(new CallbackTransformer( | ||||
|         //         function ($rolesArray) { | ||||
|         //              // transform the array to a string | ||||
|         //             return count($rolesArray)? $rolesArray[0]: null; | ||||
|         //         }, | ||||
|         //         function ($rolesString) { | ||||
|         //              // transform the string back to an array | ||||
|         //             return [$rolesString]; | ||||
|         //         } | ||||
|         // )); | ||||
|  | ||||
|         if ($options['is_creation']) { | ||||
|             $builder->add('plainPassword', RepeatedType::class, [ | ||||
|                 'mapped' => false, | ||||
|   | ||||
| @@ -22,19 +22,10 @@ use Symfony\Contracts\Translation\TranslatorInterface; | ||||
|  */ | ||||
| class SectionMenuBuilder implements LocalMenuBuilderInterface | ||||
| { | ||||
|     /** | ||||
|      * @var AuthorizationCheckerInterface | ||||
|      */ | ||||
|     protected $authorizationChecker; | ||||
|     protected AuthorizationCheckerInterface $authorizationChecker; | ||||
|  | ||||
|     /** | ||||
|      * @var TranslatorInterface | ||||
|      */ | ||||
|     protected $translator; | ||||
|     protected TranslatorInterface $translator; | ||||
|  | ||||
|     /** | ||||
|      * SectionMenuBuilder constructor. | ||||
|      */ | ||||
|     public function __construct(AuthorizationCheckerInterface $authorizationChecker, TranslatorInterface $translator) | ||||
|     { | ||||
|         $this->authorizationChecker = $authorizationChecker; | ||||
| @@ -54,6 +45,16 @@ class SectionMenuBuilder implements LocalMenuBuilderInterface | ||||
|                 'order' => 0, | ||||
|             ]); | ||||
|  | ||||
|         if ($this->authorizationChecker->isGranted('ROLE_ADMIN')) { | ||||
|             $menu->addChild($this->translator->trans('Administration'), [ | ||||
|                 'route' => 'chill_main_admin_central', | ||||
|             ]) | ||||
|                 ->setExtras([ | ||||
|                     'icons' => ['home'], | ||||
|                     'order' => 5, | ||||
|                 ]); | ||||
|         } | ||||
|  | ||||
|         $menu->addChild($this->translator->trans('Global timeline'), [ | ||||
|             'route' => 'chill_center_timeline', | ||||
|         ]) | ||||
|   | ||||
| @@ -0,0 +1,36 @@ | ||||
| <?php | ||||
|  | ||||
| /** | ||||
|  * Chill is a software for social workers | ||||
|  * | ||||
|  * For the full copyright and license information, please view | ||||
|  * the LICENSE file that was distributed with this source code. | ||||
|  */ | ||||
|  | ||||
| declare(strict_types=1); | ||||
|  | ||||
| namespace Chill\Migrations\Main; | ||||
|  | ||||
| use Doctrine\DBAL\Schema\Schema; | ||||
| use Doctrine\Migrations\AbstractMigration; | ||||
|  | ||||
| /** | ||||
|  * Auto-generated Migration: Please modify to your needs! | ||||
|  */ | ||||
| final class Version20220308104030 extends AbstractMigration | ||||
| { | ||||
|     public function down(Schema $schema): void | ||||
|     { | ||||
|         $this->addSql('ALTER TABLE users DROP roles'); | ||||
|     } | ||||
|  | ||||
|     public function getDescription(): string | ||||
|     { | ||||
|         return 'Add roles property to user'; | ||||
|     } | ||||
|  | ||||
|     public function up(Schema $schema): void | ||||
|     { | ||||
|         $this->addSql('ALTER TABLE users ADD roles JSONB DEFAULT \'["ROLE_USER"]\' NOT NULL'); | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user