From 0467ebc1ffc3b2a23acc2703b8e5a4b318d67ab9 Mon Sep 17 00:00:00 2001 From: Darshan Date: Sun, 1 Jun 2025 12:07:46 +0530 Subject: [PATCH 01/40] add: `error` attribute to migrations. --- app/config/collections/projects.php | 17 +++++++++++++ src/Appwrite/Platform/Workers/Migrations.php | 25 ++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/app/config/collections/projects.php b/app/config/collections/projects.php index 48a0938a1c..bdf44e2470 100644 --- a/app/config/collections/projects.php +++ b/app/config/collections/projects.php @@ -2341,6 +2341,23 @@ return [ 'array' => true, 'filters' => [], ], + [ + /** + * A short, human-readable error message (no stacktrace), + * unlike `errors` which contains detailed entries with full trace. + * + * This is mainly used used for csv imports as its failure need to be shown on frontend. + */ + '$id' => ID::custom('error'), + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => 256, + 'signed' => true, + 'required' => false, + 'default' => null, + 'array' => false, + 'filters' => [], + ], [ '$id' => ID::custom('search'), 'type' => Database::VAR_STRING, diff --git a/src/Appwrite/Platform/Workers/Migrations.php b/src/Appwrite/Platform/Workers/Migrations.php index 395ec1351e..1f094f4dd2 100644 --- a/src/Appwrite/Platform/Workers/Migrations.php +++ b/src/Appwrite/Platform/Workers/Migrations.php @@ -365,6 +365,7 @@ class Migrations extends Action $migration->setAttribute('errors', $errorMessages); } } finally { + $this->setMigrationError($migration, $source, $destination); $this->updateMigrationDocument($migration, $projectDocument, $queueForRealtime); if ($migration->getAttribute('status', '') === 'failed') { @@ -407,4 +408,28 @@ class Migrations extends Action } } } + + /** + * Stores a human-readable error message for migration. + * + * Only applies to migrations where the source is CSV. + */ + private function setMigrationError(Document $migration, ?Source $source, ?Destination $destination): void + { + if ($migration->isEmpty() || $source === null || $destination === null) { + return; + } + + $sourceErrors = $source->getErrors(); + $destinationErrors = $destination->getErrors(); + $migrationSource = $migration->getAttribute('source'); + + if ($migrationSource === CSV::getName()) { + if (! empty($sourceErrors)) { + $migration->setAttribute('error', $sourceErrors[0]->getMessage()); + } elseif (! empty($destinationErrors)) { + $migration->setAttribute('error', $destinationErrors[0]->getMessage()); + } + } + } } From 48d5ae0bca52f4aeacd45db1745f24340551bcbd Mon Sep 17 00:00:00 2001 From: Darshan Date: Sun, 1 Jun 2025 12:49:42 +0530 Subject: [PATCH 02/40] add: `1.8.x` migrations for adding `error` attribute. --- app/config/collections/projects.php | 1 + src/Appwrite/Migration/Migration.php | 1 + src/Appwrite/Migration/Version/V23.php | 76 ++++++++++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 src/Appwrite/Migration/Version/V23.php diff --git a/app/config/collections/projects.php b/app/config/collections/projects.php index bdf44e2470..6fe6dff0ba 100644 --- a/app/config/collections/projects.php +++ b/app/config/collections/projects.php @@ -1286,6 +1286,7 @@ return [ ] ], ], + 'deployments' => [ '$collection' => ID::custom(Database::METADATA), '$id' => ID::custom('deployments'), diff --git a/src/Appwrite/Migration/Migration.php b/src/Appwrite/Migration/Migration.php index 9071e0cabe..026ce1eb2e 100644 --- a/src/Appwrite/Migration/Migration.php +++ b/src/Appwrite/Migration/Migration.php @@ -89,6 +89,7 @@ abstract class Migration '1.7.2' => 'V22', '1.7.3' => 'V22', '1.7.4' => 'V22', + '1.8.0' => 'V23', ]; /** diff --git a/src/Appwrite/Migration/Version/V23.php b/src/Appwrite/Migration/Version/V23.php new file mode 100644 index 0000000000..89ce938657 --- /dev/null +++ b/src/Appwrite/Migration/Version/V23.php @@ -0,0 +1,76 @@ + null, + fn () => [] + ); + } + + Console::info('Migrating collections'); + $this->migrateCollections(); + } + + /** + * Migrate Collections. + * + * @return void + * @throws Exception|Throwable + */ + private function migrateCollections(): void + { + $this->migrateMigrationsCollections(); + } + + /** + * Add `error` attribute on `migrations` collection. + */ + private function migrateMigrationsCollections(): void + { + $projectInternalId = $this->project->getSequence(); + + if ($projectInternalId !== 'projects') { + return; + } + + Console::info(" └── Migrating `migrations` collections."); + + if (empty($projectInternalId)) { + throw new Exception('Project ID is null'); + } + + /** + * direct access.\ + * same as `$this->collections['projects']['migrations']['$id']`. + */ + $migrationCollectionId = 'migrations'; + + try { + $attributes = ['error']; + $this->createAttributesFromCollection($this->dbForProject, $migrationCollectionId, $attributes); + } catch (\Throwable $th) { + Console::warning('Failed to create attributes "' . \implode(', ', $attributes) . "\" in collection {$migrationCollectionId}: {$th->getMessage()}"); + } + + $this->dbForProject->purgeCachedCollection($migrationCollectionId); + } +} From 66194722a95a49f585bb7401e80a44f6fd6ce1b1 Mon Sep 17 00:00:00 2001 From: Darshan Date: Sun, 1 Jun 2025 12:56:59 +0530 Subject: [PATCH 03/40] add: `error` to response model. --- src/Appwrite/Utopia/Response/Model/Migration.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Appwrite/Utopia/Response/Model/Migration.php b/src/Appwrite/Utopia/Response/Model/Migration.php index 3be1d519a6..75aebfbc66 100644 --- a/src/Appwrite/Utopia/Response/Model/Migration.php +++ b/src/Appwrite/Utopia/Response/Model/Migration.php @@ -85,6 +85,13 @@ class Migration extends Model 'default' => [], 'example' => [], ]) + ->addRule('error', [ + 'type' => self::TYPE_STRING, + 'description' => 'A readable error message that occurred during the CSV migration process.', + 'array' => false, + 'default' => null, + 'example' => '', + ]) ; } From cdd047b459ecbae7db0ae98161c1dc149db6a7bf Mon Sep 17 00:00:00 2001 From: Darshan Date: Sun, 1 Jun 2025 13:00:44 +0530 Subject: [PATCH 04/40] bump: lockfile. --- composer.lock | 162 +++++++++++++++++++++++--------------------------- 1 file changed, 75 insertions(+), 87 deletions(-) diff --git a/composer.lock b/composer.lock index a16ee400fd..959bcee74c 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": "34142c56876c7ee1e2a798616b8ff114", + "content-hash": "6c2dda1189f3de260f4b6cc9ce9a428f", "packages": [ { "name": "adhocore/jwt", @@ -283,16 +283,16 @@ }, { "name": "brick/math", - "version": "0.12.3", + "version": "0.13.1", "source": { "type": "git", "url": "https://github.com/brick/math.git", - "reference": "866551da34e9a618e64a819ee1e01c20d8a588ba" + "reference": "fc7ed316430118cc7836bf45faff18d5dfc8de04" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/brick/math/zipball/866551da34e9a618e64a819ee1e01c20d8a588ba", - "reference": "866551da34e9a618e64a819ee1e01c20d8a588ba", + "url": "https://api.github.com/repos/brick/math/zipball/fc7ed316430118cc7836bf45faff18d5dfc8de04", + "reference": "fc7ed316430118cc7836bf45faff18d5dfc8de04", "shasum": "" }, "require": { @@ -331,7 +331,7 @@ ], "support": { "issues": "https://github.com/brick/math/issues", - "source": "https://github.com/brick/math/tree/0.12.3" + "source": "https://github.com/brick/math/tree/0.13.1" }, "funding": [ { @@ -339,7 +339,7 @@ "type": "github" } ], - "time": "2025-02-28T13:11:00+00:00" + "time": "2025-03-29T13:50:30+00:00" }, { "name": "chillerlan/php-qrcode", @@ -2323,20 +2323,20 @@ }, { "name": "ramsey/uuid", - "version": "4.7.6", + "version": "4.8.1", "source": { "type": "git", "url": "https://github.com/ramsey/uuid.git", - "reference": "91039bc1faa45ba123c4328958e620d382ec7088" + "reference": "fdf4dd4e2ff1813111bd0ad58d7a1ddbb5b56c28" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/ramsey/uuid/zipball/91039bc1faa45ba123c4328958e620d382ec7088", - "reference": "91039bc1faa45ba123c4328958e620d382ec7088", + "url": "https://api.github.com/repos/ramsey/uuid/zipball/fdf4dd4e2ff1813111bd0ad58d7a1ddbb5b56c28", + "reference": "fdf4dd4e2ff1813111bd0ad58d7a1ddbb5b56c28", "shasum": "" }, "require": { - "brick/math": "^0.8.8 || ^0.9 || ^0.10 || ^0.11 || ^0.12", + "brick/math": "^0.8.8 || ^0.9 || ^0.10 || ^0.11 || ^0.12 || ^0.13", "ext-json": "*", "php": "^8.0", "ramsey/collection": "^1.2 || ^2.0" @@ -2345,26 +2345,23 @@ "rhumsaa/uuid": "self.version" }, "require-dev": { - "captainhook/captainhook": "^5.10", + "captainhook/captainhook": "^5.25", "captainhook/plugin-composer": "^5.3", - "dealerdirect/phpcodesniffer-composer-installer": "^0.7.0", - "doctrine/annotations": "^1.8", - "ergebnis/composer-normalize": "^2.15", - "mockery/mockery": "^1.3", + "dealerdirect/phpcodesniffer-composer-installer": "^1.0", + "ergebnis/composer-normalize": "^2.47", + "mockery/mockery": "^1.6", "paragonie/random-lib": "^2", - "php-mock/php-mock": "^2.2", - "php-mock/php-mock-mockery": "^1.3", - "php-parallel-lint/php-parallel-lint": "^1.1", - "phpbench/phpbench": "^1.0", - "phpstan/extension-installer": "^1.1", - "phpstan/phpstan": "^1.8", - "phpstan/phpstan-mockery": "^1.1", - "phpstan/phpstan-phpunit": "^1.1", - "phpunit/phpunit": "^8.5 || ^9", - "ramsey/composer-repl": "^1.4", - "slevomat/coding-standard": "^8.4", - "squizlabs/php_codesniffer": "^3.5", - "vimeo/psalm": "^4.9" + "php-mock/php-mock": "^2.6", + "php-mock/php-mock-mockery": "^1.5", + "php-parallel-lint/php-parallel-lint": "^1.4.0", + "phpbench/phpbench": "^1.2.14", + "phpstan/extension-installer": "^1.4", + "phpstan/phpstan": "^2.1", + "phpstan/phpstan-mockery": "^2.0", + "phpstan/phpstan-phpunit": "^2.0", + "phpunit/phpunit": "^9.6", + "slevomat/coding-standard": "^8.18", + "squizlabs/php_codesniffer": "^3.13" }, "suggest": { "ext-bcmath": "Enables faster math with arbitrary-precision integers using BCMath.", @@ -2399,19 +2396,9 @@ ], "support": { "issues": "https://github.com/ramsey/uuid/issues", - "source": "https://github.com/ramsey/uuid/tree/4.7.6" + "source": "https://github.com/ramsey/uuid/tree/4.8.1" }, - "funding": [ - { - "url": "https://github.com/ramsey", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/ramsey/uuid", - "type": "tidelift" - } - ], - "time": "2024-04-27T21:32:50+00:00" + "time": "2025-06-01T06:28:46+00:00" }, { "name": "spomky-labs/otphp", @@ -2557,16 +2544,16 @@ }, { "name": "symfony/http-client", - "version": "v7.2.4", + "version": "v7.3.0", "source": { "type": "git", "url": "https://github.com/symfony/http-client.git", - "reference": "78981a2ffef6437ed92d4d7e2a86a82f256c6dc6" + "reference": "57e4fb86314015a695a750ace358d07a7e37b8a9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-client/zipball/78981a2ffef6437ed92d4d7e2a86a82f256c6dc6", - "reference": "78981a2ffef6437ed92d4d7e2a86a82f256c6dc6", + "url": "https://api.github.com/repos/symfony/http-client/zipball/57e4fb86314015a695a750ace358d07a7e37b8a9", + "reference": "57e4fb86314015a695a750ace358d07a7e37b8a9", "shasum": "" }, "require": { @@ -2632,7 +2619,7 @@ "http" ], "support": { - "source": "https://github.com/symfony/http-client/tree/v7.2.4" + "source": "https://github.com/symfony/http-client/tree/v7.3.0" }, "funding": [ { @@ -2648,7 +2635,7 @@ "type": "tidelift" } ], - "time": "2025-02-13T10:27:23+00:00" + "time": "2025-05-02T08:23:16+00:00" }, { "name": "symfony/http-client-contracts", @@ -5344,16 +5331,16 @@ }, { "name": "nikic/php-parser", - "version": "v5.4.0", + "version": "v5.5.0", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "447a020a1f875a434d62f2a401f53b82a396e494" + "reference": "ae59794362fe85e051a58ad36b289443f57be7a9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/447a020a1f875a434d62f2a401f53b82a396e494", - "reference": "447a020a1f875a434d62f2a401f53b82a396e494", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/ae59794362fe85e051a58ad36b289443f57be7a9", + "reference": "ae59794362fe85e051a58ad36b289443f57be7a9", "shasum": "" }, "require": { @@ -5396,9 +5383,9 @@ ], "support": { "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v5.4.0" + "source": "https://github.com/nikic/PHP-Parser/tree/v5.5.0" }, - "time": "2024-12-30T11:07:19+00:00" + "time": "2025-05-31T08:24:38+00:00" }, { "name": "phar-io/manifest", @@ -7266,23 +7253,24 @@ }, { "name": "symfony/console", - "version": "v7.2.6", + "version": "v7.3.0", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "0e2e3f38c192e93e622e41ec37f4ca70cfedf218" + "reference": "66c1440edf6f339fd82ed6c7caa76cb006211b44" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/0e2e3f38c192e93e622e41ec37f4ca70cfedf218", - "reference": "0e2e3f38c192e93e622e41ec37f4ca70cfedf218", + "url": "https://api.github.com/repos/symfony/console/zipball/66c1440edf6f339fd82ed6c7caa76cb006211b44", + "reference": "66c1440edf6f339fd82ed6c7caa76cb006211b44", "shasum": "" }, "require": { "php": ">=8.2", + "symfony/deprecation-contracts": "^2.5|^3", "symfony/polyfill-mbstring": "~1.0", "symfony/service-contracts": "^2.5|^3", - "symfony/string": "^6.4|^7.0" + "symfony/string": "^7.2" }, "conflict": { "symfony/dependency-injection": "<6.4", @@ -7339,7 +7327,7 @@ "terminal" ], "support": { - "source": "https://github.com/symfony/console/tree/v7.2.6" + "source": "https://github.com/symfony/console/tree/v7.3.0" }, "funding": [ { @@ -7355,11 +7343,11 @@ "type": "tidelift" } ], - "time": "2025-04-07T19:09:28+00:00" + "time": "2025-05-24T10:34:04+00:00" }, { "name": "symfony/filesystem", - "version": "v7.2.0", + "version": "v7.3.0", "source": { "type": "git", "url": "https://github.com/symfony/filesystem.git", @@ -7405,7 +7393,7 @@ "description": "Provides basic utilities for the filesystem", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/filesystem/tree/v7.2.0" + "source": "https://github.com/symfony/filesystem/tree/v7.3.0" }, "funding": [ { @@ -7425,16 +7413,16 @@ }, { "name": "symfony/finder", - "version": "v7.2.2", + "version": "v7.3.0", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", - "reference": "87a71856f2f56e4100373e92529eed3171695cfb" + "reference": "ec2344cf77a48253bbca6939aa3d2477773ea63d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/87a71856f2f56e4100373e92529eed3171695cfb", - "reference": "87a71856f2f56e4100373e92529eed3171695cfb", + "url": "https://api.github.com/repos/symfony/finder/zipball/ec2344cf77a48253bbca6939aa3d2477773ea63d", + "reference": "ec2344cf77a48253bbca6939aa3d2477773ea63d", "shasum": "" }, "require": { @@ -7469,7 +7457,7 @@ "description": "Finds files and directories via an intuitive fluent interface", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/finder/tree/v7.2.2" + "source": "https://github.com/symfony/finder/tree/v7.3.0" }, "funding": [ { @@ -7485,20 +7473,20 @@ "type": "tidelift" } ], - "time": "2024-12-30T19:00:17+00:00" + "time": "2024-12-30T19:00:26+00:00" }, { "name": "symfony/options-resolver", - "version": "v7.2.0", + "version": "v7.3.0", "source": { "type": "git", "url": "https://github.com/symfony/options-resolver.git", - "reference": "7da8fbac9dcfef75ffc212235d76b2754ce0cf50" + "reference": "afb9a8038025e5dbc657378bfab9198d75f10fca" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/options-resolver/zipball/7da8fbac9dcfef75ffc212235d76b2754ce0cf50", - "reference": "7da8fbac9dcfef75ffc212235d76b2754ce0cf50", + "url": "https://api.github.com/repos/symfony/options-resolver/zipball/afb9a8038025e5dbc657378bfab9198d75f10fca", + "reference": "afb9a8038025e5dbc657378bfab9198d75f10fca", "shasum": "" }, "require": { @@ -7536,7 +7524,7 @@ "options" ], "support": { - "source": "https://github.com/symfony/options-resolver/tree/v7.2.0" + "source": "https://github.com/symfony/options-resolver/tree/v7.3.0" }, "funding": [ { @@ -7552,7 +7540,7 @@ "type": "tidelift" } ], - "time": "2024-11-20T11:17:29+00:00" + "time": "2025-04-04T13:12:05+00:00" }, { "name": "symfony/polyfill-ctype", @@ -7870,16 +7858,16 @@ }, { "name": "symfony/process", - "version": "v7.2.5", + "version": "v7.3.0", "source": { "type": "git", "url": "https://github.com/symfony/process.git", - "reference": "87b7c93e57df9d8e39a093d32587702380ff045d" + "reference": "40c295f2deb408d5e9d2d32b8ba1dd61e36f05af" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/87b7c93e57df9d8e39a093d32587702380ff045d", - "reference": "87b7c93e57df9d8e39a093d32587702380ff045d", + "url": "https://api.github.com/repos/symfony/process/zipball/40c295f2deb408d5e9d2d32b8ba1dd61e36f05af", + "reference": "40c295f2deb408d5e9d2d32b8ba1dd61e36f05af", "shasum": "" }, "require": { @@ -7911,7 +7899,7 @@ "description": "Executes commands in sub-processes", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/process/tree/v7.2.5" + "source": "https://github.com/symfony/process/tree/v7.3.0" }, "funding": [ { @@ -7927,20 +7915,20 @@ "type": "tidelift" } ], - "time": "2025-03-13T12:21:46+00:00" + "time": "2025-04-17T09:11:12+00:00" }, { "name": "symfony/string", - "version": "v7.2.6", + "version": "v7.3.0", "source": { "type": "git", "url": "https://github.com/symfony/string.git", - "reference": "a214fe7d62bd4df2a76447c67c6b26e1d5e74931" + "reference": "f3570b8c61ca887a9e2938e85cb6458515d2b125" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/string/zipball/a214fe7d62bd4df2a76447c67c6b26e1d5e74931", - "reference": "a214fe7d62bd4df2a76447c67c6b26e1d5e74931", + "url": "https://api.github.com/repos/symfony/string/zipball/f3570b8c61ca887a9e2938e85cb6458515d2b125", + "reference": "f3570b8c61ca887a9e2938e85cb6458515d2b125", "shasum": "" }, "require": { @@ -7998,7 +7986,7 @@ "utf8" ], "support": { - "source": "https://github.com/symfony/string/tree/v7.2.6" + "source": "https://github.com/symfony/string/tree/v7.3.0" }, "funding": [ { @@ -8014,7 +8002,7 @@ "type": "tidelift" } ], - "time": "2025-04-20T20:18:16+00:00" + "time": "2025-04-20T20:19:01+00:00" }, { "name": "textalk/websocket", From 683eecfd2d1f20d2d86d7e8dc628da3d76cc90a0 Mon Sep 17 00:00:00 2001 From: Darshan Date: Sun, 1 Jun 2025 13:03:00 +0530 Subject: [PATCH 05/40] update: flip check order. --- src/Appwrite/Migration/Version/V23.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Appwrite/Migration/Version/V23.php b/src/Appwrite/Migration/Version/V23.php index 89ce938657..2b07a6584e 100644 --- a/src/Appwrite/Migration/Version/V23.php +++ b/src/Appwrite/Migration/Version/V23.php @@ -48,16 +48,17 @@ class V23 extends Migration { $projectInternalId = $this->project->getSequence(); + if (empty($projectInternalId)) { + throw new Exception('Project ID is null'); + } + + // not needed for `console` project. if ($projectInternalId !== 'projects') { return; } Console::info(" └── Migrating `migrations` collections."); - if (empty($projectInternalId)) { - throw new Exception('Project ID is null'); - } - /** * direct access.\ * same as `$this->collections['projects']['migrations']['$id']`. From c57967c3b85c67fc678d00d3f7076279f400207f Mon Sep 17 00:00:00 2001 From: Darshan Date: Sun, 1 Jun 2025 13:04:25 +0530 Subject: [PATCH 06/40] update: nitpick comment. --- src/Appwrite/Migration/Version/V23.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Appwrite/Migration/Version/V23.php b/src/Appwrite/Migration/Version/V23.php index 2b07a6584e..0b879a73e1 100644 --- a/src/Appwrite/Migration/Version/V23.php +++ b/src/Appwrite/Migration/Version/V23.php @@ -60,8 +60,9 @@ class V23 extends Migration Console::info(" └── Migrating `migrations` collections."); /** - * direct access.\ - * same as `$this->collections['projects']['migrations']['$id']`. + * Specifying the ID for direct access. + * + * This is same as `$this->collections['projects']['migrations']['$id']`. */ $migrationCollectionId = 'migrations'; From e48e4537def467ec49848af45c02c579e61bac59 Mon Sep 17 00:00:00 2001 From: Darshan Date: Sun, 1 Jun 2025 13:59:43 +0530 Subject: [PATCH 07/40] fix: leftovers, `getInternalId` > `getSequence`. --- .../Modules/Functions/Http/Functions/Deployment/Update.php | 2 +- src/Appwrite/Platform/Modules/Functions/Workers/Builds.php | 6 +++--- .../Platform/Modules/Sites/Http/Sites/Deployment/Update.php | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Deployment/Update.php b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Deployment/Update.php index f91c8b88e1..5595a69617 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Deployment/Update.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Deployment/Update.php @@ -109,7 +109,7 @@ class Update extends Base Query::equal("deploymentResourceType", ["function"]), Query::equal("deploymentResourceInternalId", [$function->getSequence()]), Query::equal("deploymentVcsProviderBranch", [""]), - Query::equal("projectInternalId", [$project->getInternalId()]) + Query::equal("projectInternalId", [$project->getSequence()]) ]; Authorization::skip(fn () => $dbForPlatform->foreach('rules', function (Document $rule) use ($dbForPlatform, $deployment) { diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index 0cfaf096ab..fa7cfab138 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -1087,7 +1087,7 @@ class Builds extends Action Query::equal('deploymentResourceType', ['function']), Query::equal('trigger', ['manual']), Query::equal('deploymentVcsProviderBranch', ['']), - Query::equal("projectInternalId", [$project->getInternalId()]) + Query::equal("projectInternalId", [$project->getSequence()]) ]; $rulesUpdated = false; @@ -1113,7 +1113,7 @@ class Builds extends Action Query::equal('deploymentResourceType', ['site']), Query::equal('trigger', ['manual']), Query::equal('deploymentVcsProviderBranch', ['']), - Query::equal("projectInternalId", [$project->getInternalId()]) + Query::equal("projectInternalId", [$project->getSequence()]) ]; $dbForPlatform->forEach('rules', function (Document $rule) use ($dbForPlatform, $deployment) { @@ -1170,7 +1170,7 @@ class Builds extends Action } $queries = [ - Query::equal('projectInternalId', [$project->getInternalId()]), + Query::equal('projectInternalId', [$project->getSequence()]), Query::equal('type', ['deployment']), Query::equal('deploymentResourceInternalId', [$resource->getSequence()]), Query::equal('deploymentResourceType', ['site']), diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Deployment/Update.php b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Deployment/Update.php index e71e23fa59..9fa62c2adf 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Sites/Deployment/Update.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Sites/Deployment/Update.php @@ -101,7 +101,7 @@ class Update extends Base Query::equal("deploymentResourceType", ["site"]), Query::equal("deploymentResourceInternalId", [$site->getSequence()]), Query::equal("deploymentVcsProviderBranch", [""]), - Query::equal("projectInternalId", [$project->getInternalId()]) + Query::equal("projectInternalId", [$project->getSequence()]) ]; Authorization::skip(fn () => $dbForPlatform->foreach('rules', function (Document $rule) use ($dbForPlatform, $deployment) { From 2df28bdf19851b5642c7c30dd21128ca8d3a9dc3 Mon Sep 17 00:00:00 2001 From: Darshan Date: Tue, 10 Jun 2025 12:07:58 +0530 Subject: [PATCH 08/40] remove: migrations, simplify error recording for frontend. --- app/config/collections/projects.php | 17 ---- src/Appwrite/Migration/Migration.php | 1 - src/Appwrite/Migration/Version/V23.php | 78 ------------------- src/Appwrite/Platform/Workers/Migrations.php | 47 +---------- .../Utopia/Response/Model/Migration.php | 7 -- 5 files changed, 4 insertions(+), 146 deletions(-) delete mode 100644 src/Appwrite/Migration/Version/V23.php diff --git a/app/config/collections/projects.php b/app/config/collections/projects.php index 6fe6dff0ba..ac14421382 100644 --- a/app/config/collections/projects.php +++ b/app/config/collections/projects.php @@ -2342,23 +2342,6 @@ return [ 'array' => true, 'filters' => [], ], - [ - /** - * A short, human-readable error message (no stacktrace), - * unlike `errors` which contains detailed entries with full trace. - * - * This is mainly used used for csv imports as its failure need to be shown on frontend. - */ - '$id' => ID::custom('error'), - 'type' => Database::VAR_STRING, - 'format' => '', - 'size' => 256, - 'signed' => true, - 'required' => false, - 'default' => null, - 'array' => false, - 'filters' => [], - ], [ '$id' => ID::custom('search'), 'type' => Database::VAR_STRING, diff --git a/src/Appwrite/Migration/Migration.php b/src/Appwrite/Migration/Migration.php index 026ce1eb2e..9071e0cabe 100644 --- a/src/Appwrite/Migration/Migration.php +++ b/src/Appwrite/Migration/Migration.php @@ -89,7 +89,6 @@ abstract class Migration '1.7.2' => 'V22', '1.7.3' => 'V22', '1.7.4' => 'V22', - '1.8.0' => 'V23', ]; /** diff --git a/src/Appwrite/Migration/Version/V23.php b/src/Appwrite/Migration/Version/V23.php deleted file mode 100644 index 0b879a73e1..0000000000 --- a/src/Appwrite/Migration/Version/V23.php +++ /dev/null @@ -1,78 +0,0 @@ - null, - fn () => [] - ); - } - - Console::info('Migrating collections'); - $this->migrateCollections(); - } - - /** - * Migrate Collections. - * - * @return void - * @throws Exception|Throwable - */ - private function migrateCollections(): void - { - $this->migrateMigrationsCollections(); - } - - /** - * Add `error` attribute on `migrations` collection. - */ - private function migrateMigrationsCollections(): void - { - $projectInternalId = $this->project->getSequence(); - - if (empty($projectInternalId)) { - throw new Exception('Project ID is null'); - } - - // not needed for `console` project. - if ($projectInternalId !== 'projects') { - return; - } - - Console::info(" └── Migrating `migrations` collections."); - - /** - * Specifying the ID for direct access. - * - * This is same as `$this->collections['projects']['migrations']['$id']`. - */ - $migrationCollectionId = 'migrations'; - - try { - $attributes = ['error']; - $this->createAttributesFromCollection($this->dbForProject, $migrationCollectionId, $attributes); - } catch (\Throwable $th) { - Console::warning('Failed to create attributes "' . \implode(', ', $attributes) . "\" in collection {$migrationCollectionId}: {$th->getMessage()}"); - } - - $this->dbForProject->purgeCachedCollection($migrationCollectionId); - } -} diff --git a/src/Appwrite/Platform/Workers/Migrations.php b/src/Appwrite/Platform/Workers/Migrations.php index 1f094f4dd2..7623b6ebfb 100644 --- a/src/Appwrite/Platform/Workers/Migrations.php +++ b/src/Appwrite/Platform/Workers/Migrations.php @@ -305,22 +305,10 @@ class Migrations extends Action $errorMessages = []; foreach ($sourceErrors as $error) { - $message = "Error occurred while fetching '{$error->getResourceName()}:{$error->getResourceId()}' from source with message: '{$error->getMessage()}'"; - if ($error->getPrevious()) { - $message .= " Message: ".$error->getPrevious()->getMessage() . " File: ".$error->getPrevious()->getFile() . " Line: ".$error->getPrevious()->getLine(); - } - - $errorMessages[] = $message; + $errorMessages[] = $error->jsonSerialize(); } foreach ($destinationErrors as $error) { - $message = "Error occurred while pushing '{$error->getResourceName()}:{$error->getResourceId()}' to destination with message: '{$error->getMessage()}'"; - - if ($error->getPrevious()) { - $message .= " Message: ".$error->getPrevious()->getMessage() . " File: ".$error->getPrevious()->getFile() . " Line: ".$error->getPrevious()->getLine(); - } - - /** @var MigrationException $error */ - $errorMessages[] = $message; + $errorMessages[] = $error->jsonSerialize(); } $migration->setAttribute('errors', $errorMessages); @@ -354,18 +342,15 @@ class Migrations extends Action $errorMessages = []; foreach ($sourceErrors as $error) { - /** @var MigrationException $error */ - $errorMessages[] = "Error occurred while fetching '{$error->getResourceName()}:{$error->getResourceId()}' from source with message '{$error->getMessage()}'"; + $errorMessages[] = $error->jsonSerialize(); } foreach ($destinationErrors as $error) { - /** @var MigrationException $error */ - $errorMessages[] = "Error occurred while pushing '{$error->getResourceName()}:{$error->getResourceId()}' to destination with message '{$error->getMessage()}'"; + $errorMessages[] = $error->jsonSerialize(); } $migration->setAttribute('errors', $errorMessages); } } finally { - $this->setMigrationError($migration, $source, $destination); $this->updateMigrationDocument($migration, $projectDocument, $queueForRealtime); if ($migration->getAttribute('status', '') === 'failed') { @@ -408,28 +393,4 @@ class Migrations extends Action } } } - - /** - * Stores a human-readable error message for migration. - * - * Only applies to migrations where the source is CSV. - */ - private function setMigrationError(Document $migration, ?Source $source, ?Destination $destination): void - { - if ($migration->isEmpty() || $source === null || $destination === null) { - return; - } - - $sourceErrors = $source->getErrors(); - $destinationErrors = $destination->getErrors(); - $migrationSource = $migration->getAttribute('source'); - - if ($migrationSource === CSV::getName()) { - if (! empty($sourceErrors)) { - $migration->setAttribute('error', $sourceErrors[0]->getMessage()); - } elseif (! empty($destinationErrors)) { - $migration->setAttribute('error', $destinationErrors[0]->getMessage()); - } - } - } } diff --git a/src/Appwrite/Utopia/Response/Model/Migration.php b/src/Appwrite/Utopia/Response/Model/Migration.php index 75aebfbc66..3be1d519a6 100644 --- a/src/Appwrite/Utopia/Response/Model/Migration.php +++ b/src/Appwrite/Utopia/Response/Model/Migration.php @@ -85,13 +85,6 @@ class Migration extends Model 'default' => [], 'example' => [], ]) - ->addRule('error', [ - 'type' => self::TYPE_STRING, - 'description' => 'A readable error message that occurred during the CSV migration process.', - 'array' => false, - 'default' => null, - 'example' => '', - ]) ; } From c06ff42f61f3f5bb25681ca3732802871a8baff5 Mon Sep 17 00:00:00 2001 From: Darshan Date: Thu, 12 Jun 2025 10:43:35 +0530 Subject: [PATCH 09/40] fix: attribute types; update: remove sensitive information from realtime payload. --- src/Appwrite/Platform/Workers/Migrations.php | 31 ++++++++++++++++---- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/src/Appwrite/Platform/Workers/Migrations.php b/src/Appwrite/Platform/Workers/Migrations.php index 7623b6ebfb..a59668d60a 100644 --- a/src/Appwrite/Platform/Workers/Migrations.php +++ b/src/Appwrite/Platform/Workers/Migrations.php @@ -185,13 +185,33 @@ class Migrations extends Action */ protected function updateMigrationDocument(Document $migration, Document $project, Realtime $queueForRealtime): Document { + $errorMessages = []; + $clonedMigrationDocument = clone $migration; + + // we cannot use #sensitive because + // `errors` is nested which requires an override. + $errors = $clonedMigrationDocument->getAttribute('errors', []); + + foreach ($errors as $error) { + $decoded = json_decode($error, true); + + if (is_array($decoded) && isset($decoded['trace'])) { + unset($decoded['trace']); + $errorMessages[] = json_encode($decoded); + } + } + + // set the errors back without trace + $clonedMigrationDocument->setAttribute('errors', $errorMessages); + + /** Trigger Realtime Events */ $queueForRealtime ->setProject($project) ->setSubscribers(['console', $project->getId()]) ->setEvent('migrations.[migrationId].update') ->setParam('migrationId', $migration->getId()) - ->setPayload($migration->getArrayCopy()) + ->setPayload($clonedMigrationDocument->getArrayCopy(), ['options', 'credentials']) ->trigger(); return $this->dbForProject->updateDocument('migrations', $migration->getId(), $migration); @@ -305,14 +325,13 @@ class Migrations extends Action $errorMessages = []; foreach ($sourceErrors as $error) { - $errorMessages[] = $error->jsonSerialize(); + $errorMessages[] = json_encode($error); } foreach ($destinationErrors as $error) { - $errorMessages[] = $error->jsonSerialize(); + $errorMessages[] = json_encode($error); } $migration->setAttribute('errors', $errorMessages); - $this->updateMigrationDocument($migration, $projectDocument, $queueForRealtime); return; } @@ -342,10 +361,10 @@ class Migrations extends Action $errorMessages = []; foreach ($sourceErrors as $error) { - $errorMessages[] = $error->jsonSerialize(); + $errorMessages[] = json_encode($error); } foreach ($destinationErrors as $error) { - $errorMessages[] = $error->jsonSerialize(); + $errorMessages[] = json_encode($error); } $migration->setAttribute('errors', $errorMessages); From 176c0850681789a97aac6d05d0dce8ce7c141f70 Mon Sep 17 00:00:00 2001 From: Khushboo Verma Date: Thu, 12 Jun 2025 11:43:11 +0530 Subject: [PATCH 10/40] Fix all vcs urls missing region --- app/controllers/api/vcs.php | 25 +++++++++++-------- app/controllers/general.php | 11 ++++---- .../Modules/Functions/Workers/Builds.php | 5 ++-- src/Appwrite/Platform/Workers/Webhooks.php | 3 ++- 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/app/controllers/api/vcs.php b/app/controllers/api/vcs.php index c8a0a36a85..79050c2913 100644 --- a/app/controllers/api/vcs.php +++ b/app/controllers/api/vcs.php @@ -363,6 +363,7 @@ $createGitDeployments = function (GitHub $github, string $providerInstallationId if (!empty($providerCommitHash) && $resource->getAttribute('providerSilentMode', false) === false) { $resourceName = $resource->getAttribute('name'); $projectName = $project->getAttribute('name'); + $region = $project->getAttribute('region', 'default'); $name = "{$resourceName} ({$projectName})"; $message = 'Starting...'; @@ -377,7 +378,7 @@ $createGitDeployments = function (GitHub $github, string $providerInstallationId } $owner = $github->getOwnerName($providerInstallationId); - $providerTargetUrl = $request->getProtocol() . '://' . $request->getHostname() . "/console/project-$projectId/$resourceCollection/$resourceType-$resourceId"; + $providerTargetUrl = $request->getProtocol() . '://' . $request->getHostname() . "/console/project-$region-$projectId/$resourceCollection/$resourceType-$resourceId"; $github->updateCommitStatus($repositoryName, $providerCommitHash, $owner, 'pending', $message, $providerTargetUrl, $name); } @@ -476,16 +477,6 @@ App::get('/v1/vcs/github/callback') $state = \json_decode($state, true); $projectId = $state['projectId'] ?? ''; - $defaultState = [ - 'success' => $request->getProtocol() . '://' . $request->getHostname() . "/console/project-$projectId/settings/git-installations", - 'failure' => $request->getProtocol() . '://' . $request->getHostname() . "/console/project-$projectId/settings/git-installations", - ]; - - $state = \array_merge($defaultState, $state ?? []); - - $redirectSuccess = $state['success'] ?? ''; - $redirectFailure = $state['failure'] ?? ''; - $project = $dbForPlatform->getDocument('projects', $projectId); if ($project->isEmpty()) { @@ -502,6 +493,18 @@ App::get('/v1/vcs/github/callback') throw new Exception(Exception::PROJECT_NOT_FOUND, $error); } + $region = $project->getAttribute('region', 'default'); + + $defaultState = [ + 'success' => $request->getProtocol() . '://' . $request->getHostname() . "/console/project-$region-$projectId/settings/git-installations", + 'failure' => $request->getProtocol() . '://' . $request->getHostname() . "/console/project-$region-$projectId/settings/git-installations", + ]; + + $state = \array_merge($defaultState, $state ?? []); + + $redirectSuccess = $state['success'] ?? ''; + $redirectFailure = $state['failure'] ?? ''; + // Create / Update installation if (!empty($providerInstallationId)) { $privateKey = System::getEnv('_APP_VCS_GITHUB_PRIVATE_KEY'); diff --git a/app/controllers/general.php b/app/controllers/general.php index 5beac9e1e8..14ff1aae1d 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -186,7 +186,7 @@ function router(App $utopia, Database $dbForPlatform, callable $getProjectDB, Sw $resourceId = $rule->getAttribute('deploymentResourceId', ''); $type = ($resourceType === 'site') ? 'sites' : 'functions'; $exception = new AppwriteException(AppwriteException::DEPLOYMENT_NOT_FOUND, view: $errorView); - $exception->addCTA('View deployments', $url . '/console/project-' . $projectId . '/' . $type . '/' . $resourceType . '-' . $resourceId); + $exception->addCTA('View deployments', $url . '/console/project-' . $project->getAttribute('region', 'default') . '-' . $projectId . '/' . $type . '/' . $resourceType . '-' . $resourceId); throw $exception; } @@ -319,21 +319,22 @@ function router(App $utopia, Database $dbForPlatform, callable $getProjectDB, Sw $allowAnyStatus = !\is_null($apiKey) && $apiKey->isDeploymentStatusIgnored(); if (!$allowAnyStatus && $deployment->getAttribute('status') !== 'ready') { $status = $deployment->getAttribute('status'); + $region = $project->getAttribute('region', 'default'); switch ($status) { case 'failed': $exception = new AppwriteException(AppwriteException::BUILD_FAILED, view: $errorView); - $ctaUrl = '/console/project-' . $project->getId() . '/sites/site-' . $resource->getId() . '/deployments/deployment-' . $deployment->getId(); + $ctaUrl = '/console/project-' . $region . '-' . $project->getId() . '/sites/site-' . $resource->getId() . '/deployments/deployment-' . $deployment->getId(); $exception->addCTA('View logs', $url . $ctaUrl); break; case 'canceled': $exception = new AppwriteException(AppwriteException::BUILD_CANCELED, view: $errorView); - $ctaUrl = '/console/project-' . $project->getId() . '/sites/site-' . $resource->getId() . '/deployments'; + $ctaUrl = '/console/project-' . $region . '-' . $project->getId() . '/sites/site-' . $resource->getId() . '/deployments'; $exception->addCTA('View deployments', $url . $ctaUrl); break; default: $exception = new AppwriteException(AppwriteException::BUILD_NOT_READY, view: $errorView); - $ctaUrl = '/console/project-' . $project->getId() . '/sites/site-' . $resource->getId() . '/deployments/deployment-' . $deployment->getId(); + $ctaUrl = '/console/project-' . $region . '-' . $project->getId() . '/sites/site-' . $resource->getId() . '/deployments/deployment-' . $deployment->getId(); $exception->addCTA('Reload', '/'); $exception->addCTA('View logs', $url . $ctaUrl); break; @@ -345,7 +346,7 @@ function router(App $utopia, Database $dbForPlatform, callable $getProjectDB, Sw $permissions = $resource->getAttribute('execute'); if (!(\in_array('any', $permissions)) && !(\in_array('guests', $permissions))) { $exception = new AppwriteException(AppwriteException::FUNCTION_EXECUTE_PERMISSION_MISSING, view: $errorView); - $exception->addCTA('View settings', $url . '/console/project-' . $project->getId() . '/functions/function-' . $resource->getId() . '/settings'); + $exception->addCTA('View settings', $url . '/console/project-' . $project->getAttribute('region', 'default') . '-' . $project->getId() . '/functions/function-' . $resource->getId() . '/settings'); throw $exception; } } diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index 399a4d5c44..a207845733 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -1444,10 +1444,11 @@ class Builds extends Action $hostname = System::getEnv('_APP_DOMAIN'); $projectId = $project->getId(); + $region = $project->getAttribute('region', 'default'); $resourceId = $resource->getId(); $providerTargetUrl = match ($resource->getCollection()) { - 'functions' => "{$protocol}://{$hostname}/console/project-{$projectId}/functions/function-{$resourceId}", - 'sites' => "{$protocol}://{$hostname}/console/project-{$projectId}/sites/site-{$resourceId}", + 'functions' => "{$protocol}://{$hostname}/console/project-{$region}-{$projectId}/functions/function-{$resourceId}", + 'sites' => "{$protocol}://{$hostname}/console/project-{$region}-{$projectId}/sites/site-{$resourceId}", default => throw new \Exception('Invalid resource type') }; diff --git a/src/Appwrite/Platform/Workers/Webhooks.php b/src/Appwrite/Platform/Workers/Webhooks.php index ada4d6faaa..82dfe0f1a8 100644 --- a/src/Appwrite/Platform/Workers/Webhooks.php +++ b/src/Appwrite/Platform/Workers/Webhooks.php @@ -219,6 +219,7 @@ class Webhooks extends Action ]); $projectId = $project->getId(); + $region = $project->getAttribute('region', 'default'); $webhookId = $webhook->getId(); $template = Template::fromFile(__DIR__ . '/../../../../app/config/locale/templates/email-webhook-failed.tpl'); @@ -227,7 +228,7 @@ class Webhooks extends Action $template->setParam('{{project}}', $project->getAttribute('name')); $template->setParam('{{url}}', $webhook->getAttribute('url')); $template->setParam('{{error}}', $curlError ?? 'The server returned ' . $statusCode . ' status code'); - $template->setParam('{{path}}', "/console/project-$projectId/settings/webhooks/$webhookId"); + $template->setParam('{{path}}', "/console/project-$region-$projectId/settings/webhooks/$webhookId"); $template->setParam('{{attempts}}', $attempts); $template->setParam('{{logoUrl}}', $plan['logoUrl'] ?? APP_EMAIL_LOGO_URL); From d01f1c1a7c1d6d084fcc817cea6697dbed493c51 Mon Sep 17 00:00:00 2001 From: Darshan Date: Fri, 13 Jun 2025 16:20:07 +0530 Subject: [PATCH 11/40] remove: trace from `errors`. --- .../Utopia/Response/Model/Migration.php | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/Appwrite/Utopia/Response/Model/Migration.php b/src/Appwrite/Utopia/Response/Model/Migration.php index 3be1d519a6..c74e2fb2aa 100644 --- a/src/Appwrite/Utopia/Response/Model/Migration.php +++ b/src/Appwrite/Utopia/Response/Model/Migration.php @@ -4,6 +4,7 @@ namespace Appwrite\Utopia\Response\Model; use Appwrite\Utopia\Response; use Appwrite\Utopia\Response\Model; +use Utopia\Database\Document; class Migration extends Model { @@ -107,4 +108,25 @@ class Migration extends Model { return Response::MODEL_MIGRATION; } + + public function filter(Document $document): Document + { + $errors = $document->getAttribute('errors', []); + if (empty($errors)) { + return $document; + } + + foreach ($errors as $error) { + $decoded = json_decode($error, true); + + if (is_array($decoded) && isset($decoded['trace'])) { + unset($decoded['trace']); + $errors[] = json_encode($decoded); + } + } + + $document->setAttribute('errors', $errors); + + return $document; + } } From fde2f278e8a764fa556835cfef3e95161816f8dc Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Sat, 14 Jun 2025 18:07:42 +0530 Subject: [PATCH 12/40] added invalidating sessions for the project users --- app/controllers/api/projects.php | 41 ++++++++++++++++++- app/controllers/api/users.php | 11 +++++ .../update-auth-on-password-change.md | 1 + .../Utopia/Response/Model/Project.php | 7 ++++ tests/e2e/Scopes/ProjectCustom.php | 13 ++++++ .../Projects/ProjectsConsoleClientTest.php | 25 +++++++++++ tests/e2e/Services/Users/UsersBase.php | 13 +++++- 7 files changed, 108 insertions(+), 3 deletions(-) create mode 100644 docs/references/databases/update-auth-on-password-change.md diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 51cbc097f5..cbdc1c5e05 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -94,13 +94,14 @@ App::post('/v1/projects') ->param('legalCity', '', new Text(256), 'Project legal City. Max length: 256 chars.', true) ->param('legalAddress', '', new Text(256), 'Project legal Address. Max length: 256 chars.', true) ->param('legalTaxId', '', new Text(256), 'Project legal Tax ID. Max length: 256 chars.', true) + ->param('onPasswordChange', false, new Boolean(), 'For invalding sessions', true) ->inject('request') ->inject('response') ->inject('dbForPlatform') ->inject('cache') ->inject('pools') ->inject('hooks') - ->action(function (string $projectId, string $name, string $teamId, string $region, string $description, string $logo, string $url, string $legalName, string $legalCountry, string $legalState, string $legalCity, string $legalAddress, string $legalTaxId, Request $request, Response $response, Database $dbForPlatform, Cache $cache, Group $pools, Hooks $hooks) { + ->action(function (string $projectId, string $name, string $teamId, string $region, string $description, string $logo, string $url, string $legalName, string $legalCountry, string $legalState, string $legalCity, string $legalAddress, string $legalTaxId, $onPasswordChange, Request $request, Response $response, Database $dbForPlatform, Cache $cache, Group $pools, Hooks $hooks) { $team = $dbForPlatform->getDocument('teams', $teamId); @@ -127,6 +128,7 @@ App::post('/v1/projects') 'membershipsUserName' => false, 'membershipsUserEmail' => false, 'membershipsMfa' => false, + 'onPasswordChange' => $onPasswordChange ]; foreach ($auth as $method) { @@ -2499,3 +2501,40 @@ App::delete('/v1/projects/:projectId/templates/email/:type/:locale') 'message' => $template['message'] ]), Response::MODEL_EMAIL_TEMPLATE); }); + +App::patch('/v1/projects/:projectId/auth/password-change') +->desc('Update on password change of the project') +->groups(['api', 'projects']) +->label('scope', 'projects.write') +->label('sdk', new Method( + namespace: 'projects', + group: 'auth', + name: 'updateOnPasswordChange', + description: '/docs/references/projects/update-auth-on-password-change.md', + auth: [AuthType::ADMIN], + responses: [ + new SDKResponse( + code: Response::STATUS_CODE_OK, + model: Response::MODEL_PROJECT, + ) + ] +)) +->param('projectId', '', new UID(), 'Project unique ID.') +->param('onPasswordChange', false, new Boolean(), 'For invalidating project session') +->inject('response') +->inject('dbForPlatform') +->action(function (string $projectId, bool $onPasswordChange, Response $response, Database $dbForPlatform) { + + $project = $dbForPlatform->getDocument('projects', $projectId); + + if ($project->isEmpty()) { + throw new Exception(Exception::PROJECT_NOT_FOUND); + } + + $auths = $project->getAttribute('auths', []); + $auths['onPasswordChange'] = $onPasswordChange; + $dbForPlatform->updateDocument('projects', $project->getId(), $project + ->setAttribute('auths', $auths)); + + $response->dynamic($project, Response::MODEL_PROJECT); +}); diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index d7def69464..d9dd951c09 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -1351,6 +1351,17 @@ App::patch('/v1/users/:userId/password') $user = $dbForProject->updateDocument('users', $user->getId(), $user); + $sessions = $user->getAttribute('sessions', []); + $onPasswordChange = $project->getAttribute('auths', [])['onPasswordChange']; + if ($onPasswordChange) { + foreach ($sessions as $session) { + /** @var Document $session */ + $dbForProject->deleteDocument('sessions', $session->getId()); + } + } + + $dbForProject->purgeCachedDocument('users', $user->getId()); + $queueForEvents->setParam('userId', $user->getId()); $response->dynamic($user, Response::MODEL_USER); diff --git a/docs/references/databases/update-auth-on-password-change.md b/docs/references/databases/update-auth-on-password-change.md new file mode 100644 index 0000000000..1daf0a69df --- /dev/null +++ b/docs/references/databases/update-auth-on-password-change.md @@ -0,0 +1 @@ +On password change. Should be an optional auth security setting for projects, and enabled by default for console project. \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Model/Project.php b/src/Appwrite/Utopia/Response/Model/Project.php index efd002654e..c9f900933f 100644 --- a/src/Appwrite/Utopia/Response/Model/Project.php +++ b/src/Appwrite/Utopia/Response/Model/Project.php @@ -271,6 +271,12 @@ class Project extends Model 'default' => '', 'example' => self::TYPE_DATETIME_EXAMPLE, ]) + ->addRule('onPasswordChange', [ + 'type' => self::TYPE_BOOLEAN, + 'description' => 'For invalidating all sessions', + 'default' => false, + 'example' => self::TYPE_BOOLEAN, + ]) ; $services = Config::getParam('services', []); @@ -376,6 +382,7 @@ class Project extends Model $document->setAttribute('authMembershipsUserName', $authValues['membershipsUserName'] ?? true); $document->setAttribute('authMembershipsUserEmail', $authValues['membershipsUserEmail'] ?? true); $document->setAttribute('authMembershipsMfa', $authValues['membershipsMfa'] ?? true); + $document->setAttribute('onPasswordChange', $authValues['onPasswordChange'] ?? false); foreach ($auth as $index => $method) { $key = $method['key']; diff --git a/tests/e2e/Scopes/ProjectCustom.php b/tests/e2e/Scopes/ProjectCustom.php index a354696f53..0225805054 100644 --- a/tests/e2e/Scopes/ProjectCustom.php +++ b/tests/e2e/Scopes/ProjectCustom.php @@ -200,4 +200,17 @@ trait ProjectCustom return $key['body']['secret']; } + public function updateProjectOnPasswordChangeProperty(bool $value) + { + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . self::$project['$id'] . '/auth/password-change', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'cookie' => 'a_session_console=' . $this->getRoot()['session'], + 'x-appwrite-project' => 'console', + ]), [ + 'onPasswordChange' => $value, + ]); + + return $response['headers']['status-code']; + } } diff --git a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php index aea1971be7..d77e330e6a 100644 --- a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php +++ b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php @@ -951,6 +951,31 @@ class ProjectsConsoleClientTest extends Scope return ['projectId' => $projectId]; } + /** @depends testCreateProject */ + public function testUpdateProjectOnPasswordChange($data): array + { + $id = $data['projectId']; + + // Check defaults + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => 'console', + ], $this->getHeaders())); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertFalse($response['body']['onPasswordChange']); + + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/password-change', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'onPasswordChange' => true, + ]); + $this->assertTrue($response['body']['onPasswordChange']); + + return $data; + } + /** * @depends testCreateProject */ diff --git a/tests/e2e/Services/Users/UsersBase.php b/tests/e2e/Services/Users/UsersBase.php index 00e999672f..391f31da41 100644 --- a/tests/e2e/Services/Users/UsersBase.php +++ b/tests/e2e/Services/Users/UsersBase.php @@ -1117,7 +1117,7 @@ trait UsersBase ]); $this->assertEquals(401, $session['headers']['status-code']); - + $this->updateProjectOnPasswordChangeProperty(true); $user = $this->client->call(Client::METHOD_PATCH, '/users/' . $data['userId'] . '/password', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], @@ -1129,6 +1129,15 @@ trait UsersBase $this->assertNotEmpty($user['body']['$id']); $this->assertNotEmpty($user['body']['password']); + $sessions = $this->client->call(Client::METHOD_GET, '/users/' . $data['userId'] . '/sessions', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + + $this->assertEquals($sessions['headers']['status-code'], 200); + $this->assertIsArray($sessions['body']); + $this->assertEmpty($sessions['body']['sessions']); + $session = $this->client->call(Client::METHOD_POST, '/account/sessions/email', [ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], @@ -1138,7 +1147,7 @@ trait UsersBase ]); $this->assertEquals($session['headers']['status-code'], 201); - + $this->updateProjectOnPasswordChangeProperty(false); return $data; } From 74614e8d58c9244c5f50ed33d977e1b4f5fad05b Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Sat, 14 Jun 2025 18:09:20 +0530 Subject: [PATCH 13/40] updated description of on password change --- app/controllers/api/projects.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index cbdc1c5e05..c46dc4f603 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -94,7 +94,7 @@ App::post('/v1/projects') ->param('legalCity', '', new Text(256), 'Project legal City. Max length: 256 chars.', true) ->param('legalAddress', '', new Text(256), 'Project legal Address. Max length: 256 chars.', true) ->param('legalTaxId', '', new Text(256), 'Project legal Tax ID. Max length: 256 chars.', true) - ->param('onPasswordChange', false, new Boolean(), 'For invalding sessions', true) + ->param('onPasswordChange', false, new Boolean(), 'Auth option to allow invalidating existing sessions', true) ->inject('request') ->inject('response') ->inject('dbForPlatform') @@ -2520,7 +2520,7 @@ App::patch('/v1/projects/:projectId/auth/password-change') ] )) ->param('projectId', '', new UID(), 'Project unique ID.') -->param('onPasswordChange', false, new Boolean(), 'For invalidating project session') +->param('onPasswordChange', false, new Boolean(), 'Auth option to allow invalidating existing sessions') ->inject('response') ->inject('dbForPlatform') ->action(function (string $projectId, bool $onPasswordChange, Response $response, Database $dbForPlatform) { From 774291b5d8dc0742ab7470f9de5605f27fa031c8 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Sat, 14 Jun 2025 18:15:41 +0530 Subject: [PATCH 14/40] added onPasswordChange property to the console project --- app/config/console.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/config/console.php b/app/config/console.php index 1de3a99370..5c43aa22f6 100644 --- a/app/config/console.php +++ b/app/config/console.php @@ -39,7 +39,8 @@ $console = [ 'invites' => System::getEnv('_APP_CONSOLE_INVITES', 'enabled') === 'enabled', 'limit' => (System::getEnv('_APP_CONSOLE_WHITELIST_ROOT', 'enabled') === 'enabled') ? 1 : 0, // limit signup to 1 user 'duration' => Auth::TOKEN_EXPIRATION_LOGIN_LONG, // 1 Year in seconds - 'sessionAlerts' => System::getEnv('_APP_CONSOLE_SESSION_ALERTS', 'disabled') === 'enabled' + 'sessionAlerts' => System::getEnv('_APP_CONSOLE_SESSION_ALERTS', 'disabled') === 'enabled', + 'onPasswordChange' => true ], 'authWhitelistEmails' => (!empty(System::getEnv('_APP_CONSOLE_WHITELIST_EMAILS', null))) ? \explode(',', System::getEnv('_APP_CONSOLE_WHITELIST_EMAILS', null)) : [], 'authWhitelistIPs' => (!empty(System::getEnv('_APP_CONSOLE_WHITELIST_IPS', null))) ? \explode(',', System::getEnv('_APP_CONSOLE_WHITELIST_IPS', null)) : [], From 7a0ba95231560f80c610767b1dbeb63d0a104088 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Mon, 16 Jun 2025 23:05:52 +0530 Subject: [PATCH 15/40] updated onPasswordChange to invalidate session --- app/config/console.php | 2 +- app/controllers/api/projects.php | 19 +++++++++---------- app/controllers/api/users.php | 4 ++-- .../databases/session-invalidation.md | 1 + .../update-auth-on-password-change.md | 1 - .../Utopia/Response/Model/Project.php | 4 ++-- tests/e2e/Scopes/ProjectCustom.php | 6 +++--- .../Projects/ProjectsConsoleClientTest.php | 10 +++++----- tests/e2e/Services/Users/UsersBase.php | 4 ++-- 9 files changed, 25 insertions(+), 26 deletions(-) create mode 100644 docs/references/databases/session-invalidation.md delete mode 100644 docs/references/databases/update-auth-on-password-change.md diff --git a/app/config/console.php b/app/config/console.php index 5c43aa22f6..aa7de13ba0 100644 --- a/app/config/console.php +++ b/app/config/console.php @@ -40,7 +40,7 @@ $console = [ 'limit' => (System::getEnv('_APP_CONSOLE_WHITELIST_ROOT', 'enabled') === 'enabled') ? 1 : 0, // limit signup to 1 user 'duration' => Auth::TOKEN_EXPIRATION_LOGIN_LONG, // 1 Year in seconds 'sessionAlerts' => System::getEnv('_APP_CONSOLE_SESSION_ALERTS', 'disabled') === 'enabled', - 'onPasswordChange' => true + 'invalidateSessions' => true ], 'authWhitelistEmails' => (!empty(System::getEnv('_APP_CONSOLE_WHITELIST_EMAILS', null))) ? \explode(',', System::getEnv('_APP_CONSOLE_WHITELIST_EMAILS', null)) : [], 'authWhitelistIPs' => (!empty(System::getEnv('_APP_CONSOLE_WHITELIST_IPS', null))) ? \explode(',', System::getEnv('_APP_CONSOLE_WHITELIST_IPS', null)) : [], diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index c46dc4f603..116c32fd58 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -94,14 +94,13 @@ App::post('/v1/projects') ->param('legalCity', '', new Text(256), 'Project legal City. Max length: 256 chars.', true) ->param('legalAddress', '', new Text(256), 'Project legal Address. Max length: 256 chars.', true) ->param('legalTaxId', '', new Text(256), 'Project legal Tax ID. Max length: 256 chars.', true) - ->param('onPasswordChange', false, new Boolean(), 'Auth option to allow invalidating existing sessions', true) ->inject('request') ->inject('response') ->inject('dbForPlatform') ->inject('cache') ->inject('pools') ->inject('hooks') - ->action(function (string $projectId, string $name, string $teamId, string $region, string $description, string $logo, string $url, string $legalName, string $legalCountry, string $legalState, string $legalCity, string $legalAddress, string $legalTaxId, $onPasswordChange, Request $request, Response $response, Database $dbForPlatform, Cache $cache, Group $pools, Hooks $hooks) { + ->action(function (string $projectId, string $name, string $teamId, string $region, string $description, string $logo, string $url, string $legalName, string $legalCountry, string $legalState, string $legalCity, string $legalAddress, string $legalTaxId, Request $request, Response $response, Database $dbForPlatform, Cache $cache, Group $pools, Hooks $hooks) { $team = $dbForPlatform->getDocument('teams', $teamId); @@ -128,7 +127,7 @@ App::post('/v1/projects') 'membershipsUserName' => false, 'membershipsUserEmail' => false, 'membershipsMfa' => false, - 'onPasswordChange' => $onPasswordChange + 'invalidateSessions' => true ]; foreach ($auth as $method) { @@ -2502,15 +2501,15 @@ App::delete('/v1/projects/:projectId/templates/email/:type/:locale') ]), Response::MODEL_EMAIL_TEMPLATE); }); -App::patch('/v1/projects/:projectId/auth/password-change') -->desc('Update on password change of the project') +App::patch('/v1/projects/:projectId/auth/session-invalidation') +->desc('Update invalidate session option of the project') ->groups(['api', 'projects']) ->label('scope', 'projects.write') ->label('sdk', new Method( namespace: 'projects', group: 'auth', - name: 'updateOnPasswordChange', - description: '/docs/references/projects/update-auth-on-password-change.md', + name: 'updateInvalidateSessions', + description: '/docs/references/projects/session-invalidation.md', auth: [AuthType::ADMIN], responses: [ new SDKResponse( @@ -2520,10 +2519,10 @@ App::patch('/v1/projects/:projectId/auth/password-change') ] )) ->param('projectId', '', new UID(), 'Project unique ID.') -->param('onPasswordChange', false, new Boolean(), 'Auth option to allow invalidating existing sessions') +->param('invalidateSessions', false, new Boolean(), 'Auth option to allow invalidating existing sessions') ->inject('response') ->inject('dbForPlatform') -->action(function (string $projectId, bool $onPasswordChange, Response $response, Database $dbForPlatform) { +->action(function (string $projectId, bool $invalidateSessions, Response $response, Database $dbForPlatform) { $project = $dbForPlatform->getDocument('projects', $projectId); @@ -2532,7 +2531,7 @@ App::patch('/v1/projects/:projectId/auth/password-change') } $auths = $project->getAttribute('auths', []); - $auths['onPasswordChange'] = $onPasswordChange; + $auths['invalidateSessions'] = $invalidateSessions; $dbForPlatform->updateDocument('projects', $project->getId(), $project ->setAttribute('auths', $auths)); diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index d9dd951c09..0b580170e1 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -1352,8 +1352,8 @@ App::patch('/v1/users/:userId/password') $user = $dbForProject->updateDocument('users', $user->getId(), $user); $sessions = $user->getAttribute('sessions', []); - $onPasswordChange = $project->getAttribute('auths', [])['onPasswordChange']; - if ($onPasswordChange) { + $invalidate = $project->getAttribute('auths', default: [])['invalidateSessions'] ?? false; + if ($invalidate) { foreach ($sessions as $session) { /** @var Document $session */ $dbForProject->deleteDocument('sessions', $session->getId()); diff --git a/docs/references/databases/session-invalidation.md b/docs/references/databases/session-invalidation.md new file mode 100644 index 0000000000..cbaf378624 --- /dev/null +++ b/docs/references/databases/session-invalidation.md @@ -0,0 +1 @@ +Invalidate all existing sessions. An optional auth security setting for projects, and enabled by default for console project. \ No newline at end of file diff --git a/docs/references/databases/update-auth-on-password-change.md b/docs/references/databases/update-auth-on-password-change.md deleted file mode 100644 index 1daf0a69df..0000000000 --- a/docs/references/databases/update-auth-on-password-change.md +++ /dev/null @@ -1 +0,0 @@ -On password change. Should be an optional auth security setting for projects, and enabled by default for console project. \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Model/Project.php b/src/Appwrite/Utopia/Response/Model/Project.php index c9f900933f..a944c4e6e1 100644 --- a/src/Appwrite/Utopia/Response/Model/Project.php +++ b/src/Appwrite/Utopia/Response/Model/Project.php @@ -271,7 +271,7 @@ class Project extends Model 'default' => '', 'example' => self::TYPE_DATETIME_EXAMPLE, ]) - ->addRule('onPasswordChange', [ + ->addRule('invalidateSessions', [ 'type' => self::TYPE_BOOLEAN, 'description' => 'For invalidating all sessions', 'default' => false, @@ -382,7 +382,7 @@ class Project extends Model $document->setAttribute('authMembershipsUserName', $authValues['membershipsUserName'] ?? true); $document->setAttribute('authMembershipsUserEmail', $authValues['membershipsUserEmail'] ?? true); $document->setAttribute('authMembershipsMfa', $authValues['membershipsMfa'] ?? true); - $document->setAttribute('onPasswordChange', $authValues['onPasswordChange'] ?? false); + $document->setAttribute('invalidateSessions', $authValues['invalidateSessions'] ?? false); foreach ($auth as $index => $method) { $key = $method['key']; diff --git a/tests/e2e/Scopes/ProjectCustom.php b/tests/e2e/Scopes/ProjectCustom.php index 0225805054..5b079a6482 100644 --- a/tests/e2e/Scopes/ProjectCustom.php +++ b/tests/e2e/Scopes/ProjectCustom.php @@ -200,15 +200,15 @@ trait ProjectCustom return $key['body']['secret']; } - public function updateProjectOnPasswordChangeProperty(bool $value) + public function updateProjectinvalidateSessionsProperty(bool $value) { - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . self::$project['$id'] . '/auth/password-change', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . self::$project['$id'] . '/auth/session-invalidation', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'cookie' => 'a_session_console=' . $this->getRoot()['session'], 'x-appwrite-project' => 'console', ]), [ - 'onPasswordChange' => $value, + 'invalidateSessions' => $value, ]); return $response['headers']['status-code']; diff --git a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php index d77e330e6a..5b7043805a 100644 --- a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php +++ b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php @@ -952,7 +952,7 @@ class ProjectsConsoleClientTest extends Scope } /** @depends testCreateProject */ - public function testUpdateProjectOnPasswordChange($data): array + public function testUpdateProjectInvalidateSessions($data): array { $id = $data['projectId']; @@ -963,15 +963,15 @@ class ProjectsConsoleClientTest extends Scope ], $this->getHeaders())); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertFalse($response['body']['onPasswordChange']); + $this->assertFalse($response['body']['invalidateSessions']); - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/password-change', array_merge([ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/session-invalidation', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'onPasswordChange' => true, + 'invalidateSessions' => true, ]); - $this->assertTrue($response['body']['onPasswordChange']); + $this->assertTrue($response['body']['invalidateSessions']); return $data; } diff --git a/tests/e2e/Services/Users/UsersBase.php b/tests/e2e/Services/Users/UsersBase.php index 391f31da41..0aa5784930 100644 --- a/tests/e2e/Services/Users/UsersBase.php +++ b/tests/e2e/Services/Users/UsersBase.php @@ -1117,7 +1117,7 @@ trait UsersBase ]); $this->assertEquals(401, $session['headers']['status-code']); - $this->updateProjectOnPasswordChangeProperty(true); + $this->updateProjectinvalidateSessionsProperty(true); $user = $this->client->call(Client::METHOD_PATCH, '/users/' . $data['userId'] . '/password', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], @@ -1147,7 +1147,7 @@ trait UsersBase ]); $this->assertEquals($session['headers']['status-code'], 201); - $this->updateProjectOnPasswordChangeProperty(false); + $this->updateProjectinvalidateSessionsProperty(false); return $data; } From 9bf4361761bd7de79f3ea8bf9dcb9c8de465a43e Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Mon, 16 Jun 2025 23:48:08 +0530 Subject: [PATCH 16/40] updated indentation --- app/controllers/api/projects.php | 62 ++++++++++++++++---------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 116c32fd58..8fca702850 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -2502,38 +2502,38 @@ App::delete('/v1/projects/:projectId/templates/email/:type/:locale') }); App::patch('/v1/projects/:projectId/auth/session-invalidation') -->desc('Update invalidate session option of the project') -->groups(['api', 'projects']) -->label('scope', 'projects.write') -->label('sdk', new Method( - namespace: 'projects', - group: 'auth', - name: 'updateInvalidateSessions', - description: '/docs/references/projects/session-invalidation.md', - auth: [AuthType::ADMIN], - responses: [ - new SDKResponse( - code: Response::STATUS_CODE_OK, - model: Response::MODEL_PROJECT, - ) - ] -)) -->param('projectId', '', new UID(), 'Project unique ID.') -->param('invalidateSessions', false, new Boolean(), 'Auth option to allow invalidating existing sessions') -->inject('response') -->inject('dbForPlatform') -->action(function (string $projectId, bool $invalidateSessions, Response $response, Database $dbForPlatform) { + ->desc('Update invalidate session option of the project') + ->groups(['api', 'projects']) + ->label('scope', 'projects.write') + ->label('sdk', new Method( + namespace: 'projects', + group: 'auth', + name: 'updateInvalidateSessions', + description: '/docs/references/projects/session-invalidation.md', + auth: [AuthType::ADMIN], + responses: [ + new SDKResponse( + code: Response::STATUS_CODE_OK, + model: Response::MODEL_PROJECT, + ) + ] + )) + ->param('projectId', '', new UID(), 'Project unique ID.') + ->param('invalidateSessions', false, new Boolean(), 'Auth option to allow invalidating existing sessions') + ->inject('response') + ->inject('dbForPlatform') + ->action(function (string $projectId, bool $invalidateSessions, Response $response, Database $dbForPlatform) { - $project = $dbForPlatform->getDocument('projects', $projectId); + $project = $dbForPlatform->getDocument('projects', $projectId); - if ($project->isEmpty()) { - throw new Exception(Exception::PROJECT_NOT_FOUND); - } + if ($project->isEmpty()) { + throw new Exception(Exception::PROJECT_NOT_FOUND); + } - $auths = $project->getAttribute('auths', []); - $auths['invalidateSessions'] = $invalidateSessions; - $dbForPlatform->updateDocument('projects', $project->getId(), $project - ->setAttribute('auths', $auths)); + $auths = $project->getAttribute('auths', []); + $auths['invalidateSessions'] = $invalidateSessions; + $dbForPlatform->updateDocument('projects', $project->getId(), $project + ->setAttribute('auths', $auths)); - $response->dynamic($project, Response::MODEL_PROJECT); -}); + $response->dynamic($project, Response::MODEL_PROJECT); + }); From 28fbd648645084c67d73300643441d14154da47f Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Tue, 17 Jun 2025 00:40:32 +0530 Subject: [PATCH 17/40] updated session invalidation tests , models and descriptions --- app/controllers/api/projects.php | 6 ++-- .../update-session-invalidation.md} | 0 .../Utopia/Response/Model/Project.php | 14 ++++----- tests/e2e/Scopes/ProjectCustom.php | 2 +- .../Projects/ProjectsConsoleClientTest.php | 30 +++++++++++++++++-- 5 files changed, 38 insertions(+), 14 deletions(-) rename docs/references/{databases/session-invalidation.md => projects/update-session-invalidation.md} (100%) diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 8fca702850..42bb6c3bcb 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -2508,8 +2508,8 @@ App::patch('/v1/projects/:projectId/auth/session-invalidation') ->label('sdk', new Method( namespace: 'projects', group: 'auth', - name: 'updateInvalidateSessions', - description: '/docs/references/projects/session-invalidation.md', + name: 'updateSessionInvalidation', + description: '/docs/references/projects/update-session-invalidation.md', auth: [AuthType::ADMIN], responses: [ new SDKResponse( @@ -2519,7 +2519,7 @@ App::patch('/v1/projects/:projectId/auth/session-invalidation') ] )) ->param('projectId', '', new UID(), 'Project unique ID.') - ->param('invalidateSessions', false, new Boolean(), 'Auth option to allow invalidating existing sessions') + ->param('enabled', false, new Boolean(), 'Update authentication session invalidation status. Use this endpoint to enable or disable session invalidation on password change') ->inject('response') ->inject('dbForPlatform') ->action(function (string $projectId, bool $invalidateSessions, Response $response, Database $dbForPlatform) { diff --git a/docs/references/databases/session-invalidation.md b/docs/references/projects/update-session-invalidation.md similarity index 100% rename from docs/references/databases/session-invalidation.md rename to docs/references/projects/update-session-invalidation.md diff --git a/src/Appwrite/Utopia/Response/Model/Project.php b/src/Appwrite/Utopia/Response/Model/Project.php index a944c4e6e1..ef50d81c31 100644 --- a/src/Appwrite/Utopia/Response/Model/Project.php +++ b/src/Appwrite/Utopia/Response/Model/Project.php @@ -169,6 +169,12 @@ class Project extends Model 'default' => false, 'example' => true, ]) + ->addRule('authInvalidateSessions', [ + 'type' => self::TYPE_BOOLEAN, + 'description' => 'Whether or not all existing sessions should be invalidated on password change', + 'default' => false, + 'example' => self::TYPE_BOOLEAN, + ]) ->addRule('oAuthProviders', [ 'type' => Response::MODEL_AUTH_PROVIDER, 'description' => 'List of Auth Providers.', @@ -271,12 +277,6 @@ class Project extends Model 'default' => '', 'example' => self::TYPE_DATETIME_EXAMPLE, ]) - ->addRule('invalidateSessions', [ - 'type' => self::TYPE_BOOLEAN, - 'description' => 'For invalidating all sessions', - 'default' => false, - 'example' => self::TYPE_BOOLEAN, - ]) ; $services = Config::getParam('services', []); @@ -382,7 +382,7 @@ class Project extends Model $document->setAttribute('authMembershipsUserName', $authValues['membershipsUserName'] ?? true); $document->setAttribute('authMembershipsUserEmail', $authValues['membershipsUserEmail'] ?? true); $document->setAttribute('authMembershipsMfa', $authValues['membershipsMfa'] ?? true); - $document->setAttribute('invalidateSessions', $authValues['invalidateSessions'] ?? false); + $document->setAttribute('authInvalidateSessions', $authValues['invalidateSessions'] ?? false); foreach ($auth as $index => $method) { $key = $method['key']; diff --git a/tests/e2e/Scopes/ProjectCustom.php b/tests/e2e/Scopes/ProjectCustom.php index 5b079a6482..51aebeaef7 100644 --- a/tests/e2e/Scopes/ProjectCustom.php +++ b/tests/e2e/Scopes/ProjectCustom.php @@ -208,7 +208,7 @@ trait ProjectCustom 'cookie' => 'a_session_console=' . $this->getRoot()['session'], 'x-appwrite-project' => 'console', ]), [ - 'invalidateSessions' => $value, + 'enabled' => $value, ]); return $response['headers']['status-code']; diff --git a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php index 5b7043805a..1a9cf3b586 100644 --- a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php +++ b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php @@ -963,15 +963,39 @@ class ProjectsConsoleClientTest extends Scope ], $this->getHeaders())); $this->assertEquals(200, $response['headers']['status-code']); - $this->assertFalse($response['body']['invalidateSessions']); + $this->assertTrue($response['body']['authInvalidateSessions']); $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/session-invalidation', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ], $this->getHeaders()), [ - 'invalidateSessions' => true, + 'enabled' => false, ]); - $this->assertTrue($response['body']['invalidateSessions']); + $this->assertFalse($response['body']['authInvalidateSessions']); + + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => 'console', + ], $this->getHeaders())); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertFalse($response['body']['authInvalidateSessions']); + + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/session-invalidation', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'enabled' => true, + ]); + $this->assertTrue($response['body']['authInvalidateSessions']); + + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => 'console', + ], $this->getHeaders())); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertTrue($response['body']['authInvalidateSessions']); return $data; } From c4e78613588b9a6b8f2716d90868099a87d87e01 Mon Sep 17 00:00:00 2001 From: Darshan Date: Tue, 17 Jun 2025 09:25:58 +0530 Subject: [PATCH 18/40] update: send only the relevant errors info to frontend. --- src/Appwrite/Utopia/Response/Model/Migration.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Appwrite/Utopia/Response/Model/Migration.php b/src/Appwrite/Utopia/Response/Model/Migration.php index c74e2fb2aa..508eab92a3 100644 --- a/src/Appwrite/Utopia/Response/Model/Migration.php +++ b/src/Appwrite/Utopia/Response/Model/Migration.php @@ -119,12 +119,19 @@ class Migration extends Model foreach ($errors as $error) { $decoded = json_decode($error, true); + // frontend doesn't need too many details. if (is_array($decoded) && isset($decoded['trace'])) { - unset($decoded['trace']); + unset( + $decoded['trace'], + $decoded['resourceId'], + $decoded['resourceName'], + $decoded['resourceGroup'] + ); $errors[] = json_encode($decoded); } } + // errors now only have code and message. $document->setAttribute('errors', $errors); return $document; From f31a7c007e1cae2132e5888b98d9e888510fb699 Mon Sep 17 00:00:00 2001 From: Darshan Date: Tue, 17 Jun 2025 09:47:58 +0530 Subject: [PATCH 19/40] fix: errors not being replaced but appended. --- src/Appwrite/Utopia/Response/Model/Migration.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Appwrite/Utopia/Response/Model/Migration.php b/src/Appwrite/Utopia/Response/Model/Migration.php index 508eab92a3..9027d55980 100644 --- a/src/Appwrite/Utopia/Response/Model/Migration.php +++ b/src/Appwrite/Utopia/Response/Model/Migration.php @@ -116,18 +116,19 @@ class Migration extends Model return $document; } - foreach ($errors as $error) { + foreach ($errors as $index => $error) { $decoded = json_decode($error, true); // frontend doesn't need too many details. - if (is_array($decoded) && isset($decoded['trace'])) { + if (is_array($decoded)) { unset( $decoded['trace'], $decoded['resourceId'], $decoded['resourceName'], $decoded['resourceGroup'] ); - $errors[] = json_encode($decoded); + + $errors[$index] = json_encode($decoded); } } From 149ad1a0f38560f0476c87c02b73bb3c94114002 Mon Sep 17 00:00:00 2001 From: Darshan Date: Tue, 17 Jun 2025 10:11:23 +0530 Subject: [PATCH 20/40] update: simplify filtering. --- src/Appwrite/Utopia/Response/Model/Migration.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/Appwrite/Utopia/Response/Model/Migration.php b/src/Appwrite/Utopia/Response/Model/Migration.php index 9027d55980..76e00b3097 100644 --- a/src/Appwrite/Utopia/Response/Model/Migration.php +++ b/src/Appwrite/Utopia/Response/Model/Migration.php @@ -121,14 +121,10 @@ class Migration extends Model // frontend doesn't need too many details. if (is_array($decoded)) { - unset( - $decoded['trace'], - $decoded['resourceId'], - $decoded['resourceName'], - $decoded['resourceGroup'] - ); - - $errors[$index] = json_encode($decoded); + $errors[$index] = json_encode([ + 'code' => $decoded['code'] ?? 0, + 'message' => $decoded['message'] ?? null, + ]); } } From 1fbbbee31012d5d0a430f24b6f522372af957c10 Mon Sep 17 00:00:00 2001 From: Darshan Date: Tue, 17 Jun 2025 15:01:13 +0530 Subject: [PATCH 21/40] update: add cached logic to `processDocument`. --- .../Collections/Documents/Action.php | 93 +++++++++++++++++++ .../Collections/Documents/Create.php | 39 +------- .../Collections/Documents/Delete.php | 38 +------- .../Databases/Collections/Documents/Get.php | 52 ++--------- .../Collections/Documents/Update.php | 37 +------- .../Collections/Documents/Upsert.php | 37 +------- .../Databases/Collections/Documents/XList.php | 66 ++----------- 7 files changed, 126 insertions(+), 236 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Action.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Action.php index c0e71d3730..32e26bb344 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Action.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Action.php @@ -4,6 +4,9 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Documen use Appwrite\Extend\Exception; use Appwrite\Platform\Modules\Databases\Context; +use Utopia\Database\Database; +use Utopia\Database\Document; +use Utopia\Database\Validator\Authorization; use Utopia\Platform\Action as UtopiaAction; abstract class Action extends UtopiaAction @@ -193,4 +196,94 @@ abstract class Action extends UtopiaAction { return $this->isCollectionsAPI() ? 'collection' : 'table'; } + + /** + * Resolves relationships in a document and attaches metadata. + */ + final protected function resolveDocumentRelations(Document $document, Document $collection, array &$context): bool + { + /* @type Document $database */ + $database = $context['database']; + + /* @type Database $dbForProject */ + $dbForProject = $context['dbForProject']; + + /* remove `$collection` if needed */ + $removeCollection = $context['removeCollection'] ?? false; + + /* count operations and use `continue` inside loop */ + $trackOperations = array_key_exists('trackOperations', $context); + + if (!$trackOperations) { + $context['operations'] ??= 0; + } elseif ($document->isEmpty()) { + return false; + } + + $operations = &$context['operations']; + $collectionsCache = &$context['collectionsCache']; + + $operations++; + $collectionId = $collection->getId(); + + $document->setAttribute('$databaseId', $database->getId()); + $document->setAttribute('$collectionId', $collectionId); + + if ($removeCollection) { + $document->removeAttribute('$collection'); + } + + $relationships = $collectionsCache[$collectionId] ??= \array_filter( + $collection->getAttribute('attributes', []), + fn ($attr) => $attr->getAttribute('type') === Database::VAR_RELATIONSHIP + ); + + foreach ($relationships as $relationship) { + $key = $relationship->getAttribute('key'); + $related = $document->getAttribute($key); + + if (empty($related)) { + if (\in_array(\gettype($related), ['array', 'object'])) { + $operations++; + } + continue; + } + + $relations = \is_array($related) ? $related : [$related]; + $relatedCollectionId = $relationship->getAttribute('relatedCollection'); + + if (!isset($collectionsCache[$relatedCollectionId])) { + $relatedCollectionDoc = Authorization::skip( + fn () => $dbForProject->getDocument( + 'database_' . $database->getSequence(), + $relatedCollectionId + ) + ); + + $collectionsCache[$relatedCollectionId] = \array_filter( + $relatedCollectionDoc->getAttribute('attributes', []), + fn ($attr) => $attr->getAttribute('type') === Database::VAR_RELATIONSHIP + ); + } + + foreach ($relations as $index => $relation) { + if ($relation instanceof Document) { + $relatedCollection = new Document([ + '$id' => $relatedCollectionId, + 'attributes' => $collectionsCache[$relatedCollectionId], + ]); + + $this->resolveDocumentRelations(document: $relation, collection: $relatedCollection, context: $context); + } + } + + if (\is_array($related)) { + $document->setAttribute($relationship->getAttribute('key'), \array_values($relations)); + } elseif (empty($relations)) { + $document->setAttribute($relationship->getAttribute('key'), null); + } + } + + return true; + } } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Create.php index 6005495a68..47c6acf0b7 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Create.php @@ -373,42 +373,13 @@ class Create extends Action ->setParam('tableId', $collection->getId()) ->setContext($this->getCollectionsEventsContext(), $collection); - // Add $collectionId and $databaseId for all documents - $processDocument = function (Document $table, Document $document) use (&$processDocument, $dbForProject, $database) { - $document->removeAttribute('$collection'); - $document->setAttribute('$databaseId', $database->getId()); - $document->setAttribute('$collectionId', $table->getId()); - - $relationships = \array_filter( - $table->getAttribute('attributes', []), - fn ($attribute) => $attribute->getAttribute('type') === Database::VAR_RELATIONSHIP - ); - - foreach ($relationships as $relationship) { - $related = $document->getAttribute($relationship->getAttribute('key')); - - if (empty($related)) { - continue; - } - if (!\is_array($related)) { - $related = [$related]; - } - - $relatedCollectionId = $relationship->getAttribute('relatedCollection'); - $relatedCollection = Authorization::skip( - fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $relatedCollectionId) - ); - - foreach ($related as $relation) { - if ($relation instanceof Document) { - $processDocument($relatedCollection, $relation); - } - } - } - }; + $collectionsCache = []; + $removeCollection = true; + $context = compact('database', 'dbForProject', 'collectionsCache', 'removeCollection'); foreach ($documents as $document) { - $processDocument($collection, $document); + // Add $collectionId and $databaseId for all documents + $this->resolveDocumentRelations(document: $document, collection: $collection, context: $context); } $queueForStatsUsage diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Delete.php index dc307071e4..9f1f27b1f8 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Delete.php @@ -12,7 +12,6 @@ use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; -use Utopia\Database\Document; use Utopia\Database\Exception\Conflict as ConflictException; use Utopia\Database\Exception\Restricted as RestrictedException; use Utopia\Database\Validator\Authorization; @@ -115,40 +114,11 @@ class Delete extends Action throw new Exception($this->getRestrictedException()); } + $collectionsCache = []; + $context = compact('database', 'dbForProject', 'collectionsCache'); + // Add $collection and $databaseId for all documents - $processDocument = function (Document $collection, Document $document) use (&$processDocument, $dbForProject, $database) { - $document->setAttribute('$databaseId', $database->getId()); - $document->setAttribute('$collectionId', $collection->getId()); - - $relationships = \array_filter( - $collection->getAttribute('attributes', []), - fn ($attribute) => $attribute->getAttribute('type') === Database::VAR_RELATIONSHIP - ); - - foreach ($relationships as $relationship) { - $related = $document->getAttribute($relationship->getAttribute('key')); - - if (empty($related)) { - continue; - } - if (!\is_array($related)) { - $related = [$related]; - } - - $relatedCollectionId = $relationship->getAttribute('relatedCollection'); - $relatedCollection = Authorization::skip( - fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $relatedCollectionId) - ); - - foreach ($related as $relation) { - if ($relation instanceof Document) { - $processDocument($relatedCollection, $relation); - } - } - } - }; - - $processDocument($collection, $document); + $this->resolveDocumentRelations(document: $document, collection: $collection, context: $context); $queueForStatsUsage ->addMetric(METRIC_DATABASES_OPERATIONS_WRITES, 1) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Get.php index 3f7f74ee75..bf1acb8086 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Get.php @@ -11,7 +11,6 @@ use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; -use Utopia\Database\Document; use Utopia\Database\Exception\Query as QueryException; use Utopia\Database\Query; use Utopia\Database\Validator\Authorization; @@ -101,52 +100,15 @@ class Get extends Action } $operations = 0; + $collectionsCache = []; + $trackOperations = true; + $context = compact('database', 'dbForProject', 'operations', 'trackOperations', 'collectionsCache'); - // Add $collectionId and $databaseId for all rows - $processDocument = function (Document $collection, Document $document) use (&$processDocument, $dbForProject, $database, &$operations) { - if ($document->isEmpty()) { - return; - } + // Add $collectionId and $databaseId for all documents + $this->resolveDocumentRelations(document: $document, collection: $collection, context: $context); - $operations++; - - $document->setAttribute('$databaseId', $database->getId()); - $document->setAttribute('$collectionId', $collection->getId()); - - $relationships = \array_filter( - $collection->getAttribute('attributes', []), - fn ($attribute) => $attribute->getAttribute('type') === Database::VAR_RELATIONSHIP - ); - - foreach ($relationships as $relationship) { - $related = $document->getAttribute($relationship->getAttribute('key')); - - if (empty($related)) { - if (\in_array(\gettype($related), ['array', 'object'])) { - $operations++; - } - - continue; - } - - if (!\is_array($related)) { - $related = [$related]; - } - - $relatedCollectionId = $relationship->getAttribute('relatedCollection'); - $relatedCollection = Authorization::skip( - fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $relatedCollectionId) - ); - - foreach ($related as $relation) { - if ($relation instanceof Document) { - $processDocument($relatedCollection, $relation); - } - } - } - }; - - $processDocument($collection, $document); + // get updated from the context + $operations = $context['operations']; $queueForStatsUsage ->addMetric(METRIC_DATABASES_OPERATIONS_READS, max($operations, 1)) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Update.php index 3bc97e817b..b946731c7a 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Update.php @@ -247,40 +247,11 @@ class Update extends Action throw new Exception($this->getInvalidStructureException(), $e->getMessage()); } + $collectionsCache = []; + $context = compact('database', 'dbForProject', 'collectionsCache'); + // Add $collectionId and $databaseId for all documents - $processDocument = function (Document $table, Document $row) use (&$processDocument, $dbForProject, $database) { - $row->setAttribute('$databaseId', $database->getId()); - $row->setAttribute('$collectionId', $table->getId()); - - $relationships = \array_filter( - $table->getAttribute('attributes', []), - fn ($attribute) => $attribute->getAttribute('type') === Database::VAR_RELATIONSHIP - ); - - foreach ($relationships as $relationship) { - $related = $row->getAttribute($relationship->getAttribute('key')); - - if (empty($related)) { - continue; - } - if (!\is_array($related)) { - $related = [$related]; - } - - $relatedCollectionId = $relationship->getAttribute('relatedCollection'); - $relatedCollection = Authorization::skip( - fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $relatedCollectionId) - ); - - foreach ($related as $relation) { - if ($relation instanceof Document) { - $processDocument($relatedCollection, $relation); - } - } - } - }; - - $processDocument($collection, $document); + $this->resolveDocumentRelations(document: $document, collection: $collection, context: $context); $response->dynamic($document, $this->getResponseModel()); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Upsert.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Upsert.php index ebe30f6970..d27ff632b8 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Upsert.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Upsert.php @@ -235,41 +235,12 @@ class Upsert extends Action throw new Exception($this->getInvalidStructureException(), $e->getMessage()); } + $collectionsCache = []; $document = $upserted[0]; + $context = compact('database', 'dbForProject', 'collectionsCache'); + // Add $collectionId and $databaseId for all documents - $processDocument = function (Document $table, Document $document) use (&$processDocument, $dbForProject, $database) { - $document->setAttribute('$databaseId', $database->getId()); - $document->setAttribute('$collectionId', $table->getId()); - - $relationships = \array_filter( - $table->getAttribute('attributes', []), - fn ($attribute) => $attribute->getAttribute('type') === Database::VAR_RELATIONSHIP - ); - - foreach ($relationships as $relationship) { - $related = $document->getAttribute($relationship->getAttribute('key')); - - if (empty($related)) { - continue; - } - if (!\is_array($related)) { - $related = [$related]; - } - - $relatedCollectionId = $relationship->getAttribute('relatedCollection'); - $relatedCollection = Authorization::skip( - fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $relatedCollectionId) - ); - - foreach ($related as $relation) { - if ($relation instanceof Document) { - $processDocument($relatedCollection, $relation); - } - } - } - }; - - $processDocument($collection, $document); + $this->resolveDocumentRelations(document: $document, collection: $collection, context: $context); $relationships = \array_map( fn ($document) => $document->getAttribute('key'), diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/XList.php index 0012b8339a..b87efe42de 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/XList.php @@ -130,67 +130,19 @@ class XList extends Action } $operations = 0; + $collectionsCache = []; + $trackOperations = true; + $removeCollection = true; + $context = compact('database', 'dbForProject', 'operations', 'collectionsCache', 'removeCollection', 'trackOperations'); // Add $collectionId and $databaseId for all documents - $processDocument = (function (Document $collection, Document $document) use (&$processDocument, $dbForProject, $database, &$operations): bool { - if ($document->isEmpty()) { - return false; - } - - $operations++; - - $document->removeAttribute('$collection'); - $document->setAttribute('$databaseId', $database->getId()); - $document->setAttribute('$collectionId', $collection->getId()); - - $relationships = \array_filter( - $collection->getAttribute('attributes', []), - fn ($attribute) => $attribute->getAttribute('type') === Database::VAR_RELATIONSHIP - ); - - foreach ($relationships as $relationship) { - $related = $document->getAttribute($relationship->getAttribute('key')); - - if (empty($related)) { - if (\in_array(\gettype($related), ['array', 'object'])) { - $operations++; - } - - continue; - } - - if (!\is_array($related)) { - $relations = [$related]; - } else { - $relations = $related; - } - - $relatedCollectionId = $relationship->getAttribute('relatedCollection'); - // todo: Use local cache for this getDocument - $relatedCollection = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $relatedCollectionId)); - - foreach ($relations as $index => $doc) { - if ($doc instanceof Document) { - if (!$processDocument($relatedCollection, $doc)) { - unset($relations[$index]); - } - } - } - - if (\is_array($related)) { - $document->setAttribute($relationship->getAttribute('key'), \array_values($relations)); - } elseif (empty($relations)) { - $document->setAttribute($relationship->getAttribute('key'), null); - } - } - - return true; - }); - - foreach ($documents as $row) { - $processDocument($collection, $row); + foreach ($documents as $document) { + $this->resolveDocumentRelations(document: $document, collection: $collection, context: $context); } + // get updated from the context + $operations = $context['operations']; + $queueForStatsUsage ->addMetric(METRIC_DATABASES_OPERATIONS_READS, max($operations, 1)) ->addMetric(str_replace('{databaseInternalId}', $database->getSequence(), METRIC_DATABASE_ID_OPERATIONS_READS), $operations); From 16a87535097292cad4e395def4a3ba467b89be38 Mon Sep 17 00:00:00 2001 From: Darshan Date: Tue, 17 Jun 2025 15:03:11 +0530 Subject: [PATCH 22/40] update: comment. --- .../Databases/Http/Databases/Collections/Documents/Action.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Action.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Action.php index 32e26bb344..d5e7d84695 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Action.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Action.php @@ -211,7 +211,7 @@ abstract class Action extends UtopiaAction /* remove `$collection` if needed */ $removeCollection = $context['removeCollection'] ?? false; - /* count operations and use `continue` inside loop */ + /* count operations inside loop */ $trackOperations = array_key_exists('trackOperations', $context); if (!$trackOperations) { From cc0dfd9e699b71f98d7f032add84985a72ca5d8b Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Tue, 17 Jun 2025 15:20:53 -0400 Subject: [PATCH 23/40] Revert "Update delete project scope" --- src/Appwrite/Platform/Workers/Deletes.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Workers/Deletes.php b/src/Appwrite/Platform/Workers/Deletes.php index 4e7fa1885a..43bc55583d 100644 --- a/src/Appwrite/Platform/Workers/Deletes.php +++ b/src/Appwrite/Platform/Workers/Deletes.php @@ -495,7 +495,7 @@ class Deletes extends Action * @throws Authorization * @throws DatabaseException */ - protected function deleteProject(Database $dbForPlatform, callable $getProjectDB, Device $deviceForFiles, Device $deviceForSites, Device $deviceForFunctions, Device $deviceForBuilds, Device $deviceForCache, CertificatesAdapter $certificates, Document $document): void + private function deleteProject(Database $dbForPlatform, callable $getProjectDB, Device $deviceForFiles, Device $deviceForSites, Device $deviceForFunctions, Device $deviceForBuilds, Device $deviceForCache, CertificatesAdapter $certificates, Document $document): void { $projectInternalId = $document->getInternalId(); $projectId = $document->getId(); From 8d62ada545ea072aa72447a242f3600f07734601 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Wed, 18 Jun 2025 10:54:26 +0530 Subject: [PATCH 24/40] updated example of the authInvalidateSession --- src/Appwrite/Utopia/Response/Model/Project.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Utopia/Response/Model/Project.php b/src/Appwrite/Utopia/Response/Model/Project.php index ef50d81c31..abe67e7e86 100644 --- a/src/Appwrite/Utopia/Response/Model/Project.php +++ b/src/Appwrite/Utopia/Response/Model/Project.php @@ -173,7 +173,7 @@ class Project extends Model 'type' => self::TYPE_BOOLEAN, 'description' => 'Whether or not all existing sessions should be invalidated on password change', 'default' => false, - 'example' => self::TYPE_BOOLEAN, + 'example' => true, ]) ->addRule('oAuthProviders', [ 'type' => Response::MODEL_AUTH_PROVIDER, From d6bf748a079682546a19efa54945cd110f0aee8d Mon Sep 17 00:00:00 2001 From: Darshan Date: Wed, 18 Jun 2025 12:00:19 +0530 Subject: [PATCH 25/40] address comments. --- .../Collections/Documents/Action.php | 51 +++++++++---------- .../Collections/Documents/Create.php | 12 +++-- .../Collections/Documents/Delete.php | 11 ++-- .../Databases/Collections/Documents/Get.php | 16 +++--- .../Collections/Documents/Update.php | 11 ++-- .../Collections/Documents/Upsert.php | 11 ++-- .../Databases/Collections/Documents/XList.php | 17 +++---- 7 files changed, 69 insertions(+), 60 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Action.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Action.php index d5e7d84695..52dfc62f50 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Action.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Action.php @@ -200,39 +200,31 @@ abstract class Action extends UtopiaAction /** * Resolves relationships in a document and attaches metadata. */ - final protected function resolveDocumentRelations(Document $document, Document $collection, array &$context): bool - { - /* @type Document $database */ - $database = $context['database']; + final protected function processDocument( + /* database */ + Document $database, + Document $collection, + Document $document, + Database $dbForProject, - /* @type Database $dbForProject */ - $dbForProject = $context['dbForProject']; + /* options */ + array &$collectionsCache, + ?int &$operations = null, + ): bool { - /* remove `$collection` if needed */ - $removeCollection = $context['removeCollection'] ?? false; - - /* count operations inside loop */ - $trackOperations = array_key_exists('trackOperations', $context); - - if (!$trackOperations) { - $context['operations'] ??= 0; - } elseif ($document->isEmpty()) { + if ($operations !== null && $document->isEmpty()) { return false; } - $operations = &$context['operations']; - $collectionsCache = &$context['collectionsCache']; + if ($operations !== null) { + $operations++; + } - $operations++; $collectionId = $collection->getId(); - + $document->removeAttribute('$collection'); $document->setAttribute('$databaseId', $database->getId()); $document->setAttribute('$collectionId', $collectionId); - if ($removeCollection) { - $document->removeAttribute('$collection'); - } - $relationships = $collectionsCache[$collectionId] ??= \array_filter( $collection->getAttribute('attributes', []), fn ($attr) => $attr->getAttribute('type') === Database::VAR_RELATIONSHIP @@ -243,7 +235,7 @@ abstract class Action extends UtopiaAction $related = $document->getAttribute($key); if (empty($related)) { - if (\in_array(\gettype($related), ['array', 'object'])) { + if (\in_array(\gettype($related), ['array', 'object']) && $operations !== null) { $operations++; } continue; @@ -266,14 +258,21 @@ abstract class Action extends UtopiaAction ); } - foreach ($relations as $index => $relation) { + foreach ($relations as $relation) { if ($relation instanceof Document) { $relatedCollection = new Document([ '$id' => $relatedCollectionId, 'attributes' => $collectionsCache[$relatedCollectionId], ]); - $this->resolveDocumentRelations(document: $relation, collection: $relatedCollection, context: $context); + $this->processDocument( + database: $database, + collection: $relatedCollection, + document: $relation, + dbForProject: $dbForProject, + collectionsCache: $collectionsCache, + operations: $operations + ); } } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Create.php index 47c6acf0b7..ebab4a7ece 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Create.php @@ -374,12 +374,14 @@ class Create extends Action ->setContext($this->getCollectionsEventsContext(), $collection); $collectionsCache = []; - $removeCollection = true; - $context = compact('database', 'dbForProject', 'collectionsCache', 'removeCollection'); - foreach ($documents as $document) { - // Add $collectionId and $databaseId for all documents - $this->resolveDocumentRelations(document: $document, collection: $collection, context: $context); + $this->processDocument( + database: $database, + collection: $collection, + document: $document, + dbForProject: $dbForProject, + collectionsCache: $collectionsCache, + ); } $queueForStatsUsage diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Delete.php index 9f1f27b1f8..d8ec82910c 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Delete.php @@ -115,10 +115,13 @@ class Delete extends Action } $collectionsCache = []; - $context = compact('database', 'dbForProject', 'collectionsCache'); - - // Add $collection and $databaseId for all documents - $this->resolveDocumentRelations(document: $document, collection: $collection, context: $context); + $this->processDocument( + database: $database, + collection: $collection, + document: $document, + dbForProject: $dbForProject, + collectionsCache: $collectionsCache, + ); $queueForStatsUsage ->addMetric(METRIC_DATABASES_OPERATIONS_WRITES, 1) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Get.php index bf1acb8086..fe40a2412f 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Get.php @@ -101,14 +101,14 @@ class Get extends Action $operations = 0; $collectionsCache = []; - $trackOperations = true; - $context = compact('database', 'dbForProject', 'operations', 'trackOperations', 'collectionsCache'); - - // Add $collectionId and $databaseId for all documents - $this->resolveDocumentRelations(document: $document, collection: $collection, context: $context); - - // get updated from the context - $operations = $context['operations']; + $this->processDocument( + database: $database, + collection: $collection, + document: $document, + dbForProject: $dbForProject, + collectionsCache: $collectionsCache, + operations: $operations + ); $queueForStatsUsage ->addMetric(METRIC_DATABASES_OPERATIONS_READS, max($operations, 1)) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Update.php index b946731c7a..c39eeea707 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Update.php @@ -248,10 +248,13 @@ class Update extends Action } $collectionsCache = []; - $context = compact('database', 'dbForProject', 'collectionsCache'); - - // Add $collectionId and $databaseId for all documents - $this->resolveDocumentRelations(document: $document, collection: $collection, context: $context); + $this->processDocument( + database: $database, + collection: $collection, + document: $document, + dbForProject: $dbForProject, + collectionsCache: $collectionsCache, + ); $response->dynamic($document, $this->getResponseModel()); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Upsert.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Upsert.php index d27ff632b8..fa632c7b2b 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Upsert.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Upsert.php @@ -237,10 +237,13 @@ class Upsert extends Action $collectionsCache = []; $document = $upserted[0]; - $context = compact('database', 'dbForProject', 'collectionsCache'); - - // Add $collectionId and $databaseId for all documents - $this->resolveDocumentRelations(document: $document, collection: $collection, context: $context); + $this->processDocument( + database: $database, + collection: $collection, + document: $document, + dbForProject: $dbForProject, + collectionsCache: $collectionsCache, + ); $relationships = \array_map( fn ($document) => $document->getAttribute('key'), diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/XList.php index b87efe42de..9aad8f4b77 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/XList.php @@ -131,18 +131,17 @@ class XList extends Action $operations = 0; $collectionsCache = []; - $trackOperations = true; - $removeCollection = true; - $context = compact('database', 'dbForProject', 'operations', 'collectionsCache', 'removeCollection', 'trackOperations'); - - // Add $collectionId and $databaseId for all documents foreach ($documents as $document) { - $this->resolveDocumentRelations(document: $document, collection: $collection, context: $context); + $this->processDocument( + database: $database, + collection: $collection, + document: $document, + dbForProject: $dbForProject, + collectionsCache: $collectionsCache, + operations: $operations, + ); } - // get updated from the context - $operations = $context['operations']; - $queueForStatsUsage ->addMetric(METRIC_DATABASES_OPERATIONS_READS, max($operations, 1)) ->addMetric(str_replace('{databaseInternalId}', $database->getSequence(), METRIC_DATABASE_ID_OPERATIONS_READS), $operations); From d69189bd55317fe5b31bce211669e24be6991c74 Mon Sep 17 00:00:00 2001 From: Darshan Date: Wed, 18 Jun 2025 12:02:08 +0530 Subject: [PATCH 26/40] ci: empty commit From 56494ca427f39e9baf1a646a5e1fafc4fff5aafe Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Wed, 18 Jun 2025 13:30:24 +0530 Subject: [PATCH 27/40] updated invalidation session during the change password in the account endpoint --- app/controllers/api/account.php | 9 ++++++ .../Account/AccountCustomClientTest.php | 29 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 0c53423325..1030a30e93 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -2843,6 +2843,15 @@ App::patch('/v1/account/password') ->setAttribute('hash', Auth::DEFAULT_ALGO) ->setAttribute('hashOptions', Auth::DEFAULT_ALGO_OPTIONS); + $sessions = $user->getAttribute('sessions', []); + $current = Auth::sessionVerify($sessions, Auth::$secret); + foreach ($sessions as $session) { + /** @var Document $session */ + if ($session->getId() !== $current) { + $dbForProject->deleteDocument('sessions', $session->getId()); + } + } + $user = $dbForProject->updateDocument('users', $user->getId(), $user); $queueForEvents->setParam('userId', $user->getId()); diff --git a/tests/e2e/Services/Account/AccountCustomClientTest.php b/tests/e2e/Services/Account/AccountCustomClientTest.php index 0cc2eb893a..f99b3a42a2 100644 --- a/tests/e2e/Services/Account/AccountCustomClientTest.php +++ b/tests/e2e/Services/Account/AccountCustomClientTest.php @@ -480,6 +480,20 @@ class AccountCustomClientTest extends Scope $password = $data['password'] ?? ''; $session = $data['session'] ?? ''; + for ($i = 0; $i < 5; $i++) { + $response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ]), [ + 'email' => $email, + 'password' => $password, + ]); + + $this->assertEquals(201, $response['headers']['status-code']); + sleep(1); + } + /** * Test for SUCCESS */ @@ -500,6 +514,21 @@ class AccountCustomClientTest extends Scope $this->assertTrue((new DatetimeValidator())->isValid($response['body']['registration'])); $this->assertEquals($response['body']['email'], $email); + // checking for all non active sessions are cleared + $sessionId = $data['sessionId'] ?? ''; + $response = $this->client->call(Client::METHOD_GET, '/account/sessions', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session, + ])); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals(1, $response['body']['total']); + // checking the current session or not + $this->assertEquals($sessionId, $response['body']['sessions'][0]['$id']); + $this->assertTrue($response['body']['sessions'][0]['current']); + $response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', From 225b6e841302999db5e7ef9c93c801bce100db24 Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Thu, 19 Jun 2025 02:26:58 +0530 Subject: [PATCH 28/40] updated tests and project invaldate session --- app/controllers/api/account.php | 11 +- .../Account/AccountCustomClientTest.php | 119 ++++++++++++++++-- 2 files changed, 119 insertions(+), 11 deletions(-) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 1030a30e93..d8e3be443d 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -2845,10 +2845,13 @@ App::patch('/v1/account/password') $sessions = $user->getAttribute('sessions', []); $current = Auth::sessionVerify($sessions, Auth::$secret); - foreach ($sessions as $session) { - /** @var Document $session */ - if ($session->getId() !== $current) { - $dbForProject->deleteDocument('sessions', $session->getId()); + $invalidate = $project->getAttribute('auths', default: [])['invalidateSessions'] ?? false; + if ($invalidate && !empty($current)) { + foreach ($sessions as $session) { + /** @var Document $session */ + if ($session->getId() !== $current) { + $dbForProject->deleteDocument('sessions', $session->getId()); + } } } diff --git a/tests/e2e/Services/Account/AccountCustomClientTest.php b/tests/e2e/Services/Account/AccountCustomClientTest.php index f99b3a42a2..9e75106606 100644 --- a/tests/e2e/Services/Account/AccountCustomClientTest.php +++ b/tests/e2e/Services/Account/AccountCustomClientTest.php @@ -494,6 +494,15 @@ class AccountCustomClientTest extends Scope sleep(1); } + $response = $this->client->call(Client::METHOD_GET, '/account/sessions', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session, + ])); + + $allSessions = array_map(fn ($sessionDetails) => $sessionDetails['$id'], $response['body']['sessions']); + /** * Test for SUCCESS */ @@ -514,8 +523,7 @@ class AccountCustomClientTest extends Scope $this->assertTrue((new DatetimeValidator())->isValid($response['body']['registration'])); $this->assertEquals($response['body']['email'], $email); - // checking for all non active sessions are cleared - $sessionId = $data['sessionId'] ?? ''; + $currentSessionId = $data['sessionId'] ?? ''; $response = $this->client->call(Client::METHOD_GET, '/account/sessions', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', @@ -526,19 +534,116 @@ class AccountCustomClientTest extends Scope $this->assertEquals(200, $response['headers']['status-code']); $this->assertEquals(1, $response['body']['total']); // checking the current session or not - $this->assertEquals($sessionId, $response['body']['sessions'][0]['$id']); + $this->assertEquals($currentSessionId, $response['body']['sessions'][0]['$id']); $this->assertTrue($response['body']['sessions'][0]['current']); - $response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', array_merge([ + // checking for all non active sessions are cleared + foreach ($allSessions as $sessionId) { + if ($currentSessionId === $sessionId) { + $response = $this->client->call(Client::METHOD_GET, '/account/sessions/current', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session, + ])); + + $this->assertEquals(200, $response['headers']['status-code']); + } else { + $response = $this->client->call(Client::METHOD_GET, '/account/sessions/'.$sessionId, array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session, + ])); + + $this->assertEquals(404, $response['headers']['status-code']); + } + } + + $newPassword = 'new-password'; + // updating the invalidateSession to false to check sessions are not invalidated + $this->updateProjectinvalidateSessionsProperty(false); + for ($i = 0; $i < 5; $i++) { + $response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ]), [ + 'email' => $email, + 'password' => $newPassword, + ]); + + $this->assertEquals(201, $response['headers']['status-code']); + sleep(1); + } + + $response = $this->client->call(Client::METHOD_GET, '/account/sessions', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], + 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session, + ])); + + $allSessions = array_map(fn ($sessionDetails) => $sessionDetails['$id'], $response['body']['sessions']); + + $response = $this->client->call(Client::METHOD_PATCH, '/account/password', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session, ]), [ - 'email' => $email, - 'password' => 'new-password', + 'password' => $newPassword, + 'oldPassword' => $newPassword, ]); - $this->assertEquals(201, $response['headers']['status-code']); + $this->assertEquals(200, $response['headers']['status-code']); + + foreach ($allSessions as $sessionId) { + $response = $this->client->call(Client::METHOD_GET, '/account/sessions/'.$sessionId, headers: array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session, + ])); + + $this->assertEquals(200, $response['headers']['status-code']); + } + + // setting invalidateSession to true to check the sessions are cleared or not + $this->updateProjectinvalidateSessionsProperty(true); + $response = $this->client->call(Client::METHOD_PATCH, '/account/password', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session, + ]), [ + 'password' => $newPassword, + 'oldPassword' => $newPassword, + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_GET, '/account/sessions', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session, + ])); + + $allSessions = array_map(fn ($sessionDetails) => $sessionDetails['$id'], $response['body']['sessions']); + + foreach ($allSessions as $sessionId) { + if ($currentSessionId !== $sessionId) { + $response = $this->client->call(Client::METHOD_GET, '/account/sessions/'.$sessionId, array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session, + ])); + + $this->assertEquals(404, $response['headers']['status-code']); + } + } /** * Test for FAILURE From d053282bcbe0c3fc5ab7f1515419b625190531ee Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Thu, 19 Jun 2025 02:29:21 +0530 Subject: [PATCH 29/40] linting --- .../e2e/Services/Account/AccountCustomClientTest.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/e2e/Services/Account/AccountCustomClientTest.php b/tests/e2e/Services/Account/AccountCustomClientTest.php index 9e75106606..b114a54c30 100644 --- a/tests/e2e/Services/Account/AccountCustomClientTest.php +++ b/tests/e2e/Services/Account/AccountCustomClientTest.php @@ -645,6 +645,18 @@ class AccountCustomClientTest extends Scope } } + $response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ]), [ + 'email' => $email, + 'password' => $newPassword, + ]); + + $this->assertEquals(201, $response['headers']['status-code']); + + /** * Test for FAILURE */ From c93d92abef22927abdd3a7be942f1c2ecddbabc9 Mon Sep 17 00:00:00 2001 From: Darshan Date: Thu, 19 Jun 2025 10:52:15 +0530 Subject: [PATCH 30/40] rename: tests from `collections` to `legacy`. --- .github/workflows/tests.yml | 4 ++-- .../Databases/{Collections => Legacy}/DatabasesBase.php | 2 +- .../{Collections => Legacy}/DatabasesConsoleClientTest.php | 2 +- .../{Collections => Legacy}/DatabasesCustomClientTest.php | 2 +- .../{Collections => Legacy}/DatabasesCustomServerTest.php | 2 +- .../{Collections => Legacy}/DatabasesPermissionsGuestTest.php | 2 +- .../DatabasesPermissionsMemberTest.php | 2 +- .../{Collections => Legacy}/DatabasesPermissionsScope.php | 2 +- .../{Collections => Legacy}/DatabasesPermissionsTeamTest.php | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) rename tests/e2e/Services/Databases/{Collections => Legacy}/DatabasesBase.php (99%) rename tests/e2e/Services/Databases/{Collections => Legacy}/DatabasesConsoleClientTest.php (99%) rename tests/e2e/Services/Databases/{Collections => Legacy}/DatabasesCustomClientTest.php (99%) rename tests/e2e/Services/Databases/{Collections => Legacy}/DatabasesCustomServerTest.php (99%) rename tests/e2e/Services/Databases/{Collections => Legacy}/DatabasesPermissionsGuestTest.php (99%) rename tests/e2e/Services/Databases/{Collections => Legacy}/DatabasesPermissionsMemberTest.php (99%) rename tests/e2e/Services/Databases/{Collections => Legacy}/DatabasesPermissionsScope.php (98%) rename tests/e2e/Services/Databases/{Collections => Legacy}/DatabasesPermissionsTeamTest.php (99%) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index cf1e55f7ec..766b295fff 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -145,7 +145,7 @@ jobs: Account, Avatars, Console, - Databases/Collections, + Databases/Legacy, Databases/Tables, Functions, FunctionsSchedule, @@ -214,7 +214,7 @@ jobs: Account, Avatars, Console, - Databases/Collections, + Databases/Legacy, Databases/Tables, Functions, FunctionsSchedule, diff --git a/tests/e2e/Services/Databases/Collections/DatabasesBase.php b/tests/e2e/Services/Databases/Legacy/DatabasesBase.php similarity index 99% rename from tests/e2e/Services/Databases/Collections/DatabasesBase.php rename to tests/e2e/Services/Databases/Legacy/DatabasesBase.php index 6b0aca1512..69b24d5052 100644 --- a/tests/e2e/Services/Databases/Collections/DatabasesBase.php +++ b/tests/e2e/Services/Databases/Legacy/DatabasesBase.php @@ -1,6 +1,6 @@ Date: Thu, 19 Jun 2025 10:54:56 +0530 Subject: [PATCH 31/40] change: namespace. --- .../Databases/Http/Databases/Collections/Attributes/Action.php | 2 +- .../Databases/Http/Databases/Collections/Documents/Action.php | 2 +- .../Databases/Http/Databases/Collections/Indexes/Action.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Action.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Action.php index 2ee265a18d..b115edbee8 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Action.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Action.php @@ -83,7 +83,7 @@ abstract class Action extends UtopiaAction */ final protected function getSdkNamespace(): string { - return $this->isCollectionsAPI() ? 'collections' : 'tables'; + return $this->isCollectionsAPI() ? 'databases' : 'tables'; } /** diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Action.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Action.php index 52dfc62f50..bd92e233f1 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Action.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Action.php @@ -78,7 +78,7 @@ abstract class Action extends UtopiaAction */ final protected function getSdkNamespace(): string { - return $this->isCollectionsAPI() ? 'collections' : 'tables'; + return $this->isCollectionsAPI() ? 'databases' : 'tables'; } /** diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Action.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Action.php index 4a40ea6b5f..7013259fa7 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Action.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Action.php @@ -71,7 +71,7 @@ abstract class Action extends UtopiaAction */ final protected function getSdkNamespace(): string { - return $this->isCollectionsAPI() ? 'collections' : 'tables'; + return $this->isCollectionsAPI() ? 'databases' : 'tables'; } /** From e5caa856290a5403f0deef25b22edc4193dbe6dc Mon Sep 17 00:00:00 2001 From: Darshan Date: Thu, 19 Jun 2025 11:02:31 +0530 Subject: [PATCH 32/40] update: init with module structure. --- app/controllers/general.php | 14 -------- .../Modules/Databases/Http/Init/Timeout.php | 35 +++++++++++++++++++ .../Modules/Databases/Services/Http.php | 2 ++ 3 files changed, 37 insertions(+), 14 deletions(-) create mode 100644 src/Appwrite/Platform/Modules/Databases/Http/Init/Timeout.php diff --git a/app/controllers/general.php b/app/controllers/general.php index 1872ba82e3..ba5b409a2b 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -1582,20 +1582,6 @@ foreach (Config::getParam('services', []) as $service) { } } -// legacy controller init hooks as the endpoint controller logic is now moved to a module structure. -// 1. databases -App::init() - ->groups(['api', 'database']) - ->inject('request') - ->inject('dbForProject') - ->action(function (Request $request, Database $dbForProject) { - $timeout = \intval($request->getHeader('x-appwrite-timeout')); - - if (!empty($timeout) && App::isDevelopment()) { - $dbForProject->setTimeout($timeout); - } - }); - // Check for any errors found while we were initialising the SDK Methods. if (!empty(Method::getErrors())) { throw new \Exception('Errors found during SDK initialization:' . PHP_EOL . implode(PHP_EOL, Method::getErrors())); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Init/Timeout.php b/src/Appwrite/Platform/Modules/Databases/Http/Init/Timeout.php new file mode 100644 index 0000000000..19e202981b --- /dev/null +++ b/src/Appwrite/Platform/Modules/Databases/Http/Init/Timeout.php @@ -0,0 +1,35 @@ +setType(Action::TYPE_INIT) + ->groups(['api', 'database']) + ->inject('request') + ->inject('dbForProject') + ->callback(function (Request $request, Database $dbForProject) { + $timeout = \intval($request->getHeader('x-appwrite-timeout')); + + if (!empty($timeout) && App::isDevelopment()) { + $dbForProject->setTimeout($timeout); + } + }); + } +} diff --git a/src/Appwrite/Platform/Modules/Databases/Services/Http.php b/src/Appwrite/Platform/Modules/Databases/Services/Http.php index 6c1361b0b1..a877c89345 100644 --- a/src/Appwrite/Platform/Modules/Databases/Services/Http.php +++ b/src/Appwrite/Platform/Modules/Databases/Services/Http.php @@ -2,6 +2,7 @@ namespace Appwrite\Platform\Modules\Databases\Services; +use Appwrite\Platform\Modules\Databases\Http\Init\Timeout; use Appwrite\Platform\Modules\Databases\Services\Registry\Collections as CollectionsRegistry; use Appwrite\Platform\Modules\Databases\Services\Registry\Databases as DatabasesRegistry; use Appwrite\Platform\Modules\Databases\Services\Registry\Tables as TablesRegistry; @@ -14,6 +15,7 @@ class Http extends Service $this->type = Service::TYPE_HTTP; foreach ([ + Timeout::class, DatabasesRegistry::class, CollectionsRegistry::class, TablesRegistry::class, From 1d23e2ec127bf53951f5718b2c4401a89887049a Mon Sep 17 00:00:00 2001 From: Darshan Date: Thu, 19 Jun 2025 14:31:54 +0530 Subject: [PATCH 33/40] remove: `use HTTP`. update: inline context logic. --- .../Platform/Modules/Databases/Constants.php | 24 +++++++++++++++++ .../Platform/Modules/Databases/Context.php | 26 ------------------- .../Http/Databases/Collections/Action.php | 19 +++++--------- .../Collections/Attributes/Action.php | 18 +++++-------- .../Collections/Attributes/Boolean/Create.php | 3 --- .../Collections/Attributes/Boolean/Update.php | 3 --- .../Attributes/Datetime/Create.php | 3 --- .../Attributes/Datetime/Update.php | 3 --- .../Collections/Attributes/Delete.php | 3 --- .../Collections/Attributes/Email/Create.php | 3 --- .../Collections/Attributes/Email/Update.php | 3 --- .../Collections/Attributes/Enum/Create.php | 3 --- .../Collections/Attributes/Enum/Update.php | 3 --- .../Collections/Attributes/Float/Create.php | 3 --- .../Collections/Attributes/Float/Update.php | 3 --- .../Databases/Collections/Attributes/Get.php | 3 --- .../Collections/Attributes/IP/Create.php | 3 --- .../Collections/Attributes/IP/Update.php | 3 --- .../Collections/Attributes/Integer/Create.php | 3 --- .../Collections/Attributes/Integer/Update.php | 3 --- .../Attributes/Relationship/Create.php | 3 --- .../Attributes/Relationship/Update.php | 3 --- .../Collections/Attributes/String/Create.php | 3 --- .../Collections/Attributes/String/Update.php | 3 --- .../Collections/Attributes/URL/Create.php | 3 --- .../Collections/Attributes/URL/Update.php | 3 --- .../Collections/Attributes/XList.php | 3 --- .../Http/Databases/Collections/Create.php | 3 --- .../Http/Databases/Collections/Delete.php | 3 --- .../Collections/Documents/Action.php | 18 +++++-------- .../Documents/Attribute/Decrement.php | 3 --- .../Documents/Attribute/Increment.php | 3 --- .../Collections/Documents/Bulk/Delete.php | 3 --- .../Collections/Documents/Bulk/Update.php | 3 --- .../Collections/Documents/Bulk/Upsert.php | 3 --- .../Collections/Documents/Create.php | 3 --- .../Collections/Documents/Delete.php | 3 --- .../Databases/Collections/Documents/Get.php | 3 --- .../Collections/Documents/Logs/XList.php | 3 --- .../Collections/Documents/Update.php | 3 --- .../Collections/Documents/Upsert.php | 3 --- .../Databases/Collections/Documents/XList.php | 3 --- .../Http/Databases/Collections/Get.php | 3 --- .../Databases/Collections/Indexes/Action.php | 22 +++++----------- .../Databases/Collections/Indexes/Create.php | 3 --- .../Databases/Collections/Indexes/Delete.php | 3 --- .../Databases/Collections/Indexes/Get.php | 3 --- .../Databases/Collections/Indexes/XList.php | 3 --- .../Http/Databases/Collections/Logs/XList.php | 3 --- .../Http/Databases/Collections/Update.php | 3 --- .../Http/Databases/Collections/Usage/Get.php | 3 --- .../Http/Databases/Collections/XList.php | 8 +++--- .../Databases/Http/Databases/Create.php | 3 --- .../Databases/Http/Databases/Delete.php | 3 --- .../Modules/Databases/Http/Databases/Get.php | 3 --- .../Databases/Http/Databases/Logs/XList.php | 3 --- .../Tables/Columns/Boolean/Create.php | 6 ----- .../Tables/Columns/Boolean/Update.php | 6 ----- .../Tables/Columns/Datetime/Create.php | 6 ----- .../Tables/Columns/Datetime/Update.php | 6 ----- .../Http/Databases/Tables/Columns/Delete.php | 6 ----- .../Databases/Tables/Columns/Email/Create.php | 6 ----- .../Databases/Tables/Columns/Email/Update.php | 6 ----- .../Databases/Tables/Columns/Enum/Create.php | 6 ----- .../Databases/Tables/Columns/Enum/Update.php | 6 ----- .../Databases/Tables/Columns/Float/Create.php | 6 ----- .../Databases/Tables/Columns/Float/Update.php | 6 ----- .../Http/Databases/Tables/Columns/Get.php | 6 ----- .../Databases/Tables/Columns/IP/Create.php | 6 ----- .../Databases/Tables/Columns/IP/Update.php | 6 ----- .../Tables/Columns/Integer/Create.php | 6 ----- .../Tables/Columns/Integer/Update.php | 6 ----- .../Tables/Columns/Relationship/Create.php | 6 ----- .../Tables/Columns/Relationship/Update.php | 6 ----- .../Tables/Columns/String/Create.php | 6 ----- .../Tables/Columns/String/Update.php | 6 ----- .../Databases/Tables/Columns/URL/Create.php | 6 ----- .../Databases/Tables/Columns/URL/Update.php | 6 ----- .../Http/Databases/Tables/Columns/XList.php | 6 ----- .../Http/Databases/Tables/Create.php | 6 ----- .../Http/Databases/Tables/Delete.php | 6 ----- .../Databases/Http/Databases/Tables/Get.php | 6 ----- .../Http/Databases/Tables/Indexes/Create.php | 6 ----- .../Http/Databases/Tables/Indexes/Delete.php | 6 ----- .../Http/Databases/Tables/Indexes/Get.php | 6 ----- .../Http/Databases/Tables/Indexes/XList.php | 6 ----- .../Http/Databases/Tables/Logs/XList.php | 6 ----- .../Databases/Tables/Rows/Bulk/Delete.php | 6 ----- .../Databases/Tables/Rows/Bulk/Update.php | 6 ----- .../Databases/Tables/Rows/Bulk/Upsert.php | 6 ----- .../Tables/Rows/Column/Decrement.php | 6 ----- .../Tables/Rows/Column/Increment.php | 6 ----- .../Http/Databases/Tables/Rows/Create.php | 6 ----- .../Http/Databases/Tables/Rows/Delete.php | 6 ----- .../Http/Databases/Tables/Rows/Get.php | 6 ----- .../Http/Databases/Tables/Rows/Logs/XList.php | 6 ----- .../Http/Databases/Tables/Rows/Update.php | 6 ----- .../Http/Databases/Tables/Rows/Upsert.php | 6 ----- .../Http/Databases/Tables/Rows/XList.php | 6 ----- .../Http/Databases/Tables/Update.php | 6 ----- .../Http/Databases/Tables/Usage/Get.php | 6 ----- .../Databases/Http/Databases/Tables/XList.php | 6 ----- .../Databases/Http/Databases/Update.php | 3 --- .../Databases/Http/Databases/Usage/Get.php | 3 --- .../Databases/Http/Databases/Usage/XList.php | 3 --- .../Databases/Http/Databases/XList.php | 3 --- .../Platform/Modules/Databases/Module.php | 2 ++ .../Modules/Databases/Services/Http.php | 4 ++- .../Services/Registry/Collections.php | 2 ++ 109 files changed, 62 insertions(+), 516 deletions(-) create mode 100644 src/Appwrite/Platform/Modules/Databases/Constants.php delete mode 100644 src/Appwrite/Platform/Modules/Databases/Context.php diff --git a/src/Appwrite/Platform/Modules/Databases/Constants.php b/src/Appwrite/Platform/Modules/Databases/Constants.php new file mode 100644 index 0000000000..cfc297c3f4 --- /dev/null +++ b/src/Appwrite/Platform/Modules/Databases/Constants.php @@ -0,0 +1,24 @@ +context = TABLES; } - $this->context = $context; + return parent::setHttpPath($path); } /** @@ -53,7 +48,7 @@ abstract class Action extends UtopiaAction */ final protected function isCollectionsAPI(): bool { - return $this->getContext() === Context::DATABASE_COLLECTIONS; + return $this->getContext() === COLLECTIONS; } /** diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Action.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Action.php index b115edbee8..0a977bce32 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Action.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Action.php @@ -5,7 +5,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attribu use Appwrite\Event\Database as EventDatabase; use Appwrite\Event\Event; use Appwrite\Extend\Exception; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Utopia\Response; use Appwrite\Utopia\Response as UtopiaResponse; use Throwable; @@ -29,25 +28,20 @@ abstract class Action extends UtopiaAction /** * @var string|null The current context (either 'column' or 'attribute') */ - private ?string $context = Context::DATABASE_ATTRIBUTES; + private ?string $context = ATTRIBUTES; /** * Get the correct response model. */ abstract protected function getResponseModel(): string|array; - /** - * Set the context to either `column` or `attribute`. - * - * @throws \InvalidArgumentException If the context is invalid. - */ - final protected function setContext(string $context): void + public function setHttpPath(string $path): UtopiaAction { - if (!\in_array($context, [Context::DATABASE_COLUMNS, Context::DATABASE_ATTRIBUTES], true)) { - throw new \InvalidArgumentException("Invalid context '$context'. Use `Context::DATABASE_COLUMNS` or `Context::DATABASE_ATTRIBUTES`"); + if (str_contains($path, '/:databaseId/tables')) { + $this->context = COLUMNS; } - $this->context = $context; + return parent::setHttpPath($path); } /** @@ -65,7 +59,7 @@ abstract class Action extends UtopiaAction { // columns in tables context // attributes in collections context - return $this->getContext() === Context::DATABASE_ATTRIBUTES; + return $this->getContext() === ATTRIBUTES; } /** diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Boolean/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Boolean/Create.php index b1fddc0371..c38ef8d703 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Boolean/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Boolean/Create.php @@ -13,14 +13,11 @@ use Utopia\Database\Database; use Utopia\Database\Document; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; class Create extends Action { - use HTTP; - public static function getName(): string { return 'createBooleanAttribute'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Boolean/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Boolean/Update.php index 7aa2360fb8..9bb606edf5 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Boolean/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Boolean/Update.php @@ -12,15 +12,12 @@ use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\Nullable; class Update extends Action { - use HTTP; - public static function getName(): string { return 'updateBooleanAttribute'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Datetime/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Datetime/Create.php index fd54fe0843..ff8054abe4 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Datetime/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Datetime/Create.php @@ -14,14 +14,11 @@ use Utopia\Database\Document; use Utopia\Database\Validator\Datetime as DatetimeValidator; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; class Create extends Action { - use HTTP; - public static function getName(): string { return 'createDatetimeAttribute'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Datetime/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Datetime/Update.php index 17818fec2d..5f8909a294 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Datetime/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Datetime/Update.php @@ -13,15 +13,12 @@ use Utopia\Database\Database; use Utopia\Database\Validator\Datetime as DatetimeValidator; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\Nullable; class Update extends Action { - use HTTP; - public static function getName(): string { return 'updateDatetimeAttribute'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Delete.php index 4582500091..5dba0860e2 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Delete.php @@ -15,13 +15,10 @@ use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\IndexDependency as IndexDependencyValidator; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; class Delete extends Action { - use HTTP; - public static function getName(): string { return 'deleteAttribute'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Email/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Email/Create.php index 80f0270ea3..3c703f23a7 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Email/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Email/Create.php @@ -14,14 +14,11 @@ use Utopia\Database\Database; use Utopia\Database\Document; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; class Create extends Action { - use HTTP; - public static function getName(): string { return 'createEmailAttribute'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Email/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Email/Update.php index 2f14d8a361..c8a34cf55c 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Email/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Email/Update.php @@ -13,15 +13,12 @@ use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\Nullable; class Update extends Action { - use HTTP; - public static function getName(): string { return 'updateEmailAttribute'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Enum/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Enum/Create.php index 006de12e91..99d540a4c2 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Enum/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Enum/Create.php @@ -14,7 +14,6 @@ use Utopia\Database\Database; use Utopia\Database\Document; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\ArrayList; use Utopia\Validator\Boolean; @@ -22,8 +21,6 @@ use Utopia\Validator\Text; class Create extends Action { - use HTTP; - public static function getName(): string { return 'createEnumAttribute'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Enum/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Enum/Update.php index c2f6d7696c..8624bde78d 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Enum/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Enum/Update.php @@ -12,7 +12,6 @@ use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\ArrayList; use Utopia\Validator\Boolean; @@ -21,8 +20,6 @@ use Utopia\Validator\Text; class Update extends Action { - use HTTP; - public static function getName(): string { return 'updateEnumAttribute'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Float/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Float/Create.php index 35e9bb68a1..520366f689 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Float/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Float/Create.php @@ -14,7 +14,6 @@ use Utopia\Database\Database; use Utopia\Database\Document; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\FloatValidator; @@ -22,8 +21,6 @@ use Utopia\Validator\Range; class Create extends Action { - use HTTP; - public static function getName(): string { return 'createFloatAttribute'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Float/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Float/Update.php index 2fdcf949f1..18a966d91d 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Float/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Float/Update.php @@ -12,7 +12,6 @@ use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\FloatValidator; @@ -20,8 +19,6 @@ use Utopia\Validator\Nullable; class Update extends Action { - use HTTP; - public static function getName(): string { return 'updateFloatAttribute'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Get.php index d49639e049..d751e8def0 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Get.php @@ -11,13 +11,10 @@ use Utopia\Database\Database; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; class Get extends Action { - use HTTP; - public static function getName(): string { return 'getAttribute'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/IP/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/IP/Create.php index c62e2add01..e46e508bc6 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/IP/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/IP/Create.php @@ -13,15 +13,12 @@ use Utopia\Database\Database; use Utopia\Database\Document; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\IP; class Create extends Action { - use HTTP; - public static function getName(): string { return 'createIpAttribute'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/IP/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/IP/Update.php index a3e1ea5a61..e9d9404c17 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/IP/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/IP/Update.php @@ -12,7 +12,6 @@ use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\IP; @@ -20,8 +19,6 @@ use Utopia\Validator\Nullable; class Update extends Action { - use HTTP; - public static function getName(): string { return 'updateIpAttribute'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Integer/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Integer/Create.php index 69272b6aea..e348e9a2a6 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Integer/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Integer/Create.php @@ -14,7 +14,6 @@ use Utopia\Database\Database; use Utopia\Database\Document; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\Integer; @@ -22,8 +21,6 @@ use Utopia\Validator\Range; class Create extends Action { - use HTTP; - public static function getName(): string { return 'createIntegerAttribute'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Integer/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Integer/Update.php index 9c05382173..bbbf045115 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Integer/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Integer/Update.php @@ -12,7 +12,6 @@ use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\Integer; @@ -20,8 +19,6 @@ use Utopia\Validator\Nullable; class Update extends Action { - use HTTP; - public static function getName(): string { return 'updateIntegerAttribute'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Relationship/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Relationship/Create.php index fa8d0ad750..795ea445c8 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Relationship/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Relationship/Create.php @@ -15,15 +15,12 @@ use Utopia\Database\Document; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\WhiteList; class Create extends Action { - use HTTP; - public static function getName(): string { return 'createRelationshipAttribute'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Relationship/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Relationship/Update.php index da2d0b9b08..7202a3e4e6 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Relationship/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Relationship/Update.php @@ -12,14 +12,11 @@ use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\WhiteList; class Update extends Action { - use HTTP; - public static function getName(): string { return 'updateRelationshipAttribute'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/String/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/String/Create.php index cc989f6687..8ce8626f3a 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/String/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/String/Create.php @@ -14,7 +14,6 @@ use Utopia\Database\Database; use Utopia\Database\Document; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator; use Utopia\Validator\Boolean; @@ -23,8 +22,6 @@ use Utopia\Validator\Text; class Create extends Action { - use HTTP; - public static function getName(): string { return 'createStringAttribute'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/String/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/String/Update.php index b3f4cf3f03..b359b83eaa 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/String/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/String/Update.php @@ -12,7 +12,6 @@ use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator; use Utopia\Validator\Boolean; @@ -22,8 +21,6 @@ use Utopia\Validator\Text; class Update extends Action { - use HTTP; - public static function getName(): string { return 'updateStringAttribute'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/URL/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/URL/Create.php index 2d72533cf1..27bc2d38c1 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/URL/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/URL/Create.php @@ -13,15 +13,12 @@ use Utopia\Database\Database; use Utopia\Database\Document; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\URL; class Create extends Action { - use HTTP; - public static function getName(): string { return 'createUrlAttribute'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/URL/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/URL/Update.php index e5c4288d92..ae48c43653 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/URL/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/URL/Update.php @@ -12,7 +12,6 @@ use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\Nullable; @@ -20,8 +19,6 @@ use Utopia\Validator\URL; class Update extends Action { - use HTTP; - public static function getName(): string { return 'updateUrlAttribute'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/XList.php index 2509115e13..e09420d7ce 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/XList.php @@ -16,13 +16,10 @@ use Utopia\Database\Query; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\Query\Cursor; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; class XList extends Action { - use HTTP; - public static function getName(): string { return 'listAttributes'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Create.php index 5edce7715f..176c3ca853 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Create.php @@ -21,15 +21,12 @@ use Utopia\Database\Helpers\Permission; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\Permissions; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\Text; class Create extends Action { - use HTTP; - public static function getName(): string { return 'createCollection'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Delete.php index b8080ab471..e4618a40b7 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Delete.php @@ -13,13 +13,10 @@ use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; class Delete extends Action { - use HTTP; - public static function getName(): string { return 'deleteCollection'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Action.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Action.php index bd92e233f1..bfebca4cf7 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Action.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Action.php @@ -3,7 +3,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Documents; use Appwrite\Extend\Exception; -use Appwrite\Platform\Modules\Databases\Context; use Utopia\Database\Database; use Utopia\Database\Document; use Utopia\Database\Validator\Authorization; @@ -14,25 +13,20 @@ abstract class Action extends UtopiaAction /** * @var string|null The current context (either 'row' or 'document') */ - private ?string $context = Context::DATABASE_DOCUMENTS; + private ?string $context = DOCUMENTS; /** * Get the response model used in the SDK and HTTP responses. */ abstract protected function getResponseModel(): string; - /** - * Set the context to either `row` or `document`. - * - * @throws \InvalidArgumentException If the context is invalid. - */ - final protected function setContext(string $context): void + public function setHttpPath(string $path): UtopiaAction { - if (!\in_array($context, [Context::DATABASE_ROWS, Context::DATABASE_DOCUMENTS], true)) { - throw new \InvalidArgumentException("Invalid context '$context'. Use `Context::DATABASE_ROWS` or `Context::DATABASE_DOCUMENTS`"); + if (str_contains($path, '/:databaseId/tables')) { + $this->context = ROWS; } - $this->context = $context; + return parent::setHttpPath($path); } /** @@ -60,7 +54,7 @@ abstract class Action extends UtopiaAction { // rows in tables api context // documents in collections api context - return $this->getContext() === Context::DATABASE_DOCUMENTS; + return $this->getContext() === DOCUMENTS; } /** diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Decrement.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Decrement.php index 9a8da5858c..40035ac302 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Decrement.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Decrement.php @@ -19,14 +19,11 @@ use Utopia\Database\Exception\Type as TypeException; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Numeric; class Decrement extends Action { - use HTTP; - public static function getName(): string { return 'decrementDocumentAttribute'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Increment.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Increment.php index b65ca3c285..90694d1c69 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Increment.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Increment.php @@ -19,14 +19,11 @@ use Utopia\Database\Exception\Type as TypeException; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Numeric; class Increment extends Action { - use HTTP; - public static function getName(): string { return 'incrementDocumentAttribute'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Delete.php index bee3b35599..4ec852f7c5 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Delete.php @@ -17,15 +17,12 @@ use Utopia\Database\Exception\Query as QueryException; use Utopia\Database\Exception\Restricted as RestrictedException; use Utopia\Database\Query; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\ArrayList; use Utopia\Validator\Text; class Delete extends Action { - use HTTP; - public static function getName(): string { return 'deleteDocuments'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Update.php index 23c8d5d58e..d391c805fa 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Update.php @@ -19,7 +19,6 @@ use Utopia\Database\Exception\Structure as StructureException; use Utopia\Database\Query; use Utopia\Database\Validator\Permissions; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\ArrayList; use Utopia\Validator\JSON; @@ -27,8 +26,6 @@ use Utopia\Validator\Text; class Update extends Action { - use HTTP; - public static function getName(): string { return 'updateDocuments'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Upsert.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Upsert.php index 770f7a4d95..f4c8c2e6d2 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Upsert.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Upsert.php @@ -17,15 +17,12 @@ use Utopia\Database\Exception\Duplicate as DuplicateException; use Utopia\Database\Exception\Relationship as RelationshipException; use Utopia\Database\Exception\Structure as StructureException; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\ArrayList; use Utopia\Validator\JSON; class Upsert extends Action { - use HTTP; - public static function getName(): string { return 'upsertDocuments'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Create.php index ebab4a7ece..6c1fdae5e6 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Create.php @@ -25,15 +25,12 @@ use Utopia\Database\Helpers\Role; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\Permissions; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\ArrayList; use Utopia\Validator\JSON; class Create extends Action { - use HTTP; - public static function getName(): string { return 'createDocument'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Delete.php index d8ec82910c..8c8cec2986 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Delete.php @@ -16,13 +16,10 @@ use Utopia\Database\Exception\Conflict as ConflictException; use Utopia\Database\Exception\Restricted as RestrictedException; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; class Delete extends Action { - use HTTP; - public static function getName(): string { return 'deleteDocument'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Get.php index fe40a2412f..7376fe770a 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Get.php @@ -15,15 +15,12 @@ use Utopia\Database\Exception\Query as QueryException; use Utopia\Database\Query; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\ArrayList; use Utopia\Validator\Text; class Get extends Action { - use HTTP; - public static function getName(): string { return 'getDocument'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Logs/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Logs/XList.php index 4f4dad9882..3fe25b9441 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Logs/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Logs/XList.php @@ -23,13 +23,10 @@ use Utopia\Database\Validator\Query\Limit; use Utopia\Database\Validator\Query\Offset; use Utopia\Database\Validator\UID; use Utopia\Locale\Locale; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; class XList extends Action { - use HTTP; - public static function getName(): string { return 'listDocumentLogs'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Update.php index c39eeea707..ce822ca713 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Update.php @@ -23,14 +23,11 @@ use Utopia\Database\Helpers\Role; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\Permissions; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\JSON; class Update extends Action { - use HTTP; - public static function getName(): string { return 'updateDocument'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Upsert.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Upsert.php index fa632c7b2b..7a077fed0d 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Upsert.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Upsert.php @@ -24,14 +24,11 @@ use Utopia\Database\Helpers\Role; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\Permissions; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\JSON; class Upsert extends Action { - use HTTP; - public static function getName(): string { return 'upsertDocument'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/XList.php index 9aad8f4b77..2e76942db1 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/XList.php @@ -18,15 +18,12 @@ use Utopia\Database\Query; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\Query\Cursor; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\ArrayList; use Utopia\Validator\Text; class XList extends Action { - use HTTP; - public static function getName(): string { return 'listDocuments'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Get.php index 0359025fc5..e35a924657 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Get.php @@ -11,13 +11,10 @@ use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; class Get extends Action { - use HTTP; - public static function getName(): string { return 'getCollection'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Action.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Action.php index 7013259fa7..33c2977be5 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Action.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Action.php @@ -3,7 +3,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Indexes; use Appwrite\Extend\Exception; -use Appwrite\Platform\Modules\Databases\Context; use Utopia\Platform\Action as UtopiaAction; abstract class Action extends UtopiaAction @@ -11,25 +10,20 @@ abstract class Action extends UtopiaAction /** * The current API context (either 'columnIndex' or 'index'). */ - private ?string $context = Context::DATABASE_INDEX; + private ?string $context = INDEX; /** * Get the response model used in the SDK and HTTP responses. */ abstract protected function getResponseModel(): string; - /** - * Set the current API context. - * - * @param string $context Must be either `DATABASE_INDEX` or `DATABASE_COLUMN_INDEX`. - */ - final protected function setContext(string $context): void + public function setHttpPath(string $path): UtopiaAction { - if (!\in_array($context, [Context::DATABASE_INDEX, Context::DATABASE_COLUMN_INDEX], true)) { - throw new \InvalidArgumentException("Invalid context '$context'. Must be either `Context::DATABASE_COLUMN_INDEX` or `Context::DATABASE_INDEX`."); + if (str_contains($path, '/:databaseId/tables')) { + $this->context = COLUMN_INDEX; } - $this->context = $context; + return parent::setHttpPath($path); } /** @@ -37,9 +31,7 @@ abstract class Action extends UtopiaAction */ final protected function getParentContext(): string { - return $this->getContext() === Context::DATABASE_INDEX - ? Context::DATABASE_ATTRIBUTES - : Context::DATABASE_COLUMNS; + return $this->getContext() === INDEX ? ATTRIBUTES : COLUMNS; } /** @@ -55,7 +47,7 @@ abstract class Action extends UtopiaAction */ final protected function isCollectionsAPI(): bool { - return $this->getParentContext() === Context::DATABASE_ATTRIBUTES; + return $this->getParentContext() === ATTRIBUTES; } /** diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Create.php index 9dbd7924c6..9003fbb4a9 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Create.php @@ -19,7 +19,6 @@ use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\Index as IndexValidator; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\ArrayList; use Utopia\Validator\Integer; @@ -28,8 +27,6 @@ use Utopia\Validator\WhiteList; class Create extends Action { - use HTTP; - public static function getName(): string { return 'createIndex'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Delete.php index bb0b7bc4ca..701ab103ad 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Delete.php @@ -14,13 +14,10 @@ use Utopia\Database\Database; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; class Delete extends Action { - use HTTP; - public static function getName(): string { return 'deleteIndex'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Get.php index e29bbf6647..c5b81fe231 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Get.php @@ -12,13 +12,10 @@ use Utopia\Database\Database; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; class Get extends Action { - use HTTP; - public static function getName(): string { return 'getIndex'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/XList.php index dae25a3335..36c52f711e 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/XList.php @@ -17,13 +17,10 @@ use Utopia\Database\Query; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\Query\Cursor; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; class XList extends Action { - use HTTP; - public static function getName(): string { return 'listIndexes'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Logs/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Logs/XList.php index 2f9ac2c8c0..70bb14e9d8 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Logs/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Logs/XList.php @@ -23,13 +23,10 @@ use Utopia\Database\Validator\Query\Limit; use Utopia\Database\Validator\Query\Offset; use Utopia\Database\Validator\UID; use Utopia\Locale\Locale; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; class XList extends Action { - use HTTP; - public static function getName(): string { return 'listCollectionLogs'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Update.php index cc41d716d4..fd3b1e8bda 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Update.php @@ -14,15 +14,12 @@ use Utopia\Database\Helpers\Permission; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\Permissions; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\Text; class Update extends Action { - use HTTP; - public static function getName(): string { return 'updateCollection'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Usage/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Usage/Get.php index 0c565806cc..e5335d6abf 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Usage/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Usage/Get.php @@ -15,14 +15,11 @@ use Utopia\Database\Document; use Utopia\Database\Query; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\WhiteList; class Get extends Action { - use HTTP; - public static function getName(): string { return 'getCollectionUsage'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/XList.php index d3ddb9301f..ae63a40e64 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/XList.php @@ -17,14 +17,11 @@ use Utopia\Database\Query; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\Query\Cursor; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Text; class XList extends Action { - use HTTP; - public static function getName(): string { return 'listCollections'; @@ -68,6 +65,11 @@ class XList extends Action public function action(string $databaseId, array $queries, string $search, UtopiaResponse $response, Database $dbForProject): void { + print_r(json_encode([ + 'context' => $this->getContext(), + 'model' => $this->getResponseModel() + ], JSON_PRETTY_PRINT)); + $database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); if ($database->isEmpty()) { diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Create.php index 3b9efa2fca..38374402fb 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Create.php @@ -19,15 +19,12 @@ use Utopia\Database\Exception\Limit as LimitException; use Utopia\Database\Exception\Structure as StructureException; use Utopia\Database\Helpers\ID; use Utopia\Platform\Action; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\Text; class Create extends Action { - use HTTP; - public static function getName(): string { return 'createDatabase'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Delete.php index b9b475f699..56cf1a4296 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Delete.php @@ -13,13 +13,10 @@ use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; use Utopia\Database\Validator\UID; use Utopia\Platform\Action; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; class Delete extends Action { - use HTTP; - public static function getName(): string { return 'deleteDatabase'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Get.php index c2c6a57da1..f478dc7917 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Get.php @@ -11,13 +11,10 @@ use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; use Utopia\Database\Validator\UID; use Utopia\Platform\Action; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; class Get extends Action { - use HTTP; - public static function getName(): string { return 'getDatabase'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Logs/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Logs/XList.php index a531110398..52f2ad93b6 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Logs/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Logs/XList.php @@ -23,13 +23,10 @@ use Utopia\Database\Validator\Query\Offset; use Utopia\Database\Validator\UID; use Utopia\Locale\Locale; use Utopia\Platform\Action; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; class XList extends Action { - use HTTP; - public static function getName(): string { return 'listDatabaseLogs'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Boolean/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Boolean/Create.php index b8675877f3..9e65e6e5b3 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Boolean/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Boolean/Create.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Columns\Boolean; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Boolean\Create as BooleanCreate; use Appwrite\SDK\AuthType; use Appwrite\SDK\Method; @@ -10,14 +9,11 @@ use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; class Create extends BooleanCreate { - use HTTP; - public static function getName(): string { return 'createBooleanColumn'; @@ -30,8 +26,6 @@ class Create extends BooleanCreate public function __construct() { - $this->setContext(Context::DATABASE_COLUMNS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/columns/boolean') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Boolean/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Boolean/Update.php index 09d01cae21..f7eff81ae3 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Boolean/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Boolean/Update.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Columns\Boolean; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Boolean\Update as BooleanUpdate; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -11,15 +10,12 @@ use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\Nullable; class Update extends BooleanUpdate { - use HTTP; - public static function getName(): string { return 'updateBooleanColumn'; @@ -32,8 +28,6 @@ class Update extends BooleanUpdate public function __construct() { - $this->setContext(Context::DATABASE_COLUMNS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/columns/boolean/:key') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Datetime/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Datetime/Create.php index 34ead7c33d..5bb83733a4 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Datetime/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Datetime/Create.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Columns\Datetime; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Datetime\Create as DatetimeCreate; use Appwrite\SDK\AuthType; use Appwrite\SDK\Method; @@ -12,14 +11,11 @@ use Utopia\Database\Database; use Utopia\Database\Validator\Datetime as DatetimeValidator; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; class Create extends DatetimeCreate { - use HTTP; - public static function getName(): string { return 'createDatetimeColumn'; @@ -32,8 +28,6 @@ class Create extends DatetimeCreate public function __construct() { - $this->setContext(Context::DATABASE_COLUMNS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/columns/datetime') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Datetime/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Datetime/Update.php index 5b026cd373..6710f76aaa 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Datetime/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Datetime/Update.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Columns\Datetime; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Datetime\Update as DatetimeUpdate; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -13,15 +12,12 @@ use Utopia\Database\Database; use Utopia\Database\Validator\Datetime as DatetimeValidator; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\Nullable; class Update extends DatetimeUpdate { - use HTTP; - public static function getName(): string { return 'updateDatetimeColumn'; @@ -34,8 +30,6 @@ class Update extends DatetimeUpdate public function __construct() { - $this->setContext(Context::DATABASE_COLUMNS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/columns/datetime/:key') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Delete.php index 567cb02169..b85248e8c3 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Delete.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Columns; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Delete as AttributesDelete; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -11,13 +10,10 @@ use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; class Delete extends AttributesDelete { - use HTTP; - public static function getName(): string { return 'deleteColumn'; @@ -31,8 +27,6 @@ class Delete extends AttributesDelete public function __construct() { - $this->setContext(Context::DATABASE_COLUMNS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_DELETE) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/columns/:key') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Email/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Email/Create.php index f5bb2f5220..6aade1aa50 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Email/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Email/Create.php @@ -3,7 +3,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Columns\Email; use Appwrite\Network\Validator\Email; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Email\Create as EmailCreate; use Appwrite\SDK\AuthType; use Appwrite\SDK\Method; @@ -11,14 +10,11 @@ use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; class Create extends EmailCreate { - use HTTP; - public static function getName(): string { return 'createEmailColumn'; @@ -31,8 +27,6 @@ class Create extends EmailCreate public function __construct() { - $this->setContext(Context::DATABASE_COLUMNS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/columns/email') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Email/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Email/Update.php index faba9279b5..10213c87bb 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Email/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Email/Update.php @@ -3,7 +3,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Columns\Email; use Appwrite\Network\Validator\Email; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Email\Update as EmailUpdate; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -12,15 +11,12 @@ use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\Nullable; class Update extends EmailUpdate { - use HTTP; - public static function getName(): string { return 'updateEmailColumn'; @@ -33,8 +29,6 @@ class Update extends EmailUpdate public function __construct() { - $this->setContext(Context::DATABASE_COLUMNS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/columns/email/:key') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Enum/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Enum/Create.php index ec1d36a916..8e9a658aa8 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Enum/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Enum/Create.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Columns\Enum; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Enum\Create as EnumCreate; use Appwrite\SDK\AuthType; use Appwrite\SDK\Method; @@ -11,7 +10,6 @@ use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\ArrayList; use Utopia\Validator\Boolean; @@ -19,8 +17,6 @@ use Utopia\Validator\Text; class Create extends EnumCreate { - use HTTP; - public static function getName(): string { return 'createEnumColumn'; @@ -33,8 +29,6 @@ class Create extends EnumCreate public function __construct() { - $this->setContext(Context::DATABASE_COLUMNS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/columns/enum') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Enum/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Enum/Update.php index ef2c829e0a..d1418e5144 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Enum/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Enum/Update.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Columns\Enum; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Enum\Update as EnumUpdate; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -12,7 +11,6 @@ use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\ArrayList; use Utopia\Validator\Boolean; @@ -21,8 +19,6 @@ use Utopia\Validator\Text; class Update extends EnumUpdate { - use HTTP; - public static function getName(): string { return 'updateEnumColumn'; @@ -35,8 +31,6 @@ class Update extends EnumUpdate public function __construct() { - $this->setContext(Context::DATABASE_COLUMNS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/columns/enum/:key') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Float/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Float/Create.php index 32579017c6..5c99b90f52 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Float/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Float/Create.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Columns\Float; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Float\Create as FloatCreate; use Appwrite\SDK\AuthType; use Appwrite\SDK\Method; @@ -10,15 +9,12 @@ use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\FloatValidator; class Create extends FloatCreate { - use HTTP; - public static function getName(): string { return 'createFloatColumn'; @@ -31,8 +27,6 @@ class Create extends FloatCreate public function __construct() { - $this->setContext(Context::DATABASE_COLUMNS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/columns/float') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Float/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Float/Update.php index 4ed420cfa0..5360ca0304 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Float/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Float/Update.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Columns\Float; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Float\Update as FloatUpdate; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -11,7 +10,6 @@ use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\FloatValidator; @@ -19,8 +17,6 @@ use Utopia\Validator\Nullable; class Update extends FloatUpdate { - use HTTP; - public static function getName(): string { return 'updateFloatColumn'; @@ -33,8 +29,6 @@ class Update extends FloatUpdate public function __construct() { - $this->setContext(Context::DATABASE_COLUMNS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/columns/float/:key') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Get.php index ed28f96535..17777409d2 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Get.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Columns; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Get as AttributesGet; use Appwrite\SDK\AuthType; use Appwrite\SDK\Method; @@ -10,13 +9,10 @@ use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; class Get extends AttributesGet { - use HTTP; - public static function getName(): string { return 'getColumn'; @@ -40,8 +36,6 @@ class Get extends AttributesGet public function __construct() { - $this->setContext(Context::DATABASE_COLUMNS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_GET) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/columns/:key') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/IP/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/IP/Create.php index 8acc47f051..cb58a14cbe 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/IP/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/IP/Create.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Columns\IP; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\IP\Create as IPCreate; use Appwrite\SDK\AuthType; use Appwrite\SDK\Method; @@ -10,15 +9,12 @@ use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\IP; class Create extends IPCreate { - use HTTP; - public static function getName(): string { return 'createIpColumn'; @@ -31,8 +27,6 @@ class Create extends IPCreate public function __construct() { - $this->setContext(Context::DATABASE_COLUMNS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/columns/ip') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/IP/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/IP/Update.php index c43f132c13..ef4c62a51f 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/IP/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/IP/Update.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Columns\IP; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\IP\Update as IPUpdate; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -11,7 +10,6 @@ use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\IP; @@ -19,8 +17,6 @@ use Utopia\Validator\Nullable; class Update extends IPUpdate { - use HTTP; - public static function getName(): string { return 'updateIpColumn'; @@ -33,8 +29,6 @@ class Update extends IPUpdate public function __construct() { - $this->setContext(Context::DATABASE_COLUMNS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/columns/ip/:key') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Integer/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Integer/Create.php index 7694e9d74f..6ca6cc4b93 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Integer/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Integer/Create.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Columns\Integer; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Integer\Create as IntegerCreate; use Appwrite\SDK\AuthType; use Appwrite\SDK\Method; @@ -10,15 +9,12 @@ use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\Integer; class Create extends IntegerCreate { - use HTTP; - public static function getName(): string { return 'createIntegerColumn'; @@ -31,8 +27,6 @@ class Create extends IntegerCreate public function __construct() { - $this->setContext(Context::DATABASE_COLUMNS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/columns/integer') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Integer/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Integer/Update.php index b3ce988830..764ae31f35 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Integer/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Integer/Update.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Columns\Integer; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Integer\Update as IntegerUpdate; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -11,7 +10,6 @@ use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\Integer; @@ -19,8 +17,6 @@ use Utopia\Validator\Nullable; class Update extends IntegerUpdate { - use HTTP; - public static function getName(): string { return 'updateIntegerColumn'; @@ -33,8 +29,6 @@ class Update extends IntegerUpdate public function __construct() { - $this->setContext(Context::DATABASE_COLUMNS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/columns/integer/:key') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Relationship/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Relationship/Create.php index 133f772605..20e89396a0 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Relationship/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Relationship/Create.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Columns\Relationship; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Relationship\Create as RelationshipCreate; use Appwrite\SDK\AuthType; use Appwrite\SDK\Method; @@ -11,15 +10,12 @@ use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\WhiteList; class Create extends RelationshipCreate { - use HTTP; - public static function getName(): string { return 'createRelationshipColumn'; @@ -32,8 +28,6 @@ class Create extends RelationshipCreate public function __construct() { - $this->setContext(Context::DATABASE_COLUMNS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/columns/relationship') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Relationship/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Relationship/Update.php index ef1d8c7a33..508c5da57a 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Relationship/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Relationship/Update.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Columns\Relationship; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Relationship\Update as RelationshipUpdate; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -12,14 +11,11 @@ use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\WhiteList; class Update extends RelationshipUpdate { - use HTTP; - public static function getName(): string { return 'updateRelationshipColumn'; @@ -32,8 +28,6 @@ class Update extends RelationshipUpdate public function __construct() { - $this->setContext(Context::DATABASE_COLUMNS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/columns/:key/relationship') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/String/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/String/Create.php index ed7989fbc3..a11ee3464e 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/String/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/String/Create.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Columns\String; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\String\Create as StringCreate; use Appwrite\SDK\AuthType; use Appwrite\SDK\Method; @@ -10,7 +9,6 @@ use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator; use Utopia\Validator\Boolean; @@ -19,8 +17,6 @@ use Utopia\Validator\Text; class Create extends StringCreate { - use HTTP; - public static function getName(): string { return 'createStringColumn'; @@ -33,8 +29,6 @@ class Create extends StringCreate public function __construct() { - $this->setContext(Context::DATABASE_COLUMNS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/columns/string') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/String/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/String/Update.php index f7ec773e3c..92df091866 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/String/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/String/Update.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Columns\String; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\String\Update as StringUpdate; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -11,7 +10,6 @@ use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator; use Utopia\Validator\Boolean; @@ -21,8 +19,6 @@ use Utopia\Validator\Text; class Update extends StringUpdate { - use HTTP; - public static function getName(): string { return 'updateStringColumn'; @@ -35,8 +31,6 @@ class Update extends StringUpdate public function __construct() { - $this->setContext(Context::DATABASE_COLUMNS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/columns/string/:key') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/URL/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/URL/Create.php index 0e6fe7cff3..84c488ccfc 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/URL/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/URL/Create.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Columns\URL; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\URL\Create as URLCreate; use Appwrite\SDK\AuthType; use Appwrite\SDK\Method; @@ -10,15 +9,12 @@ use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\URL; class Create extends URLCreate { - use HTTP; - public static function getName(): string { return 'createUrlColumn'; @@ -31,8 +27,6 @@ class Create extends URLCreate public function __construct() { - $this->setContext(Context::DATABASE_COLUMNS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/columns/url') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/URL/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/URL/Update.php index 6f3698c0cf..d3681b9358 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/URL/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/URL/Update.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Columns\URL; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\URL\Update as URLUpdate; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -11,7 +10,6 @@ use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\Nullable; @@ -19,8 +17,6 @@ use Utopia\Validator\URL; class Update extends URLUpdate { - use HTTP; - public static function getName(): string { return 'updateUrlColumn'; @@ -33,8 +29,6 @@ class Update extends URLUpdate public function __construct() { - $this->setContext(Context::DATABASE_COLUMNS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/columns/url/:key') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/XList.php index c6ceb35f48..29a108f180 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/XList.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Columns; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\XList as AttributesXList; use Appwrite\SDK\AuthType; use Appwrite\SDK\Method; @@ -10,13 +9,10 @@ use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Database\Validator\Queries\Columns; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; class XList extends AttributesXList { - use HTTP; - public static function getName(): string { return 'listColumns'; @@ -29,8 +25,6 @@ class XList extends AttributesXList public function __construct() { - $this->setContext(Context::DATABASE_COLUMNS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_GET) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/columns') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Create.php index c20865d110..273791f154 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Create.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Create as CollectionCreate; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -12,15 +11,12 @@ use Appwrite\Utopia\Database\Validator\CustomId; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\Permissions; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\Text; class Create extends CollectionCreate { - use HTTP; - public static function getName(): string { return 'createTable'; @@ -33,8 +29,6 @@ class Create extends CollectionCreate public function __construct() { - $this->setContext(Context::DATABASE_TABLES); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) ->setHttpPath('/v1/databases/:databaseId/tables') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Delete.php index 85e52ac37d..0a20a20f54 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Delete.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Delete as CollectionDelete; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -10,13 +9,10 @@ use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; class Delete extends CollectionDelete { - use HTTP; - public static function getName(): string { return 'deleteTable'; @@ -29,8 +25,6 @@ class Delete extends CollectionDelete public function __construct() { - $this->setContext(Context::DATABASE_TABLES); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_DELETE) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Get.php index 473dfb6273..7f565231f9 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Get.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Get as CollectionGet; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -10,13 +9,10 @@ use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; class Get extends CollectionGet { - use HTTP; - public static function getName(): string { return 'getTable'; @@ -29,8 +25,6 @@ class Get extends CollectionGet public function __construct() { - $this->setContext(Context::DATABASE_TABLES); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_GET) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Indexes/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Indexes/Create.php index e57e962e87..b11892e0f9 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Indexes/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Indexes/Create.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Indexes; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Indexes\Create as IndexCreate; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -12,7 +11,6 @@ use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\ArrayList; use Utopia\Validator\Integer; @@ -21,8 +19,6 @@ use Utopia\Validator\WhiteList; class Create extends IndexCreate { - use HTTP; - public static function getName(): string { return 'createColumnIndex'; @@ -35,8 +31,6 @@ class Create extends IndexCreate public function __construct() { - $this->setContext(Context::DATABASE_COLUMN_INDEX); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/indexes') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Indexes/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Indexes/Delete.php index 7cda1ce471..4ff9638f27 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Indexes/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Indexes/Delete.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Indexes; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Indexes\Delete as IndexDelete; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -11,13 +10,10 @@ use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; class Delete extends IndexDelete { - use HTTP; - public static function getName(): string { return 'updateColumnIndex'; @@ -34,8 +30,6 @@ class Delete extends IndexDelete public function __construct() { - $this->setContext(Context::DATABASE_COLUMN_INDEX); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_DELETE) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/indexes/:key') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Indexes/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Indexes/Get.php index 3bee87de4a..79529fda66 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Indexes/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Indexes/Get.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Indexes; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Indexes\Get as IndexGet; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -11,13 +10,10 @@ use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; class Get extends IndexGet { - use HTTP; - public static function getName(): string { return 'getColumnIndex'; @@ -30,8 +26,6 @@ class Get extends IndexGet public function __construct() { - $this->setContext(Context::DATABASE_COLUMN_INDEX); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_GET) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/indexes/:key') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Indexes/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Indexes/XList.php index 1af13dc82e..12581a4fc3 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Indexes/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Indexes/XList.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Indexes; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Indexes\XList as IndexXList; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -11,13 +10,10 @@ use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Database\Validator\Queries\Indexes; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; class XList extends IndexXList { - use HTTP; - public static function getName(): string { return 'listColumnIndexes'; @@ -30,8 +26,6 @@ class XList extends IndexXList public function __construct() { - $this->setContext(Context::DATABASE_COLUMN_INDEX); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_GET) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/indexes') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Logs/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Logs/XList.php index 244cebe3ad..8e652c5416 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Logs/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Logs/XList.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Logs; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Logs\XList as CollectionLogXList; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -12,13 +11,10 @@ use Utopia\Database\Validator\Queries; use Utopia\Database\Validator\Query\Limit; use Utopia\Database\Validator\Query\Offset; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; class XList extends CollectionLogXList { - use HTTP; - public static function getName(): string { return 'listTableLogs'; @@ -26,8 +22,6 @@ class XList extends CollectionLogXList public function __construct() { - $this->setContext(Context::DATABASE_TABLES); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_GET) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/logs') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Bulk/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Bulk/Delete.php index 9ddff818e3..945450aee3 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Bulk/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Bulk/Delete.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Rows\Bulk; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Documents\Bulk\Delete as DocumentsDelete; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -10,15 +9,12 @@ use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\ArrayList; use Utopia\Validator\Text; class Delete extends DocumentsDelete { - use HTTP; - public static function getName(): string { return 'deleteRows'; @@ -31,8 +27,6 @@ class Delete extends DocumentsDelete public function __construct() { - $this->setContext(Context::DATABASE_ROWS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_DELETE) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/rows') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Bulk/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Bulk/Update.php index 1b9ddb60ab..916d683491 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Bulk/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Bulk/Update.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Rows\Bulk; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Documents\Bulk\Update as DocumentsUpdate; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -10,7 +9,6 @@ use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\ArrayList; use Utopia\Validator\JSON; @@ -18,8 +16,6 @@ use Utopia\Validator\Text; class Update extends DocumentsUpdate { - use HTTP; - public static function getName(): string { return 'updateRows'; @@ -32,8 +28,6 @@ class Update extends DocumentsUpdate public function __construct() { - $this->setContext(Context::DATABASE_ROWS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/rows') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Bulk/Upsert.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Bulk/Upsert.php index 2b4117c23e..65c848a7c4 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Bulk/Upsert.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Bulk/Upsert.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Rows\Bulk; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Documents\Bulk\Upsert as DocumentsUpsert; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -10,15 +9,12 @@ use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\ArrayList; use Utopia\Validator\JSON; class Upsert extends DocumentsUpsert { - use HTTP; - public static function getName(): string { return 'upsertRows'; @@ -31,8 +27,6 @@ class Upsert extends DocumentsUpsert public function __construct() { - $this->setContext(Context::DATABASE_ROWS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_PUT) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/rows') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Column/Decrement.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Column/Decrement.php index 128d578cde..916c051d8a 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Column/Decrement.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Column/Decrement.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Rows\Column; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Documents\Attribute\Decrement as DecrementDocumentAttribute; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -11,14 +10,11 @@ use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Numeric; class Decrement extends DecrementDocumentAttribute { - use HTTP; - public static function getName(): string { return 'decrementRowColumn'; @@ -31,8 +27,6 @@ class Decrement extends DecrementDocumentAttribute public function __construct() { - $this->setContext(Context::DATABASE_ROWS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/rows/:rowId/:column/decrement') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Column/Increment.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Column/Increment.php index a3e256d561..ba78833744 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Column/Increment.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Column/Increment.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Rows\Column; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Documents\Attribute\Increment as IncrementDocumentAttribute; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -11,14 +10,11 @@ use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Numeric; class Increment extends IncrementDocumentAttribute { - use HTTP; - public static function getName(): string { return 'incrementRowColumn'; @@ -31,8 +27,6 @@ class Increment extends IncrementDocumentAttribute public function __construct() { - $this->setContext(Context::DATABASE_ROWS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/rows/:rowId/:column/increment') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Create.php index 03e5548ddb..ba2b461d6e 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Create.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Rows; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Documents\Create as DocumentCreate; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -14,15 +13,12 @@ use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; use Utopia\Database\Validator\Permissions; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\ArrayList; use Utopia\Validator\JSON; class Create extends DocumentCreate { - use HTTP; - public static function getName(): string { return 'createRow'; @@ -40,8 +36,6 @@ class Create extends DocumentCreate public function __construct() { - $this->setContext(Context::DATABASE_ROWS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/rows') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Delete.php index 5edf4e0b73..27fe101f1d 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Delete.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Rows; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Documents\Delete as DocumentDelete; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -10,13 +9,10 @@ use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; class Delete extends DocumentDelete { - use HTTP; - public static function getName(): string { return 'deleteRow'; @@ -35,8 +31,6 @@ class Delete extends DocumentDelete public function __construct() { - $this->setContext(Context::DATABASE_ROWS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_DELETE) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/rows/:rowId') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Get.php index 74e1f90497..8100abbea5 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Get.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Rows; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Documents\Get as DocumentGet; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -10,15 +9,12 @@ use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\ArrayList; use Utopia\Validator\Text; class Get extends DocumentGet { - use HTTP; - public static function getName(): string { return 'getRow'; @@ -31,8 +27,6 @@ class Get extends DocumentGet public function __construct() { - $this->setContext(Context::DATABASE_ROWS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_GET) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/rows/:rowId') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Logs/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Logs/XList.php index 1cc5202152..f39a77323f 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Logs/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Logs/XList.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Rows\Logs; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Documents\Logs\XList as DocumentLogXList; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -12,13 +11,10 @@ use Utopia\Database\Validator\Queries; use Utopia\Database\Validator\Query\Limit; use Utopia\Database\Validator\Query\Offset; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; class XList extends DocumentLogXList { - use HTTP; - public static function getName(): string { return 'listRowLogs'; @@ -26,8 +22,6 @@ class XList extends DocumentLogXList public function __construct() { - $this->setContext(Context::DATABASE_ROWS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_GET) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/rows/:rowId/logs') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Update.php index d37f5cc92f..9fa596ecc0 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Update.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Rows; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Documents\Update as DocumentUpdate; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -12,14 +11,11 @@ use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; use Utopia\Database\Validator\Permissions; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\JSON; class Update extends DocumentUpdate { - use HTTP; - public static function getName(): string { return 'updateRow'; @@ -32,8 +28,6 @@ class Update extends DocumentUpdate public function __construct() { - $this->setContext(Context::DATABASE_ROWS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/rows/:rowId') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Upsert.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Upsert.php index 800efa9cde..5c0fde708b 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Upsert.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Upsert.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Rows; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Documents\Upsert as DocumentUpsert; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -12,14 +11,11 @@ use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; use Utopia\Database\Validator\Permissions; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\JSON; class Upsert extends DocumentUpsert { - use HTTP; - public static function getName(): string { return 'upsertRow'; @@ -32,8 +28,6 @@ class Upsert extends DocumentUpsert public function __construct() { - $this->setContext(Context::DATABASE_ROWS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_PUT) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/rows/:rowId') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/XList.php index 9d03603a0e..b7ad763e36 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/XList.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Rows; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Documents\XList as DocumentXList; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -10,15 +9,12 @@ use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\ArrayList; use Utopia\Validator\Text; class XList extends DocumentXList { - use HTTP; - public static function getName(): string { return 'listRows'; @@ -31,8 +27,6 @@ class XList extends DocumentXList public function __construct() { - $this->setContext(Context::DATABASE_ROWS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_GET) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/rows') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Update.php index ab71634fb2..210b281e57 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Update.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Update as CollectionUpdate; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -11,15 +10,12 @@ use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\Permissions; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\Text; class Update extends CollectionUpdate { - use HTTP; - public static function getName(): string { return 'updateTable'; @@ -32,8 +28,6 @@ class Update extends CollectionUpdate public function __construct() { - $this->setContext(Context::DATABASE_TABLES); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_PUT) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Usage/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Usage/Get.php index 9fb5fc8c17..c82eaae7c5 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Usage/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Usage/Get.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Usage; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Usage\Get as CollectionUsageGet; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -10,14 +9,11 @@ use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\WhiteList; class Get extends CollectionUsageGet { - use HTTP; - public static function getName(): string { return 'getTableUsage'; @@ -30,8 +26,6 @@ class Get extends CollectionUsageGet public function __construct() { - $this->setContext(Context::DATABASE_TABLES); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_GET) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/usage') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/XList.php index f6f48ace40..391b91a3dd 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/XList.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\XList as CollectionXList; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -11,14 +10,11 @@ use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Database\Validator\Queries\Tables; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Text; class XList extends CollectionXList { - use HTTP; - public static function getName(): string { return 'listTables'; @@ -31,8 +27,6 @@ class XList extends CollectionXList public function __construct() { - $this->setContext(Context::DATABASE_TABLES); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_GET) ->setHttpPath('/v1/databases/:databaseId/tables') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Update.php index a0e440c657..a746f4ce4c 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Update.php @@ -12,15 +12,12 @@ use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; use Utopia\Database\Validator\UID; use Utopia\Platform\Action; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\Text; class Update extends Action { - use HTTP; - public static function getName(): string { return 'updateDatabase'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Usage/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Usage/Get.php index 1a85380767..5482d25269 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Usage/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Usage/Get.php @@ -15,14 +15,11 @@ use Utopia\Database\Query; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\UID; use Utopia\Platform\Action; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\WhiteList; class Get extends Action { - use HTTP; - public static function getName(): string { return 'getUsage'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Usage/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Usage/XList.php index 2d551465db..fd3a95cd24 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Usage/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Usage/XList.php @@ -13,14 +13,11 @@ use Utopia\Database\Document; use Utopia\Database\Query; use Utopia\Database\Validator\Authorization; use Utopia\Platform\Action; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\WhiteList; class XList extends Action { - use HTTP; - public static function getName(): string { return 'listUsages'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/XList.php index 7179be90ec..52f3fd2b55 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/XList.php @@ -16,14 +16,11 @@ use Utopia\Database\Exception\Query as QueryException; use Utopia\Database\Query; use Utopia\Database\Validator\Query\Cursor; use Utopia\Platform\Action; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Text; class XList extends Action { - use HTTP; - public static function getName(): string { return 'listDatabases'; diff --git a/src/Appwrite/Platform/Modules/Databases/Module.php b/src/Appwrite/Platform/Modules/Databases/Module.php index f8686999dd..bf336413d4 100644 --- a/src/Appwrite/Platform/Modules/Databases/Module.php +++ b/src/Appwrite/Platform/Modules/Databases/Module.php @@ -2,6 +2,8 @@ namespace Appwrite\Platform\Modules\Databases; +require_once __DIR__ . '/Constants.php'; + use Appwrite\Platform\Modules\Databases\Services\Http; use Appwrite\Platform\Modules\Databases\Services\Workers; use Utopia\Platform; diff --git a/src/Appwrite/Platform/Modules/Databases/Services/Http.php b/src/Appwrite/Platform/Modules/Databases/Services/Http.php index a877c89345..d2f66f3657 100644 --- a/src/Appwrite/Platform/Modules/Databases/Services/Http.php +++ b/src/Appwrite/Platform/Modules/Databases/Services/Http.php @@ -14,8 +14,10 @@ class Http extends Service { $this->type = Service::TYPE_HTTP; + // Project database timeout init hook! + $this->addAction(Timeout::getName(), new Timeout()); + foreach ([ - Timeout::class, DatabasesRegistry::class, CollectionsRegistry::class, TablesRegistry::class, diff --git a/src/Appwrite/Platform/Modules/Databases/Services/Registry/Collections.php b/src/Appwrite/Platform/Modules/Databases/Services/Registry/Collections.php index d036d2fd7b..bb0002ed47 100644 --- a/src/Appwrite/Platform/Modules/Databases/Services/Registry/Collections.php +++ b/src/Appwrite/Platform/Modules/Databases/Services/Registry/Collections.php @@ -35,6 +35,7 @@ use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Documents\Bul use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Documents\Create as CreateDocument; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Documents\Delete as DeleteDocument; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Documents\Get as GetDocument; +use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Documents\Logs\XList as ListDocumentLogs; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Documents\Update as UpdateDocument; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Documents\Upsert as UpsertDocument; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Documents\XList as ListDocuments; @@ -90,6 +91,7 @@ class Collections extends Base $service->addAction(DeleteDocument::getName(), new DeleteDocument()); $service->addAction(DeleteDocuments::getName(), new DeleteDocuments()); $service->addAction(ListDocuments::getName(), new ListDocuments()); + $service->addAction(ListDocumentLogs::getName(), new ListDocumentLogs()); $service->addAction(IncrementDocumentAttribute::getName(), new IncrementDocumentAttribute()); $service->addAction(DecrementDocumentAttribute::getName(), new DecrementDocumentAttribute()); From 03b40262331cfae6a01b8fff5913ab3c79b9a25c Mon Sep 17 00:00:00 2001 From: Darshan Date: Thu, 19 Jun 2025 14:33:23 +0530 Subject: [PATCH 34/40] remove: leftover. --- .../Http/Databases/Collections/Documents/Attribute/Increment.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Increment.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Increment.php index 90694d1c69..6755d313c0 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Increment.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Increment.php @@ -99,7 +99,6 @@ class Increment extends Action } catch (ConflictException) { throw new Exception($this->getConflictException()); } catch (NotFoundException) { - // todo: @itznotabug what do we name this exception now? throw new Exception($this->getStructureNotFoundException()); } catch (LimitException) { throw new Exception($this->getLimitException(), $this->getSdkNamespace() . ' "' . $attribute . '" has reached the maximum value of ' . $max); From 60ab787894f963b38fb6a3449ca26e848d3d4a21 Mon Sep 17 00:00:00 2001 From: Darshan Date: Thu, 19 Jun 2025 14:33:58 +0530 Subject: [PATCH 35/40] address comments. --- .../Databases/Http/Databases/Collections/Attributes/Action.php | 2 +- .../Databases/Http/Databases/Collections/Attributes/Delete.php | 2 +- .../Databases/Http/Databases/Collections/Attributes/Get.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Action.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Action.php index 0a977bce32..3f331edc9a 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Action.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Action.php @@ -221,7 +221,7 @@ abstract class Action extends UtopiaAction /** * Get the proper column/attribute type based on set context. */ - final protected function getCorrectModel(string $type, string $format): string + final protected function getModel(string $type, string $format): string { $isCollections = $this->isCollectionsAPI(); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Delete.php index 5dba0860e2..271ea56f29 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Delete.php @@ -138,7 +138,7 @@ class Delete extends Action $type = $attribute->getAttribute('type'); $format = $attribute->getAttribute('format'); - $model = $this->getCorrectModel($type, $format); + $model = $this->getModel($type, $format); $queueForEvents ->setContext('database', $db) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Get.php index d751e8def0..579f7883e0 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Get.php @@ -91,7 +91,7 @@ class Get extends Action $attribute->setAttribute($key, $option); } - $model = $this->getCorrectModel($type, $format); + $model = $this->getModel($type, $format); $attribute->setAttribute('encrypt', in_array('encrypt', $filters)); From 3d6acaa19c7e25bce884bbb0397d3ff4b6993a36 Mon Sep 17 00:00:00 2001 From: Darshan Date: Thu, 19 Jun 2025 14:49:42 +0530 Subject: [PATCH 36/40] address comments. --- .../Platform/Modules/Databases/Http/Databases/Tables/Create.php | 2 +- .../Platform/Modules/Databases/Http/Databases/Tables/Update.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Create.php index 273791f154..92b29ffdc6 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Create.php @@ -57,7 +57,7 @@ class Create extends CollectionCreate ->param('tableId', '', new CustomId(), 'Unique Id. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.') ->param('name', '', new Text(128), 'Table name. Max length: 128 chars.') ->param('permissions', null, new Permissions(APP_LIMIT_ARRAY_PARAMS_SIZE), 'An array of permissions strings. By default, no user is granted with any permissions. [Learn more about permissions](https://appwrite.io/docs/permissions).', true) - ->param('rowSecurity', false, new Boolean(true), 'Enables configuring permissions for individual rows. A user needs one of row or table level permissions to access a document. [Learn more about permissions](https://appwrite.io/docs/permissions).', true) + ->param('rowSecurity', false, new Boolean(true), 'Enables configuring permissions for individual rows. A user needs one of row or table level permissions to access a row. [Learn more about permissions](https://appwrite.io/docs/permissions).', true) ->param('enabled', true, new Boolean(), 'Is table enabled? When set to \'disabled\', users cannot access the table but Server SDKs with and API key can still read and write to the table. No data is lost when this is toggled.', true) ->inject('response') ->inject('dbForProject') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Update.php index 210b281e57..62a1b3bdee 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Update.php @@ -54,7 +54,7 @@ class Update extends CollectionUpdate )) ->param('databaseId', '', new UID(), 'Database ID.') ->param('tableId', '', new UID(), 'Table ID.') - ->param('name', null, new Text(128), 'Collection name. Max length: 128 chars.') + ->param('name', null, new Text(128), 'Table name. Max length: 128 chars.') ->param('permissions', null, new Permissions(APP_LIMIT_ARRAY_PARAMS_SIZE), 'An array of permission strings. By default, the current permissions are inherited. [Learn more about permissions](https://appwrite.io/docs/permissions).', true) ->param('rowSecurity', false, new Boolean(true), 'Enables configuring permissions for individual rows. A user needs one of row or table level permissions to access a document. [Learn more about permissions](https://appwrite.io/docs/permissions).', true) ->param('enabled', true, new Boolean(), 'Is table enabled? When set to \'disabled\', users cannot access the table but Server SDKs with and API key can still read and write to the table. No data is lost when this is toggled.', true) From caf23083003a4ac44897018a684ffe38ff6328a0 Mon Sep 17 00:00:00 2001 From: Darshan Date: Thu, 19 Jun 2025 14:50:15 +0530 Subject: [PATCH 37/40] address comment. --- .../Modules/Databases/Http/Databases/Collections/XList.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/XList.php index ae63a40e64..3a9868dec2 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/XList.php @@ -65,11 +65,6 @@ class XList extends Action public function action(string $databaseId, array $queries, string $search, UtopiaResponse $response, Database $dbForProject): void { - print_r(json_encode([ - 'context' => $this->getContext(), - 'model' => $this->getResponseModel() - ], JSON_PRETTY_PRINT)); - $database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); if ($database->isEmpty()) { From 5287a3d6190960320888ab2ebe7bb88779927f41 Mon Sep 17 00:00:00 2001 From: Darshan Date: Thu, 19 Jun 2025 14:52:01 +0530 Subject: [PATCH 38/40] address comment. --- .../Databases/Http/Databases/Collections/Attributes/Delete.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Delete.php index 271ea56f29..5816de31a2 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Delete.php @@ -26,7 +26,6 @@ class Delete extends Action protected function getResponseModel(): string|array { - // we should correctly & carefully set the context later. return UtopiaResponse::MODEL_NONE; } From 7ebe8f6c9e687b665166d481697c60866a9addc6 Mon Sep 17 00:00:00 2001 From: Darshan Date: Thu, 19 Jun 2025 17:34:16 +0530 Subject: [PATCH 39/40] revert: legacy tests namespacing to old. --- tests/e2e/Services/GraphQL/Base.php | 80 ++++++------ .../{Collections => Legacy}/AbuseTest.php | 2 +- .../{Collections => Legacy}/AuthTest.php | 8 +- .../DatabaseClientTest.php | 22 ++-- .../DatabaseServerTest.php | 118 +++++++++--------- 5 files changed, 115 insertions(+), 115 deletions(-) rename tests/e2e/Services/GraphQL/{Collections => Legacy}/AbuseTest.php (99%) rename tests/e2e/Services/GraphQL/{Collections => Legacy}/AuthTest.php (96%) rename tests/e2e/Services/GraphQL/{Collections => Legacy}/DatabaseClientTest.php (94%) rename tests/e2e/Services/GraphQL/{Collections => Legacy}/DatabaseServerTest.php (91%) diff --git a/tests/e2e/Services/GraphQL/Base.php b/tests/e2e/Services/GraphQL/Base.php index f001265caf..3da4dc11a3 100644 --- a/tests/e2e/Services/GraphQL/Base.php +++ b/tests/e2e/Services/GraphQL/Base.php @@ -626,7 +626,7 @@ trait Base }'; case self::$CREATE_STRING_ATTRIBUTE: return 'mutation createStringAttribute($databaseId: String!, $collectionId: String!, $key: String!, $size: Int!, $required: Boolean!, $default: String, $array: Boolean){ - collectionsCreateStringAttribute(databaseId: $databaseId, collectionId: $collectionId, key: $key, size: $size, required: $required, default: $default, array: $array) { + databasesCreateStringAttribute(databaseId: $databaseId, collectionId: $collectionId, key: $key, size: $size, required: $required, default: $default, array: $array) { key required default @@ -635,7 +635,7 @@ trait Base }'; case self::$CREATE_INTEGER_ATTRIBUTE: return 'mutation createIntegerAttribute($databaseId: String!, $collectionId: String!, $key: String!, $required: Boolean!, $min: Int, $max: Int, $default: Int, $array: Boolean){ - collectionsCreateIntegerAttribute(databaseId: $databaseId, collectionId: $collectionId, key: $key, min: $min, max: $max, required: $required, default: $default, array: $array) { + databasesCreateIntegerAttribute(databaseId: $databaseId, collectionId: $collectionId, key: $key, min: $min, max: $max, required: $required, default: $default, array: $array) { key required min @@ -646,7 +646,7 @@ trait Base }'; case self::$CREATE_FLOAT_ATTRIBUTE: return 'mutation createFloatAttribute($databaseId: String!, $collectionId: String!, $key: String!, $required: Boolean!, $min: Float, $max: Float, $default: Float, $array: Boolean){ - collectionsCreateFloatAttribute(databaseId: $databaseId, collectionId: $collectionId, key: $key, min: $min, max: $max, required: $required, default: $default, array: $array) { + databasesCreateFloatAttribute(databaseId: $databaseId, collectionId: $collectionId, key: $key, min: $min, max: $max, required: $required, default: $default, array: $array) { key required min @@ -657,7 +657,7 @@ trait Base }'; case self::$CREATE_BOOLEAN_ATTRIBUTE: return 'mutation createBooleanAttribute($databaseId: String!, $collectionId: String!, $key: String!, $required: Boolean!, $default: Boolean, $array: Boolean){ - collectionsCreateBooleanAttribute(databaseId: $databaseId, collectionId: $collectionId, key: $key, required: $required, default: $default, array: $array) { + databasesCreateBooleanAttribute(databaseId: $databaseId, collectionId: $collectionId, key: $key, required: $required, default: $default, array: $array) { key required default @@ -666,7 +666,7 @@ trait Base }'; case self::$CREATE_URL_ATTRIBUTE: return 'mutation createUrlAttribute($databaseId: String!, $collectionId: String!, $key: String!, $required: Boolean!, $default: String, $array: Boolean){ - collectionsCreateUrlAttribute(databaseId: $databaseId, collectionId: $collectionId, key: $key, required: $required, default: $default, array: $array) { + databasesCreateUrlAttribute(databaseId: $databaseId, collectionId: $collectionId, key: $key, required: $required, default: $default, array: $array) { key required default @@ -675,7 +675,7 @@ trait Base }'; case self::$CREATE_EMAIL_ATTRIBUTE: return 'mutation createEmailAttribute($databaseId: String!, $collectionId: String!, $key: String!, $required: Boolean!, $default: String, $array: Boolean){ - collectionsCreateEmailAttribute(databaseId: $databaseId, collectionId: $collectionId, key: $key, required: $required, default: $default, array: $array) { + databasesCreateEmailAttribute(databaseId: $databaseId, collectionId: $collectionId, key: $key, required: $required, default: $default, array: $array) { key required default @@ -684,7 +684,7 @@ trait Base }'; case self::$CREATE_IP_ATTRIBUTE: return 'mutation createIpAttribute($databaseId: String!, $collectionId: String!, $key: String!, $required: Boolean!, $default: String, $array: Boolean){ - collectionsCreateIpAttribute(databaseId: $databaseId, collectionId: $collectionId, key: $key, required: $required, default: $default, array: $array) { + databasesCreateIpAttribute(databaseId: $databaseId, collectionId: $collectionId, key: $key, required: $required, default: $default, array: $array) { key required default @@ -693,7 +693,7 @@ trait Base }'; case self::$CREATE_ENUM_ATTRIBUTE: return 'mutation createEnumAttribute($databaseId: String!, $collectionId: String!, $key: String!, $elements: [String!]!, $required: Boolean!, $default: String, $array: Boolean){ - collectionsCreateEnumAttribute(databaseId: $databaseId, collectionId: $collectionId, key: $key, elements: $elements, required: $required, default: $default, array: $array) { + databasesCreateEnumAttribute(databaseId: $databaseId, collectionId: $collectionId, key: $key, elements: $elements, required: $required, default: $default, array: $array) { key elements required @@ -703,7 +703,7 @@ trait Base }'; case self::$CREATE_DATETIME_ATTRIBUTE: return 'mutation createDatetimeAttribute($databaseId: String!, $collectionId: String!, $key: String!, $required: Boolean!, $default: String, $array: Boolean){ - collectionsCreateDatetimeAttribute(databaseId: $databaseId, collectionId: $collectionId, key: $key, required: $required, default: $default, array: $array) { + databasesCreateDatetimeAttribute(databaseId: $databaseId, collectionId: $collectionId, key: $key, required: $required, default: $default, array: $array) { key required default @@ -712,7 +712,7 @@ trait Base }'; case self::$CREATE_RELATIONSHIP_ATTRIBUTE: return 'mutation createRelationshipAttribute($databaseId: String!, $collectionId: String!, $relatedCollectionId: String!, $type: String!, $twoWay: Boolean, $key: String, $twoWayKey: String, $onDelete: String){ - collectionsCreateRelationshipAttribute(databaseId: $databaseId, collectionId: $collectionId, relatedCollectionId: $relatedCollectionId, type: $type, twoWay: $twoWay, key: $key, twoWayKey: $twoWayKey, onDelete: $onDelete) { + databasesCreateRelationshipAttribute(databaseId: $databaseId, collectionId: $collectionId, relatedCollectionId: $relatedCollectionId, type: $type, twoWay: $twoWay, key: $key, twoWayKey: $twoWayKey, onDelete: $onDelete) { relatedCollection relationType twoWay @@ -723,14 +723,14 @@ trait Base }'; case self::$UPDATE_STRING_ATTRIBUTE: return 'mutation updateStringAttribute($databaseId: String!, $collectionId: String!, $key: String!, $required: Boolean!, $default: String){ - collectionsUpdateStringAttribute(databaseId: $databaseId, collectionId: $collectionId, key: $key, required: $required, default: $default) { + databasesUpdateStringAttribute(databaseId: $databaseId, collectionId: $collectionId, key: $key, required: $required, default: $default) { required default } }'; case self::$UPDATE_INTEGER_ATTRIBUTE: return 'mutation updateIntegerAttribute($databaseId: String!, $collectionId: String!, $key: String!, $required: Boolean!, $min: Int!, $max: Int!, $default: Int){ - collectionsUpdateIntegerAttribute(databaseId: $databaseId, collectionId: $collectionId, key: $key, required: $required, min: $min, max: $max, default: $default) { + databasesUpdateIntegerAttribute(databaseId: $databaseId, collectionId: $collectionId, key: $key, required: $required, min: $min, max: $max, default: $default) { required min max @@ -739,7 +739,7 @@ trait Base }'; case self::$UPDATE_FLOAT_ATTRIBUTE: return 'mutation updateFloatAttribute($databaseId: String!, $collectionId: String!, $key: String!, $required: Boolean!, $min: Float!, $max: Float!, $default: Float){ - collectionsUpdateFloatAttribute(databaseId: $databaseId, collectionId: $collectionId, key: $key, min: $min, max: $max, required: $required, default: $default) { + databasesUpdateFloatAttribute(databaseId: $databaseId, collectionId: $collectionId, key: $key, min: $min, max: $max, required: $required, default: $default) { required min max @@ -748,35 +748,35 @@ trait Base }'; case self::$UPDATE_BOOLEAN_ATTRIBUTE: return 'mutation updateBooleanAttribute($databaseId: String!, $collectionId: String!, $key: String!, $required: Boolean!, $default: Boolean){ - collectionsUpdateBooleanAttribute(databaseId: $databaseId, collectionId: $collectionId, key: $key, required: $required, default: $default) { + databasesUpdateBooleanAttribute(databaseId: $databaseId, collectionId: $collectionId, key: $key, required: $required, default: $default) { required default } }'; case self::$UPDATE_URL_ATTRIBUTE: return 'mutation updateUrlAttribute($databaseId: String!, $collectionId: String!, $key: String!, $required: Boolean!, $default: String){ - collectionsUpdateUrlAttribute(databaseId: $databaseId, collectionId: $collectionId, key: $key, required: $required, default: $default) { + databasesUpdateUrlAttribute(databaseId: $databaseId, collectionId: $collectionId, key: $key, required: $required, default: $default) { required default } }'; case self::$UPDATE_EMAIL_ATTRIBUTE: return 'mutation updateEmailAttribute($databaseId: String!, $collectionId: String!, $key: String!, $required: Boolean!, $default: String){ - collectionsUpdateEmailAttribute(databaseId: $databaseId, collectionId: $collectionId, key: $key, required: $required, default: $default) { + databasesUpdateEmailAttribute(databaseId: $databaseId, collectionId: $collectionId, key: $key, required: $required, default: $default) { required default } }'; case self::$UPDATE_IP_ATTRIBUTE: return 'mutation updateIpAttribute($databaseId: String!, $collectionId: String!, $key: String!, $required: Boolean!, $default: String){ - collectionsUpdateIpAttribute(databaseId: $databaseId, collectionId: $collectionId, key: $key, required: $required, default: $default) { + databasesUpdateIpAttribute(databaseId: $databaseId, collectionId: $collectionId, key: $key, required: $required, default: $default) { required default } }'; case self::$UPDATE_ENUM_ATTRIBUTE: return 'mutation updateEnumAttribute($databaseId: String!, $collectionId: String!, $key: String!, $elements: [String!]!, $required: Boolean!, $default: String){ - collectionsUpdateEnumAttribute(databaseId: $databaseId, collectionId: $collectionId, key: $key, elements: $elements, required: $required, default: $default) { + databasesUpdateEnumAttribute(databaseId: $databaseId, collectionId: $collectionId, key: $key, elements: $elements, required: $required, default: $default) { elements required default @@ -784,14 +784,14 @@ trait Base }'; case self::$UPDATE_DATETIME_ATTRIBUTE: return 'mutation updateDatetimeAttribute($databaseId: String!, $collectionId: String!, $key: String!, $required: Boolean!, $default: String){ - collectionsUpdateDatetimeAttribute(databaseId: $databaseId, collectionId: $collectionId, key: $key, required: $required, default: $default) { + databasesUpdateDatetimeAttribute(databaseId: $databaseId, collectionId: $collectionId, key: $key, required: $required, default: $default) { required default } }'; case self::$UPDATE_RELATIONSHIP_ATTRIBUTE: return 'mutation updateRelationshipAttribute($databaseId: String!, $collectionId: String!, $key: String!, $onDelete: String){ - collectionsUpdateRelationshipAttribute(databaseId: $databaseId, collectionId: $collectionId, key: $key, onDelete: $onDelete) { + databasesUpdateRelationshipAttribute(databaseId: $databaseId, collectionId: $collectionId, key: $key, onDelete: $onDelete) { relatedCollection relationType twoWay @@ -978,7 +978,7 @@ trait Base }'; case self::$CREATE_INDEX: return 'mutation createIndex($databaseId: String!, $collectionId: String!, $key: String!, $type: String!, $attributes: [String!]!, $orders: [String!]){ - collectionsCreateIndex(databaseId: $databaseId, collectionId: $collectionId, key: $key, type: $type, attributes: $attributes, orders: $orders) { + databasesCreateIndex(databaseId: $databaseId, collectionId: $collectionId, key: $key, type: $type, attributes: $attributes, orders: $orders) { key type status @@ -986,7 +986,7 @@ trait Base }'; case self::$GET_INDEXES: return 'query listIndexes($databaseId: String!, $collectionId: String!) { - collectionsListIndexes(databaseId: $databaseId, collectionId: $collectionId) { + databasesListIndexes(databaseId: $databaseId, collectionId: $collectionId) { total indexes { key @@ -997,7 +997,7 @@ trait Base }'; case self::$GET_INDEX: return 'query getIndex($databaseId: String!, $collectionId: String!, $key: String!) { - collectionsGetIndex(databaseId: $databaseId, collectionId: $collectionId, key: $key) { + databasesGetIndex(databaseId: $databaseId, collectionId: $collectionId, key: $key) { key type status @@ -1005,7 +1005,7 @@ trait Base }'; case self::$DELETE_INDEX: return 'mutation deleteIndex($databaseId: String!, $collectionId: String!, $key: String!) { - collectionsDeleteIndex(databaseId: $databaseId, collectionId: $collectionId, key: $key) { + databasesDeleteIndex(databaseId: $databaseId, collectionId: $collectionId, key: $key) { status } }'; @@ -1044,7 +1044,7 @@ trait Base }'; case self::$GET_ATTRIBUTES: return 'query listAttributes($databaseId: String!, $collectionId: String!) { - collectionsListAttributes(databaseId: $databaseId, collectionId: $collectionId) { + databasesListAttributes(databaseId: $databaseId, collectionId: $collectionId) { total attributes { ...attributeProperties @@ -1053,13 +1053,13 @@ trait Base }' . PHP_EOL . self::$FRAGMENT_ATTRIBUTES; case self::$GET_ATTRIBUTE: return 'query getAttribute($databaseId: String!, $collectionId: String!, $key: String!) { - collectionsGetAttribute(databaseId: $databaseId, collectionId: $collectionId, key: $key) { + databasesGetAttribute(databaseId: $databaseId, collectionId: $collectionId, key: $key) { ...attributeProperties } }' . PHP_EOL . self::$FRAGMENT_ATTRIBUTES; case self::$DELETE_ATTRIBUTE: return 'mutation deleteAttribute($databaseId: String!, $collectionId: String!, $key: String!) { - collectionsDeleteAttribute(databaseId: $databaseId, collectionId: $collectionId, key: $key) { + databasesDeleteAttribute(databaseId: $databaseId, collectionId: $collectionId, key: $key) { status } }'; @@ -1087,7 +1087,7 @@ trait Base case self::$GET_DOCUMENT: return 'query getDocument($databaseId: String!, $collectionId: String!, $documentId: String!) { - collectionsGetDocument(databaseId: $databaseId, collectionId: $collectionId, documentId: $documentId) { + databasesGetDocument(databaseId: $databaseId, collectionId: $collectionId, documentId: $documentId) { _id _collectionId _permissions @@ -1096,7 +1096,7 @@ trait Base }'; case self::$GET_DOCUMENTS: return 'query listDocuments($databaseId: String!, $collectionId: String!){ - collectionsListDocuments(databaseId: $databaseId, collectionId: $collectionId) { + databasesListDocuments(databaseId: $databaseId, collectionId: $collectionId) { total documents { _id @@ -1108,7 +1108,7 @@ trait Base }'; case self::$CREATE_DOCUMENT: return 'mutation createDocument($databaseId: String!, $collectionId: String!, $documentId: String!, $data: Json!, $permissions: [String!]){ - collectionsCreateDocument(databaseId: $databaseId, collectionId: $collectionId, documentId: $documentId, data: $data, permissions: $permissions) { + databasesCreateDocument(databaseId: $databaseId, collectionId: $collectionId, documentId: $documentId, data: $data, permissions: $permissions) { _id _collectionId _permissions @@ -1116,7 +1116,7 @@ trait Base }'; case self::$CREATE_DOCUMENTS: return 'mutation createDocuments($databaseId: String!, $collectionId: String!, $documents: [Json!]!) { - collectionsCreateDocuments(databaseId: $databaseId, collectionId: $collectionId, documents: $documents) { + databasesCreateDocuments(databaseId: $databaseId, collectionId: $collectionId, documents: $documents) { documents { _id _collectionId @@ -1227,7 +1227,7 @@ trait Base }'; case self::$UPDATE_DOCUMENT: return 'mutation updateDocument($databaseId: String!, $collectionId: String!, $documentId: String!, $data: Json!, $permissions: [String!]){ - collectionsUpdateDocument(databaseId: $databaseId, collectionId: $collectionId, documentId: $documentId, data: $data, permissions: $permissions) { + databasesUpdateDocument(databaseId: $databaseId, collectionId: $collectionId, documentId: $documentId, data: $data, permissions: $permissions) { _id _collectionId data @@ -1235,7 +1235,7 @@ trait Base }'; case self::$UPSERT_DOCUMENT: return 'mutation upsertDocument($databaseId: String!, $collectionId: String!, $documentId: String!, $data: Json!, $permissions: [String!] = []) { - collectionsUpsertDocument(databaseId: $databaseId, collectionId: $collectionId, documentId: $documentId, data: $data, permissions: $permissions) { + databasesUpsertDocument(databaseId: $databaseId, collectionId: $collectionId, documentId: $documentId, data: $data, permissions: $permissions) { _id _databaseId _collectionId @@ -1244,7 +1244,7 @@ trait Base }'; case self::$UPDATE_DOCUMENTS: return 'mutation updateDocuments($databaseId: String!, $collectionId: String!, $data: Json!, $queries: [String!]) { - collectionsUpdateDocuments(databaseId: $databaseId, collectionId: $collectionId, data: $data, queries: $queries) { + databasesUpdateDocuments(databaseId: $databaseId, collectionId: $collectionId, data: $data, queries: $queries) { total documents { _id @@ -1257,7 +1257,7 @@ trait Base }'; case self::$UPSERT_DOCUMENTS: return 'mutation upsertDocuments($databaseId: String!, $collectionId: String!, $documents: [Json!]!) { - collectionsUpsertDocuments(databaseId: $databaseId, collectionId: $collectionId, documents: $documents) { + databasesUpsertDocuments(databaseId: $databaseId, collectionId: $collectionId, documents: $documents) { total documents { _id @@ -1270,7 +1270,7 @@ trait Base }'; case self::$DELETE_DOCUMENTS: return 'mutation deleteDocuments($databaseId: String!, $collectionId: String!, $queries: [String!] = []) { - collectionsDeleteDocuments(databaseId: $databaseId, collectionId: $collectionId, queries: $queries) { + databasesDeleteDocuments(databaseId: $databaseId, collectionId: $collectionId, queries: $queries) { total documents { _id @@ -1282,7 +1282,7 @@ trait Base }'; case self::$DELETE_DOCUMENT: return 'mutation deleteDocument($databaseId: String!, $collectionId: String!, $documentId: String!){ - collectionsDeleteDocument(databaseId: $databaseId, collectionId: $collectionId, documentId: $documentId) { + databasesDeleteDocument(databaseId: $databaseId, collectionId: $collectionId, documentId: $documentId) { status } }'; @@ -2844,7 +2844,7 @@ trait Base status } } - collectionsCreateStringAttribute(databaseId: $databaseId, collectionId: $collectionId, key: "name", size: 255, required: true) { + databasesCreateStringAttribute(databaseId: $databaseId, collectionId: $collectionId, key: "name", size: 255, required: true) { key type status @@ -2853,7 +2853,7 @@ trait Base default array } - collectionsCreateIntegerAttribute(databaseId: $databaseId, collectionId: $collectionId, key: "age", min: 0, max: 150, required: true) { + databasesCreateIntegerAttribute(databaseId: $databaseId, collectionId: $collectionId, key: "age", min: 0, max: 150, required: true) { key type status @@ -2863,7 +2863,7 @@ trait Base default array } - collectionsCreateBooleanAttribute(databaseId: $databaseId, collectionId: $collectionId, key: "alive", required: false, default: true) { + databasesCreateBooleanAttribute(databaseId: $databaseId, collectionId: $collectionId, key: "alive", required: false, default: true) { key type status diff --git a/tests/e2e/Services/GraphQL/Collections/AbuseTest.php b/tests/e2e/Services/GraphQL/Legacy/AbuseTest.php similarity index 99% rename from tests/e2e/Services/GraphQL/Collections/AbuseTest.php rename to tests/e2e/Services/GraphQL/Legacy/AbuseTest.php index a58a57ec5a..d579ddb128 100644 --- a/tests/e2e/Services/GraphQL/Collections/AbuseTest.php +++ b/tests/e2e/Services/GraphQL/Legacy/AbuseTest.php @@ -1,6 +1,6 @@ [ 'databaseId' => $this->database['body']['data']['databasesCreate']['_id'], 'collectionId' => $this->collection['body']['data']['databasesCreateCollection']['_id'], - 'documentId' => $document['body']['data']['collectionsCreateDocument']['_id'], + 'documentId' => $document['body']['data']['databasesCreateDocument']['_id'], ] ]; $document = $this->client->call(Client::METHOD_POST, '/graphql', [ @@ -188,7 +188,7 @@ class AuthTest extends Scope 'cookie' => 'a_session_' . $projectId . '=' . $this->token1, ], $gqlPayload); - $this->assertIsArray($document['body']['data']['collectionsGetDocument']); + $this->assertIsArray($document['body']['data']['databasesGetDocument']); $this->assertArrayNotHasKey('errors', $document['body']); // Try to read as account 2 @@ -238,7 +238,7 @@ class AuthTest extends Scope 'variables' => [ 'databaseId' => $this->database['body']['data']['databasesCreate']['_id'], 'collectionId' => $this->collection['body']['data']['databasesCreateCollection']['_id'], - 'documentId' => $document['body']['data']['collectionsCreateDocument']['_id'], + 'documentId' => $document['body']['data']['databasesCreateDocument']['_id'], ] ]; $document = $this->client->call(Client::METHOD_POST, '/graphql', [ diff --git a/tests/e2e/Services/GraphQL/Collections/DatabaseClientTest.php b/tests/e2e/Services/GraphQL/Legacy/DatabaseClientTest.php similarity index 94% rename from tests/e2e/Services/GraphQL/Collections/DatabaseClientTest.php rename to tests/e2e/Services/GraphQL/Legacy/DatabaseClientTest.php index 349d580d64..c2c63e41c0 100644 --- a/tests/e2e/Services/GraphQL/Collections/DatabaseClientTest.php +++ b/tests/e2e/Services/GraphQL/Legacy/DatabaseClientTest.php @@ -1,6 +1,6 @@ assertArrayNotHasKey('errors', $attribute['body']); $this->assertIsArray($attribute['body']['data']); - $this->assertIsArray($attribute['body']['data']['collectionsCreateStringAttribute']); + $this->assertIsArray($attribute['body']['data']['databasesCreateStringAttribute']); return $data; } @@ -141,7 +141,7 @@ class DatabaseClientTest extends Scope $this->assertArrayNotHasKey('errors', $attribute['body']); $this->assertIsArray($attribute['body']['data']); - $this->assertIsArray($attribute['body']['data']['collectionsCreateIntegerAttribute']); + $this->assertIsArray($attribute['body']['data']['databasesCreateIntegerAttribute']); return $data; } @@ -182,7 +182,7 @@ class DatabaseClientTest extends Scope $this->assertArrayNotHasKey('errors', $document['body']); $this->assertIsArray($document['body']['data']); - $document = $document['body']['data']['collectionsCreateDocument']; + $document = $document['body']['data']['databasesCreateDocument']; $this->assertIsArray($document); return [ @@ -215,7 +215,7 @@ class DatabaseClientTest extends Scope $this->assertArrayNotHasKey('errors', $documents['body']); $this->assertIsArray($documents['body']['data']); - $this->assertIsArray($documents['body']['data']['collectionsListDocuments']); + $this->assertIsArray($documents['body']['data']['databasesListDocuments']); } /** @@ -242,7 +242,7 @@ class DatabaseClientTest extends Scope $this->assertArrayNotHasKey('errors', $document['body']); $this->assertIsArray($document['body']['data']); - $this->assertIsArray($document['body']['data']['collectionsGetDocument']); + $this->assertIsArray($document['body']['data']['databasesGetDocument']); } /** @@ -272,7 +272,7 @@ class DatabaseClientTest extends Scope $this->assertArrayNotHasKey('errors', $document['body']); $this->assertIsArray($document['body']['data']); - $document = $document['body']['data']['collectionsUpdateDocument']; + $document = $document['body']['data']['databasesUpdateDocument']; $this->assertIsArray($document); $this->assertStringContainsString('New Document Name', $document['data']); @@ -377,7 +377,7 @@ class DatabaseClientTest extends Scope ]; $res = $this->client->call(Client::METHOD_POST, '/graphql', $headers, $payload); $this->assertArrayNotHasKey('errors', $res['body']); - $this->assertCount(10, $res['body']['data']['collectionsCreateDocuments']['documents']); + $this->assertCount(10, $res['body']['data']['databasesCreateDocuments']['documents']); return [ 'databaseId' => $databaseId, @@ -418,7 +418,7 @@ class DatabaseClientTest extends Scope ]; $res = $this->client->call(Client::METHOD_POST, '/graphql', $headers, $payload); $this->assertArrayNotHasKey('errors', $res['body']); - $this->assertCount(10, $res['body']['data']['collectionsUpdateDocuments']['documents']); + $this->assertCount(10, $res['body']['data']['databasesUpdateDocuments']['documents']); return $data; } @@ -449,7 +449,7 @@ class DatabaseClientTest extends Scope ]; $res = $this->client->call(Client::METHOD_POST, '/graphql', $headers, $payload); $this->assertArrayNotHasKey('errors', $res['body']); - $this->assertCount(2, $res['body']['data']['collectionsUpsertDocuments']['documents']); + $this->assertCount(2, $res['body']['data']['databasesUpsertDocuments']['documents']); return $data; } @@ -475,7 +475,7 @@ class DatabaseClientTest extends Scope ]; $res = $this->client->call(Client::METHOD_POST, '/graphql', $headers, $payload); $this->assertArrayNotHasKey('errors', $res['body']); - $this->assertCount(11, $res['body']['data']['collectionsDeleteDocuments']['documents']); + $this->assertCount(11, $res['body']['data']['databasesDeleteDocuments']['documents']); return $data; } diff --git a/tests/e2e/Services/GraphQL/Collections/DatabaseServerTest.php b/tests/e2e/Services/GraphQL/Legacy/DatabaseServerTest.php similarity index 91% rename from tests/e2e/Services/GraphQL/Collections/DatabaseServerTest.php rename to tests/e2e/Services/GraphQL/Legacy/DatabaseServerTest.php index 3e5b457308..3ecc96eaa0 100644 --- a/tests/e2e/Services/GraphQL/Collections/DatabaseServerTest.php +++ b/tests/e2e/Services/GraphQL/Legacy/DatabaseServerTest.php @@ -1,6 +1,6 @@ assertArrayNotHasKey('errors', $attribute['body']); $this->assertIsArray($attribute['body']['data']); - $this->assertIsArray($attribute['body']['data']['collectionsCreateStringAttribute']); + $this->assertIsArray($attribute['body']['data']['databasesCreateStringAttribute']); return $data; } @@ -170,9 +170,9 @@ class DatabaseServerTest extends Scope ], $this->getHeaders()), $gqlPayload); $this->assertIsArray($attribute['body']['data']); - $this->assertIsArray($attribute['body']['data']['collectionsUpdateStringAttribute']); - $this->assertFalse($attribute['body']['data']['collectionsUpdateStringAttribute']['required']); - $this->assertEquals('Default Value', $attribute['body']['data']['collectionsUpdateStringAttribute']['default']); + $this->assertIsArray($attribute['body']['data']['databasesUpdateStringAttribute']); + $this->assertFalse($attribute['body']['data']['databasesUpdateStringAttribute']['required']); + $this->assertEquals('Default Value', $attribute['body']['data']['databasesUpdateStringAttribute']['default']); $this->assertEquals(200, $attribute['headers']['status-code']); return $data; @@ -205,7 +205,7 @@ class DatabaseServerTest extends Scope $this->assertArrayNotHasKey('errors', $attribute['body']); $this->assertIsArray($attribute['body']['data']); - $this->assertIsArray($attribute['body']['data']['collectionsCreateIntegerAttribute']); + $this->assertIsArray($attribute['body']['data']['databasesCreateIntegerAttribute']); return $data; } @@ -240,11 +240,11 @@ class DatabaseServerTest extends Scope ], $this->getHeaders()), $gqlPayload); $this->assertIsArray($attribute['body']['data']); - $this->assertIsArray($attribute['body']['data']['collectionsUpdateIntegerAttribute']); - $this->assertFalse($attribute['body']['data']['collectionsUpdateIntegerAttribute']['required']); - $this->assertEquals(12, $attribute['body']['data']['collectionsUpdateIntegerAttribute']['min']); - $this->assertEquals(160, $attribute['body']['data']['collectionsUpdateIntegerAttribute']['max']); - $this->assertEquals(50, $attribute['body']['data']['collectionsUpdateIntegerAttribute']['default']); + $this->assertIsArray($attribute['body']['data']['databasesUpdateIntegerAttribute']); + $this->assertFalse($attribute['body']['data']['databasesUpdateIntegerAttribute']['required']); + $this->assertEquals(12, $attribute['body']['data']['databasesUpdateIntegerAttribute']['min']); + $this->assertEquals(160, $attribute['body']['data']['databasesUpdateIntegerAttribute']['max']); + $this->assertEquals(50, $attribute['body']['data']['databasesUpdateIntegerAttribute']['default']); $this->assertEquals(200, $attribute['headers']['status-code']); return $data; @@ -275,7 +275,7 @@ class DatabaseServerTest extends Scope $this->assertArrayNotHasKey('errors', $attribute['body']); $this->assertIsArray($attribute['body']['data']); - $this->assertIsArray($attribute['body']['data']['collectionsCreateBooleanAttribute']); + $this->assertIsArray($attribute['body']['data']['databasesCreateBooleanAttribute']); return $data; } @@ -308,9 +308,9 @@ class DatabaseServerTest extends Scope ], $this->getHeaders()), $gqlPayload); $this->assertIsArray($attribute['body']['data']); - $this->assertIsArray($attribute['body']['data']['collectionsUpdateBooleanAttribute']); - $this->assertFalse($attribute['body']['data']['collectionsUpdateBooleanAttribute']['required']); - $this->assertTrue($attribute['body']['data']['collectionsUpdateBooleanAttribute']['default']); + $this->assertIsArray($attribute['body']['data']['databasesUpdateBooleanAttribute']); + $this->assertFalse($attribute['body']['data']['databasesUpdateBooleanAttribute']['required']); + $this->assertTrue($attribute['body']['data']['databasesUpdateBooleanAttribute']['default']); $this->assertEquals(200, $attribute['headers']['status-code']); return $data; @@ -344,7 +344,7 @@ class DatabaseServerTest extends Scope $this->assertArrayNotHasKey('errors', $attribute['body']); $this->assertIsArray($attribute['body']['data']); - $this->assertIsArray($attribute['body']['data']['collectionsCreateFloatAttribute']); + $this->assertIsArray($attribute['body']['data']['databasesCreateFloatAttribute']); return $data; } @@ -379,11 +379,11 @@ class DatabaseServerTest extends Scope ], $this->getHeaders()), $gqlPayload); $this->assertIsArray($attribute['body']['data']); - $this->assertIsArray($attribute['body']['data']['collectionsUpdateFloatAttribute']); - $this->assertFalse($attribute['body']['data']['collectionsUpdateFloatAttribute']['required']); - $this->assertEquals(100.0, $attribute['body']['data']['collectionsUpdateFloatAttribute']['min']); - $this->assertEquals(1000000.0, $attribute['body']['data']['collectionsUpdateFloatAttribute']['max']); - $this->assertEquals(2500.0, $attribute['body']['data']['collectionsUpdateFloatAttribute']['default']); + $this->assertIsArray($attribute['body']['data']['databasesUpdateFloatAttribute']); + $this->assertFalse($attribute['body']['data']['databasesUpdateFloatAttribute']['required']); + $this->assertEquals(100.0, $attribute['body']['data']['databasesUpdateFloatAttribute']['min']); + $this->assertEquals(1000000.0, $attribute['body']['data']['databasesUpdateFloatAttribute']['max']); + $this->assertEquals(2500.0, $attribute['body']['data']['databasesUpdateFloatAttribute']['default']); $this->assertEquals(200, $attribute['headers']['status-code']); return $data; @@ -414,7 +414,7 @@ class DatabaseServerTest extends Scope $this->assertArrayNotHasKey('errors', $attribute['body']); $this->assertIsArray($attribute['body']['data']); - $this->assertIsArray($attribute['body']['data']['collectionsCreateEmailAttribute']); + $this->assertIsArray($attribute['body']['data']['databasesCreateEmailAttribute']); return $data; } @@ -447,9 +447,9 @@ class DatabaseServerTest extends Scope ], $this->getHeaders()), $gqlPayload); $this->assertIsArray($attribute['body']['data']); - $this->assertIsArray($attribute['body']['data']['collectionsUpdateEmailAttribute']); - $this->assertFalse($attribute['body']['data']['collectionsUpdateEmailAttribute']['required']); - $this->assertEquals('torsten@appwrite.io', $attribute['body']['data']['collectionsUpdateEmailAttribute']['default']); + $this->assertIsArray($attribute['body']['data']['databasesUpdateEmailAttribute']); + $this->assertFalse($attribute['body']['data']['databasesUpdateEmailAttribute']['required']); + $this->assertEquals('torsten@appwrite.io', $attribute['body']['data']['databasesUpdateEmailAttribute']['default']); $this->assertEquals(200, $attribute['headers']['status-code']); return $data; @@ -485,7 +485,7 @@ class DatabaseServerTest extends Scope $this->assertArrayNotHasKey('errors', $attribute['body']); $this->assertIsArray($attribute['body']['data']); - $this->assertIsArray($attribute['body']['data']['collectionsCreateEnumAttribute']); + $this->assertIsArray($attribute['body']['data']['databasesCreateEnumAttribute']); return $data; } @@ -524,11 +524,11 @@ class DatabaseServerTest extends Scope ], $this->getHeaders()), $gqlPayload); $this->assertIsArray($attribute['body']['data']); - $this->assertIsArray($attribute['body']['data']['collectionsUpdateEnumAttribute']); - $this->assertFalse($attribute['body']['data']['collectionsUpdateEnumAttribute']['required']); - $this->assertEquals('tech', $attribute['body']['data']['collectionsUpdateEnumAttribute']['default']); - $this->assertContains('tech', $attribute['body']['data']['collectionsUpdateEnumAttribute']['elements']); - $this->assertNotContains('guest', $attribute['body']['data']['collectionsUpdateEnumAttribute']['elements']); + $this->assertIsArray($attribute['body']['data']['databasesUpdateEnumAttribute']); + $this->assertFalse($attribute['body']['data']['databasesUpdateEnumAttribute']['required']); + $this->assertEquals('tech', $attribute['body']['data']['databasesUpdateEnumAttribute']['default']); + $this->assertContains('tech', $attribute['body']['data']['databasesUpdateEnumAttribute']['elements']); + $this->assertNotContains('guest', $attribute['body']['data']['databasesUpdateEnumAttribute']['elements']); $this->assertEquals(200, $attribute['headers']['status-code']); return $data; @@ -559,7 +559,7 @@ class DatabaseServerTest extends Scope $this->assertArrayNotHasKey('errors', $attribute['body']); $this->assertIsArray($attribute['body']['data']); - $this->assertIsArray($attribute['body']['data']['collectionsCreateDatetimeAttribute']); + $this->assertIsArray($attribute['body']['data']['databasesCreateDatetimeAttribute']); return $data; } @@ -592,9 +592,9 @@ class DatabaseServerTest extends Scope ], $this->getHeaders()), $gqlPayload); $this->assertIsArray($attribute['body']['data']); - $this->assertIsArray($attribute['body']['data']['collectionsUpdateDatetimeAttribute']); - $this->assertFalse($attribute['body']['data']['collectionsUpdateDatetimeAttribute']['required']); - $this->assertEquals('2000-01-01T00:00:00Z', $attribute['body']['data']['collectionsUpdateDatetimeAttribute']['default']); + $this->assertIsArray($attribute['body']['data']['databasesUpdateDatetimeAttribute']); + $this->assertFalse($attribute['body']['data']['databasesUpdateDatetimeAttribute']['required']); + $this->assertEquals('2000-01-01T00:00:00Z', $attribute['body']['data']['databasesUpdateDatetimeAttribute']['default']); $this->assertEquals(200, $attribute['headers']['status-code']); return $data; @@ -627,7 +627,7 @@ class DatabaseServerTest extends Scope $this->assertArrayNotHasKey('errors', $attribute['body']); $this->assertIsArray($attribute['body']['data']); - $this->assertIsArray($attribute['body']['data']['collectionsCreateRelationshipAttribute']); + $this->assertIsArray($attribute['body']['data']['databasesCreateRelationshipAttribute']); return $data; } @@ -658,7 +658,7 @@ class DatabaseServerTest extends Scope $this->assertArrayNotHasKey('errors', $attribute['body']); $this->assertIsArray($attribute['body']['data']); - $this->assertIsArray($attribute['body']['data']['collectionsUpdateRelationshipAttribute']); + $this->assertIsArray($attribute['body']['data']['databasesUpdateRelationshipAttribute']); return $data; } @@ -689,7 +689,7 @@ class DatabaseServerTest extends Scope $this->assertArrayNotHasKey('errors', $attribute['body']); $this->assertIsArray($attribute['body']['data']); - $this->assertIsArray($attribute['body']['data']['collectionsCreateIpAttribute']); + $this->assertIsArray($attribute['body']['data']['databasesCreateIpAttribute']); return $data; } @@ -722,9 +722,9 @@ class DatabaseServerTest extends Scope ], $this->getHeaders()), $gqlPayload); $this->assertIsArray($attribute['body']['data']); - $this->assertIsArray($attribute['body']['data']['collectionsUpdateIpAttribute']); - $this->assertFalse($attribute['body']['data']['collectionsUpdateIpAttribute']['required']); - $this->assertEquals('127.0.0.1', $attribute['body']['data']['collectionsUpdateIpAttribute']['default']); + $this->assertIsArray($attribute['body']['data']['databasesUpdateIpAttribute']); + $this->assertFalse($attribute['body']['data']['databasesUpdateIpAttribute']['required']); + $this->assertEquals('127.0.0.1', $attribute['body']['data']['databasesUpdateIpAttribute']['default']); $this->assertEquals(200, $attribute['headers']['status-code']); return $data; @@ -756,7 +756,7 @@ class DatabaseServerTest extends Scope $this->assertArrayNotHasKey('errors', $attribute['body']); $this->assertIsArray($attribute['body']['data']); - $this->assertIsArray($attribute['body']['data']['collectionsCreateUrlAttribute']); + $this->assertIsArray($attribute['body']['data']['databasesCreateUrlAttribute']); return $data; } @@ -789,9 +789,9 @@ class DatabaseServerTest extends Scope ], $this->getHeaders()), $gqlPayload); $this->assertIsArray($attribute['body']['data']); - $this->assertIsArray($attribute['body']['data']['collectionsUpdateUrlAttribute']); - $this->assertFalse($attribute['body']['data']['collectionsUpdateUrlAttribute']['required']); - $this->assertEquals('https://cloud.appwrite.io', $attribute['body']['data']['collectionsUpdateUrlAttribute']['default']); + $this->assertIsArray($attribute['body']['data']['databasesUpdateUrlAttribute']); + $this->assertFalse($attribute['body']['data']['databasesUpdateUrlAttribute']['required']); + $this->assertEquals('https://cloud.appwrite.io', $attribute['body']['data']['databasesUpdateUrlAttribute']['default']); $this->assertEquals(200, $attribute['headers']['status-code']); } @@ -825,12 +825,12 @@ class DatabaseServerTest extends Scope $this->assertArrayNotHasKey('errors', $index['body']); $this->assertIsArray($index['body']['data']); - $this->assertIsArray($index['body']['data']['collectionsCreateIndex']); + $this->assertIsArray($index['body']['data']['databasesCreateIndex']); return [ 'database' => $data['database'], 'collection' => $data['collection'], - 'index' => $index['body']['data']['collectionsCreateIndex'], + 'index' => $index['body']['data']['databasesCreateIndex'], ]; } @@ -876,7 +876,7 @@ class DatabaseServerTest extends Scope $this->assertArrayNotHasKey('errors', $document['body']); $this->assertIsArray($document['body']['data']); - $document = $document['body']['data']['collectionsCreateDocument']; + $document = $document['body']['data']['databasesCreateDocument']; $this->assertIsArray($document); return [ @@ -1044,7 +1044,7 @@ class DatabaseServerTest extends Scope $this->assertArrayNotHasKey('errors', $attributes['body']); $this->assertIsArray($attributes['body']['data']); - $this->assertIsArray($attributes['body']['data']['collectionsListAttributes']); + $this->assertIsArray($attributes['body']['data']['databasesListAttributes']); } /** @@ -1071,7 +1071,7 @@ class DatabaseServerTest extends Scope $this->assertArrayNotHasKey('errors', $attribute['body']); $this->assertIsArray($attribute['body']['data']); - $this->assertIsArray($attribute['body']['data']['collectionsGetAttribute']); + $this->assertIsArray($attribute['body']['data']['databasesGetAttribute']); } /** @@ -1097,7 +1097,7 @@ class DatabaseServerTest extends Scope $this->assertArrayNotHasKey('errors', $indices['body']); $this->assertIsArray($indices['body']['data']); - $this->assertIsArray($indices['body']['data']['collectionsListIndexes']); + $this->assertIsArray($indices['body']['data']['databasesListIndexes']); } /** @@ -1124,7 +1124,7 @@ class DatabaseServerTest extends Scope $this->assertArrayNotHasKey('errors', $index['body']); $this->assertIsArray($index['body']['data']); - $this->assertIsArray($index['body']['data']['collectionsGetIndex']); + $this->assertIsArray($index['body']['data']['databasesGetIndex']); } /** @@ -1150,7 +1150,7 @@ class DatabaseServerTest extends Scope $this->assertArrayNotHasKey('errors', $documents['body']); $this->assertIsArray($documents['body']['data']); - $this->assertIsArray($documents['body']['data']['collectionsListDocuments']); + $this->assertIsArray($documents['body']['data']['databasesListDocuments']); } /** @@ -1177,7 +1177,7 @@ class DatabaseServerTest extends Scope $this->assertArrayNotHasKey('errors', $document['body']); $this->assertIsArray($document['body']['data']); - $this->assertIsArray($document['body']['data']['collectionsGetDocument']); + $this->assertIsArray($document['body']['data']['databasesGetDocument']); } // /** @@ -1308,7 +1308,7 @@ class DatabaseServerTest extends Scope $this->assertArrayNotHasKey('errors', $document['body']); $this->assertIsArray($document['body']['data']); - $document = $document['body']['data']['collectionsUpdateDocument']; + $document = $document['body']['data']['databasesUpdateDocument']; $this->assertIsArray($document); $this->assertStringContainsString('New Document Name', $document['data']); } @@ -1538,7 +1538,7 @@ class DatabaseServerTest extends Scope ]; $res = $this->client->call(Client::METHOD_POST, '/graphql', $headers, $payload); $this->assertArrayNotHasKey('errors', $res['body']); - $this->assertCount(10, $res['body']['data']['collectionsCreateDocuments']['documents']); + $this->assertCount(10, $res['body']['data']['databasesCreateDocuments']['documents']); return [ 'databaseId' => $databaseId, @@ -1578,7 +1578,7 @@ class DatabaseServerTest extends Scope ]; $res = $this->client->call(Client::METHOD_POST, '/graphql', $headers, $payload); $this->assertArrayNotHasKey('errors', $res['body']); - $this->assertCount(10, $res['body']['data']['collectionsUpdateDocuments']['documents']); + $this->assertCount(10, $res['body']['data']['databasesUpdateDocuments']['documents']); return $data; } @@ -1608,7 +1608,7 @@ class DatabaseServerTest extends Scope ]; $res = $this->client->call(Client::METHOD_POST, '/graphql', $headers, $payload); $this->assertArrayNotHasKey('errors', $res['body']); - $this->assertCount(2, $res['body']['data']['collectionsUpsertDocuments']['documents']); + $this->assertCount(2, $res['body']['data']['databasesUpsertDocuments']['documents']); return $data; } @@ -1633,7 +1633,7 @@ class DatabaseServerTest extends Scope ]; $res = $this->client->call(Client::METHOD_POST, '/graphql', $headers, $payload); $this->assertArrayNotHasKey('errors', $res['body']); - $this->assertCount(11, $res['body']['data']['collectionsDeleteDocuments']['documents']); + $this->assertCount(11, $res['body']['data']['databasesDeleteDocuments']['documents']); return $data; } From 531f50a2c74b279a98ab85b9aaf61f53f0f81e1d Mon Sep 17 00:00:00 2001 From: Darshan Date: Thu, 19 Jun 2025 17:59:29 +0530 Subject: [PATCH 40/40] fix: sdk namespacing and graphql tests. --- .../Http/Databases/Collections/Action.php | 8 ++++++++ .../Http/Databases/Tables/Columns/XList.php | 2 +- .../Http/Databases/Tables/Create.php | 6 +++--- .../Http/Databases/Tables/Delete.php | 6 +++--- .../Databases/Http/Databases/Tables/Get.php | 6 +++--- .../Http/Databases/Tables/Update.php | 6 +++--- .../Http/Databases/Tables/Usage/Get.php | 2 +- .../Databases/Http/Databases/Tables/XList.php | 8 ++++---- .../Database/Validator/Queries/Attributes.php | 2 +- .../Validator/Queries/Collections.php | 2 +- .../Database/Validator/Queries/Columns.php | 4 ++-- .../Database/Validator/Queries/Tables.php | 6 +++--- tests/e2e/Services/GraphQL/Base.php | 20 +++++++++---------- .../e2e/Services/GraphQL/Tables/AbuseTest.php | 4 ++-- .../e2e/Services/GraphQL/Tables/AuthTest.php | 10 +++++----- .../GraphQL/Tables/DatabaseClientTest.php | 4 ++-- .../GraphQL/Tables/DatabaseServerTest.php | 12 +++++------ 17 files changed, 58 insertions(+), 50 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Action.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Action.php index 0e3202d979..9329300ffa 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Action.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Action.php @@ -59,6 +59,14 @@ abstract class Action extends UtopiaAction return $this->isCollectionsAPI() ? 'collections' : 'tables'; } + /** + * Get the SDK namespace for the current action. + */ + final protected function getSdkNamespace(): string + { + return $this->isCollectionsAPI() ? 'databases' : 'tables'; + } + /** * Get the exception to throw when the resource already exists. */ diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/XList.php index 29a108f180..8190f2ec71 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/XList.php @@ -47,7 +47,7 @@ class XList extends AttributesXList )) ->param('databaseId', '', new UID(), 'Database ID.') ->param('tableId', '', new UID(), 'Table ID.') - ->param('queries', [], new Columns(), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' queries are allowed, each ' . APP_LIMIT_ARRAY_ELEMENT_SIZE . ' characters long. You may filter on the following attributes: ' . implode(', ', Columns::ALLOWED_ATTRIBUTES), true) + ->param('queries', [], new Columns(), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' queries are allowed, each ' . APP_LIMIT_ARRAY_ELEMENT_SIZE . ' characters long. You may filter on the following attributes: ' . implode(', ', Columns::ALLOWED_COLUMNS), true) ->inject('response') ->inject('dbForProject') ->callback($this->action(...)); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Create.php index 92b29ffdc6..0bfdef5249 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Create.php @@ -19,7 +19,7 @@ class Create extends CollectionCreate { public static function getName(): string { - return 'createTable'; + return 'create'; } protected function getResponseModel(): string @@ -40,8 +40,8 @@ class Create extends CollectionCreate ->label('audits.event', 'table.create') ->label('audits.resource', 'database/{request.databaseId}/table/{response.$id}') ->label('sdk', new Method( - namespace: 'databases', - group: $this->getSdkGroup(), + namespace: $this->getSdkNamespace(), + group: null, name: self::getName(), description: '/docs/references/databases/create-collection.md', auth: [AuthType::KEY], diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Delete.php index 0a20a20f54..caa7197acb 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Delete.php @@ -15,7 +15,7 @@ class Delete extends CollectionDelete { public static function getName(): string { - return 'deleteTable'; + return 'delete'; } protected function getResponseModel(): string @@ -36,8 +36,8 @@ class Delete extends CollectionDelete ->label('audits.event', 'table.delete') ->label('audits.resource', 'database/{request.databaseId}/table/{request.tableId}') ->label('sdk', new Method( - namespace: 'databases', - group: $this->getSdkGroup(), + namespace: $this->getSdkNamespace(), + group: null, name: self::getName(), description: '/docs/references/databases/delete-collection.md', auth: [AuthType::KEY], diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Get.php index 7f565231f9..40672ba51f 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Get.php @@ -15,7 +15,7 @@ class Get extends CollectionGet { public static function getName(): string { - return 'getTable'; + return 'get'; } protected function getResponseModel(): string @@ -33,8 +33,8 @@ class Get extends CollectionGet ->label('scope', 'collections.read') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( - namespace: 'databases', - group: $this->getSdkGroup(), + namespace: $this->getSdkNamespace(), + group: null, name: self::getName(), description: '/docs/references/databases/get-collection.md', auth: [AuthType::KEY], diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Update.php index 62a1b3bdee..f800e7b1de 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Update.php @@ -18,7 +18,7 @@ class Update extends CollectionUpdate { public static function getName(): string { - return 'updateTable'; + return 'update'; } protected function getResponseModel(): string @@ -39,8 +39,8 @@ class Update extends CollectionUpdate ->label('audits.event', 'table.update') ->label('audits.resource', 'database/{request.databaseId}/table/{request.tableId}') ->label('sdk', new Method( - namespace: 'databases', - group: $this->getSdkGroup(), + namespace: $this->getSdkNamespace(), + group: null, name: self::getName(), description: '/docs/references/databases/update-collection.md', auth: [AuthType::KEY], diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Usage/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Usage/Get.php index c82eaae7c5..ca990eeab6 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Usage/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Usage/Get.php @@ -34,7 +34,7 @@ class Get extends CollectionUsageGet ->label('scope', 'collections.read') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( - namespace: 'databases', + namespace: $this->getSdkNamespace(), group: null, name: self::getName(), description: '/docs/references/databases/get-collection-usage.md', diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/XList.php index 391b91a3dd..34000d97b1 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/XList.php @@ -17,7 +17,7 @@ class XList extends CollectionXList { public static function getName(): string { - return 'listTables'; + return 'list'; } protected function getResponseModel(): string @@ -35,8 +35,8 @@ class XList extends CollectionXList ->label('scope', 'collections.read') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( - namespace: 'databases', - group: $this->getSdkGroup(), + namespace: $this->getSdkNamespace(), + group: null, name: self::getName(), description: '/docs/references/databases/list-collections.md', auth: [AuthType::KEY], @@ -49,7 +49,7 @@ class XList extends CollectionXList contentType: ContentType::JSON )) ->param('databaseId', '', new UID(), 'Database ID.') - ->param('queries', [], new Tables(), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' queries are allowed, each ' . APP_LIMIT_ARRAY_ELEMENT_SIZE . ' characters long. You may filter on the following attributes: ' . implode(', ', Tables::ALLOWED_ATTRIBUTES), true) + ->param('queries', [], new Tables(), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' queries are allowed, each ' . APP_LIMIT_ARRAY_ELEMENT_SIZE . ' characters long. You may filter on the following attributes: ' . implode(', ', Tables::ALLOWED_COLUMNS), true) ->param('search', '', new Text(256), 'Search term to filter your list results. Max length: 256 chars.', true) ->inject('response') ->inject('dbForProject') diff --git a/src/Appwrite/Utopia/Database/Validator/Queries/Attributes.php b/src/Appwrite/Utopia/Database/Validator/Queries/Attributes.php index 4a35c82b73..953948c045 100644 --- a/src/Appwrite/Utopia/Database/Validator/Queries/Attributes.php +++ b/src/Appwrite/Utopia/Database/Validator/Queries/Attributes.php @@ -4,7 +4,7 @@ namespace Appwrite\Utopia\Database\Validator\Queries; class Attributes extends Base { - public const ALLOWED_ATTRIBUTES = [ + public const array ALLOWED_ATTRIBUTES = [ 'key', 'type', 'size', diff --git a/src/Appwrite/Utopia/Database/Validator/Queries/Collections.php b/src/Appwrite/Utopia/Database/Validator/Queries/Collections.php index 6e8fcb8339..cdaaa104dc 100644 --- a/src/Appwrite/Utopia/Database/Validator/Queries/Collections.php +++ b/src/Appwrite/Utopia/Database/Validator/Queries/Collections.php @@ -4,7 +4,7 @@ namespace Appwrite\Utopia\Database\Validator\Queries; class Collections extends Base { - public const ALLOWED_ATTRIBUTES = [ + public const array ALLOWED_ATTRIBUTES = [ 'name', 'enabled', 'documentSecurity' diff --git a/src/Appwrite/Utopia/Database/Validator/Queries/Columns.php b/src/Appwrite/Utopia/Database/Validator/Queries/Columns.php index 3c2742bfdd..c990dfc18a 100644 --- a/src/Appwrite/Utopia/Database/Validator/Queries/Columns.php +++ b/src/Appwrite/Utopia/Database/Validator/Queries/Columns.php @@ -4,7 +4,7 @@ namespace Appwrite\Utopia\Database\Validator\Queries; class Columns extends Base { - public const ALLOWED_ATTRIBUTES = [ + public const array ALLOWED_COLUMNS = [ 'key', 'type', 'size', @@ -20,6 +20,6 @@ class Columns extends Base */ public function __construct() { - parent::__construct('attributes', self::ALLOWED_ATTRIBUTES); + parent::__construct('attributes', self::ALLOWED_COLUMNS); } } diff --git a/src/Appwrite/Utopia/Database/Validator/Queries/Tables.php b/src/Appwrite/Utopia/Database/Validator/Queries/Tables.php index 5a1fc4ec6d..f3aadb69ac 100644 --- a/src/Appwrite/Utopia/Database/Validator/Queries/Tables.php +++ b/src/Appwrite/Utopia/Database/Validator/Queries/Tables.php @@ -4,10 +4,10 @@ namespace Appwrite\Utopia\Database\Validator\Queries; class Tables extends Base { - public const ALLOWED_ATTRIBUTES = [ + public const array ALLOWED_COLUMNS = [ 'name', 'enabled', - 'documentSecurity' + 'rowSecurity' ]; /** @@ -16,6 +16,6 @@ class Tables extends Base */ public function __construct() { - parent::__construct('collections', self::ALLOWED_ATTRIBUTES); + parent::__construct('collections', self::ALLOWED_COLUMNS); } } diff --git a/tests/e2e/Services/GraphQL/Base.php b/tests/e2e/Services/GraphQL/Base.php index 3da4dc11a3..bd3c792248 100644 --- a/tests/e2e/Services/GraphQL/Base.php +++ b/tests/e2e/Services/GraphQL/Base.php @@ -580,8 +580,8 @@ trait Base } }'; case self::$GET_TABLE: - return 'query getTable($databaseId: String!, $tableId: String!) { - databasesGetTable(databaseId: $databaseId, tableId: $tableId) { + return 'query tablesGet($databaseId: String!, $tableId: String!) { + tablesGet(databaseId: $databaseId, tableId: $tableId) { _id _permissions rowSecurity @@ -589,8 +589,8 @@ trait Base } }'; case self::$GET_TABLES: - return 'query listTables($databaseId: String!) { - databasesListTables(databaseId: $databaseId) { + return 'query tablesList($databaseId: String!) { + tablesList(databaseId: $databaseId) { total tables { _id @@ -601,8 +601,8 @@ trait Base } }'; case self::$CREATE_TABLE: - return 'mutation createTable($databaseId: String!, $tableId: String!, $name: String!, $rowSecurity: Boolean!, $permissions: [String!]!) { - databasesCreateTable(databaseId: $databaseId, tableId: $tableId, name: $name, rowSecurity: $rowSecurity, permissions: $permissions) { + return 'mutation tablesCreate($databaseId: String!, $tableId: String!, $name: String!, $rowSecurity: Boolean!, $permissions: [String!]!) { + tablesCreate(databaseId: $databaseId, tableId: $tableId, name: $name, rowSecurity: $rowSecurity, permissions: $permissions) { _id _permissions rowSecurity @@ -610,8 +610,8 @@ trait Base } }'; case self::$UPDATE_TABLE: - return 'mutation updateTable($databaseId: String!, $tableId: String!, $name: String!, $rowSecurity: Boolean!, $permissions: [String!], $enabled: Boolean) { - databasesUpdateTable(databaseId: $databaseId, tableId: $tableId, name: $name, rowSecurity: $rowSecurity, permissions: $permissions, enabled: $enabled) { + return 'mutation tablesUpdate($databaseId: String!, $tableId: String!, $name: String!, $rowSecurity: Boolean!, $permissions: [String!], $enabled: Boolean) { + tablesUpdate(databaseId: $databaseId, tableId: $tableId, name: $name, rowSecurity: $rowSecurity, permissions: $permissions, enabled: $enabled) { _id _permissions rowSecurity @@ -619,8 +619,8 @@ trait Base } }'; case self::$DELETE_TABLE: - return 'mutation deleteTable($databaseId: String!, $tableId: String!) { - databasesDeleteTable(databaseId: $databaseId, tableId: $tableId) { + return 'mutation tablesDelete($databaseId: String!, $tableId: String!) { + tablesDelete(databaseId: $databaseId, tableId: $tableId) { status } }'; diff --git a/tests/e2e/Services/GraphQL/Tables/AbuseTest.php b/tests/e2e/Services/GraphQL/Tables/AbuseTest.php index abb5019d55..8b759aa1ce 100644 --- a/tests/e2e/Services/GraphQL/Tables/AbuseTest.php +++ b/tests/e2e/Services/GraphQL/Tables/AbuseTest.php @@ -132,7 +132,7 @@ class AbuseTest extends Scope 'x-appwrite-key' => $this->getProject()['apiKey'], ], $gqlPayload); - $databaseId = $response['body']['data']['databasesCreate']['_id']; + $databaseId = $response['body']['data']['tablesCreate']['_id']; $query = $this->getQuery(self::$CREATE_TABLE); $gqlPayload = [ @@ -155,7 +155,7 @@ class AbuseTest extends Scope 'x-appwrite-key' => $this->getProject()['apiKey'], ], $gqlPayload); - $tableId = $response['body']['data']['databasesCreateTable']['_id']; + $tableId = $response['body']['data']['tablesCreate']['_id']; $query = $this->getQuery(self::$CREATE_STRING_COLUMN); $gqlPayload = [ diff --git a/tests/e2e/Services/GraphQL/Tables/AuthTest.php b/tests/e2e/Services/GraphQL/Tables/AuthTest.php index 681607d599..21d581d207 100644 --- a/tests/e2e/Services/GraphQL/Tables/AuthTest.php +++ b/tests/e2e/Services/GraphQL/Tables/AuthTest.php @@ -128,7 +128,7 @@ class AuthTest extends Scope 'query' => $query, 'variables' => [ 'databaseId' => $this->database['body']['data']['databasesCreate']['_id'], - 'tableId' => $this->table['body']['data']['databasesCreateTable']['_id'], + 'tableId' => $this->table['body']['data']['tablesCreate']['_id'], 'key' => 'name', 'size' => 256, 'required' => true, @@ -154,7 +154,7 @@ class AuthTest extends Scope 'query' => $query, 'variables' => [ 'databaseId' => $this->database['body']['data']['databasesCreate']['_id'], - 'tableId' => $this->table['body']['data']['databasesCreateTable']['_id'], + 'tableId' => $this->table['body']['data']['tablesCreate']['_id'], 'rowId' => ID::unique(), 'data' => [ 'name' => 'John Doe', @@ -178,7 +178,7 @@ class AuthTest extends Scope 'query' => $query, 'variables' => [ 'databaseId' => $this->database['body']['data']['databasesCreate']['_id'], - 'tableId' => $this->table['body']['data']['databasesCreateTable']['_id'], + 'tableId' => $this->table['body']['data']['tablesCreate']['_id'], 'rowId' => $row['body']['data']['tablesCreateRow']['_id'], ] ]; @@ -213,7 +213,7 @@ class AuthTest extends Scope 'query' => $query, 'variables' => [ 'databaseId' => $this->database['body']['data']['databasesCreate']['_id'], - 'tableId' => $this->table['body']['data']['databasesCreateTable']['_id'], + 'tableId' => $this->table['body']['data']['tablesCreate']['_id'], 'rowId' => ID::unique(), 'data' => [ 'name' => 'John Doe', @@ -237,7 +237,7 @@ class AuthTest extends Scope 'query' => $query, 'variables' => [ 'databaseId' => $this->database['body']['data']['databasesCreate']['_id'], - 'tableId' => $this->table['body']['data']['databasesCreateTable']['_id'], + 'tableId' => $this->table['body']['data']['tablesCreate']['_id'], 'rowId' => $row['body']['data']['tablesCreateRow']['_id'], ] ]; diff --git a/tests/e2e/Services/GraphQL/Tables/DatabaseClientTest.php b/tests/e2e/Services/GraphQL/Tables/DatabaseClientTest.php index c5cba6c47f..5ff8e65922 100644 --- a/tests/e2e/Services/GraphQL/Tables/DatabaseClientTest.php +++ b/tests/e2e/Services/GraphQL/Tables/DatabaseClientTest.php @@ -75,7 +75,7 @@ class DatabaseClientTest extends Scope $this->assertIsArray($table['body']['data']); $this->assertArrayNotHasKey('errors', $table['body']); - $table = $table['body']['data']['databasesCreateTable']; + $table = $table['body']['data']['tablesCreate']; $this->assertEquals('Actors', $table['name']); return [ @@ -349,7 +349,7 @@ class DatabaseClientTest extends Scope $res = $this->client->call(Client::METHOD_POST, '/graphql', $headers, $payload); $this->assertArrayNotHasKey('errors', $res['body']); - $tableId = $res['body']['data']['databasesCreateTable']['_id']; + $tableId = $res['body']['data']['tablesCreate']['_id']; // Step 3: Create column $query = $this->getQuery(self::$CREATE_STRING_COLUMN); diff --git a/tests/e2e/Services/GraphQL/Tables/DatabaseServerTest.php b/tests/e2e/Services/GraphQL/Tables/DatabaseServerTest.php index 61cb57911a..e4e9b34f35 100644 --- a/tests/e2e/Services/GraphQL/Tables/DatabaseServerTest.php +++ b/tests/e2e/Services/GraphQL/Tables/DatabaseServerTest.php @@ -75,7 +75,7 @@ class DatabaseServerTest extends Scope $this->assertIsArray($table['body']['data']); $this->assertArrayNotHasKey('errors', $table['body']); - $table = $table['body']['data']['databasesCreateTable']; + $table = $table['body']['data']['tablesCreate']; $this->assertEquals('Actors', $table['name']); $gqlPayload = [ @@ -101,7 +101,7 @@ class DatabaseServerTest extends Scope $this->assertIsArray($table2['body']['data']); $this->assertArrayNotHasKey('errors', $table2['body']); - $table2 = $table2['body']['data']['databasesCreateTable']; + $table2 = $table2['body']['data']['tablesCreate']; $this->assertEquals('Movies', $table2['name']); return [ @@ -992,7 +992,7 @@ class DatabaseServerTest extends Scope $this->assertArrayNotHasKey('errors', $tables['body']); $this->assertIsArray($tables['body']['data']); - $this->assertIsArray($tables['body']['data']['databasesListTables']); + $this->assertIsArray($tables['body']['data']['tablesList']); } /** @@ -1018,7 +1018,7 @@ class DatabaseServerTest extends Scope $this->assertArrayNotHasKey('errors', $table['body']); $this->assertIsArray($table['body']['data']); - $this->assertIsArray($table['body']['data']['databasesGetTable']); + $this->assertIsArray($table['body']['data']['tablesGet']); } /** @@ -1279,7 +1279,7 @@ class DatabaseServerTest extends Scope $this->assertArrayNotHasKey('errors', $table['body']); $this->assertIsArray($table['body']['data']); - $this->assertIsArray($table['body']['data']['databasesUpdateTable']); + $this->assertIsArray($table['body']['data']['tablesUpdate']); } /** @@ -1510,7 +1510,7 @@ class DatabaseServerTest extends Scope $res = $this->client->call(Client::METHOD_POST, '/graphql', $headers, $payload); $this->assertArrayNotHasKey('errors', $res['body']); - $tableId = $res['body']['data']['databasesCreateTable']['_id']; + $tableId = $res['body']['data']['tablesCreate']['_id']; // Step 3: Create column $query = $this->getQuery(self::$CREATE_STRING_COLUMN);