diff --git a/src/Bundle/ChillMainBundle/Entity/User.php b/src/Bundle/ChillMainBundle/Entity/User.php index 76fd7196d..9fc1856f2 100644 --- a/src/Bundle/ChillMainBundle/Entity/User.php +++ b/src/Bundle/ChillMainBundle/Entity/User.php @@ -138,6 +138,11 @@ class User implements AdvancedUserInterface */ private ?string $usernameCanonical = null; + /** + * @ORM\Column(type="json") + */ + private array $roles = ['ROLE_USER']; + /** * User constructor. */ @@ -146,36 +151,17 @@ 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) - { - $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 +175,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 +193,7 @@ class User implements AdvancedUserInterface return $this->groupCenters; } - /** - * Get id. - * - * @return int - */ - public function getId() + public function getId(): ?int { return $this->id; } @@ -243,23 +218,20 @@ 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']; + $roles = $this->roles; + $roles[] = 'ROLE_USER'; + + return array_unique($roles); } - /** - * @return string|null - */ - public function getSalt() + public function getSalt(): ?string { return $this->salt; } @@ -269,50 +241,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; } @@ -349,6 +303,13 @@ class User implements AdvancedUserInterface } } + public function addGroupCenter(GroupCenter $groupCenter): self + { + $this->groupCenters->add($groupCenter); + + return $this; + } + /** * Set attributes. * @@ -363,97 +324,83 @@ 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 setRoles($roles): self + { + $this->roles = $roles; + return $this; + } + + 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 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 +425,7 @@ class User implements AdvancedUserInterface return $this; } - /** - * @param $usernameCanonical - * - * @return $this - */ - public function setUsernameCanonical($usernameCanonical) + public function setUsernameCanonical($usernameCanonical): self { $this->usernameCanonical = $usernameCanonical; diff --git a/src/Bundle/ChillMainBundle/migrations/Version20220308104030.php b/src/Bundle/ChillMainBundle/migrations/Version20220308104030.php new file mode 100644 index 000000000..f70d6e5f6 --- /dev/null +++ b/src/Bundle/ChillMainBundle/migrations/Version20220308104030.php @@ -0,0 +1,29 @@ +addSql('ALTER TABLE users ADD roles JSON NOT NULL'); + } + + public function down(Schema $schema): void + { + $this->addSql('ALTER TABLE users DROP roles'); + } +}