mirror of
https://github.com/tiennm99/coolify.git
synced 2026-10-18 20:14:42 +00:00
Add new role enum and apply authorization
This commit is contained in:
1 parent
a4b4b93b30
commit
44f0458eb6
2 files changed
+54
-7
No files matched your search
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
enum Role: string
|
||||
{
|
||||
case MEMBER = 'member';
|
||||
case ADMIN = 'admin';
|
||||
case OWNER = 'owner';
|
||||
|
||||
public function rank(): int
|
||||
{
|
||||
return match ($this) {
|
||||
self::MEMBER => 1,
|
||||
self::ADMIN => 2,
|
||||
self::OWNER => 3,
|
||||
};
|
||||
}
|
||||
|
||||
public function lt(Role|string $role): bool
|
||||
{
|
||||
if (is_string($role)) {
|
||||
$role = Role::from($role);
|
||||
}
|
||||
|
||||
return $this->rank() < $role->rank();
|
||||
}
|
||||
|
||||
public function gt(Role|string $role): bool
|
||||
{
|
||||
if (is_string($role)) {
|
||||
$role = Role::from($role);
|
||||
}
|
||||
|
||||
return $this->rank() > $role->rank();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user