Merge pull request #3795 from appwrite/feat-assign-member-role
Assign member role for all of a users confirmed team memberships
This commit is contained in:
commit
6d17d7f0f6
4 changed files with 78 additions and 61 deletions
14
composer.lock
generated
14
composer.lock
generated
|
@ -2060,16 +2060,16 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "utopia-php/database",
|
"name": "utopia-php/database",
|
||||||
"version": "0.25.1",
|
"version": "0.25.2",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/utopia-php/database.git",
|
"url": "https://github.com/utopia-php/database.git",
|
||||||
"reference": "9d013ce3c111d1477d7986483f1003dcab2b9d14"
|
"reference": "140bbedf1c4d622990fb94d26681fcca235cd5b9"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/utopia-php/database/zipball/9d013ce3c111d1477d7986483f1003dcab2b9d14",
|
"url": "https://api.github.com/repos/utopia-php/database/zipball/140bbedf1c4d622990fb94d26681fcca235cd5b9",
|
||||||
"reference": "9d013ce3c111d1477d7986483f1003dcab2b9d14",
|
"reference": "140bbedf1c4d622990fb94d26681fcca235cd5b9",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
|
@ -2118,9 +2118,9 @@
|
||||||
],
|
],
|
||||||
"support": {
|
"support": {
|
||||||
"issues": "https://github.com/utopia-php/database/issues",
|
"issues": "https://github.com/utopia-php/database/issues",
|
||||||
"source": "https://github.com/utopia-php/database/tree/0.25.1"
|
"source": "https://github.com/utopia-php/database/tree/0.25.2"
|
||||||
},
|
},
|
||||||
"time": "2022-09-07T14:47:52+00:00"
|
"time": "2022-09-09T03:58:01+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "utopia-php/domains",
|
"name": "utopia-php/domains",
|
||||||
|
@ -5384,5 +5384,5 @@
|
||||||
"platform-overrides": {
|
"platform-overrides": {
|
||||||
"php": "8.0"
|
"php": "8.0"
|
||||||
},
|
},
|
||||||
"plugin-api-version": "2.2.0"
|
"plugin-api-version": "2.3.0"
|
||||||
}
|
}
|
||||||
|
|
|
@ -431,11 +431,14 @@ class Auth
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($node['teamId']) && isset($node['roles'])) {
|
if (isset($node['$id']) && isset($node['teamId'])) {
|
||||||
$roles[] = Role::team($node['teamId'])->toString();
|
$roles[] = Role::team($node['teamId'])->toString();
|
||||||
|
$roles[] = Role::member($node['$id'])->toString();
|
||||||
|
|
||||||
foreach ($node['roles'] as $nodeRole) { // Set all team roles
|
if (isset($node['roles'])) {
|
||||||
$roles[] = Role::team($node['teamId'], $nodeRole)->toString();
|
foreach ($node['roles'] as $nodeRole) { // Set all team roles
|
||||||
|
$roles[] = Role::team($node['teamId'], $nodeRole)->toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -353,16 +353,58 @@ class AuthTest extends TestCase
|
||||||
'$id' => ID::custom('123'),
|
'$id' => ID::custom('123'),
|
||||||
'memberships' => [
|
'memberships' => [
|
||||||
[
|
[
|
||||||
'confirm' => true,
|
'$id' => ID::custom('456'),
|
||||||
'teamId' => ID::custom('abc'),
|
'teamId' => ID::custom('abc'),
|
||||||
|
'confirm' => true,
|
||||||
'roles' => [
|
'roles' => [
|
||||||
'administrator',
|
'administrator',
|
||||||
'moderator'
|
'moderator'
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'confirm' => true,
|
'$id' => ID::custom('abc'),
|
||||||
'teamId' => ID::custom('def'),
|
'teamId' => ID::custom('def'),
|
||||||
|
'confirm' => true,
|
||||||
|
'roles' => [
|
||||||
|
'guest'
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
|
||||||
|
$roles = Auth::getRoles($user);
|
||||||
|
|
||||||
|
$this->assertCount(9, $roles);
|
||||||
|
$this->assertContains(Role::users()->toString(), $roles);
|
||||||
|
$this->assertContains(Role::user(ID::custom('123'))->toString(), $roles);
|
||||||
|
$this->assertContains(Role::team(ID::custom('abc'))->toString(), $roles);
|
||||||
|
$this->assertContains(Role::team(ID::custom('abc'), 'administrator')->toString(), $roles);
|
||||||
|
$this->assertContains(Role::team(ID::custom('abc'), 'moderator')->toString(), $roles);
|
||||||
|
$this->assertContains(Role::team(ID::custom('def'))->toString(), $roles);
|
||||||
|
$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);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPrivilegedUserRoles(): void
|
||||||
|
{
|
||||||
|
Authorization::setRole(Auth::USER_ROLE_OWNER);
|
||||||
|
$user = new Document([
|
||||||
|
'$id' => ID::custom('123'),
|
||||||
|
'memberships' => [
|
||||||
|
[
|
||||||
|
'$id' => ID::custom('def'),
|
||||||
|
'teamId' => ID::custom('abc'),
|
||||||
|
'confirm' => true,
|
||||||
|
'roles' => [
|
||||||
|
'administrator',
|
||||||
|
'moderator'
|
||||||
|
]
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'$id' => ID::custom('abc'),
|
||||||
|
'teamId' => ID::custom('def'),
|
||||||
|
'confirm' => true,
|
||||||
'roles' => [
|
'roles' => [
|
||||||
'guest'
|
'guest'
|
||||||
]
|
]
|
||||||
|
@ -373,42 +415,6 @@ class AuthTest extends TestCase
|
||||||
$roles = Auth::getRoles($user);
|
$roles = Auth::getRoles($user);
|
||||||
|
|
||||||
$this->assertCount(7, $roles);
|
$this->assertCount(7, $roles);
|
||||||
$this->assertContains(Role::users()->toString(), $roles);
|
|
||||||
$this->assertContains(Role::user(ID::custom('123'))->toString(), $roles);
|
|
||||||
$this->assertContains(Role::team(ID::custom('abc'))->toString(), $roles);
|
|
||||||
$this->assertContains(Role::team(ID::custom('abc'), 'administrator')->toString(), $roles);
|
|
||||||
$this->assertContains(Role::team(ID::custom('abc'), 'moderator')->toString(), $roles);
|
|
||||||
$this->assertContains(Role::team(ID::custom('def'))->toString(), $roles);
|
|
||||||
$this->assertContains(Role::team(ID::custom('def'), 'guest')->toString(), $roles);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testPrivilegedUserRoles(): void
|
|
||||||
{
|
|
||||||
Authorization::setRole(Auth::USER_ROLE_OWNER);
|
|
||||||
$user = new Document([
|
|
||||||
'$id' => ID::custom('123'),
|
|
||||||
'memberships' => [
|
|
||||||
[
|
|
||||||
'confirm' => true,
|
|
||||||
'teamId' => ID::custom('abc'),
|
|
||||||
'roles' => [
|
|
||||||
'administrator',
|
|
||||||
'moderator'
|
|
||||||
]
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'confirm' => true,
|
|
||||||
'teamId' => ID::custom('def'),
|
|
||||||
'roles' => [
|
|
||||||
'guest'
|
|
||||||
]
|
|
||||||
]
|
|
||||||
]
|
|
||||||
]);
|
|
||||||
|
|
||||||
$roles = Auth::getRoles($user);
|
|
||||||
|
|
||||||
$this->assertCount(5, $roles);
|
|
||||||
$this->assertNotContains(Role::users()->toString(), $roles);
|
$this->assertNotContains(Role::users()->toString(), $roles);
|
||||||
$this->assertNotContains(Role::user(ID::custom('123'))->toString(), $roles);
|
$this->assertNotContains(Role::user(ID::custom('123'))->toString(), $roles);
|
||||||
$this->assertContains(Role::team(ID::custom('abc'))->toString(), $roles);
|
$this->assertContains(Role::team(ID::custom('abc'))->toString(), $roles);
|
||||||
|
@ -416,6 +422,8 @@ class AuthTest extends TestCase
|
||||||
$this->assertContains(Role::team(ID::custom('abc'), 'moderator')->toString(), $roles);
|
$this->assertContains(Role::team(ID::custom('abc'), 'moderator')->toString(), $roles);
|
||||||
$this->assertContains(Role::team(ID::custom('def'))->toString(), $roles);
|
$this->assertContains(Role::team(ID::custom('def'))->toString(), $roles);
|
||||||
$this->assertContains(Role::team(ID::custom('def'), 'guest')->toString(), $roles);
|
$this->assertContains(Role::team(ID::custom('def'), 'guest')->toString(), $roles);
|
||||||
|
$this->assertContains(Role::member(ID::custom('def'))->toString(), $roles);
|
||||||
|
$this->assertContains(Role::member(ID::custom('abc'))->toString(), $roles);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testAppUserRoles(): void
|
public function testAppUserRoles(): void
|
||||||
|
@ -425,16 +433,18 @@ class AuthTest extends TestCase
|
||||||
'$id' => ID::custom('123'),
|
'$id' => ID::custom('123'),
|
||||||
'memberships' => [
|
'memberships' => [
|
||||||
[
|
[
|
||||||
'confirm' => true,
|
'$id' => ID::custom('def'),
|
||||||
'teamId' => ID::custom('abc'),
|
'teamId' => ID::custom('abc'),
|
||||||
|
'confirm' => true,
|
||||||
'roles' => [
|
'roles' => [
|
||||||
'administrator',
|
'administrator',
|
||||||
'moderator'
|
'moderator'
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'confirm' => true,
|
'$id' => ID::custom('abc'),
|
||||||
'teamId' => ID::custom('def'),
|
'teamId' => ID::custom('def'),
|
||||||
|
'confirm' => true,
|
||||||
'roles' => [
|
'roles' => [
|
||||||
'guest'
|
'guest'
|
||||||
]
|
]
|
||||||
|
@ -444,7 +454,7 @@ class AuthTest extends TestCase
|
||||||
|
|
||||||
$roles = Auth::getRoles($user);
|
$roles = Auth::getRoles($user);
|
||||||
|
|
||||||
$this->assertCount(5, $roles);
|
$this->assertCount(7, $roles);
|
||||||
$this->assertNotContains(Role::users()->toString(), $roles);
|
$this->assertNotContains(Role::users()->toString(), $roles);
|
||||||
$this->assertNotContains(Role::user(ID::custom('123'))->toString(), $roles);
|
$this->assertNotContains(Role::user(ID::custom('123'))->toString(), $roles);
|
||||||
$this->assertContains(Role::team(ID::custom('abc'))->toString(), $roles);
|
$this->assertContains(Role::team(ID::custom('abc'))->toString(), $roles);
|
||||||
|
@ -452,5 +462,7 @@ class AuthTest extends TestCase
|
||||||
$this->assertContains(Role::team(ID::custom('abc'), 'moderator')->toString(), $roles);
|
$this->assertContains(Role::team(ID::custom('abc'), 'moderator')->toString(), $roles);
|
||||||
$this->assertContains(Role::team(ID::custom('def'))->toString(), $roles);
|
$this->assertContains(Role::team(ID::custom('def'))->toString(), $roles);
|
||||||
$this->assertContains(Role::team(ID::custom('def'), 'guest')->toString(), $roles);
|
$this->assertContains(Role::team(ID::custom('def'), 'guest')->toString(), $roles);
|
||||||
|
$this->assertContains(Role::member(ID::custom('def'))->toString(), $roles);
|
||||||
|
$this->assertContains(Role::member(ID::custom('abc'))->toString(), $roles);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,8 +54,9 @@ class MessagingChannelsTest extends TestCase
|
||||||
'$id' => ID::custom('user' . $this->connectionsCount),
|
'$id' => ID::custom('user' . $this->connectionsCount),
|
||||||
'memberships' => [
|
'memberships' => [
|
||||||
[
|
[
|
||||||
'confirm' => true,
|
'$id' => ID::custom('member' . $i),
|
||||||
'teamId' => ID::custom('team' . $i),
|
'teamId' => ID::custom('team' . $i),
|
||||||
|
'confirm' => true,
|
||||||
'roles' => [
|
'roles' => [
|
||||||
empty($index % 2)
|
empty($index % 2)
|
||||||
? Auth::USER_ROLE_ADMIN
|
? Auth::USER_ROLE_ADMIN
|
||||||
|
@ -122,11 +123,11 @@ class MessagingChannelsTest extends TestCase
|
||||||
* Check for correct amount of subscriptions:
|
* Check for correct amount of subscriptions:
|
||||||
* - XXX users
|
* - XXX users
|
||||||
* - XXX teams
|
* - XXX teams
|
||||||
* - XXX team roles (2 roles per team)
|
* - XXX team roles (3 roles per team)
|
||||||
* - 1 guests
|
* - 1 guests
|
||||||
* - 1 users
|
* - 1 users
|
||||||
*/
|
*/
|
||||||
$this->assertCount(($this->connectionsAuthenticated + (3 * $this->connectionsPerChannel) + 2), $this->realtime->subscriptions['1']);
|
$this->assertCount(($this->connectionsAuthenticated + (4 * $this->connectionsPerChannel) + 2), $this->realtime->subscriptions['1']);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check for connections
|
* Check for connections
|
||||||
|
@ -138,7 +139,7 @@ class MessagingChannelsTest extends TestCase
|
||||||
$this->realtime->unsubscribe(-1);
|
$this->realtime->unsubscribe(-1);
|
||||||
|
|
||||||
$this->assertCount($this->connectionsTotal, $this->realtime->connections);
|
$this->assertCount($this->connectionsTotal, $this->realtime->connections);
|
||||||
$this->assertCount(($this->connectionsAuthenticated + (3 * $this->connectionsPerChannel) + 2), $this->realtime->subscriptions['1']);
|
$this->assertCount(($this->connectionsAuthenticated + (4 * $this->connectionsPerChannel) + 2), $this->realtime->subscriptions['1']);
|
||||||
|
|
||||||
for ($i = 0; $i < $this->connectionsCount; $i++) {
|
for ($i = 0; $i < $this->connectionsCount; $i++) {
|
||||||
$this->realtime->unsubscribe($i);
|
$this->realtime->unsubscribe($i);
|
||||||
|
@ -259,6 +260,7 @@ class MessagingChannelsTest extends TestCase
|
||||||
|
|
||||||
for ($i = 0; $i < $this->connectionsPerChannel; $i++) {
|
for ($i = 0; $i < $this->connectionsPerChannel; $i++) {
|
||||||
$permissions[] = Role::team(ID::custom('team' . $i))->toString();
|
$permissions[] = Role::team(ID::custom('team' . $i))->toString();
|
||||||
|
$permissions[] = Role::member(ID::custom('member' . $i))->toString();
|
||||||
}
|
}
|
||||||
$event = [
|
$event = [
|
||||||
'project' => '1',
|
'project' => '1',
|
||||||
|
@ -284,13 +286,13 @@ class MessagingChannelsTest extends TestCase
|
||||||
$this->assertStringEndsWith($index, $receiver);
|
$this->assertStringEndsWith($index, $receiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$role = empty($index % 2)
|
||||||
|
? Auth::USER_ROLE_ADMIN
|
||||||
|
: 'member';
|
||||||
|
|
||||||
$permissions = [
|
$permissions = [
|
||||||
Role::team(
|
Role::team(ID::custom('team' . $index), $role)->toString(),
|
||||||
ID::custom('team' . $index),
|
Role::member(ID::custom('member' . $index))->toString()
|
||||||
(empty($index % 2)
|
|
||||||
? Auth::USER_ROLE_ADMIN
|
|
||||||
: 'member')
|
|
||||||
)->toString()
|
|
||||||
];
|
];
|
||||||
|
|
||||||
$event = [
|
$event = [
|
||||||
|
|
Loading…
Reference in a new issue