From 1ab86c9331668850a7d7838d4c67bf7169f424a6 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 3 Aug 2022 16:17:49 +1200 Subject: [PATCH] Role reference updates --- app/controllers/api/account.php | 5 +- app/controllers/api/databases.php | 2 +- app/http.php | 3 +- app/realtime.php | 6 +- app/views/console/databases/collection.phtml | 4 +- app/views/console/databases/document.phtml | 4 +- app/views/console/functions/function.phtml | 2 +- app/views/console/settings/index.phtml | 2 +- app/views/console/storage/bucket.phtml | 14 +- docs/specs/authentication.drawio.svg | 4 +- src/Appwrite/Messaging/Adapter/Realtime.php | 6 +- .../Specification/Format/Swagger2.php | 2 +- .../Utopia/Response/Model/Execution.php | 2 +- src/Appwrite/Utopia/Response/Model/File.php | 2 +- src/Appwrite/Utopia/Response/Model/Func.php | 2 +- .../e2e/Services/Databases/DatabasesBase.php | 231 +++++++++++------- .../Databases/DatabasesConsoleClientTest.php | 8 +- .../Databases/DatabasesCustomClientTest.php | 11 +- .../Databases/DatabasesCustomServerTest.php | 80 +++--- .../DatabasesPermissionsGuestTest.php | 22 +- .../DatabasesPermissionsMemberTest.php | 64 +++-- .../DatabasesPermissionsTeamTest.php | 14 +- .../Realtime/RealtimeConsoleClientTest.php | 7 +- .../Realtime/RealtimeCustomClientTest.php | 60 +++-- tests/e2e/Services/Storage/StorageBase.php | 84 ++++--- .../Storage/StorageCustomClientTest.php | 51 ++-- .../Storage/StorageCustomServerTest.php | 10 +- tests/e2e/Services/Webhooks/WebhooksBase.php | 49 ++-- .../Webhooks/WebhooksCustomServerTest.php | 10 +- tests/extensions/TestHook.php | 4 +- tests/unit/Auth/AuthTest.php | 8 +- .../unit/Messaging/MessagingChannelsTest.php | 6 +- tests/unit/Messaging/MessagingGuestTest.php | 6 +- tests/unit/Messaging/MessagingTest.php | 20 +- 34 files changed, 484 insertions(+), 321 deletions(-) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index f8f782b6a..2f74113ab 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -897,7 +897,7 @@ App::post('/v1/account/sessions/phone') $user = Authorization::skip(fn () => $dbForProject->createDocument('users', new Document([ '$id' => $userId, '$permissions' => [ - 'read(any)', + 'read(any)', 'write(user:' . $userId . ')' ], 'email' => null, @@ -1174,8 +1174,7 @@ App::post('/v1/account/sessions/anonymous') Authorization::setRole('user:' . $user->getId()); - $session = $dbForProject->createDocument('sessions', $session - -->setAttribute('$permissions', [ + $session = $dbForProject->createDocument('sessions', $session-- > setAttribute('$permissions', [ 'read(user: ' . $user->getId() . ')', 'write(user:' . $user->getId() . ')' ])); diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index f395ce49d..84f70cd77 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -757,7 +757,7 @@ App::put('/v1/databases/:databaseId/collections/:collectionId') ->inject('audits') ->inject('usage') ->inject('events') - ->action(function (string $databaseId, string $collectionId, string $name, ?array $permissions, bool $documentSecurity, bool $enabled, Response $response, Database $dbForProject, EventAudit $audits, Stats $usage, Event $events) { + ->action(function (string $databaseId, string $collectionId, string $name, ?array $permissions, bool $documentSecurity, bool $enabled, Response $response, Database $dbForProject, EventAudit $audits, Stats $usage, Event $events) { $database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); diff --git a/app/http.php b/app/http.php index e7944e4f6..68bf3959d 100644 --- a/app/http.php +++ b/app/http.php @@ -163,7 +163,6 @@ $http->on('start', function (Server $http) use ($payloadSize, $register) { '$id' => 'default', '$collection' => 'buckets', 'name' => 'Default', - 'permission' => 'file', 'maximumFileSize' => (int) App::getEnv('_APP_STORAGE_LIMIT', 0), // 10MB 'allowedFileExtensions' => [], 'enabled' => true, @@ -254,7 +253,7 @@ $http->on('request', function (SwooleRequest $swooleRequest, SwooleResponse $swo try { Authorization::cleanRoles(); - Authorization::setRole('role:all'); + Authorization::setRole('any'); $app->run($request, $response); } catch (\Throwable $th) { diff --git a/app/realtime.php b/app/realtime.php index 36620f51b..920d96dc0 100644 --- a/app/realtime.php +++ b/app/realtime.php @@ -202,7 +202,7 @@ $server->onWorkerStart(function (int $workerId) use ($server, $register, $stats, /** * Sending current connections to project channels on the console project every 5 seconds. */ - if ($realtime->hasSubscriber('console', 'role:member', 'project')) { + if ($realtime->hasSubscriber('console', 'users', 'project')) { [$database, $returnDatabase] = getDatabase($register, '_console'); $payload = []; @@ -253,12 +253,12 @@ $server->onWorkerStart(function (int $workerId) use ($server, $register, $stats, /** * Sending test message for SDK E2E tests every 5 seconds. */ - if ($realtime->hasSubscriber('console', 'role:guest', 'tests')) { + if ($realtime->hasSubscriber('console', 'guests', 'tests')) { $payload = ['response' => 'WS:/v1/realtime:passed']; $event = [ 'project' => 'console', - 'roles' => ['role:guest'], + 'roles' => ['guests'], 'data' => [ 'events' => ['test.event'], 'channels' => ['tests'], diff --git a/app/views/console/databases/collection.phtml b/app/views/console/databases/collection.phtml index 2428e3066..a77979c58 100644 --- a/app/views/console/databases/collection.phtml +++ b/app/views/console/databases/collection.phtml @@ -553,11 +553,11 @@ $logs = $this->getParam('logs', null);
-
Add 'role:all' for wildcard access
+
Add 'any' for wildcard access
-
Add 'role:all' for wildcard access
+
Add 'any' for wildcard access
diff --git a/app/views/console/databases/document.phtml b/app/views/console/databases/document.phtml index 17dc35f22..e6f71a1e1 100644 --- a/app/views/console/databases/document.phtml +++ b/app/views/console/databases/document.phtml @@ -321,11 +321,11 @@ $logs = $this->getParam('logs', null); -
Add 'role:all' for wildcard access
+
Add 'any' for wildcard access
-
Add 'role:all' for wildcard access
+
Add 'any' for wildcard access
diff --git a/app/views/console/functions/function.phtml b/app/views/console/functions/function.phtml index 5d5cc20b9..ca32ad75a 100644 --- a/app/views/console/functions/function.phtml +++ b/app/views/console/functions/function.phtml @@ -537,7 +537,7 @@ sort($patterns); -
Add 'role:all' for wildcard access
+
Add 'any' for wildcard access
diff --git a/app/views/console/settings/index.phtml b/app/views/console/settings/index.phtml index aed016b17..9b355a7e6 100644 --- a/app/views/console/settings/index.phtml +++ b/app/views/console/settings/index.phtml @@ -57,7 +57,7 @@ $smtpEnabled = $this->getParam('smtpEnabled', false);
- +

diff --git a/app/views/console/storage/bucket.phtml b/app/views/console/storage/bucket.phtml index 81af5c81b..232e69c93 100644 --- a/app/views/console/storage/bucket.phtml +++ b/app/views/console/storage/bucket.phtml @@ -133,11 +133,11 @@ $fileLimitHuman = $this->getParam('fileLimitHuman', 0); -
Add 'role:all' for wildcard access
+
Add 'any' for wildcard access
-
Add 'role:all' for wildcard access
+
Add 'any' for wildcard access
getParam('fileLimitHuman', 0);
(Max file size allowed: )
- -
Add 'role:all' for wildcard access
+ +
Add 'any' for wildcard access
-
Add 'role:all' for wildcard access
+
Add 'any' for wildcard access