From c9e6bfbdb38d17f0895158fbc9b507914980a89e Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Mon, 9 Dec 2024 16:48:41 +1300 Subject: [PATCH 1/6] Update database --- composer.json | 2 +- composer.lock | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/composer.json b/composer.json index 512e203a5e..afd870b3d6 100644 --- a/composer.json +++ b/composer.json @@ -51,7 +51,7 @@ "utopia-php/cache": "0.11.*", "utopia-php/cli": "0.15.*", "utopia-php/config": "0.2.*", - "utopia-php/database": "0.53.200", + "utopia-php/database": "0.53.27", "utopia-php/domains": "0.5.*", "utopia-php/dsn": "0.2.1", "utopia-php/framework": "0.33.*", diff --git a/composer.lock b/composer.lock index db5dac1b33..4c761dfd91 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "fae350df93342992edd8f639948e1570", + "content-hash": "cfa976b029b0e8f53ef617056d04face", "packages": [ { "name": "adhocore/jwt", @@ -3476,16 +3476,16 @@ }, { "name": "utopia-php/database", - "version": "0.53.200", + "version": "0.53.27", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "570c63a3760d0e1404679ddfacd9484af40bd9fc" + "reference": "d3a8cae6e743a6a1a5719b860762a03aabce678a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/570c63a3760d0e1404679ddfacd9484af40bd9fc", - "reference": "570c63a3760d0e1404679ddfacd9484af40bd9fc", + "url": "https://api.github.com/repos/utopia-php/database/zipball/d3a8cae6e743a6a1a5719b860762a03aabce678a", + "reference": "d3a8cae6e743a6a1a5719b860762a03aabce678a", "shasum": "" }, "require": { @@ -3526,9 +3526,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/0.53.200" + "source": "https://github.com/utopia-php/database/tree/0.53.27" }, - "time": "2024-12-01T07:59:15+00:00" + "time": "2024-12-02T08:53:55+00:00" }, { "name": "utopia-php/domains", @@ -8556,7 +8556,7 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": {}, "prefer-stable": false, "prefer-lowest": false, "platform": { @@ -8580,5 +8580,5 @@ "platform-overrides": { "php": "8.3" }, - "plugin-api-version": "2.2.0" + "plugin-api-version": "2.6.0" } From 8f390a70c73853d7ad583211dbed29f574506d49 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 12 Dec 2024 18:54:58 +1300 Subject: [PATCH 2/6] Fix self-hosted region check default --- app/init.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/init.php b/app/init.php index 058cf82833..47186bfc86 100644 --- a/app/init.php +++ b/app/init.php @@ -1334,7 +1334,7 @@ App::setResource('project', function ($dbForConsole, $request, $console) { $project = Authorization::skip(fn () => $dbForConsole->getDocument('projects', $projectId)); - if ($project->getAttribute('region') !== System::getEnv('_APP_REGION')) { + if ($project->getAttribute('region') !== System::getEnv('_APP_REGION', 'default')) { var_dump(System::getEnv('_APP_REGION')); var_dump($project->getAttribute('region')); throw new Exception(Exception::GENERAL_ACCESS_FORBIDDEN, 'Project is not accessible in this region. Please make sure you are using the correct endpoint'); From f4637e1b7dc12a80cdf5599e21ea9108c6d5b78c Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 12 Dec 2024 18:55:25 +1300 Subject: [PATCH 3/6] Create audit/abuse for V2 --- app/controllers/api/projects.php | 3 --- app/http.php | 10 ++++++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 9a6bd0d799..66a6fb812f 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -128,7 +128,6 @@ App::post('/v1/projects') $databases = Config::getParam('pools-database', []); - if ($region !== 'default') { $databaseKeys = System::getEnv('_APP_DATABASE_KEYS', ''); $keys = explode(',', $databaseKeys); @@ -235,8 +234,6 @@ App::post('/v1/projects') $create = false; } - - if ($create || $projectTables) { $audit = new Audit($dbForProject); $audit->setup(); diff --git a/app/http.php b/app/http.php index aaa8dfca0e..b99a6cfad3 100644 --- a/app/http.php +++ b/app/http.php @@ -292,6 +292,16 @@ $http->on(Constant::EVENT_START, function (Server $http) use ($payloadSize, $reg Console::success('[Setup] - Skip: metadata table already exists'); } + if ($dbForProject->getCollection(Audit::COLLECTION)->isEmpty()) { + $audit = new Audit($dbForProject); + $audit->setup(); + } + + if ($dbForProject->getCollection(TimeLimit::COLLECTION)->isEmpty()) { + $adapter = new TimeLimit("", 0, 1, $dbForProject); + $adapter->setup(); + } + foreach ($projectCollections as $key => $collection) { if (($collection['$collection'] ?? '') !== Database::METADATA) { continue; From 9a89cc1332d9e329a9ad1f812b836a20cb921da5 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 12 Dec 2024 19:06:35 +1300 Subject: [PATCH 4/6] Remove logs --- app/controllers/api/databases.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index 33b37bb1b6..aad072c50a 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -2895,11 +2895,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/documents') } $collection = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getInternalId(), $collectionId)); - var_dump('database_' . $database->getInternalId()); - var_dump($collectionId); - var_dump($collection); - var_dump($isAPIKey); - var_dump($isPrivilegedUser); + if ($collection->isEmpty() || (!$collection->getAttribute('enabled', false) && !$isAPIKey && !$isPrivilegedUser)) { throw new Exception(Exception::COLLECTION_NOT_FOUND); } From 39e4a046256acd7f077e110150a29f7d66624480 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 12 Dec 2024 20:31:50 +1300 Subject: [PATCH 5/6] Fix default region --- app/http.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/http.php b/app/http.php index b99a6cfad3..839272bd31 100644 --- a/app/http.php +++ b/app/http.php @@ -265,7 +265,7 @@ $http->on(Constant::EVENT_START, function (Server $http) use ($payloadSize, $reg $sharedTablesV1 = \explode(',', System::getEnv('_APP_DATABASE_SHARED_TABLES_V1', '')); $sharedTablesV2 = \array_diff($sharedTables, $sharedTablesV1); - $region = System::getEnv('_APP_REGION', 'fra'); + $region = System::getEnv('_APP_REGION', 'default'); $cache = $app->getResource('cache'); $regionDatabases = \array_filter( @@ -292,12 +292,16 @@ $http->on(Constant::EVENT_START, function (Server $http) use ($payloadSize, $reg Console::success('[Setup] - Skip: metadata table already exists'); } + Console::info('Checking audit collection'); if ($dbForProject->getCollection(Audit::COLLECTION)->isEmpty()) { + Console::info('Creating audit collection'); $audit = new Audit($dbForProject); $audit->setup(); } + Console::info('Checking abuse collection'); if ($dbForProject->getCollection(TimeLimit::COLLECTION)->isEmpty()) { + Console::info('Creating abuse collection'); $adapter = new TimeLimit("", 0, 1, $dbForProject); $adapter->setup(); } From 54d1ef257d1b931c7160883aa10c08df2161baf2 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 12 Dec 2024 21:01:26 +1300 Subject: [PATCH 6/6] Remove logs --- app/http.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/app/http.php b/app/http.php index 839272bd31..b14e653c44 100644 --- a/app/http.php +++ b/app/http.php @@ -292,16 +292,12 @@ $http->on(Constant::EVENT_START, function (Server $http) use ($payloadSize, $reg Console::success('[Setup] - Skip: metadata table already exists'); } - Console::info('Checking audit collection'); if ($dbForProject->getCollection(Audit::COLLECTION)->isEmpty()) { - Console::info('Creating audit collection'); $audit = new Audit($dbForProject); $audit->setup(); } - Console::info('Checking abuse collection'); if ($dbForProject->getCollection(TimeLimit::COLLECTION)->isEmpty()) { - Console::info('Creating abuse collection'); $adapter = new TimeLimit("", 0, 1, $dbForProject); $adapter->setup(); }