diff --git a/src/Appwrite/Auth/Auth.php b/src/Appwrite/Auth/Auth.php index 7217a87680..25c6b36e08 100644 --- a/src/Appwrite/Auth/Auth.php +++ b/src/Appwrite/Auth/Auth.php @@ -456,6 +456,10 @@ class Auth } } + foreach ($user->getAttribute('labels', []) as $label) { + $roles[] = 'label:' . $label; + } + return $roles; } diff --git a/tests/unit/Auth/AuthTest.php b/tests/unit/Auth/AuthTest.php index e64ef37dfe..aa8ff492f6 100644 --- a/tests/unit/Auth/AuthTest.php +++ b/tests/unit/Auth/AuthTest.php @@ -352,6 +352,10 @@ class AuthTest extends TestCase { $user = new Document([ '$id' => ID::custom('123'), + 'labels' => [ + 'vip', + 'admin' + ], 'emailVerification' => true, 'phoneVerification' => true, 'memberships' => [ @@ -377,7 +381,7 @@ class AuthTest extends TestCase $roles = Auth::getRoles($user); - $this->assertCount(11, $roles); + $this->assertCount(13, $roles); $this->assertContains(Role::users()->toString(), $roles); $this->assertContains(Role::user(ID::custom('123'))->toString(), $roles); $this->assertContains(Role::users(Roles::DIMENSION_VERIFIED)->toString(), $roles); @@ -389,6 +393,8 @@ class AuthTest extends TestCase $this->assertContains(Role::team(ID::custom('def'), 'guest')->toString(), $roles); $this->assertContains(Role::member(ID::custom('456'))->toString(), $roles); $this->assertContains(Role::member(ID::custom('abc'))->toString(), $roles); + $this->assertContains('label:vip', $roles); + $this->assertContains('label:admin', $roles); // Disable all verification $user['emailVerification'] = false;