From 77a28a2de71a02e19c21ec6cdc8577a2fe585923 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Mon, 15 Aug 2022 23:24:31 +1200 Subject: [PATCH] Don't use ID helper with existing ID's --- app/controllers/api/account.php | 82 +++++++++---------- app/controllers/api/databases.php | 12 +-- app/controllers/api/functions.php | 12 +-- app/controllers/api/projects.php | 14 ++-- app/controllers/api/storage.php | 8 +- app/controllers/api/teams.php | 52 ++++++------ app/realtime.php | 2 +- app/workers/builds.php | 4 +- app/workers/functions.php | 10 ++- .../e2e/Services/Databases/DatabasesBase.php | 38 ++++----- .../Databases/DatabasesCustomClientTest.php | 6 +- .../Databases/DatabasesCustomServerTest.php | 12 +-- .../DatabasesPermissionsTeamTest.php | 16 ++-- tests/e2e/Services/Storage/StorageBase.php | 12 +-- tests/e2e/Services/Teams/TeamsBase.php | 4 +- tests/e2e/Services/Teams/TeamsBaseClient.php | 8 +- 16 files changed, 147 insertions(+), 145 deletions(-) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 65e2103aec..e5ab90df82 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -99,11 +99,11 @@ App::post('/v1/account') try { $userId = $userId == 'unique()' ? ID::unique() : $userId; $user = Authorization::skip(fn() => $dbForProject->createDocument('users', new Document([ - '$id' => ID::custom($userId), + '$id' => $userId, '$permissions' => [ Permission::read(Role::any()), - Permission::update(Role::user(ID::custom($userId))), - Permission::delete(Role::user(ID::custom($userId))), + Permission::update(Role::user($userId)), + Permission::delete(Role::user($userId)), ], 'email' => $email, 'emailVerification' => false, @@ -189,8 +189,8 @@ App::post('/v1/account/sessions/email') $session = new Document(array_merge( [ '$id' => ID::unique(), - 'userId' => ID::custom($profile->getId()), - 'userInternalId' => ID::custom($profile->getInternalId()), + 'userId' => $profile->getId(), + 'userInternalId' => $profile->getInternalId(), 'provider' => Auth::SESSION_PROVIDER_EMAIL, 'providerUid' => $email, 'secret' => Auth::hash($secret), // One way hash encryption to protect DB leak @@ -207,9 +207,9 @@ App::post('/v1/account/sessions/email') Authorization::setRole('user:' . $profile->getId()); $session = $dbForProject->createDocument('sessions', $session->setAttribute('$permissions', [ - Permission::read(Role::user(ID::custom($profile->getId()))), - Permission::update(Role::user(ID::custom($profile->getId()))), - Permission::delete(Role::user(ID::custom($profile->getId()))), + Permission::read(Role::user($profile->getId())), + Permission::update(Role::user($profile->getId())), + Permission::delete(Role::user($profile->getId())), ])); $dbForProject->deleteCachedDocument('users', $profile->getId()); @@ -526,8 +526,8 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect') $session = new Document(array_merge([ '$id' => ID::unique(), - 'userId' => ID::custom($user->getId()), - 'userInternalId' => ID::custom($user->getInternalId()), + 'userId' => $user->getId(), + 'userInternalId' => $user->getInternalId(), 'provider' => $provider, 'providerUid' => $oauth2ID, 'providerAccessToken' => $accessToken, @@ -558,9 +558,9 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect') $dbForProject->updateDocument('users', $user->getId(), $user); $session = $dbForProject->createDocument('sessions', $session->setAttribute('$permissions', [ - Permission::read(Role::user(ID::custom($user->getId()))), - Permission::update(Role::user(ID::custom($user->getId()))), - Permission::delete(Role::user(ID::custom($user->getId()))), + Permission::read(Role::user($user->getId())), + Permission::update(Role::user($user->getId())), + Permission::delete(Role::user($user->getId())), ])); $dbForProject->deleteCachedDocument('users', $user->getId()); @@ -662,8 +662,8 @@ App::post('/v1/account/sessions/magic-url') '$id' => $userId, '$permissions' => [ Permission::read(Role::any()), - Permission::update(Role::user(ID::custom($userId))), - Permission::delete(Role::user(ID::custom($userId))), + Permission::update(Role::user($userId)), + Permission::delete(Role::user($userId)), ], 'email' => $email, 'emailVerification' => false, @@ -698,9 +698,9 @@ App::post('/v1/account/sessions/magic-url') $token = $dbForProject->createDocument('tokens', $token ->setAttribute('$permissions', [ - Permission::read(Role::user(ID::custom($user->getId()))), - Permission::update(Role::user(ID::custom($user->getId()))), - Permission::delete(Role::user(ID::custom($user->getId()))), + Permission::read(Role::user($user->getId())), + Permission::update(Role::user($user->getId())), + Permission::delete(Role::user($user->getId())), ])); $dbForProject->deleteCachedDocument('users', $user->getId()); @@ -807,9 +807,9 @@ App::put('/v1/account/sessions/magic-url') $session = $dbForProject->createDocument('sessions', $session ->setAttribute('$permissions', [ - Permission::read(Role::user(ID::custom($user->getId()))), - Permission::update(Role::user(ID::custom($user->getId()))), - Permission::delete(Role::user(ID::custom($user->getId()))), + Permission::read(Role::user($user->getId())), + Permission::update(Role::user($user->getId())), + Permission::delete(Role::user($user->getId())), ])); $dbForProject->deleteCachedDocument('users', $user->getId()); @@ -912,8 +912,8 @@ App::post('/v1/account/sessions/phone') '$id' => $userId, '$permissions' => [ Permission::read(Role::any()), - Permission::update(Role::user(ID::custom($userId))), - Permission::delete(Role::user(ID::custom($userId))), + Permission::update(Role::user($userId)), + Permission::delete(Role::user($userId)), ], 'email' => null, 'phone' => $number, @@ -950,9 +950,9 @@ App::post('/v1/account/sessions/phone') $token = $dbForProject->createDocument('tokens', $token ->setAttribute('$permissions', [ - Permission::read(Role::user(ID::custom($user->getId()))), - Permission::update(Role::user(ID::custom($user->getId()))), - Permission::delete(Role::user(ID::custom($user->getId()))), + Permission::read(Role::user($user->getId())), + Permission::update(Role::user($user->getId())), + Permission::delete(Role::user($user->getId())), ])); $dbForProject->deleteCachedDocument('users', $user->getId()); @@ -1046,9 +1046,9 @@ App::put('/v1/account/sessions/phone') $session = $dbForProject->createDocument('sessions', $session ->setAttribute('$permissions', [ - Permission::read(Role::user(ID::custom($user->getId()))), - Permission::update(Role::user(ID::custom($user->getId()))), - Permission::delete(Role::user(ID::custom($user->getId()))), + Permission::read(Role::user($user->getId())), + Permission::update(Role::user($user->getId())), + Permission::delete(Role::user($user->getId())), ])); $dbForProject->deleteCachedDocument('users', $user->getId()); @@ -1194,9 +1194,9 @@ App::post('/v1/account/sessions/anonymous') Authorization::setRole('user:' . $user->getId()); $session = $dbForProject->createDocument('sessions', $session-> setAttribute('$permissions', [ - Permission::read(Role::user(ID::custom($user->getId()))), - Permission::update(Role::user(ID::custom($user->getId()))), - Permission::delete(Role::user(ID::custom($user->getId()))), + Permission::read(Role::user($user->getId())), + Permission::update(Role::user($user->getId())), + Permission::delete(Role::user($user->getId())), ])); $dbForProject->deleteCachedDocument('users', $user->getId()); @@ -2021,9 +2021,9 @@ App::post('/v1/account/recovery') $recovery = $dbForProject->createDocument('tokens', $recovery ->setAttribute('$permissions', [ - Permission::read(Role::user(ID::custom($profile->getId()))), - Permission::update(Role::user(ID::custom($profile->getId()))), - Permission::delete(Role::user(ID::custom($profile->getId()))), + Permission::read(Role::user($profile->getId())), + Permission::update(Role::user($profile->getId())), + Permission::delete(Role::user($profile->getId())), ])); $dbForProject->deleteCachedDocument('users', $profile->getId()); @@ -2183,9 +2183,9 @@ App::post('/v1/account/verification') $verification = $dbForProject->createDocument('tokens', $verification ->setAttribute('$permissions', [ - Permission::read(Role::user(ID::custom($user->getId()))), - Permission::update(Role::user(ID::custom($user->getId()))), - Permission::delete(Role::user(ID::custom($user->getId()))), + Permission::read(Role::user($user->getId())), + Permission::update(Role::user($user->getId())), + Permission::delete(Role::user($user->getId())), ])); $dbForProject->deleteCachedDocument('users', $user->getId()); @@ -2339,9 +2339,9 @@ App::post('/v1/account/verification/phone') $verification = $dbForProject->createDocument('tokens', $verification ->setAttribute('$permissions', [ - Permission::read(Role::user(ID::custom($user->getId()))), - Permission::update(Role::user(ID::custom($user->getId()))), - Permission::delete(Role::user(ID::custom($user->getId()))), + Permission::read(Role::user($user->getId())), + Permission::update(Role::user($user->getId())), + Permission::delete(Role::user($user->getId())), ])); $dbForProject->deleteCachedDocument('users', $user->getId()); diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index 6d277cfdc7..ea1634fc0e 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -99,10 +99,10 @@ function createAttribute(string $databaseId, string $collectionId, Document $att $attribute = new Document([ '$id' => ID::custom($db->getInternalId() . '_' . $collection->getInternalId() . '_' . $key), 'key' => $key, - 'databaseInternalId' => ID::custom($db->getInternalId()), - 'databaseId' => ID::custom($db->getId()), - 'collectionInternalId' => ID::custom($collection->getInternalId()), - 'collectionId' => ID::custom($collectionId), + 'databaseInternalId' => $db->getInternalId(), + 'databaseId' => $db->getId(), + 'collectionInternalId' => $collection->getInternalId(), + 'collectionId' => $collectionId, 'type' => $type, 'status' => 'processing', // processing, available, failed, deleting, stuck 'size' => $size, @@ -196,7 +196,7 @@ App::post('/v1/databases') foreach ($collections['attributes'] as $attribute) { $attributes[] = new Document([ - '$id' => ID::custom($attribute['$id']), + '$id' => $attribute['$id'], 'type' => $attribute['type'], 'size' => $attribute['size'], 'required' => $attribute['required'], @@ -210,7 +210,7 @@ App::post('/v1/databases') foreach ($collections['indexes'] as $index) { $indexes[] = new Document([ - '$id' => ID::custom($index['$id']), + '$id' => $index['$id'], 'type' => $index['type'], 'attributes' => $index['attributes'], 'lengths' => $index['lengths'], diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index e778c6bd05..08d2e8283c 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -585,7 +585,7 @@ App::post('/v1/functions/:functionId/deployments') Permission::update(Role::any()), Permission::delete(Role::any()), ], - 'resourceId' => ID::custom($function->getId()), + 'resourceId' => $function->getId(), 'resourceType' => 'functions', 'entrypoint' => $entrypoint, 'path' => $path, @@ -877,9 +877,9 @@ App::post('/v1/functions/:functionId/executions') /** @var Document $execution */ $execution = Authorization::skip(fn () => $dbForProject->createDocument('executions', new Document([ '$id' => $executionId, - '$permissions' => !$user->isEmpty() ? [Permission::read(Role::user(ID::custom($user->getId())))] : [], - 'functionId' => ID::custom($function->getId()), - 'deploymentId' => ID::custom($deployment->getId()), + '$permissions' => !$user->isEmpty() ? [Permission::read(Role::user($user->getId()))] : [], + 'functionId' => $function->getId(), + 'deploymentId' => $deployment->getId(), 'trigger' => 'http', // http / schedule / event 'status' => 'waiting', // waiting / processing / completed / failed 'statusCode' => 0, @@ -904,8 +904,8 @@ App::post('/v1/functions/:functionId/executions') if (!$current->isEmpty()) { $jwtObj = new JWT(App::getEnv('_APP_OPENSSL_KEY_V1'), 'HS256', 900, 10); // Instantiate with key, algo, maxAge and leeway. $jwt = $jwtObj->encode([ - 'userId' => ID::custom($user->getId()), - 'sessionId' => ID::custom($current->getId()), + 'userId' => $user->getId(), + 'sessionId' => $current->getId(), ]); } } diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index a7ec2b1a84..976d5e84b3 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -99,8 +99,8 @@ App::post('/v1/projects') Permission::delete(Role::team(ID::custom($teamId), 'developer')), ], 'name' => $name, - 'teamInternalId' => ID::custom($team->getInternalId()), - 'teamId' => ID::custom($team->getId()), + 'teamInternalId' => $team->getInternalId(), + 'teamId' => $team->getId(), 'description' => $description, 'logo' => $logo, 'url' => $url, @@ -141,7 +141,7 @@ App::post('/v1/projects') foreach ($collection['attributes'] as $attribute) { $attributes[] = new Document([ - '$id' => ID::custom($attribute['$id']), + '$id' => $attribute['$id'], 'type' => $attribute['type'], 'size' => $attribute['size'], 'required' => $attribute['required'], @@ -155,7 +155,7 @@ App::post('/v1/projects') foreach ($collection['indexes'] as $index) { $indexes[] = new Document([ - '$id' => ID::custom($index['$id']), + '$id' => $index['$id'], 'type' => $index['type'], 'attributes' => $index['attributes'], 'lengths' => $index['lengths'], @@ -612,8 +612,8 @@ App::post('/v1/projects/:projectId/webhooks') Permission::update(Role::any()), Permission::delete(Role::any()), ], - 'projectInternalId' => ID::custom($project->getInternalId()), - 'projectId' => ID::custom($project->getId()), + 'projectInternalId' => $project->getInternalId(), + 'projectId' => $project->getId(), 'name' => $name, 'events' => $events, 'url' => $url, @@ -861,7 +861,7 @@ App::post('/v1/projects/:projectId/keys') Permission::delete(Role::any()), ], 'projectInternalId' => $project->getInternalId(), - 'projectId' => ID::custom($project->getId()), + 'projectId' => $project->getId(), 'name' => $name, 'scopes' => $scopes, 'expire' => $expire, diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index 3698b479cb..36c4ad1f71 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -84,7 +84,7 @@ App::post('/v1/storage/buckets') foreach ($files['attributes'] as $attribute) { $attributes[] = new Document([ - '$id' => ID::custom($attribute['$id']), + '$id' => $attribute['$id'], 'type' => $attribute['type'], 'size' => $attribute['size'], 'required' => $attribute['required'], @@ -98,7 +98,7 @@ App::post('/v1/storage/buckets') foreach ($files['indexes'] as $index) { $indexes[] = new Document([ - '$id' => ID::custom($index['$id']), + '$id' => $index['$id'], 'type' => $index['type'], 'attributes' => $index['attributes'], 'lengths' => $index['lengths'], @@ -108,7 +108,7 @@ App::post('/v1/storage/buckets') $dbForProject->createDocument('buckets', new Document([ '$id' => $bucketId, - '$collection' => ID::custom('buckets'), + '$collection' => 'buckets', '$permissions' => $permissions, 'name' => $name, 'maximumFileSize' => $maximumFileSize, @@ -539,7 +539,7 @@ App::post('/v1/storage/buckets/:bucketId/files') $doc = new Document([ '$id' => $fileId, '$permissions' => $permissions, - 'bucketId' => ID::custom($bucket->getId()), + 'bucketId' => $bucket->getId(), 'name' => $fileName, 'path' => $path, 'signature' => $fileHash, diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index 65023e42f8..12c642105c 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -65,9 +65,9 @@ App::post('/v1/teams') $team = Authorization::skip(fn() => $dbForProject->createDocument('teams', new Document([ '$id' => $teamId, '$permissions' => [ - Permission::read(Role::team(ID::custom($teamId))), - Permission::update(Role::team(ID::custom($teamId), 'owner')), - Permission::delete(Role::team(ID::custom($teamId), 'owner')), + Permission::read(Role::team($teamId)), + Permission::update(Role::team($teamId), 'owner'), + Permission::delete(Role::team($teamId), 'owner'), ], 'name' => $name, 'total' => ($isPrivilegedUser || $isAppUser) ? 0 : 1, @@ -79,17 +79,17 @@ App::post('/v1/teams') $membership = new Document([ '$id' => $membershipId, '$permissions' => [ - Permission::read(Role::user(ID::custom($user->getId()))), - Permission::read(Role::team(ID::custom($team->getId()))), - Permission::update(Role::user(ID::custom($user->getId()))), - Permission::update(Role::team(ID::custom($team->getId()), 'owner')), - Permission::delete(Role::user(ID::custom($user->getId()))), - Permission::delete(Role::team(ID::custom($team->getId()), 'owner')), + Permission::read(Role::user($user->getId())), + Permission::read(Role::team($team->getId())), + Permission::update(Role::user($user->getId())), + Permission::update(Role::team($team->getId(), 'owner')), + Permission::delete(Role::user($user->getId())), + Permission::delete(Role::team($team->getId(), 'owner')), ], - 'userId' => ID::custom($user->getId()), + 'userId' => $user->getId(), 'userInternalId' => $user->getInternalId(), - 'teamId' => ID::custom($team->getId()), - 'teamInternalId' => ID::custom($team->getInternalId()), + 'teamId' => $team->getId(), + 'teamInternalId' => $team->getInternalId(), 'roles' => $roles, 'invited' => DateTime::now(), 'joined' => DateTime::now(), @@ -392,15 +392,15 @@ App::post('/v1/teams/:teamId/memberships') '$id' => $membershipId, '$permissions' => [ Permission::read(Role::any()), - Permission::update(Role::user(ID::custom($invitee->getId()))), - Permission::update(Role::team(ID::custom($team->getId()), 'owner')), - Permission::delete(Role::user(ID::custom($invitee->getId()))), - Permission::delete(Role::team(ID::custom($team->getId()), 'owner')), + Permission::update(Role::user($invitee->getId())), + Permission::update(Role::team($team->getId(), 'owner')), + Permission::delete(Role::user($invitee->getId())), + Permission::delete(Role::team($team->getId(), 'owner')), ], - 'userId' => ID::custom($invitee->getId()), - 'userInternalId' => ID::custom($invitee->getInternalId()), - 'teamId' => ID::custom($team->getId()), - 'teamInternalId' => ID::custom($team->getInternalId()), + 'userId' => $invitee->getId(), + 'userInternalId' => $invitee->getInternalId(), + 'teamId' => $team->getId(), + 'teamInternalId' => $team->getInternalId(), 'roles' => $roles, 'invited' => DateTime::now(), 'joined' => ($isPrivilegedUser || $isAppUser) ? DateTime::now() : null, @@ -735,8 +735,8 @@ App::patch('/v1/teams/:teamId/memberships/:membershipId/status') $secret = Auth::tokenGenerator(); $session = new Document(array_merge([ '$id' => ID::unique(), - 'userId' => ID::custom($user->getId()), - 'userInternalId' => ID::custom($user->getInternalId()), + 'userId' => $user->getId(), + 'userInternalId' => $user->getInternalId(), 'provider' => Auth::SESSION_PROVIDER_EMAIL, 'providerUid' => $user->getAttribute('email'), 'secret' => Auth::hash($secret), // One way hash encryption to protect DB leak @@ -748,9 +748,9 @@ App::patch('/v1/teams/:teamId/memberships/:membershipId/status') $session = $dbForProject->createDocument('sessions', $session ->setAttribute('$permissions', [ - Permission::read(Role::user(ID::custom($user->getId()))), - Permission::update(Role::user(ID::custom($user->getId()))), - Permission::delete(Role::user(ID::custom($user->getId()))), + Permission::read(Role::user($user->getId())), + Permission::update(Role::user($user->getId())), + Permission::delete(Role::user($user->getId())), ])); $dbForProject->deleteCachedDocument('users', $user->getId()); @@ -914,7 +914,7 @@ App::get('/v1/teams/:teamId/logs') $output[$i] = new Document([ 'event' => $log['event'], - 'userId' => ID::custom($log['userId']), + 'userId' => $log['userId'], 'userEmail' => $log['data']['userEmail'] ?? null, 'userName' => $log['data']['userName'] ?? null, 'mode' => $log['data']['mode'] ?? null, diff --git a/app/realtime.php b/app/realtime.php index df737a85bb..9488885026 100644 --- a/app/realtime.php +++ b/app/realtime.php @@ -444,7 +444,7 @@ $server->onOpen(function (int $connection, SwooleRequest $request) use ($server, ])); $stats->set($project->getId(), [ - 'projectId' => ID::custom($project->getId()), + 'projectId' => $project->getId(), 'teamId' => $project->getAttribute('teamId') ]); $stats->incr($project->getId(), 'connections'); diff --git a/app/workers/builds.php b/app/workers/builds.php index 87eccb0d72..aa6070af42 100644 --- a/app/workers/builds.php +++ b/app/workers/builds.php @@ -84,7 +84,7 @@ class BuildsV1 extends Worker '$id' => $buildId, '$permissions' => [], 'startTime' => $startTime, - 'deploymentId' => ID::custom($deployment->getId()), + 'deploymentId' => $deployment->getId(), 'status' => 'processing', 'outputPath' => '', 'runtime' => $function->getAttribute('runtime'), @@ -124,7 +124,7 @@ class BuildsV1 extends Worker /** Trigger Realtime */ $allEvents = Event::generateEvents('functions.[functionId].deployments.[deploymentId].update', [ - 'functionId' => ID::custom($function->getId()), + 'functionId' => $function->getId(), 'deploymentId' => $deployment->getId() ]); $target = Realtime::fromPayload( diff --git a/app/workers/functions.php b/app/workers/functions.php index 182c1791b5..ea7ba4c4c2 100644 --- a/app/workers/functions.php +++ b/app/workers/functions.php @@ -15,7 +15,9 @@ use Utopia\Database\Database; use Utopia\Database\DateTime; use Utopia\Database\Document; use Utopia\Database\ID; +use Utopia\Database\Permission; use Utopia\Database\Query; +use Utopia\Database\Role; require_once __DIR__ . '/../init.php'; @@ -238,9 +240,9 @@ class FunctionsV1 extends Worker $executionId = ID::unique(); $execution = $dbForProject->createDocument('executions', new Document([ '$id' => $executionId, - '$permissions' => $user->isEmpty() ? [] : [Permission::read(Role::user(ID::custom($user->getId())))], - 'functionId' => ID::custom($functionId), - 'deploymentId' => ID::custom($deploymentId), + '$permissions' => $user->isEmpty() ? [] : [Permission::read(Role::user($user->getId()))], + 'functionId' => $functionId, + 'deploymentId' => $deploymentId, 'trigger' => $trigger, 'status' => 'waiting', 'statusCode' => 0, @@ -327,7 +329,7 @@ class FunctionsV1 extends Worker /** Trigger realtime event */ $allEvents = Event::generateEvents('functions.[functionId].executions.[executionId].update', [ - 'functionId' => ID::custom($function->getId()), + 'functionId' => $function->getId(), 'executionId' => $execution->getId() ]); $target = Realtime::fromPayload( diff --git a/tests/e2e/Services/Databases/DatabasesBase.php b/tests/e2e/Services/Databases/DatabasesBase.php index 868c5114e3..9bbd589ea8 100644 --- a/tests/e2e/Services/Databases/DatabasesBase.php +++ b/tests/e2e/Services/Databases/DatabasesBase.php @@ -95,9 +95,9 @@ trait DatabasesBase 'title' => 'Captain America', ], 'permissions' => [ - Permission::read(Role::user(ID::custom($this->getUser()['$id']))), - Permission::update(Role::user(ID::custom($this->getUser()['$id']))), - Permission::delete(Role::user(ID::custom($this->getUser()['$id']))), + Permission::read(Role::user($this->getUser()['$id'])), + Permission::update(Role::user($this->getUser()['$id'])), + Permission::delete(Role::user($this->getUser()['$id'])), ], ]); @@ -873,9 +873,9 @@ trait DatabasesBase ] ], 'permissions' => [ - Permission::read(Role::user(ID::custom($this->getUser()['$id']))), - Permission::update(Role::user(ID::custom($this->getUser()['$id']))), - Permission::delete(Role::user(ID::custom($this->getUser()['$id']))), + Permission::read(Role::user($this->getUser()['$id'])), + Permission::update(Role::user($this->getUser()['$id'])), + Permission::delete(Role::user($this->getUser()['$id'])), ] ]); @@ -895,9 +895,9 @@ trait DatabasesBase ] ], 'permissions' => [ - Permission::read(Role::user(ID::custom($this->getUser()['$id']))), - Permission::update(Role::user(ID::custom($this->getUser()['$id']))), - Permission::delete(Role::user(ID::custom($this->getUser()['$id']))), + Permission::read(Role::user($this->getUser()['$id'])), + Permission::update(Role::user($this->getUser()['$id'])), + Permission::delete(Role::user($this->getUser()['$id'])), ] ]); @@ -917,9 +917,9 @@ trait DatabasesBase ], ], 'permissions' => [ - Permission::read(Role::user(ID::custom($this->getUser()['$id']))), - Permission::update(Role::user(ID::custom($this->getUser()['$id']))), - Permission::delete(Role::user(ID::custom($this->getUser()['$id']))), + Permission::read(Role::user($this->getUser()['$id'])), + Permission::update(Role::user($this->getUser()['$id'])), + Permission::delete(Role::user($this->getUser()['$id'])), ] ]); @@ -932,9 +932,9 @@ trait DatabasesBase 'releaseYear' => 2020, // Missing title, expect an 400 error ], 'permissions' => [ - Permission::read(Role::user(ID::custom($this->getUser()['$id']))), - Permission::update(Role::user(ID::custom($this->getUser()['$id']))), - Permission::delete(Role::user(ID::custom($this->getUser()['$id']))), + Permission::read(Role::user($this->getUser()['$id'])), + Permission::update(Role::user($this->getUser()['$id'])), + Permission::delete(Role::user($this->getUser()['$id'])), ] ]); @@ -1529,9 +1529,9 @@ trait DatabasesBase '$createdAt' => 5 // Should be ignored ], 'permissions' => [ - Permission::read(Role::user(ID::custom($this->getUser()['$id']))), - Permission::update(Role::user(ID::custom($this->getUser()['$id']))), - Permission::delete(Role::user(ID::custom($this->getUser()['$id']))), + Permission::read(Role::user($this->getUser()['$id'])), + Permission::update(Role::user($this->getUser()['$id'])), + Permission::delete(Role::user($this->getUser()['$id'])), ], ]); @@ -1601,7 +1601,7 @@ trait DatabasesBase 'actors' => [], ], 'permissions' => [ - Permission::read(Role::user(ID::custom($this->getUser()['$id']))), + Permission::read(Role::user($this->getUser()['$id'])), Permission::update(Role::user(ID::custom($this->getUser()['$id']))), Permission::delete(Role::user(ID::custom($this->getUser()['$id']))), ] diff --git a/tests/e2e/Services/Databases/DatabasesCustomClientTest.php b/tests/e2e/Services/Databases/DatabasesCustomClientTest.php index 1d7ed8bf2b..3ed1879288 100644 --- a/tests/e2e/Services/Databases/DatabasesCustomClientTest.php +++ b/tests/e2e/Services/Databases/DatabasesCustomClientTest.php @@ -82,9 +82,9 @@ class DatabasesCustomClientTest extends Scope ], 'permissions' => [ Permission::read(Role::user(ID::custom('user2'))), - Permission::read(Role::user(ID::custom($userId))), - Permission::update(Role::user(ID::custom($userId))), - Permission::delete(Role::user(ID::custom($userId))), + Permission::read(Role::user($userId)), + Permission::update(Role::user($userId)), + Permission::delete(Role::user($userId)), ], ]); diff --git a/tests/e2e/Services/Databases/DatabasesCustomServerTest.php b/tests/e2e/Services/Databases/DatabasesCustomServerTest.php index 73d89cac7b..40238550f7 100644 --- a/tests/e2e/Services/Databases/DatabasesCustomServerTest.php +++ b/tests/e2e/Services/Databases/DatabasesCustomServerTest.php @@ -858,9 +858,9 @@ class DatabasesCustomServerTest extends Scope 'lastName' => 'Holland', ], 'permissions' => [ - Permission::read(Role::user(ID::custom($this->getUser()['$id']))), - Permission::update(Role::user(ID::custom($this->getUser()['$id']))), - Permission::delete(Role::user(ID::custom($this->getUser()['$id']))), + Permission::read(Role::user($this->getUser()['$id'])), + Permission::update(Role::user($this->getUser()['$id'])), + Permission::delete(Role::user($this->getUser()['$id'])), ], ]); @@ -874,9 +874,9 @@ class DatabasesCustomServerTest extends Scope 'lastName' => 'Jackson', ], 'permissions' => [ - Permission::read(Role::user(ID::custom($this->getUser()['$id']))), - Permission::update(Role::user(ID::custom($this->getUser()['$id']))), - Permission::delete(Role::user(ID::custom($this->getUser()['$id']))), + Permission::read(Role::user($this->getUser()['$id'])), + Permission::update(Role::user($this->getUser()['$id'])), + Permission::delete(Role::user($this->getUser()['$id'])), ], ]); diff --git a/tests/e2e/Services/Databases/DatabasesPermissionsTeamTest.php b/tests/e2e/Services/Databases/DatabasesPermissionsTeamTest.php index 8c3a2b1422..07275c7524 100644 --- a/tests/e2e/Services/Databases/DatabasesPermissionsTeamTest.php +++ b/tests/e2e/Services/Databases/DatabasesPermissionsTeamTest.php @@ -48,10 +48,10 @@ class DatabasesPermissionsTeamTest extends Scope 'collectionId' => ID::custom('collection1'), 'name' => 'Collection 1', 'permissions' => [ - Permission::read(Role::team(ID::custom($teams['team1']['$id']))), - Permission::create(Role::team(ID::custom($teams['team1']['$id']), 'admin')), - Permission::update(Role::team(ID::custom($teams['team1']['$id']), 'admin')), - Permission::delete(Role::team(ID::custom($teams['team1']['$id']), 'admin')), + Permission::read(Role::team($teams['team1']['$id'])), + Permission::create(Role::team($teams['team1']['$id'], 'admin')), + Permission::update(Role::team($teams['team1']['$id'], 'admin')), + Permission::delete(Role::team($teams['team1']['$id'], 'admin')), ], ]); @@ -67,10 +67,10 @@ class DatabasesPermissionsTeamTest extends Scope 'collectionId' => ID::custom('collection2'), 'name' => 'Collection 2', 'permissions' => [ - Permission::read(Role::team(ID::custom($teams['team2']['$id']))), - Permission::create(Role::team(ID::custom($teams['team2']['$id']), 'owner')), - Permission::update(Role::team(ID::custom($teams['team2']['$id']), 'owner')), - Permission::delete(Role::team(ID::custom($teams['team2']['$id']), 'owner')), + Permission::read(Role::team($teams['team2']['$id'])), + Permission::create(Role::team($teams['team2']['$id'], 'owner')), + Permission::update(Role::team($teams['team2']['$id'], 'owner')), + Permission::delete(Role::team($teams['team2']['$id'], 'owner')), ] ]); diff --git a/tests/e2e/Services/Storage/StorageBase.php b/tests/e2e/Services/Storage/StorageBase.php index dd5f33295c..1159db66cf 100644 --- a/tests/e2e/Services/Storage/StorageBase.php +++ b/tests/e2e/Services/Storage/StorageBase.php @@ -575,9 +575,9 @@ trait StorageBase 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'permissions' => [ - Permission::read(Role::user(ID::custom($this->getUser()['$id']))), - Permission::update(Role::user(ID::custom($this->getUser()['$id']))), - Permission::delete(Role::user(ID::custom($this->getUser()['$id']))), + Permission::read(Role::user($this->getUser()['$id'])), + Permission::update(Role::user($this->getUser()['$id'])), + Permission::delete(Role::user($this->getUser()['$id'])), ] ]); @@ -605,9 +605,9 @@ trait StorageBase 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ 'permissions' => [ - Permission::read(Role::user(ID::custom($this->getUser()['$id']))), - Permission::update(Role::user(ID::custom($this->getUser()['$id']))), - Permission::delete(Role::user(ID::custom($this->getUser()['$id']))), + Permission::read(Role::user($this->getUser()['$id'])), + Permission::update(Role::user($this->getUser()['$id'])), + Permission::delete(Role::user($this->getUser()['$id'])), ] ]); diff --git a/tests/e2e/Services/Teams/TeamsBase.php b/tests/e2e/Services/Teams/TeamsBase.php index fd2affcd6b..3299c98fa3 100644 --- a/tests/e2e/Services/Teams/TeamsBase.php +++ b/tests/e2e/Services/Teams/TeamsBase.php @@ -32,12 +32,12 @@ trait TeamsBase $teamUid = $response1['body']['$id']; $teamName = $response1['body']['name']; - $teamId = \uniqid(); + $teamId = ID::unique() $response2 = $this->client->call(Client::METHOD_POST, '/teams', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'teamId' => ID::custom($teamId), + 'teamId' => $teamId, 'name' => 'Manchester United' ]); diff --git a/tests/e2e/Services/Teams/TeamsBaseClient.php b/tests/e2e/Services/Teams/TeamsBaseClient.php index e01501a8cb..e07e9fbb18 100644 --- a/tests/e2e/Services/Teams/TeamsBaseClient.php +++ b/tests/e2e/Services/Teams/TeamsBaseClient.php @@ -240,7 +240,7 @@ trait TeamsBaseClient 'x-appwrite-project' => $this->getProject()['$id'], ]), [ 'secret' => $secret, - 'userId' => ID::custom($userUid), + 'userId' => $userUid, ]); $this->assertEquals(200, $response['headers']['status-code']); @@ -320,7 +320,7 @@ trait TeamsBaseClient 'x-appwrite-project' => $this->getProject()['$id'], ]), [ 'secret' => 'sdasdasd', - 'userId' => ID::custom($userUid), + 'userId' => $userUid, ]); $this->assertEquals(401, $response['headers']['status-code']); @@ -331,7 +331,7 @@ trait TeamsBaseClient 'x-appwrite-project' => $this->getProject()['$id'], ]), [ 'secret' => '', - 'userId' => ID::custom($userUid), + 'userId' => $userUid, ]); $this->assertEquals(400, $response['headers']['status-code']); @@ -364,7 +364,7 @@ trait TeamsBaseClient 'x-appwrite-project' => $this->getProject()['$id'], ]), [ 'secret' => $secret, - 'userId' => ID::custom($userUid), + 'userId' => $userUid, ]); $this->assertEquals(409, $response['headers']['status-code']);