From 09f357725697cf8e2b0d2896ec8658a597611a46 Mon Sep 17 00:00:00 2001 From: Steven Nguyen Date: Fri, 26 May 2023 17:40:30 -0700 Subject: [PATCH] Update Appwrite to add User labels to Auth roles --- src/Appwrite/Auth/Auth.php | 4 ++++ tests/unit/Auth/AuthTest.php | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Appwrite/Auth/Auth.php b/src/Appwrite/Auth/Auth.php index 7217a8768..25c6b36e0 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 e64ef37df..aa8ff492f 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;