diff --git a/migrations/Version20240417160406.php b/migrations/Version20240417160406.php new file mode 100644 index 0000000..13f8496 --- /dev/null +++ b/migrations/Version20240417160406.php @@ -0,0 +1,36 @@ +addSql('ALTER TABLE user ADD super_admin TINYINT(1) NOT NULL'); + } + + public function postUp(Schema $schema): void + { + $this->connection->executeQuery('UPDATE user SET super_admin = 0'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE user DROP super_admin'); + } +} diff --git a/src/Entity/User.php b/src/Entity/User.php index 96f5eb6..9553520 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -39,6 +39,9 @@ class User implements UserInterface, TimestampableEntityInterface #[ORM\Column(type: 'json')] private array $roles = []; + #[ORM\Column] + private bool $superAdmin = false; + #[ORM\Column(nullable: true)] private ?\DateTimeImmutable $lastLoginAt = null; @@ -159,6 +162,18 @@ class User implements UserInterface, TimestampableEntityInterface return in_array($role, $this->getRoles()); } + public function isSuperAdmin(): bool + { + return $this->superAdmin; + } + + public function setSuperAdmin(bool $superAdmin): static + { + $this->superAdmin = $superAdmin; + + return $this; + } + public function getLastLoginAt(): ?\DateTimeImmutable { return $this->lastLoginAt; diff --git a/src/Security/Voter/ImpersonationVoter.php b/src/Security/Voter/ImpersonationVoter.php index 691301b..12574f2 100644 --- a/src/Security/Voter/ImpersonationVoter.php +++ b/src/Security/Voter/ImpersonationVoter.php @@ -40,6 +40,10 @@ class ImpersonationVoter extends Voter } // Admin is the only role allowed to impersonate - return $this->security->isGranted('ROLE_ADMIN'); + if (false === $this->security->isGranted('ROLE_ADMIN')) { + return false; + } + + return $currentUser->isSuperAdmin(); } } diff --git a/templates/administrative/teamer/index.html.twig b/templates/administrative/teamer/index.html.twig index ce9d33d..1773c60 100644 --- a/templates/administrative/teamer/index.html.twig +++ b/templates/administrative/teamer/index.html.twig @@ -94,6 +94,11 @@