mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Add permission allowed for user type check function
This commit is contained in:
1 parent
ac11617655
commit
686c42ae07
1 file changed
+27
@@ -53,4 +53,31 @@ class PermissionsProcessor
|
||||
}
|
||||
return $permissions;
|
||||
}
|
||||
|
||||
public static function allowedForUserType(?array $permissions): bool
|
||||
{
|
||||
if (\is_null($permissions)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Users can only manage their own roles, API keys and Admin users can manage any
|
||||
$roles = Authorization::getRoles();
|
||||
|
||||
if (!Auth::isAppUser($roles) && !Auth::isPrivilegedUser($roles)) {
|
||||
foreach (Database::PERMISSIONS as $type) {
|
||||
foreach ($permissions as $permission) {
|
||||
if (!\str_starts_with($permission, $type)) {
|
||||
continue;
|
||||
}
|
||||
$matches = \explode(',', \str_replace([$type, '(', ')', ' '], '', $permission));
|
||||
foreach ($matches as $role) {
|
||||
if (!Authorization::isRole($role)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user