From 0d1b1ddef67cb8a49c4741ed6dc96d5086a14f2f Mon Sep 17 00:00:00 2001 From: fogelito Date: Tue, 14 Jun 2022 20:15:22 +0300 Subject: [PATCH] Adding Account + teams + users Internal Ids to colleactions --- app/config/collections.php | 19 +++++++++++++++---- app/controllers/api/teams.php | 5 +++++ composer.json | 2 +- .../Database/DatabaseCustomServerTest.php | 4 ++-- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/app/config/collections.php b/app/config/collections.php index a4d9aee8a6..e87e2a4b9a 100644 --- a/app/config/collections.php +++ b/app/config/collections.php @@ -1570,7 +1570,7 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'teamId', + '$id' => 'userId', 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, @@ -1581,7 +1581,18 @@ $collections = [ 'filters' => [], ], [ - '$id' => 'userId', + '$id' => 'teamInternalId', + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => Database::LENGTH_KEY, + 'signed' => true, + 'required' => false, + 'default' => null, + 'array' => false, + 'filters' => [], + ], + [ + '$id' => 'teamId', 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, @@ -1662,7 +1673,7 @@ $collections = [ [ '$id' => '_key_unique', 'type' => Database::INDEX_UNIQUE, - 'attributes' => ['teamId', 'userId'], + 'attributes' => ['teamInternalId', 'userInternalId'], 'lengths' => [Database::LENGTH_KEY, Database::LENGTH_KEY], 'orders' => [Database::ORDER_ASC, Database::ORDER_ASC], ], @@ -1676,7 +1687,7 @@ $collections = [ [ '$id' => '_key_team', 'type' => Database::INDEX_KEY, - 'attributes' => ['teamId'], + 'attributes' => ['teamInternalId'], 'lengths' => [Database::LENGTH_KEY], 'orders' => [Database::ORDER_ASC], ], diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index a983745a95..58a48844d0 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -74,7 +74,9 @@ App::post('/v1/teams') '$read' => ['user:' . $user->getId(), 'team:' . $team->getId()], '$write' => ['user:' . $user->getId(), 'team:' . $team->getId() . '/owner'], 'userId' => $user->getId(), + 'userInternalId' => $user->getInternalId(), 'teamId' => $team->getId(), + 'teamInternalId' => $team->getInternalId(), 'roles' => $roles, 'invited' => \time(), 'joined' => \time(), @@ -367,7 +369,9 @@ App::post('/v1/teams/:teamId/memberships') '$read' => ['role:all'], '$write' => ['user:' . $invitee->getId(), 'team:' . $team->getId() . '/owner'], 'userId' => $invitee->getId(), + 'userInternalId' => $invitee->getInternalId(), 'teamId' => $team->getId(), + 'teamInternalId' => $team->getInternalId(), 'roles' => $roles, 'invited' => \time(), 'joined' => ($isPrivilegedUser || $isAppUser) ? \time() : 0, @@ -702,6 +706,7 @@ App::patch('/v1/teams/:teamId/memberships/:membershipId/status') $session = new Document(array_merge([ '$id' => $dbForProject->getId(), '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 diff --git a/composer.json b/composer.json index 0bb4e1b858..1413568c9c 100644 --- a/composer.json +++ b/composer.json @@ -45,7 +45,7 @@ "utopia-php/cache": "0.6.*", "utopia-php/cli": "0.12.*", "utopia-php/config": "0.2.*", - "utopia-php/database": "0.18.*", + "utopia-php/database": "dev-bug-last-internal-id as 0.18.1", "utopia-php/locale": "0.4.*", "utopia-php/registry": "0.5.*", "utopia-php/preloader": "0.2.*", diff --git a/tests/e2e/Services/Database/DatabaseCustomServerTest.php b/tests/e2e/Services/Database/DatabaseCustomServerTest.php index 96fd657545..a6febe5060 100644 --- a/tests/e2e/Services/Database/DatabaseCustomServerTest.php +++ b/tests/e2e/Services/Database/DatabaseCustomServerTest.php @@ -792,7 +792,7 @@ class DatabaseCustomServerTest extends Scope // testing for indexLimit = 64 // MariaDB, MySQL, and MongoDB create 3 indexes per new collection // Add up to the limit, then check if the next index throws IndexLimitException - for ($i = 0; $i < 61; $i++) { + for ($i = 0; $i < 59; $i++) { // $this->assertEquals(true, static::getDatabase()->createIndex('indexLimit', "index{$i}", Database::INDEX_KEY, ["test{$i}"], [16])); $index = $this->client->call(Client::METHOD_POST, '/database/collections/' . $collectionId . '/indexes', array_merge([ 'content-type' => 'application/json', @@ -821,7 +821,7 @@ class DatabaseCustomServerTest extends Scope $this->assertIsArray($collection['body']['attributes']); $this->assertIsArray($collection['body']['indexes']); $this->assertCount(64, $collection['body']['attributes']); - $this->assertCount(61, $collection['body']['indexes']); + $this->assertCount(59, $collection['body']['indexes']); $tooMany = $this->client->call(Client::METHOD_POST, '/database/collections/' . $collectionId . '/indexes', array_merge([ 'content-type' => 'application/json',