diff --git a/src/Appwrite/Auth/Auth.php b/src/Appwrite/Auth/Auth.php index 09680024ba..37a2ea8d39 100644 --- a/src/Appwrite/Auth/Auth.php +++ b/src/Appwrite/Auth/Auth.php @@ -427,6 +427,10 @@ class Auth } foreach ($user->getAttribute('memberships', []) as $node) { + if (!isset($node['confirm']) || !$node['confirm']) { + continue; + } + if (isset($node['teamId']) && isset($node['roles'])) { $roles[] = Role::team($node['teamId'])->toString(); diff --git a/tests/e2e/Services/Teams/TeamsConsoleClientTest.php b/tests/e2e/Services/Teams/TeamsConsoleClientTest.php index 996405c416..0f32425c92 100644 --- a/tests/e2e/Services/Teams/TeamsConsoleClientTest.php +++ b/tests/e2e/Services/Teams/TeamsConsoleClientTest.php @@ -63,4 +63,67 @@ class TeamsConsoleClientTest extends Scope $this->assertEquals(204, $response['headers']['status-code']); } + + /** + * @depends testCreateTeam + */ + public function testTeamMembershipPerms($data): array + { + $teamUid = $data['teamUid'] ?? ''; + $teamName = $data['teamName'] ?? ''; + $email = uniqid() . 'friend@localhost.test'; + $name = 'Friend User'; + $password = 'password'; + + // Create a user account before we create a invite so we can check if the user has permissions when it shouldn't + $user = $this->client->call(Client::METHOD_POST, '/account', [ + 'content-type' => 'application/json', + 'x-appwrite-project' => 'console'], [ + 'userId' => 'unique()', + 'email' => $email, + 'password' => $password, + 'name' => $name, + ], false); + + $this->assertEquals(201, $user['headers']['status-code']); + + /** + * Test for SUCCESS + */ + $response = $this->client->call(Client::METHOD_POST, '/teams/' . $teamUid . '/memberships', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'email' => $email, + 'name' => $name, + 'roles' => ['admin', 'editor'], + 'url' => 'http://localhost:5000/join-us#title' + ]); + + $this->assertEquals(201, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_GET, '/users', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + $this->assertEquals(401, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_GET, '/teams/' . $teamUid . '/memberships', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + + $this->assertEquals(200, $response['headers']['status-code']); + + $ownerMembershipUid = $response['body']['memberships'][1]['$id']; + + $response = $this->client->call(Client::METHOD_DELETE, '/teams/' . $teamUid . '/memberships/' . $ownerMembershipUid, array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + $this->assertEquals(204, $response['headers']['status-code']); + + return $data; + } } diff --git a/tests/unit/Auth/AuthTest.php b/tests/unit/Auth/AuthTest.php index 362b0ee9b4..4cd180b956 100644 --- a/tests/unit/Auth/AuthTest.php +++ b/tests/unit/Auth/AuthTest.php @@ -353,6 +353,7 @@ class AuthTest extends TestCase '$id' => ID::custom('123'), 'memberships' => [ [ + 'confirm' => true, 'teamId' => ID::custom('abc'), 'roles' => [ 'administrator', @@ -360,6 +361,7 @@ class AuthTest extends TestCase ] ], [ + 'confirm' => true, 'teamId' => ID::custom('def'), 'roles' => [ 'guest' @@ -387,6 +389,7 @@ class AuthTest extends TestCase '$id' => ID::custom('123'), 'memberships' => [ [ + 'confirm' => true, 'teamId' => ID::custom('abc'), 'roles' => [ 'administrator', @@ -394,6 +397,7 @@ class AuthTest extends TestCase ] ], [ + 'confirm' => true, 'teamId' => ID::custom('def'), 'roles' => [ 'guest' @@ -421,6 +425,7 @@ class AuthTest extends TestCase '$id' => ID::custom('123'), 'memberships' => [ [ + 'confirm' => true, 'teamId' => ID::custom('abc'), 'roles' => [ 'administrator', @@ -428,6 +433,7 @@ class AuthTest extends TestCase ] ], [ + 'confirm' => true, 'teamId' => ID::custom('def'), 'roles' => [ 'guest' diff --git a/tests/unit/Messaging/MessagingChannelsTest.php b/tests/unit/Messaging/MessagingChannelsTest.php index b97df78196..26a1106688 100644 --- a/tests/unit/Messaging/MessagingChannelsTest.php +++ b/tests/unit/Messaging/MessagingChannelsTest.php @@ -54,6 +54,7 @@ class MessagingChannelsTest extends TestCase '$id' => ID::custom('user' . $this->connectionsCount), 'memberships' => [ [ + 'confirm' => true, 'teamId' => ID::custom('team' . $i), 'roles' => [ empty($index % 2)