Reduce duplicated logic when checking if an API key is admin

This commit is contained in:
Alejandro Celaya
2023-03-04 10:22:46 +01:00
parent 83c53c8b2e
commit e51384fcc0
6 changed files with 17 additions and 13 deletions

View File

@@ -114,9 +114,12 @@ class ApiKey extends AbstractEntity
return Spec::andX(...$specs);
}
public function isAdmin(): bool
/**
* @return ($apiKey is null ? true : boolean)
*/
public static function isAdmin(?ApiKey $apiKey): bool
{
return $this->roles->isEmpty();
return $apiKey === null || $apiKey->roles->isEmpty();
}
public function hasRole(Role $role): bool