feat(Auth): improve getRoles method

This commit is contained in:
Torsten Dittmann 2021-09-03 17:07:09 +02:00
parent b617afb17c
commit 0b344e182c

View file

@ -3,6 +3,7 @@
namespace Appwrite\Auth;
use Appwrite\Database\Document;
use Appwrite\Database\Validator\Authorization;
class Auth
{
@ -282,11 +283,13 @@ class Auth
*/
public static function getRoles(Document $user): array
{
if ($user->getId()) {
$roles[] = 'user:'.$user->getId();
$roles[] = 'role:'.Auth::USER_ROLE_MEMBER;
} else {
return ['role:'.Auth::USER_ROLE_GUEST];
if (self::isPrivilegedUser(Authorization::$roles) || self::isAppUser(Authorization::$roles)) {
if ($user->getId()) {
$roles[] = 'user:'.$user->getId();
$roles[] = 'role:'.Auth::USER_ROLE_MEMBER;
} else {
return ['role:'.Auth::USER_ROLE_GUEST];
}
}
foreach ($user->getAttribute('memberships', []) as $node) {