From 80ad740d36f9529cf9653baacae4ec0f6bae1caf Mon Sep 17 00:00:00 2001 From: Tejas Raskar Date: Wed, 20 Aug 2025 14:34:43 +0530 Subject: [PATCH 01/60] docs: update the directory structure in CONTRIBUTING.md --- CONTRIBUTING.md | 78 +++++++++++++++++++++++++++++++------------------ 1 file changed, 50 insertions(+), 28 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c6837673d5..96b0614165 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -222,51 +222,73 @@ Appwrite's current structure is a combination of both [Monolithic](https://en.wi ```bash . ├── app # Main application +│ ├── assets +│ │ ├── dbip +│ │ ├── fonts +│ │ └── security │ ├── config # Config files +│ │ ├── avatars +│ │ ├── collections +│ │ ├── locale +│ │ ├── specs +│ │ ├── storage +│ │ └── templates │ ├── controllers # API & dashboard controllers │ │ ├── api │ │ ├── shared │ │ └── web -│ ├── db # DB schemas -│ ├── sdks # SDKs generated copies (used for generating code examples) -│ ├── tasks # Server CLI commands -│ ├── views # HTML server-side templates -│ └── workers # Background workers +│ ├── init # DB schemas +│ │ └── database +│ └── views # HTML server-side templates +│ ├── general +│ └── install ├── bin # Server executables (tasks & workers) -├── docker # Docker related resources and configs +├── dev # Debugger config ├── docs # Docs and tutorials │ ├── examples +│ ├── lists │ ├── references +│ ├── sdks │ ├── services │ ├── specs │ └── tutorials ├── public # Public files -│ ├── dist │ ├── fonts │ ├── images -│ ├── scripts -│ └── styles -├── src # Supporting libraries (each lib has one role, common libs are released as individual projects) -│ └── Appwrite -│ ├── Auth -│ ├── Detector -│ ├── Docker -| ├── DSN -│ ├── Event -│ ├── Extend -│ ├── GraphQL -│ ├── Messaging -│ ├── Migration -│ ├── Network -│ ├── OpenSSL -│ ├── Promises -│ ├── Specification -│ ├── Task -│ ├── Template -│ ├── URL -│ └── Utopia +│ ├── sdk-console +│ ├── sdk-project +│ └── sdk-web +├── src # Supporting libraries (each lib has one role, common libs are released as +│ ├── Appwrite +│ │ ├── Auth +│ │ ├── Certificates +│ │ ├── Deletes +│ │ ├── Detector +│ │ ├── Docker +│ │ ├── Event +│ │ ├── Extend +│ │ ├── Functions/Validator +│ │ ├── GraphQL +│ │ ├── Hooks +│ │ ├── Messaging +│ │ ├── Migration +│ │ ├── Network +│ │ ├── OpenSSL +│ │ ├── Platform +│ │ ├── Promises +│ │ ├── PubSub +│ │ ├── SDK +│ │ ├── Task/Validator +│ │ ├── Template +│ │ ├── Transformation +│ │ ├── URL +│ │ ├── Utopia +│ │ └── Vcs +│ └── Executor └── tests # End to end & unit tests + ├── benchmarks ├── e2e + ├── extensions ├── resources └── unit ``` From 59f178d634675e4c1e516228e028cba2ba6b8d0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Thu, 18 Dec 2025 13:37:50 +0100 Subject: [PATCH 02/60] Improve PHP types for extensability --- src/Appwrite/Auth/Key.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Appwrite/Auth/Key.php b/src/Appwrite/Auth/Key.php index b1f3836fb6..1adfa2be2d 100644 --- a/src/Appwrite/Auth/Key.php +++ b/src/Appwrite/Auth/Key.php @@ -95,15 +95,12 @@ class Key * Decode the given secret key into a Key object, containing the project ID, type, role, scopes, and name. * Can be a stored API key or a dynamic key (JWT). * - * @param Document $project - * @param string $key - * @return Key * @throws Exception */ public static function decode( Document $project, string $key - ): Key { + ): static { if (\str_contains($key, '_')) { [$type, $secret] = \explode('_', $key, 2); } else { From 6f16b56f31b7f0670dd1f1c22ab8cbc3265e48fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Thu, 18 Dec 2025 15:55:11 +0100 Subject: [PATCH 03/60] Allow Key extensions --- src/Appwrite/Auth/Key.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Appwrite/Auth/Key.php b/src/Appwrite/Auth/Key.php index 1adfa2be2d..df906ccd15 100644 --- a/src/Appwrite/Auth/Key.php +++ b/src/Appwrite/Auth/Key.php @@ -11,6 +11,9 @@ use Utopia\Database\DateTime; use Utopia\Database\Document; use Utopia\System\System; +/** + * @template T of Key + */ class Key { public function __construct( @@ -96,6 +99,7 @@ class Key * Can be a stored API key or a dynamic key (JWT). * * @throws Exception + * @return T */ public static function decode( Document $project, From 1c3f778da9d9fb4a9e2f6de8aa7ac0a3a048bf5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Fri, 19 Dec 2025 12:26:15 +0100 Subject: [PATCH 04/60] PR review fix --- src/Appwrite/Auth/Key.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Auth/Key.php b/src/Appwrite/Auth/Key.php index df906ccd15..44f546eaa4 100644 --- a/src/Appwrite/Auth/Key.php +++ b/src/Appwrite/Auth/Key.php @@ -104,7 +104,7 @@ class Key public static function decode( Document $project, string $key - ): static { + ) { if (\str_contains($key, '_')) { [$type, $secret] = \explode('_', $key, 2); } else { From 0a3877a9006a3033cb39040ec2ba831978e5f8f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Fri, 19 Dec 2025 13:09:34 +0100 Subject: [PATCH 05/60] New DB schema --- app/config/collections/platform.php | 37 +++++++++++++++++++---------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/app/config/collections/platform.php b/app/config/collections/platform.php index d44d9b725c..eb4184b72a 100644 --- a/app/config/collections/platform.php +++ b/app/config/collections/platform.php @@ -622,27 +622,38 @@ return [ 'name' => 'keys', 'attributes' => [ [ - '$id' => ID::custom('projectInternalId'), - 'type' => Database::VAR_STRING, - 'format' => '', - 'size' => Database::LENGTH_KEY, - 'signed' => true, - 'required' => true, - 'default' => null, - 'array' => false, - 'filters' => [], - ], - [ - '$id' => ID::custom('projectId'), + '$id' => ID::custom('resourceId'), 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, 'signed' => true, 'required' => false, - 'default' => 0, + 'default' => null, 'array' => false, 'filters' => [], ], + [ + '$id' => ID::custom('resourceInternalId'), + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => Database::LENGTH_KEY, + 'signed' => true, + 'required' => false, + 'default' => null, + 'array' => false, + 'filters' => [], + ], + [ + '$id' => ID::custom('resourceType'), // project, team, user + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => Database::LENGTH_KEY, + 'signed' => true, + 'required' => false, + 'default' => null, + 'array' => false, + 'filters' => [] + ], [ '$id' => ID::custom('name'), 'type' => Database::VAR_STRING, From 69d5ce0f550bc4d5411e3ca7b6d010abd45769a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Fri, 19 Dec 2025 13:40:32 +0100 Subject: [PATCH 06/60] Switch over to resource-based key DB structure --- app/config/collections/platform.php | 2 +- app/controllers/api/projects.php | 17 +++++++++++------ app/controllers/mock.php | 5 +++-- app/init/database/filters.php | 3 ++- src/Appwrite/Platform/Workers/Deletes.php | 3 ++- .../Platform/Workers/StatsResources.php | 3 ++- 6 files changed, 21 insertions(+), 12 deletions(-) diff --git a/app/config/collections/platform.php b/app/config/collections/platform.php index eb4184b72a..0ad1b3fbc0 100644 --- a/app/config/collections/platform.php +++ b/app/config/collections/platform.php @@ -653,7 +653,7 @@ return [ 'default' => null, 'array' => false, 'filters' => [] - ], + ], [ '$id' => ID::custom('name'), 'type' => Database::VAR_STRING, diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index c4d703d744..45a63e4966 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -1497,8 +1497,9 @@ App::post('/v1/projects/:projectId/keys') Permission::update(Role::any()), Permission::delete(Role::any()), ], - 'projectInternalId' => $project->getSequence(), - 'projectId' => $project->getId(), + 'resourceInternalId' => $project->getSequence(), + 'resourceId' => $project->getId(), + 'resourceType' => 'projects', 'name' => $name, 'scopes' => $scopes, 'expire' => $expire, @@ -1546,7 +1547,8 @@ App::get('/v1/projects/:projectId/keys') } $keys = $dbForPlatform->find('keys', [ - Query::equal('projectInternalId', [$project->getSequence()]), + Query::equal('resourceInternalId', [$project->getSequence()]), + Query::equal('resourceType', ['projects']), Query::limit(5000), ]); @@ -1587,7 +1589,8 @@ App::get('/v1/projects/:projectId/keys/:keyId') $key = $dbForPlatform->findOne('keys', [ Query::equal('$id', [$keyId]), - Query::equal('projectInternalId', [$project->getSequence()]), + Query::equal('resourceInternalId', [$project->getSequence()]), + Query::equal('resourceType', ['projects']), ]); if ($key->isEmpty()) { @@ -1631,7 +1634,8 @@ App::put('/v1/projects/:projectId/keys/:keyId') $key = $dbForPlatform->findOne('keys', [ Query::equal('$id', [$keyId]), - Query::equal('projectInternalId', [$project->getSequence()]), + Query::equal('resourceInternalId', [$project->getSequence()]), + Query::equal('resourceType', ['projects']), ]); if ($key->isEmpty()) { @@ -1682,7 +1686,8 @@ App::delete('/v1/projects/:projectId/keys/:keyId') $key = $dbForPlatform->findOne('keys', [ Query::equal('$id', [$keyId]), - Query::equal('projectInternalId', [$project->getSequence()]), + Query::equal('resourceInternalId', [$project->getSequence()]), + Query::equal('resourceType', ['projects']), ]); if ($key->isEmpty()) { diff --git a/app/controllers/mock.php b/app/controllers/mock.php index 6f092a5d19..2c0ef443ee 100644 --- a/app/controllers/mock.php +++ b/app/controllers/mock.php @@ -200,8 +200,9 @@ App::post('/v1/mock/api-key-unprefixed') Permission::update(Role::any()), Permission::delete(Role::any()), ], - 'projectInternalId' => $project->getSequence(), - 'projectId' => $project->getId(), + 'resourceType' => 'projects', + 'resourceInternalId' => $project->getSequence(), + 'resourceId' => $project->getId(), 'name' => 'Outdated key', 'scopes' => $scopes, 'expire' => null, diff --git a/app/init/database/filters.php b/app/init/database/filters.php index 2bff778017..590c78be42 100644 --- a/app/init/database/filters.php +++ b/app/init/database/filters.php @@ -135,7 +135,8 @@ Database::addFilter( function (mixed $value, Document $document, Database $database) { return $database->getAuthorization()->skip(fn () => $database ->find('keys', [ - Query::equal('projectInternalId', [$document->getSequence()]), + Query::equal('resourceInternalId', [$document->getSequence()]), + Query::equal('resourceType', ['projects']), Query::limit(APP_LIMIT_SUBQUERY), ])); } diff --git a/src/Appwrite/Platform/Workers/Deletes.php b/src/Appwrite/Platform/Workers/Deletes.php index 247044f4c3..072dfa9bf9 100644 --- a/src/Appwrite/Platform/Workers/Deletes.php +++ b/src/Appwrite/Platform/Workers/Deletes.php @@ -562,7 +562,8 @@ class Deletes extends Action // Delete Keys $this->deleteByGroup('keys', [ - Query::equal('projectInternalId', [$projectInternalId]), + Query::equal('resourceInternalId', [$projectInternalId]), + Query::equal('resourceType', ['projects']), Query::orderAsc() ], $dbForPlatform); diff --git a/src/Appwrite/Platform/Workers/StatsResources.php b/src/Appwrite/Platform/Workers/StatsResources.php index 1ef348091a..118f83c031 100644 --- a/src/Appwrite/Platform/Workers/StatsResources.php +++ b/src/Appwrite/Platform/Workers/StatsResources.php @@ -111,7 +111,8 @@ class StatsResources extends Action Query::equal('projectInternalId', [$project->getSequence()]) ]); $keys = $dbForPlatform->count('keys', [ - Query::equal('projectInternalId', [$project->getSequence()]) + Query::equal('resourceInternalId', [$project->getSequence()]), + Query::equal('resourceType', ['projects']), ]); $domains = $dbForPlatform->count('rules', [ From 859d146e852cb5bcc2012a059ee8006229d9a0fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Fri, 19 Dec 2025 13:41:18 +0100 Subject: [PATCH 07/60] Apply suggestions from code review --- app/config/collections/platform.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/config/collections/platform.php b/app/config/collections/platform.php index 0ad1b3fbc0..5538f59133 100644 --- a/app/config/collections/platform.php +++ b/app/config/collections/platform.php @@ -644,7 +644,7 @@ return [ 'filters' => [], ], [ - '$id' => ID::custom('resourceType'), // project, team, user + '$id' => ID::custom('resourceType'), // projects, teams, users 'type' => Database::VAR_STRING, 'format' => '', 'size' => Database::LENGTH_KEY, From c69382f29f6e8fa52ee53ea03657b6879754817c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Fri, 19 Dec 2025 16:11:43 +0100 Subject: [PATCH 08/60] Fix invalid index --- app/config/collections/platform.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/config/collections/platform.php b/app/config/collections/platform.php index 5538f59133..16eafc9d4a 100644 --- a/app/config/collections/platform.php +++ b/app/config/collections/platform.php @@ -723,9 +723,9 @@ return [ ], 'indexes' => [ [ - '$id' => ID::custom('_key_project'), + '$id' => ID::custom('_key_resource'), 'type' => Database::INDEX_KEY, - 'attributes' => ['projectInternalId'], + 'attributes' => ['resourceType', 'resourceInternalId'], 'lengths' => [Database::LENGTH_KEY], 'orders' => [Database::ORDER_ASC], ], From ca43281fa9df2ec551da2e4d467bafcce1fdd337 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Sat, 20 Dec 2025 09:20:39 +0100 Subject: [PATCH 09/60] Simplify PR --- src/Appwrite/Auth/Key.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Appwrite/Auth/Key.php b/src/Appwrite/Auth/Key.php index 44f546eaa4..b23f2cc816 100644 --- a/src/Appwrite/Auth/Key.php +++ b/src/Appwrite/Auth/Key.php @@ -11,9 +11,6 @@ use Utopia\Database\DateTime; use Utopia\Database\Document; use Utopia\System\System; -/** - * @template T of Key - */ class Key { public function __construct( @@ -99,12 +96,11 @@ class Key * Can be a stored API key or a dynamic key (JWT). * * @throws Exception - * @return T */ public static function decode( Document $project, string $key - ) { + ): Key { if (\str_contains($key, '_')) { [$type, $secret] = \explode('_', $key, 2); } else { From 465912822fdab0fdc21c4801930b9d878b064b50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 22 Dec 2025 11:32:45 +0100 Subject: [PATCH 10/60] Mark reused key response public --- src/Appwrite/Utopia/Response/Model/Key.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Utopia/Response/Model/Key.php b/src/Appwrite/Utopia/Response/Model/Key.php index 1adab4417b..38aa0748df 100644 --- a/src/Appwrite/Utopia/Response/Model/Key.php +++ b/src/Appwrite/Utopia/Response/Model/Key.php @@ -10,7 +10,7 @@ class Key extends Model /** * @var bool */ - protected bool $public = false; + protected bool $public = true; public function __construct() { From 09d71e73afbb86b4d3ab00f7779c3e85fd88d01c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 22 Dec 2025 11:37:38 +0100 Subject: [PATCH 11/60] keys list to be public as its reused for more types of keys --- src/Appwrite/Utopia/Response.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Utopia/Response.php b/src/Appwrite/Utopia/Response.php index 33351bea14..68c2cb14c8 100644 --- a/src/Appwrite/Utopia/Response.php +++ b/src/Appwrite/Utopia/Response.php @@ -466,7 +466,7 @@ class Response extends SwooleResponse ->setModel(new BaseList('Executions List', self::MODEL_EXECUTION_LIST, 'executions', self::MODEL_EXECUTION)) ->setModel(new BaseList('Projects List', self::MODEL_PROJECT_LIST, 'projects', self::MODEL_PROJECT, true, false)) ->setModel(new BaseList('Webhooks List', self::MODEL_WEBHOOK_LIST, 'webhooks', self::MODEL_WEBHOOK, true, false)) - ->setModel(new BaseList('API Keys List', self::MODEL_KEY_LIST, 'keys', self::MODEL_KEY, true, false)) + ->setModel(new BaseList('API Keys List', self::MODEL_KEY_LIST, 'keys', self::MODEL_KEY, true, true)) // Public because reused for more key types ->setModel(new BaseList('Dev Keys List', self::MODEL_DEV_KEY_LIST, 'devKeys', self::MODEL_DEV_KEY, true, false)) ->setModel(new BaseList('Auth Providers List', self::MODEL_AUTH_PROVIDER_LIST, 'platforms', self::MODEL_AUTH_PROVIDER, true, false)) ->setModel(new BaseList('Platforms List', self::MODEL_PLATFORM_LIST, 'platforms', self::MODEL_PLATFORM, true, false)) From bce3ce85d514c759fb9ae696b1b178be09c5b93a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Tue, 23 Dec 2025 11:59:38 +0100 Subject: [PATCH 12/60] account key support --- app/init/resources.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/app/init/resources.php b/app/init/resources.php index 30717141f6..6d2ce06709 100644 --- a/app/init/resources.php +++ b/app/init/resources.php @@ -430,6 +430,25 @@ App::setResource('user', function (string $mode, Document $project, Document $co } } } + + // Account based on account API key + $accountKey = $request->getHeader('x-appwrite-key', ''); + $accountKeyId = $request->getHeader('x-appwrite-user', ''); + if (!empty($accountKeyId) && !empty($accountKey)) { + $accountKeyUser = Authorization::skip(fn () => $dbForPlatform->getDocument('users', $accountKeyId)); + if (!$accountKeyUser->isEmpty()) { + $key = $accountKeyUser->find( + key: 'secret', + find: $accountKey, + subject: 'keys' + ); + + if (!empty($key)) { + $user = $accountKeyUser; + } + } + } + $dbForProject->setMetadata('user', $user->getId()); $dbForPlatform->setMetadata('user', $user->getId()); From 6f7cca7d6860b8f6349f642bf8615a70d005fe20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Tue, 23 Dec 2025 12:06:30 +0100 Subject: [PATCH 13/60] Allow key header for account keys --- app/controllers/shared/api.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index 83b56f626a..c4ca334921 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -301,10 +301,6 @@ App::init() // Step 5: API Key Authentication if (!empty($apiKey)) { - // Verify no user session exists simultaneously - if (!$user->isEmpty()) { - throw new Exception(Exception::USER_API_KEY_AND_SESSION_SET); - } // Check if key is expired if ($apiKey->isExpired()) { throw new Exception(Exception::PROJECT_KEY_EXPIRED); From b0bd9e5b78ded2f0cac989bb7f7ef572265406dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Tue, 23 Dec 2025 12:09:07 +0100 Subject: [PATCH 14/60] Fix security requirement --- app/init/resources.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/init/resources.php b/app/init/resources.php index 6d2ce06709..24287ca243 100644 --- a/app/init/resources.php +++ b/app/init/resources.php @@ -433,9 +433,9 @@ App::setResource('user', function (string $mode, Document $project, Document $co // Account based on account API key $accountKey = $request->getHeader('x-appwrite-key', ''); - $accountKeyId = $request->getHeader('x-appwrite-user', ''); - if (!empty($accountKeyId) && !empty($accountKey)) { - $accountKeyUser = Authorization::skip(fn () => $dbForPlatform->getDocument('users', $accountKeyId)); + $accountKeyUserId = $request->getHeader('x-appwrite-user', ''); + if (!empty($accountKeyUserId) && !empty($accountKey)) { + $accountKeyUser = Authorization::skip(fn () => $dbForPlatform->getDocument('users', $accountKeyUserId)); if (!$accountKeyUser->isEmpty()) { $key = $accountKeyUser->find( key: 'secret', From cca49f8f6a2b2a06ab1afdfe00d09ad36ad79b27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Tue, 23 Dec 2025 12:11:01 +0100 Subject: [PATCH 15/60] Improve docs --- app/init/resources.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/init/resources.php b/app/init/resources.php index 24287ca243..c59ef5553a 100644 --- a/app/init/resources.php +++ b/app/init/resources.php @@ -333,6 +333,7 @@ App::setResource('user', function (string $mode, Document $project, Document $co * 5. Regardless of the results from steps 1-4, attempts to fetch the JWT token. * 6. If the JWT user has a valid session ID, updates the user variable with the user from `projectDB`, * overwriting the previous value. + * 7. If account key is passed, use user of the account key as long as user ID header matches too */ Authorization::setDefaultStatus(true); From 6e47fb6c7021e775ea468b0dcd42da5d10c91e8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Tue, 23 Dec 2025 13:06:19 +0100 Subject: [PATCH 16/60] Implement auth for organization and account keys --- app/config/scopes/account.php | 13 +++ app/config/scopes/organization.php | 42 +++++++++ app/config/{scopes.php => scopes/project.php} | 0 app/controllers/api/projects.php | 6 +- app/controllers/mock.php | 2 +- app/init/configs.php | 4 +- app/init/constants.php | 2 + app/init/resources.php | 6 +- src/Appwrite/Auth/Key.php | 86 +++++++++++++++++++ .../Functions/Http/Functions/Create.php | 2 +- .../Functions/Http/Functions/Update.php | 2 +- src/Appwrite/Platform/Tasks/Screenshot.php | 2 +- 12 files changed, 156 insertions(+), 11 deletions(-) create mode 100644 app/config/scopes/account.php create mode 100644 app/config/scopes/organization.php rename app/config/{scopes.php => scopes/project.php} (100%) diff --git a/app/config/scopes/account.php b/app/config/scopes/account.php new file mode 100644 index 0000000000..f11e49ca76 --- /dev/null +++ b/app/config/scopes/account.php @@ -0,0 +1,13 @@ + [ + "description" => 'Access to manage account, it\'s organizations, sessions, tokens, and billing.', + ],"teams.read" => [ + "description" => 'Access to read account\'s organizations.', + ],"teams.write" => [ + "description" => 'Access to create, update and delete account\'s organizations and it\'s memberships.', + ], +]; diff --git a/app/config/scopes/organization.php b/app/config/scopes/organization.php new file mode 100644 index 0000000000..ca4160881d --- /dev/null +++ b/app/config/scopes/organization.php @@ -0,0 +1,42 @@ + [ + "description" => 'Access to read project\'s platforms', + ], + "platforms.write" => [ + "description" => + 'Access to create, update, and delete project\'s platforms', + ], + "projects.read" => [ + "description" => 'Access to read organization\'s projects', + ], + "projects.write" => [ + "description" => + "Access to create, update, and delete projects in organization", + ], + "keys.read" => [ + "description" => 'Access to read project\'s API keys', + ], + "keys.write" => [ + "description" => + "Access to create, update, and delete project\'s API keys", + ], + "devKeys.read" => [ + "description" => 'Access to read project\'s development keys', + ], + "devKeys.write" => [ + "description" => + "Access to create, update, and delete project\'s development keys", + ], + "webhooks.read" => [ + "description" => + "Access to read project\'s webhooks", + ], + "webhooks.write" => [ + "description" => + "Access to create, update, and delete project\'s webhooks", + ], +]; diff --git a/app/config/scopes.php b/app/config/scopes/project.php similarity index 100% rename from app/config/scopes.php rename to app/config/scopes/project.php diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 45a63e4966..c23ac05a6e 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -1478,7 +1478,7 @@ App::post('/v1/projects/:projectId/keys') )) ->param('projectId', '', new UID(), 'Project unique ID.') ->param('name', null, new Text(128), 'Key name. Max length: 128 chars.') - ->param('scopes', null, new Nullable(new ArrayList(new WhiteList(array_keys(Config::getParam('scopes')), true), APP_LIMIT_ARRAY_PARAMS_SIZE)), 'Key scopes list. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' scopes are allowed.') + ->param('scopes', null, new Nullable(new ArrayList(new WhiteList(array_keys(Config::getParam('projectScopes')), true), APP_LIMIT_ARRAY_PARAMS_SIZE)), 'Key scopes list. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' scopes are allowed.') ->param('expire', null, new Nullable(new DatetimeValidator()), 'Expiration time in [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) format. Use null for unlimited expiration.', true) ->inject('response') ->inject('dbForPlatform') @@ -1620,7 +1620,7 @@ App::put('/v1/projects/:projectId/keys/:keyId') ->param('projectId', '', new UID(), 'Project unique ID.') ->param('keyId', '', new UID(), 'Key unique ID.') ->param('name', null, new Text(128), 'Key name. Max length: 128 chars.') - ->param('scopes', null, new Nullable(new ArrayList(new WhiteList(array_keys(Config::getParam('scopes')), true), APP_LIMIT_ARRAY_PARAMS_SIZE)), 'Key scopes list. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' events are allowed.') + ->param('scopes', null, new Nullable(new ArrayList(new WhiteList(array_keys(Config::getParam('projectScopes')), true), APP_LIMIT_ARRAY_PARAMS_SIZE)), 'Key scopes list. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' events are allowed.') ->param('expire', null, new Nullable(new DatetimeValidator()), 'Expiration time in [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) format. Use null for unlimited expiration.', true) ->inject('response') ->inject('dbForPlatform') @@ -1721,7 +1721,7 @@ App::post('/v1/projects/:projectId/jwts') ] )) ->param('projectId', '', new UID(), 'Project unique ID.') - ->param('scopes', [], new ArrayList(new WhiteList(array_keys(Config::getParam('scopes')), true), APP_LIMIT_ARRAY_PARAMS_SIZE), 'List of scopes allowed for JWT key. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' scopes are allowed.') + ->param('scopes', [], new ArrayList(new WhiteList(array_keys(Config::getParam('projectScopes')), true), APP_LIMIT_ARRAY_PARAMS_SIZE), 'List of scopes allowed for JWT key. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' scopes are allowed.') ->param('duration', 900, new Range(0, 3600), 'Time in seconds before JWT expires. Default duration is 900 seconds, and maximum is 3600 seconds.', true) ->inject('response') ->inject('dbForPlatform') diff --git a/app/controllers/mock.php b/app/controllers/mock.php index 2c0ef443ee..29f35e9c3c 100644 --- a/app/controllers/mock.php +++ b/app/controllers/mock.php @@ -191,7 +191,7 @@ App::post('/v1/mock/api-key-unprefixed') throw new Exception(Exception::PROJECT_NOT_FOUND); } - $scopes = array_keys(Config::getParam('scopes')); + $scopes = array_keys(Config::getParam('projectScopes')); $key = new Document([ '$id' => ID::unique(), diff --git a/app/init/configs.php b/app/init/configs.php index 19be7755dd..d5748707cf 100644 --- a/app/init/configs.php +++ b/app/init/configs.php @@ -22,7 +22,9 @@ Config::load('collections', __DIR__ . '/../config/collections.php', $configAdapt Config::load('frameworks', __DIR__ . '/../config/frameworks.php', $configAdapter); Config::load('usage', __DIR__ . '/../config/usage.php', $configAdapter); Config::load('roles', __DIR__ . '/../config/roles.php', $configAdapter); // User roles and scopes -Config::load('scopes', __DIR__ . '/../config/scopes.php', $configAdapter); // User roles and scopes +Config::load('projectScopes', __DIR__ . '/../config/scopes/project.php', $configAdapter); +Config::load('organizationScopes', __DIR__ . '/../config/scopes/organization.php', $configAdapter); +Config::load('accountScopes', __DIR__ . '/../config/scopes/account.php', $configAdapter); Config::load('services', __DIR__ . '/../config/services.php', $configAdapter); // List of services Config::load('variables', __DIR__ . '/../config/variables.php', $configAdapter); // List of env variables Config::load('regions', __DIR__ . '/../config/regions.php', $configAdapter); // List of available regions diff --git a/app/init/constants.php b/app/init/constants.php index 78b8e3a5ae..3a8eb72e62 100644 --- a/app/init/constants.php +++ b/app/init/constants.php @@ -243,6 +243,8 @@ const MESSAGE_TYPE_PUSH = 'push'; // API key types const API_KEY_STANDARD = 'standard'; const API_KEY_DYNAMIC = 'dynamic'; +const API_KEY_ORGANIZATION = 'organization'; +const API_KEY_ACCOUNT = 'account'; // Usage metrics const METRIC_TEAMS = 'teams'; const METRIC_USERS = 'users'; diff --git a/app/init/resources.php b/app/init/resources.php index c59ef5553a..1db546e0d0 100644 --- a/app/init/resources.php +++ b/app/init/resources.php @@ -1072,15 +1072,15 @@ App::setResource('previewHostname', function (Request $request, ?Key $apiKey) { return ''; }, ['request', 'apiKey']); -App::setResource('apiKey', function (Request $request, Document $project): ?Key { +App::setResource('apiKey', function (Request $request, Document $project, Document $team, Document $user): ?Key { $key = $request->getHeader('x-appwrite-key'); if (empty($key)) { return null; } - return Key::decode($project, $key); -}, ['request', 'project']); + return Key::decode($project, $team, $user, $key); +}, ['request', 'project', 'team', 'user']); App::setResource('executor', fn () => new Executor()); diff --git a/src/Appwrite/Auth/Key.php b/src/Appwrite/Auth/Key.php index b23f2cc816..7f2d27ed5e 100644 --- a/src/Appwrite/Auth/Key.php +++ b/src/Appwrite/Auth/Key.php @@ -15,6 +15,8 @@ class Key { public function __construct( protected string $projectId, + protected string $teamId, + protected string $userId, protected string $type, protected string $role, protected array $scopes, @@ -99,6 +101,8 @@ class Key */ public static function decode( Document $project, + Document $team, + Document $user, string $key ): Key { if (\str_contains($key, '_')) { @@ -115,6 +119,8 @@ class Key $guestKey = new Key( $project->getId(), + '', + '', $type, User::ROLE_GUESTS, $roles[User::ROLE_GUESTS]['scopes'] ?? [], @@ -152,6 +158,8 @@ class Key return new Key( $projectId, + '', + '', $type, $role, $scopes, @@ -185,12 +193,90 @@ class Key return new Key( $project->getId(), + '', + '', $type, $role, $scopes, $name, $expired ); + case API_KEY_ACCOUNT: + $key = $user->find( + key: 'secret', + find: $key, + subject: 'keys' + ); + + // Invalid key + if (!$key) { + return $guestKey; + } + + $expire = $key->getAttribute('expire'); + $expired = false; + if (!empty($expire) && $expire < DateTime::formatTz(DateTime::now())) { + $expired = true; + } + + $name = $key->getAttribute('name', 'UNKNOWN'); + + $role = User::ROLE_USERS; + + $roles = Config::getParam('roles', []); + $scopes = $roles[$role]['scopes'] ?? []; + $scopes = $key->getAttribute('scopes', []); + + $key = new Key( + '', + '', + $user->getId(), + $type, + $role, + $scopes, + $name, + $expired + ); + + return $key; + case API_KEY_ORGANIZATION: + $key = $team->find( + key: 'secret', + find: $key, + subject: 'keys' + ); + + // Invalid key + if (!$key) { + return $guestKey; + } + + $expire = $key->getAttribute('expire'); + $expired = false; + if (!empty($expire) && $expire < DateTime::formatTz(DateTime::now())) { + $expired = true; + } + + $name = $key->getAttribute('name', 'UNKNOWN'); + + $role = User::ROLE_APPS; + + $roles = Config::getParam('roles', []); + $scopes = $roles[$role]['scopes'] ?? []; + $scopes = $key->getAttribute('scopes', []); + + $key = new Key( + '', + $team->getId(), + '', + $type, + $role, + $scopes, + $name, + $expired + ); + + return $key; default: return $guestKey; } diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Create.php b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Create.php index 5c226c5925..94667a9fac 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Create.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Create.php @@ -87,7 +87,7 @@ class Create extends Base ->param('logging', true, new Boolean(), 'When disabled, executions will exclude logs and errors, and will be slightly faster.', true) ->param('entrypoint', '', new Text(1028, 0), 'Entrypoint File. This path is relative to the "providerRootDirectory".', true) ->param('commands', '', new Text(8192, 0), 'Build Commands.', true) - ->param('scopes', [], new ArrayList(new WhiteList(array_keys(Config::getParam('scopes')), true), APP_LIMIT_ARRAY_PARAMS_SIZE), 'List of scopes allowed for API key auto-generated for every execution. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' scopes are allowed.', true) + ->param('scopes', [], new ArrayList(new WhiteList(array_keys(Config::getParam('projectScopes')), true), APP_LIMIT_ARRAY_PARAMS_SIZE), 'List of scopes allowed for API key auto-generated for every execution. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' scopes are allowed.', true) ->param('installationId', '', new Text(128, 0), 'Appwrite Installation ID for VCS (Version Control System) deployment.', true) ->param('providerRepositoryId', '', new Text(128, 0), 'Repository ID of the repo linked to the function.', true) ->param('providerBranch', '', new Text(128, 0), 'Production branch for the repo linked to the function.', true) diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php index adb29bc533..227ec3f026 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Functions/Update.php @@ -83,7 +83,7 @@ class Update extends Base ->param('logging', true, new Boolean(), 'When disabled, executions will exclude logs and errors, and will be slightly faster.', true) ->param('entrypoint', '', new Text(1028, 0), 'Entrypoint File. This path is relative to the "providerRootDirectory".', true) ->param('commands', '', new Text(8192, 0), 'Build Commands.', true) - ->param('scopes', [], new ArrayList(new WhiteList(array_keys(Config::getParam('scopes')), true), APP_LIMIT_ARRAY_PARAMS_SIZE), 'List of scopes allowed for API Key auto-generated for every execution. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' scopes are allowed.', true) + ->param('scopes', [], new ArrayList(new WhiteList(array_keys(Config::getParam('projectScopes')), true), APP_LIMIT_ARRAY_PARAMS_SIZE), 'List of scopes allowed for API Key auto-generated for every execution. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' scopes are allowed.', true) ->param('installationId', '', new Text(128, 0), 'Appwrite Installation ID for VCS (Version Controle System) deployment.', true) ->param('providerRepositoryId', null, new Nullable(new Text(128, 0)), 'Repository ID of the repo linked to the function', true) ->param('providerBranch', '', new Text(128, 0), 'Production branch for the repo linked to the function', true) diff --git a/src/Appwrite/Platform/Tasks/Screenshot.php b/src/Appwrite/Platform/Tasks/Screenshot.php index 7ad95c6e72..4df3ab91df 100644 --- a/src/Appwrite/Platform/Tasks/Screenshot.php +++ b/src/Appwrite/Platform/Tasks/Screenshot.php @@ -190,7 +190,7 @@ class Screenshot extends Action 'cookie' => $cookieConsole ], [ 'name' => 'Screenshot API key', - 'scopes' => \array_keys(Config::getParam('scopes', [])) + 'scopes' => \array_keys(Config::getParam('projectScopes', [])) ]); if ($response['headers']['status-code'] !== 201) { From c0c1d693c267c23e61b0d34414f682690c2b6e93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Tue, 23 Dec 2025 13:06:25 +0100 Subject: [PATCH 17/60] DB schema update for keys --- app/config/collections/platform.php | 30 +++++++++++++++++++++++++++- app/init/database/filters.php | 31 +++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/app/config/collections/platform.php b/app/config/collections/platform.php index 16eafc9d4a..395a1c5d3b 100644 --- a/app/config/collections/platform.php +++ b/app/config/collections/platform.php @@ -6,7 +6,7 @@ use Utopia\Database\Helpers\ID; $providers = Config::getParam('oAuthProviders', []); -return [ +$platformCollections = [ 'projects' => [ '$collection' => ID::custom(Database::METADATA), '$id' => ID::custom('projects'), @@ -1914,3 +1914,31 @@ return [ 'indexes' => [] ], ]; + +// Organization API keys subquery +$platformCollections['teams']['attributes'][] = [ + '$id' => ID::custom('keys'), + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => 16384, + 'signed' => true, + 'required' => false, + 'default' => null, + 'array' => false, + 'filters' => ['subQueryOrganizationKeys'], +]; + +// Account API keys subquery +$platformCollections['users']['attributes'][] = [ + '$id' => ID::custom('keys'), + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => 16384, + 'signed' => true, + 'required' => false, + 'default' => null, + 'array' => false, + 'filters' => ['subQueryAccountKeys'], +]; + +return $platformCollections; diff --git a/app/init/database/filters.php b/app/init/database/filters.php index d8624c496e..166b3f7163 100644 --- a/app/init/database/filters.php +++ b/app/init/database/filters.php @@ -434,3 +434,34 @@ Database::addFilter( return $value; } ); + + +Database::addFilter( + 'subQueryOrganizationKeys', + function (mixed $value) { + return; + }, + function (mixed $value, Document $document, Database $database) { + return Authorization::skip(fn () => $database + ->find('keys', [ + Query::equal('resourceType', ['teams']), + Query::equal('resourceInternalId', [$document->getSequence()]), + Query::limit(APP_LIMIT_SUBQUERY), + ])); + } +); + +Database::addFilter( + 'subQueryAccountKeys', + function (mixed $value) { + return; + }, + function (mixed $value, Document $document, Database $database) { + return Authorization::skip(fn () => $database + ->find('keys', [ + Query::equal('resourceType', ['users']), + Query::equal('resourceInternalId', [$document->getSequence()]), + Query::limit(APP_LIMIT_SUBQUERY), + ])); + } +); From 9477a5d9802cd848b1bbeb914811a7816723364f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Tue, 23 Dec 2025 13:30:43 +0100 Subject: [PATCH 18/60] Fix extensability of collections --- app/config/collections.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/config/collections.php b/app/config/collections.php index 533dee57a8..a74e079dce 100644 --- a/app/config/collections.php +++ b/app/config/collections.php @@ -26,8 +26,8 @@ unset($common['files']); $collections = [ 'buckets' => $buckets, 'databases' => $databases, - 'projects' => array_merge($projects, $common), - 'console' => array_merge($platform, $common), + 'projects' => array_merge_recursive($projects, $common), + 'console' => array_merge_recursive($platform, $common), 'logs' => $logs, ]; From c08acedf6ac05e128cb33bbebde1522bbdbec984 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Tue, 23 Dec 2025 15:12:41 +0100 Subject: [PATCH 19/60] Fix key test --- tests/unit/Auth/KeyTest.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/unit/Auth/KeyTest.php b/tests/unit/Auth/KeyTest.php index 920608e82f..727162433a 100644 --- a/tests/unit/Auth/KeyTest.php +++ b/tests/unit/Auth/KeyTest.php @@ -24,8 +24,12 @@ class KeyTest extends TestCase $roleScopes = Config::getParam('roles', [])[User::ROLE_APPS]['scopes']; $key = static::generateKey($projectId, $usage, $scopes); - $project = new Document(['$id' => $projectId,]); - $decoded = Key::decode($project, $key); + $decoded = Key::decode( + project: new Document(['$id' => $projectId]), + team: new Document(), + user: new Document(), + key: $key, + ); $this->assertEquals($projectId, $decoded->getProjectId()); $this->assertEquals(API_KEY_DYNAMIC, $decoded->getType()); From c54d1d29a58a5cbfb92c90d2d5510029e75094da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Sat, 27 Dec 2025 18:44:01 +0100 Subject: [PATCH 20/60] Update stats of all key ypes --- app/controllers/shared/api.php | 52 +++++++++++++++++++++++++--------- src/Appwrite/Auth/Key.php | 10 +++++++ 2 files changed, 49 insertions(+), 13 deletions(-) diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index c4ca334921..e1786a30d0 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -330,22 +330,46 @@ App::init() // For standard keys, update last accessed time if ($apiKey->getType() === API_KEY_STANDARD) { - $dbKey = $project->find( - key: 'secret', - find: $request->getHeader('x-appwrite-key', ''), - subject: 'keys' - ); + if (!empty($apiKey->getProjectId())) { + $dbKey = $project->find( + key: 'secret', + find: $request->getHeader('x-appwrite-key', ''), + subject: 'keys' + ); + } elseif (!empty($apiKey->getUserId())) { + $dbKey = $user->find( + key: 'secret', + find: $request->getHeader('x-appwrite-key', ''), + subject: 'keys' + ); + } elseif (!empty($apiKey->getTeamId())) { + $dbKey = $team->find( + key: 'secret', + find: $request->getHeader('x-appwrite-key', ''), + subject: 'keys' + ); + } if (!$dbKey) { throw new Exception(Exception::USER_UNAUTHORIZED); } + $purgeResource = function () use ($apiKey, $dbForPlatform, $project, $user, $team) { + if (!empty($apiKey->getProjectId())) { + $dbForPlatform->purgeCachedDocument('projects', $project->getId()); + } elseif (!empty($apiKey->getUserId())) { + $dbForPlatform->purgeCachedDocument('users', $user->getId()); + } elseif (!empty($apiKey->getTeamId())) { + $dbForPlatform->purgeCachedDocument('teams', $team->getId()); + } + }; + + $updates = new Document(); + $accessedAt = $dbKey->getAttribute('accessedAt', 0); if (DateTime::formatTz(DateTime::addSeconds(new \DateTime(), -APP_KEY_ACCESS)) > $accessedAt) { - $dbKey->setAttribute('accessedAt', DateTime::now()); - $dbForPlatform->updateDocument('keys', $dbKey->getId(), $dbKey); - $dbForPlatform->purgeCachedDocument('projects', $project->getId()); + $updates->setAttribute('accessedAt', DateTime::now()); } $sdkValidator = new WhiteList($servers, true); @@ -356,15 +380,17 @@ App::init() if (!in_array($sdk, $sdks)) { $sdks[] = $sdk; - $dbKey->setAttribute('sdks', $sdks); - /** Update access time as well */ - $dbKey->setAttribute('accessedAt', Datetime::now()); - $dbForPlatform->updateDocument('keys', $dbKey->getId(), $dbKey); - $dbForPlatform->purgeCachedDocument('projects', $project->getId()); + $updates->setAttribute('sdks', $sdks); + $updates->setAttribute('accessedAt', Datetime::now()); } } + if (!$updates->isEmpty()) { + $dbForPlatform->updateDocument('keys', $dbKey->getId(), $updates); + $purgeResource(); + } + $queueForAudits->setUser($user); } } // Admin User Authentication diff --git a/src/Appwrite/Auth/Key.php b/src/Appwrite/Auth/Key.php index 7f2d27ed5e..c4310164cc 100644 --- a/src/Appwrite/Auth/Key.php +++ b/src/Appwrite/Auth/Key.php @@ -36,6 +36,16 @@ class Key return $this->projectId; } + public function getUserId(): string + { + return $this->userId; + } + + public function getTeamId(): string + { + return $this->teamId; + } + public function getType(): string { return $this->type; From ee0f15eed64a4ec896fe1a11e6628a851903d99a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Sat, 27 Dec 2025 19:08:12 +0100 Subject: [PATCH 21/60] QA bug fixing --- app/controllers/shared/api.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index e1786a30d0..58e81a4868 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -329,7 +329,7 @@ App::init() } // For standard keys, update last accessed time - if ($apiKey->getType() === API_KEY_STANDARD) { + if (\in_array($apiKey->getType(), [API_KEY_STANDARD, API_KEY_ORGANIZATION, API_KEY_ACCOUNT])) { if (!empty($apiKey->getProjectId())) { $dbKey = $project->find( key: 'secret', @@ -356,11 +356,11 @@ App::init() $purgeResource = function () use ($apiKey, $dbForPlatform, $project, $user, $team) { if (!empty($apiKey->getProjectId())) { - $dbForPlatform->purgeCachedDocument('projects', $project->getId()); + Authorization::skip(fn () => $dbForPlatform->purgeCachedDocument('projects', $project->getId())); } elseif (!empty($apiKey->getUserId())) { - $dbForPlatform->purgeCachedDocument('users', $user->getId()); + Authorization::skip(fn () => $dbForPlatform->purgeCachedDocument('users', $user->getId())); } elseif (!empty($apiKey->getTeamId())) { - $dbForPlatform->purgeCachedDocument('teams', $team->getId()); + Authorization::skip(fn () => $dbForPlatform->purgeCachedDocument('teams', $team->getId())); } }; @@ -387,7 +387,7 @@ App::init() } if (!$updates->isEmpty()) { - $dbForPlatform->updateDocument('keys', $dbKey->getId(), $updates); + Authorization::skip(fn () => $dbForPlatform->updateDocument('keys', $dbKey->getId(), $updates)); $purgeResource(); } From 6774de4eef7987955c794d0b1e3043240e260ee0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Sat, 27 Dec 2025 19:18:25 +0100 Subject: [PATCH 22/60] add todo --- tests/unit/Auth/KeyTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unit/Auth/KeyTest.php b/tests/unit/Auth/KeyTest.php index 727162433a..ab577e9c2f 100644 --- a/tests/unit/Auth/KeyTest.php +++ b/tests/unit/Auth/KeyTest.php @@ -10,6 +10,7 @@ use Utopia\Config\Config; use Utopia\Database\Document; use Utopia\System\System; +// TODO: Check diff of Key.php, and update unit tests accordingly class KeyTest extends TestCase { public function testDecode(): void From b4c1b96d43277360d787d67a205558f00d86a836 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Sat, 27 Dec 2025 19:28:08 +0100 Subject: [PATCH 23/60] Fix General tests --- app/controllers/general.php | 2 +- app/init/resources.php | 2 +- docker-compose.yml | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/controllers/general.php b/app/controllers/general.php index 23de89af27..c3ceb07d09 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -1402,7 +1402,7 @@ App::error() $template = $error->getView() ?? (($route) ? $route->getLabel('error', null) : null); // TODO: Ideally use group 'api' here, but all wildcard routes seem to have 'api' at the moment - if (!\str_starts_with($route->getPath(), '/v1')) { + if (empty($route) || !\str_starts_with($route->getPath(), '/v1')) { $template = __DIR__ . '/../views/general/error.phtml'; } diff --git a/app/init/resources.php b/app/init/resources.php index 1db546e0d0..77bae318b8 100644 --- a/app/init/resources.php +++ b/app/init/resources.php @@ -1017,7 +1017,7 @@ App::setResource('team', function (Document $project, Database $dbForPlatform, A $teamInternalId = $project->getAttribute('teamInternalId', ''); } else { $route = $utopia->match($request); - $path = $route->getPath(); + $path = !empty($route) ? $route->getPath() : $request->getURI(); if (str_starts_with($path, '/v1/projects/:projectId')) { $uri = $request->getURI(); $pid = explode('/', $uri)[3]; diff --git a/docker-compose.yml b/docker-compose.yml index 3b935b84fb..c045ad1647 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -98,6 +98,7 @@ services: - ./public:/usr/src/code/public - ./src:/usr/src/code/src - ./dev:/usr/src/code/dev + # - ./vendor/utopia-php/framework:/usr/src/code/vendor/utopia-php/framework depends_on: - mariadb - redis From 04f660e44bc98cd874cacf00289797208f5b5c6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Sun, 28 Dec 2025 10:06:29 +0100 Subject: [PATCH 24/60] Dedicate project test --- .../Projects/ProjectsConsoleClientTest.php | 234 +++++++++--------- 1 file changed, 116 insertions(+), 118 deletions(-) diff --git a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php index 769d3a4c85..f0608595f7 100644 --- a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php +++ b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php @@ -1765,124 +1765,6 @@ class ProjectsConsoleClientTest extends Scope return $data; } - /** - * @depends testUpdateProjectAuthLimit - */ - public function testUpdateProjectAuthSessionsLimit($data): array - { - $id = $data['projectId'] ?? ''; - - /** - * Test for failure - */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/max-sessions', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'limit' => 0, - ]); - - $this->assertEquals(400, $response['headers']['status-code']); - - /** - * Test for SUCCESS - */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/max-sessions', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'limit' => 1, - ]); - - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertNotEmpty($response['body']['$id']); - $this->assertEquals(1, $response['body']['authSessionsLimit']); - - $email = uniqid() . 'user@localhost.test'; - $password = 'password'; - $name = 'User Name'; - - /** - * Create new user - */ - $response = $this->client->call(Client::METHOD_POST, '/account', array_merge([ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'x-appwrite-project' => $id, - ]), [ - 'userId' => ID::unique(), - 'email' => $email, - 'password' => $password, - 'name' => $name, - ]); - - $this->assertEquals(201, $response['headers']['status-code']); - - /** - * create new session - */ - $response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', array_merge([ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'x-appwrite-project' => $id, - ]), [ - 'email' => $email, - 'password' => $password, - ]); - - - $this->assertEquals(201, $response['headers']['status-code']); - $sessionId1 = $response['body']['$id']; - - /** - * create new session - */ - $response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', array_merge([ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'x-appwrite-project' => $id, - ]), [ - 'email' => $email, - 'password' => $password, - ]); - - - $this->assertEquals(201, $response['headers']['status-code']); - $sessionCookie = $response['headers']['set-cookie']; - $sessionId2 = $response['body']['$id']; - - /** - * List sessions - */ - $this->assertEventually(function () use ($id, $sessionCookie, $sessionId2) { - $response = $this->client->call(Client::METHOD_GET, '/account/sessions', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'x-appwrite-project' => $id, - 'Cookie' => $sessionCookie, - ]); - - $this->assertEquals(200, $response['headers']['status-code']); - $sessions = $response['body']['sessions']; - - $this->assertEquals(1, count($sessions)); - $this->assertEquals($sessionId2, $sessions[0]['$id']); - }); - - /** - * Reset Limit - */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/max-sessions', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'limit' => 10, - ]); - - return $data; - } - - /** * @depends testUpdateProjectAuthLimit */ @@ -5380,4 +5262,120 @@ class ProjectsConsoleClientTest extends Scope /** * Devkeys Tests ends here ------------------------------------------------ */ + + public function testUpdateProjectAuthSessionsLimit(): void + { + $id = $this->setupProject([ + 'projectId' => ID::unique(), + 'name' => 'testUpdateProjectAuthSessionsLimit', + 'region' => System::getEnv('_APP_REGION', 'default') + ]); + + /** + * Test for failure + */ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/max-sessions', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'limit' => 0, + ]); + + $this->assertEquals(400, $response['headers']['status-code']); + + /** + * Test for SUCCESS + */ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/max-sessions', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'limit' => 1, + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertNotEmpty($response['body']['$id']); + $this->assertEquals(1, $response['body']['authSessionsLimit']); + + $email = uniqid() . 'user@localhost.test'; + $password = 'password'; + $name = 'User Name'; + + /** + * Create new user + */ + $response = $this->client->call(Client::METHOD_POST, '/account', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $id, + ]), [ + 'userId' => ID::unique(), + 'email' => $email, + 'password' => $password, + 'name' => $name, + ]); + + $this->assertEquals(201, $response['headers']['status-code']); + + /** + * create new session + */ + $response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $id, + ]), [ + 'email' => $email, + 'password' => $password, + ]); + + + $this->assertEquals(201, $response['headers']['status-code']); + $sessionId1 = $response['body']['$id']; + + /** + * create new session + */ + $response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $id, + ]), [ + 'email' => $email, + 'password' => $password, + ]); + + + $this->assertEquals(201, $response['headers']['status-code']); + $sessionCookie = $response['headers']['set-cookie']; + $sessionId2 = $response['body']['$id']; + + /** + * List sessions + */ + $this->assertEventually(function () use ($id, $sessionCookie, $sessionId2) { + $response = $this->client->call(Client::METHOD_GET, '/account/sessions', [ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $id, + 'Cookie' => $sessionCookie, + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $sessions = $response['body']['sessions']; + + $this->assertEquals(1, count($sessions)); + $this->assertEquals($sessionId2, $sessions[0]['$id']); + }); + + /** + * Reset Limit + */ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/max-sessions', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'limit' => 10, + ]); + } } From 7c56a76feb7bacf10f302f15afc23ae333044642 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 29 Dec 2025 08:59:07 +0100 Subject: [PATCH 25/60] self PR review fixes --- app/config/scopes/account.php | 6 +- app/init/resources.php | 9 +- src/Appwrite/Utopia/Response/Model/Key.php | 2 +- .../Projects/ProjectsConsoleClientTest.php | 234 +++++++++--------- 4 files changed, 131 insertions(+), 120 deletions(-) diff --git a/app/config/scopes/account.php b/app/config/scopes/account.php index f11e49ca76..ec98281458 100644 --- a/app/config/scopes/account.php +++ b/app/config/scopes/account.php @@ -5,9 +5,11 @@ return [ "account" => [ "description" => 'Access to manage account, it\'s organizations, sessions, tokens, and billing.', - ],"teams.read" => [ + ], + "teams.read" => [ "description" => 'Access to read account\'s organizations.', - ],"teams.write" => [ + ], + "teams.write" => [ "description" => 'Access to create, update and delete account\'s organizations and it\'s memberships.', ], ]; diff --git a/app/init/resources.php b/app/init/resources.php index 77bae318b8..236f861ef0 100644 --- a/app/init/resources.php +++ b/app/init/resources.php @@ -44,6 +44,7 @@ use Utopia\Config\Config; use Utopia\Database\Adapter\Pool as DatabasePool; use Utopia\Database\Database; use Utopia\Database\DateTime as DatabaseDateTime; +use Utopia\Database\DateTime as DatabaseDateTime; use Utopia\Database\Document; use Utopia\Database\Query; use Utopia\Database\Validator\Authorization; @@ -444,7 +445,13 @@ App::setResource('user', function (string $mode, Document $project, Document $co subject: 'keys' ); - if (!empty($key)) { + $expired = false; + $expire = $key->getAttribute('expire'); + if (!empty($expire) && $expire < DatabaseDateTime::formatTz(DatabaseDateTime::now())) { + $expired = true; + } + + if (!empty($key) && !$expired) { $user = $accountKeyUser; } } diff --git a/src/Appwrite/Utopia/Response/Model/Key.php b/src/Appwrite/Utopia/Response/Model/Key.php index 38aa0748df..a13c9146cd 100644 --- a/src/Appwrite/Utopia/Response/Model/Key.php +++ b/src/Appwrite/Utopia/Response/Model/Key.php @@ -10,7 +10,7 @@ class Key extends Model /** * @var bool */ - protected bool $public = true; + protected bool $public = true; // Public because reused for more key types public function __construct() { diff --git a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php index f0608595f7..f2887d951b 100644 --- a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php +++ b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php @@ -2079,6 +2079,124 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(201, $response['headers']['status-code']); } + public function testUpdateProjectAuthSessionsLimit(): void + { + $id = $this->setupProject([ + 'projectId' => ID::unique(), + 'name' => 'testUpdateProjectAuthSessionsLimit', + 'region' => System::getEnv('_APP_REGION', 'default') + ]); + + /** + * Test for failure + */ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/max-sessions', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'limit' => 0, + ]); + + $this->assertEquals(400, $response['headers']['status-code']); + + /** + * Test for SUCCESS + */ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/max-sessions', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'limit' => 1, + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertNotEmpty($response['body']['$id']); + $this->assertEquals(1, $response['body']['authSessionsLimit']); + + $email = uniqid() . 'user@localhost.test'; + $password = 'password'; + $name = 'User Name'; + + /** + * Create new user + */ + $response = $this->client->call(Client::METHOD_POST, '/account', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $id, + ]), [ + 'userId' => ID::unique(), + 'email' => $email, + 'password' => $password, + 'name' => $name, + ]); + + $this->assertEquals(201, $response['headers']['status-code']); + + /** + * create new session + */ + $response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $id, + ]), [ + 'email' => $email, + 'password' => $password, + ]); + + + $this->assertEquals(201, $response['headers']['status-code']); + $sessionId1 = $response['body']['$id']; + + /** + * create new session + */ + $response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $id, + ]), [ + 'email' => $email, + 'password' => $password, + ]); + + + $this->assertEquals(201, $response['headers']['status-code']); + $sessionCookie = $response['headers']['set-cookie']; + $sessionId2 = $response['body']['$id']; + + /** + * List sessions + */ + $this->assertEventually(function () use ($id, $sessionCookie, $sessionId2) { + $response = $this->client->call(Client::METHOD_GET, '/account/sessions', [ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $id, + 'Cookie' => $sessionCookie, + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $sessions = $response['body']['sessions']; + + $this->assertEquals(1, count($sessions)); + $this->assertEquals($sessionId2, $sessions[0]['$id']); + }); + + /** + * Reset Limit + */ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/max-sessions', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'limit' => 10, + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + } + /** * @depends testUpdateProjectAuthLimit */ @@ -5262,120 +5380,4 @@ class ProjectsConsoleClientTest extends Scope /** * Devkeys Tests ends here ------------------------------------------------ */ - - public function testUpdateProjectAuthSessionsLimit(): void - { - $id = $this->setupProject([ - 'projectId' => ID::unique(), - 'name' => 'testUpdateProjectAuthSessionsLimit', - 'region' => System::getEnv('_APP_REGION', 'default') - ]); - - /** - * Test for failure - */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/max-sessions', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'limit' => 0, - ]); - - $this->assertEquals(400, $response['headers']['status-code']); - - /** - * Test for SUCCESS - */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/max-sessions', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'limit' => 1, - ]); - - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertNotEmpty($response['body']['$id']); - $this->assertEquals(1, $response['body']['authSessionsLimit']); - - $email = uniqid() . 'user@localhost.test'; - $password = 'password'; - $name = 'User Name'; - - /** - * Create new user - */ - $response = $this->client->call(Client::METHOD_POST, '/account', array_merge([ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'x-appwrite-project' => $id, - ]), [ - 'userId' => ID::unique(), - 'email' => $email, - 'password' => $password, - 'name' => $name, - ]); - - $this->assertEquals(201, $response['headers']['status-code']); - - /** - * create new session - */ - $response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', array_merge([ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'x-appwrite-project' => $id, - ]), [ - 'email' => $email, - 'password' => $password, - ]); - - - $this->assertEquals(201, $response['headers']['status-code']); - $sessionId1 = $response['body']['$id']; - - /** - * create new session - */ - $response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', array_merge([ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'x-appwrite-project' => $id, - ]), [ - 'email' => $email, - 'password' => $password, - ]); - - - $this->assertEquals(201, $response['headers']['status-code']); - $sessionCookie = $response['headers']['set-cookie']; - $sessionId2 = $response['body']['$id']; - - /** - * List sessions - */ - $this->assertEventually(function () use ($id, $sessionCookie, $sessionId2) { - $response = $this->client->call(Client::METHOD_GET, '/account/sessions', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'x-appwrite-project' => $id, - 'Cookie' => $sessionCookie, - ]); - - $this->assertEquals(200, $response['headers']['status-code']); - $sessions = $response['body']['sessions']; - - $this->assertEquals(1, count($sessions)); - $this->assertEquals($sessionId2, $sessions[0]['$id']); - }); - - /** - * Reset Limit - */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/max-sessions', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'limit' => 10, - ]); - } } From 5f5d9b4fcb1fd9cbbe4e2be9414147e5b3d40e34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 29 Dec 2025 09:04:47 +0100 Subject: [PATCH 26/60] Add async key cleanup --- app/controllers/api/teams.php | 12 +++++++-- app/init/constants.php | 1 + src/Appwrite/Platform/Workers/Deletes.php | 30 +++++++++++++++++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index 8771588d3a..661e99ef1b 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -431,15 +431,23 @@ App::delete('/v1/teams/:teamId') throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Failed to remove team from DB'); } + $clone = clone $team; + + // Sync delete $deletes = new Deletes(); - $deletes->deleteMemberships($getProjectDB, $team, $project); + $deletes->deleteMemberships($getProjectDB, $clone, $project); if ($project->getId() === 'console') { $queueForDeletes ->setType(DELETE_TYPE_TEAM_PROJECTS) - ->setDocument($team); + ->setDocument($clone); } + // Async delete + $queueForDeletes + ->setType(DELETE_TYPE_DOCUMENT) + ->setDocument($clone); + $queueForEvents ->setParam('teamId', $team->getId()) ->setPayload($response->output($team, Response::MODEL_TEAM)) diff --git a/app/init/constants.php b/app/init/constants.php index 3a8eb72e62..b27c681bcd 100644 --- a/app/init/constants.php +++ b/app/init/constants.php @@ -189,6 +189,7 @@ const DELETE_TYPE_SITES = 'sites'; const DELETE_TYPE_FUNCTIONS = 'functions'; const DELETE_TYPE_DEPLOYMENTS = 'deployments'; const DELETE_TYPE_USERS = 'users'; +const DELETE_TYPE_TEAMS = 'teams'; const DELETE_TYPE_TEAM_PROJECTS = 'teams_projects'; const DELETE_TYPE_EXECUTIONS = 'executions'; const DELETE_TYPE_AUDIT = 'audit'; diff --git a/src/Appwrite/Platform/Workers/Deletes.php b/src/Appwrite/Platform/Workers/Deletes.php index 5cd2402783..2f9ecaeee1 100644 --- a/src/Appwrite/Platform/Workers/Deletes.php +++ b/src/Appwrite/Platform/Workers/Deletes.php @@ -120,6 +120,9 @@ class Deletes extends Action case DELETE_TYPE_USERS: $this->deleteUser($getProjectDB, $document, $project); break; + case DELETE_TYPE_TEAMS: + $this->deleteTeam($getProjectDB, $document, $project); + break; case DELETE_TYPE_BUCKETS: $this->deleteBucket($getProjectDB, $deviceForFiles, $document, $project); break; @@ -634,6 +637,24 @@ class Deletes extends Action $deviceForCache->delete($deviceForCache->getRoot(), true); } + private function deleteTeam(callable $getProjectDB, Document $document, Document $project): void + { + $teamId = $document->getId(); + $teamInternalId = $document->getSequence(); + $dbForProject = $getProjectDB($project); + + if ($project->getId() === 'console') { + // Delete Keys + $this->deleteByGroup('keys', [ + Query::equal('resourceInternalId', [$teamInternalId]), + Query::equal('resourceType', ['teams']), + Query::orderAsc() + ], $dbForProject); + } + + $dbForProject->purgeCachedDocument('teams', $teamId); + } + /** * @param callable $getProjectDB * @param Document $document user document @@ -653,6 +674,15 @@ class Deletes extends Action Query::orderAsc() ], $dbForProject); + if ($project->getId() === 'console') { + // Delete Keys + $this->deleteByGroup('keys', [ + Query::equal('resourceInternalId', [$userInternalId]), + Query::equal('resourceType', ['users']), + Query::orderAsc() + ], $dbForProject); + } + $dbForProject->purgeCachedDocument('users', $userId); // Delete Memberships and decrement team membership counts From eb2c616089aefc69b5afdf3038f407674012c5e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 29 Dec 2025 10:47:27 +0100 Subject: [PATCH 27/60] Improve key unit tests --- app/config/scopes/account.php | 2 +- app/init/resources.php | 17 +++--- tests/unit/Auth/KeyTest.php | 102 +++++++++++++++++++++++++++++++++- 3 files changed, 111 insertions(+), 10 deletions(-) diff --git a/app/config/scopes/account.php b/app/config/scopes/account.php index ec98281458..5041408b2d 100644 --- a/app/config/scopes/account.php +++ b/app/config/scopes/account.php @@ -4,7 +4,7 @@ return [ "account" => [ - "description" => 'Access to manage account, it\'s organizations, sessions, tokens, and billing.', + "description" => 'Access to manage account, its organizations, sessions, tokens, and billing.', ], "teams.read" => [ "description" => 'Access to read account\'s organizations.', diff --git a/app/init/resources.php b/app/init/resources.php index 236f861ef0..b0ee04fbc6 100644 --- a/app/init/resources.php +++ b/app/init/resources.php @@ -44,7 +44,6 @@ use Utopia\Config\Config; use Utopia\Database\Adapter\Pool as DatabasePool; use Utopia\Database\Database; use Utopia\Database\DateTime as DatabaseDateTime; -use Utopia\Database\DateTime as DatabaseDateTime; use Utopia\Database\Document; use Utopia\Database\Query; use Utopia\Database\Validator\Authorization; @@ -445,14 +444,16 @@ App::setResource('user', function (string $mode, Document $project, Document $co subject: 'keys' ); - $expired = false; - $expire = $key->getAttribute('expire'); - if (!empty($expire) && $expire < DatabaseDateTime::formatTz(DatabaseDateTime::now())) { - $expired = true; - } + if (!empty($key)) { + $expired = false; + $expire = $key->getAttribute('expire'); + if (!empty($expire) && $expire < DatabaseDateTime::formatTz(DatabaseDateTime::now())) { + $expired = true; + } - if (!empty($key) && !$expired) { - $user = $accountKeyUser; + if (!$expired) { + $user = $accountKeyUser; + } } } } diff --git a/tests/unit/Auth/KeyTest.php b/tests/unit/Auth/KeyTest.php index ab577e9c2f..b713513ff5 100644 --- a/tests/unit/Auth/KeyTest.php +++ b/tests/unit/Auth/KeyTest.php @@ -10,11 +10,11 @@ use Utopia\Config\Config; use Utopia\Database\Document; use Utopia\System\System; -// TODO: Check diff of Key.php, and update unit tests accordingly class KeyTest extends TestCase { public function testDecode(): void { + // Decode dynamic key $projectId = 'test'; $usage = false; $scopes = [ @@ -23,6 +23,7 @@ class KeyTest extends TestCase 'documents.read', ]; $roleScopes = Config::getParam('roles', [])[User::ROLE_APPS]['scopes']; + $guestRoleScopes = Config::getParam('roles', [])[User::ROLE_GUESTS]['scopes']; $key = static::generateKey($projectId, $usage, $scopes); $decoded = Key::decode( @@ -33,9 +34,108 @@ class KeyTest extends TestCase ); $this->assertEquals($projectId, $decoded->getProjectId()); + $this->assertEquals('', $decoded->getTeamId()); + $this->assertEquals('', $decoded->getUserId()); $this->assertEquals(API_KEY_DYNAMIC, $decoded->getType()); $this->assertEquals(User::ROLE_APPS, $decoded->getRole()); $this->assertEquals(\array_merge($scopes, $roleScopes), $decoded->getScopes()); + + // Decode standard key + $scopes = ['custom.write']; + $decoded = Key::decode( + project: new Document(['$id' => $projectId, 'keys' => [ + new Document([ + 'secret' => 'standard_abcd1234', + 'expire' => null, + 'name' => 'Standard key', + 'scopes' => $scopes + ]) + ]]), + team: new Document(), + user: new Document(), + key: 'standard_abcd1234', + ); + $this->assertEquals($projectId, $decoded->getProjectId()); + $this->assertEquals('', $decoded->getTeamId()); + $this->assertEquals('', $decoded->getUserId()); + $this->assertEquals(API_KEY_STANDARD, $decoded->getType()); + $this->assertEquals(User::ROLE_APPS, $decoded->getRole()); + $this->assertEquals(\array_merge($scopes, $roleScopes), $decoded->getScopes()); + + // Decode depricated standard key + $scopes = ['custom.write']; + $decoded = Key::decode( + project: new Document(['$id' => $projectId, 'keys' => [ + new Document([ + 'secret' => 'abcd1234', + 'expire' => null, + 'name' => 'Standard key', + 'scopes' => ['custom.write'] + ]) + ]]), + team: new Document(), + user: new Document(), + key: 'abcd1234', + ); + $this->assertEquals($projectId, $decoded->getProjectId()); + $this->assertEquals('', $decoded->getTeamId()); + $this->assertEquals('', $decoded->getUserId()); + $this->assertEquals(API_KEY_STANDARD, $decoded->getType()); + $this->assertEquals(User::ROLE_APPS, $decoded->getRole()); + $this->assertEquals(\array_merge($scopes, $roleScopes), $decoded->getScopes()); + + // Decode invalid standard key + $scopes = ['custom.write']; + $decoded = Key::decode( + project: new Document(['$id' => $projectId, 'keys' => [ + new Document([ + 'secret' => 'standard_abcd1234', + 'expire' => null, + 'name' => 'Standard key', + 'scopes' => ['custom.write'] + ]) + ]]), + team: new Document(), + user: new Document(), + key: 'standard_efgh5678', + ); + $this->assertEquals($projectId, $decoded->getProjectId()); + $this->assertEquals('', $decoded->getTeamId()); + $this->assertEquals('', $decoded->getUserId()); + $this->assertEquals(API_KEY_STANDARD, $decoded->getType()); + $this->assertEquals(User::ROLE_GUESTS, $decoded->getRole()); + $this->assertEquals($guestRoleScopes, $decoded->getScopes()); + + // Decode expired standard key + $scopes = ['custom.write']; + $yesterday = (new \DateTimeImmutable('-1 day'))->format('Y-m-d\TH:i:s\Z'); + $decoded = Key::decode( + project: new Document(['$id' => $projectId, 'keys' => [ + new Document([ + 'secret' => 'standard_abcd1234', + 'expire' => $yesterday, + 'name' => 'Standard key', + 'scopes' => $scopes + ]) + ]]), + team: new Document(), + user: new Document(), + key: 'standard_abcd1234', + ); + $this->assertEquals(true, $decoded->isExpired()); + $this->assertEquals($projectId, $decoded->getProjectId()); + $this->assertEquals('', $decoded->getTeamId()); + $this->assertEquals('', $decoded->getUserId()); + $this->assertEquals(API_KEY_STANDARD, $decoded->getType()); + $this->assertEquals(User::ROLE_APPS, $decoded->getRole()); + $this->assertEquals(\array_merge($scopes, $roleScopes), $decoded->getScopes()); + + // Decode account key + // Decode invalid account key + // Decode expired account key + // Decode organization key + // Decode invalid organization key + // Decode exired organization key } private static function generateKey( From ee911e3df613ee2550427b8435b9e4b2d9b55e77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 29 Dec 2025 11:21:49 +0100 Subject: [PATCH 28/60] Finalize unit key tests --- src/Appwrite/Auth/Key.php | 5 +- tests/unit/Auth/KeyTest.php | 215 +++++++++++++++++++++++++++++++++++- 2 files changed, 212 insertions(+), 8 deletions(-) diff --git a/src/Appwrite/Auth/Key.php b/src/Appwrite/Auth/Key.php index c4310164cc..8f645f6f08 100644 --- a/src/Appwrite/Auth/Key.php +++ b/src/Appwrite/Auth/Key.php @@ -146,6 +146,7 @@ class Key leeway: 0 ); + $payload = []; try { $payload = $jwtObj->decode($secret); } catch (JWTException) { @@ -233,8 +234,6 @@ class Key $role = User::ROLE_USERS; - $roles = Config::getParam('roles', []); - $scopes = $roles[$role]['scopes'] ?? []; $scopes = $key->getAttribute('scopes', []); $key = new Key( @@ -271,8 +270,6 @@ class Key $role = User::ROLE_APPS; - $roles = Config::getParam('roles', []); - $scopes = $roles[$role]['scopes'] ?? []; $scopes = $key->getAttribute('scopes', []); $key = new Key( diff --git a/tests/unit/Auth/KeyTest.php b/tests/unit/Auth/KeyTest.php index b713513ff5..830ac29dd0 100644 --- a/tests/unit/Auth/KeyTest.php +++ b/tests/unit/Auth/KeyTest.php @@ -39,6 +39,70 @@ class KeyTest extends TestCase $this->assertEquals(API_KEY_DYNAMIC, $decoded->getType()); $this->assertEquals(User::ROLE_APPS, $decoded->getRole()); $this->assertEquals(\array_merge($scopes, $roleScopes), $decoded->getScopes()); + $this->assertEquals('Dynamic Key', $decoded->getName()); + + // Decode dyamic key with extras + $extra = [ + 'disabledMetrics' => ['metric123'], + 'hostnameOverride' => true, + 'bannerDisabled' => true, + 'projectCheckDisabled' => true, + 'previewAuthDisabled' => true, + 'deploymentStatusIgnored' => true, + ]; + $key = static::generateKey($projectId, $usage, $scopes, extra: $extra); + $decoded = Key::decode( + project: new Document(['$id' => $projectId]), + team: new Document(), + user: new Document(), + key: $key, + ); + $this->assertEquals($projectId, $decoded->getProjectId()); + $this->assertEquals('', $decoded->getTeamId()); + $this->assertEquals('', $decoded->getUserId()); + $this->assertEquals(API_KEY_DYNAMIC, $decoded->getType()); + $this->assertEquals(User::ROLE_APPS, $decoded->getRole()); + $this->assertEquals(\array_merge($scopes, $roleScopes), $decoded->getScopes()); + $this->assertEquals('Dynamic Key', $decoded->getName()); + $this->assertEquals(['metric123'], $decoded->getDisabledMetrics()); + $this->assertEquals(true, $decoded->getHostnameOverride()); + $this->assertEquals(true, $decoded->isBannerDisabled()); + $this->assertEquals(true, $decoded->isProjectCheckDisabled()); + $this->assertEquals(true, $decoded->isPreviewAuthDisabled()); + $this->assertEquals(true, $decoded->isDeploymentStatusIgnored()); + + // Decode invalid dynamic key + $invalidKey = API_KEY_DYNAMIC . '_invalid_jwt_token'; + $decoded = Key::decode( + project: new Document(['$id' => $projectId]), + team: new Document(), + user: new Document(), + key: $invalidKey, + ); + $this->assertEquals($projectId, $decoded->getProjectId()); + $this->assertEquals('', $decoded->getTeamId()); + $this->assertEquals('', $decoded->getUserId()); + $this->assertEquals(API_KEY_DYNAMIC, $decoded->getType()); + $this->assertEquals(User::ROLE_GUESTS, $decoded->getRole()); + $this->assertEquals($guestRoleScopes, $decoded->getScopes()); + $this->assertEquals('UNKNOWN', $decoded->getName()); + + // Decode expired dynamic key + $expiredKey = static::generateKey($projectId, $usage, $scopes, maxAge: 1, timestamp: time() - 60); + \sleep(2); + $decoded = Key::decode( + project: new Document(['$id' => $projectId]), + team: new Document(), + user: new Document(), + key: $expiredKey, + ); + $this->assertEquals($projectId, $decoded->getProjectId()); + $this->assertEquals('', $decoded->getTeamId()); + $this->assertEquals('', $decoded->getUserId()); + $this->assertEquals(API_KEY_DYNAMIC, $decoded->getType()); + $this->assertEquals(User::ROLE_GUESTS, $decoded->getRole()); + $this->assertEquals($guestRoleScopes, $decoded->getScopes()); + $this->assertEquals('UNKNOWN', $decoded->getName()); // Decode standard key $scopes = ['custom.write']; @@ -61,6 +125,7 @@ class KeyTest extends TestCase $this->assertEquals(API_KEY_STANDARD, $decoded->getType()); $this->assertEquals(User::ROLE_APPS, $decoded->getRole()); $this->assertEquals(\array_merge($scopes, $roleScopes), $decoded->getScopes()); + $this->assertEquals('Standard key', $decoded->getName()); // Decode depricated standard key $scopes = ['custom.write']; @@ -83,6 +148,7 @@ class KeyTest extends TestCase $this->assertEquals(API_KEY_STANDARD, $decoded->getType()); $this->assertEquals(User::ROLE_APPS, $decoded->getRole()); $this->assertEquals(\array_merge($scopes, $roleScopes), $decoded->getScopes()); + $this->assertEquals('Standard key', $decoded->getName()); // Decode invalid standard key $scopes = ['custom.write']; @@ -105,6 +171,7 @@ class KeyTest extends TestCase $this->assertEquals(API_KEY_STANDARD, $decoded->getType()); $this->assertEquals(User::ROLE_GUESTS, $decoded->getRole()); $this->assertEquals($guestRoleScopes, $decoded->getScopes()); + $this->assertEquals('UNKNOWN', $decoded->getName()); // Decode expired standard key $scopes = ['custom.write']; @@ -129,32 +196,172 @@ class KeyTest extends TestCase $this->assertEquals(API_KEY_STANDARD, $decoded->getType()); $this->assertEquals(User::ROLE_APPS, $decoded->getRole()); $this->assertEquals(\array_merge($scopes, $roleScopes), $decoded->getScopes()); + $this->assertEquals('Standard key', $decoded->getName()); // Decode account key + $userId = 'user123'; + $scopes = ['teams.write']; + $decoded = Key::decode( + project: new Document(['$id' => $projectId]), + team: new Document(), + user: new Document(['$id' => $userId, 'keys' => [ + new Document([ + 'secret' => 'account_abcd1234', + 'expire' => null, + 'name' => 'Account key', + 'scopes' => $scopes + ]) + ]]), + key: 'account_abcd1234', + ); + $this->assertEquals('', $decoded->getProjectId()); + $this->assertEquals('', $decoded->getTeamId()); + $this->assertEquals($userId, $decoded->getUserId()); + $this->assertEquals(API_KEY_ACCOUNT, $decoded->getType()); + $this->assertEquals(User::ROLE_USERS, $decoded->getRole()); + $this->assertEquals($scopes, $decoded->getScopes()); + $this->assertEquals('Account key', $decoded->getName()); + // Decode invalid account key + $scopes = ['teams.write']; + $decoded = Key::decode( + project: new Document(['$id' => $projectId]), + team: new Document(), + user: new Document(['$id' => $userId, 'keys' => [ + new Document([ + 'secret' => 'account_abcd1234', + 'expire' => null, + 'name' => 'Account key', + 'scopes' => $scopes + ]) + ]]), + key: 'account_efgh5678', + ); + $this->assertEquals($projectId, $decoded->getProjectId()); + $this->assertEquals('', $decoded->getTeamId()); + $this->assertEquals('', $decoded->getUserId()); + $this->assertEquals(API_KEY_ACCOUNT, $decoded->getType()); + $this->assertEquals(User::ROLE_GUESTS, $decoded->getRole()); + $this->assertEquals($guestRoleScopes, $decoded->getScopes()); + $this->assertEquals('UNKNOWN', $decoded->getName()); + // Decode expired account key + $scopes = ['teams.write']; + $decoded = Key::decode( + project: new Document(['$id' => $projectId]), + team: new Document(), + user: new Document(['$id' => $userId, 'keys' => [ + new Document([ + 'secret' => 'account_abcd1234', + 'expire' => $yesterday, + 'name' => 'Account key', + 'scopes' => $scopes + ]) + ]]), + key: 'account_abcd1234', + ); + $this->assertEquals(true, $decoded->isExpired()); + $this->assertEquals('', $decoded->getProjectId()); + $this->assertEquals('', $decoded->getTeamId()); + $this->assertEquals($userId, $decoded->getUserId()); + $this->assertEquals(API_KEY_ACCOUNT, $decoded->getType()); + $this->assertEquals(User::ROLE_USERS, $decoded->getRole()); + $this->assertEquals($scopes, $decoded->getScopes()); + $this->assertEquals('Account key', $decoded->getName()); + // Decode organization key + $teamId = 'team123'; + $scopes = ['projects.write']; + $decoded = Key::decode( + project: new Document(['$id' => $projectId]), + team: new Document(['$id' => $teamId, 'keys' => [ + new Document([ + 'secret' => 'organization_abcd1234', + 'expire' => null, + 'name' => 'Organization key', + 'scopes' => $scopes + ]) + ]]), + user: new Document(), + key: 'organization_abcd1234', + ); + $this->assertEquals('', $decoded->getProjectId()); + $this->assertEquals($teamId, $decoded->getTeamId()); + $this->assertEquals('', $decoded->getUserId()); + $this->assertEquals(API_KEY_ORGANIZATION, $decoded->getType()); + $this->assertEquals(User::ROLE_APPS, $decoded->getRole()); + $this->assertEquals($scopes, $decoded->getScopes()); + $this->assertEquals('Organization key', $decoded->getName()); + // Decode invalid organization key - // Decode exired organization key + $scopes = ['projects.write']; + $decoded = Key::decode( + project: new Document(['$id' => $projectId]), + team: new Document(['$id' => $teamId, 'keys' => [ + new Document([ + 'secret' => 'organization_abcd1234', + 'expire' => null, + 'name' => 'Organization key', + 'scopes' => $scopes + ]) + ]]), + user: new Document(), + key: 'organization_efgh5678', + ); + $this->assertEquals($projectId, $decoded->getProjectId()); + $this->assertEquals('', $decoded->getTeamId()); + $this->assertEquals('', $decoded->getUserId()); + $this->assertEquals(API_KEY_ORGANIZATION, $decoded->getType()); + $this->assertEquals(User::ROLE_GUESTS, $decoded->getRole()); + $this->assertEquals($guestRoleScopes, $decoded->getScopes()); + $this->assertEquals('UNKNOWN', $decoded->getName()); + + // Decode expired organization key + $scopes = ['projects.write']; + $decoded = Key::decode( + project: new Document(['$id' => $projectId]), + team: new Document(['$id' => $teamId, 'keys' => [ + new Document([ + 'secret' => 'organization_abcd1234', + 'expire' => $yesterday, + 'name' => 'Organization key', + 'scopes' => $scopes + ]) + ]]), + user: new Document(), + key: 'organization_abcd1234', + ); + $this->assertEquals(true, $decoded->isExpired()); + $this->assertEquals('', $decoded->getProjectId()); + $this->assertEquals($teamId, $decoded->getTeamId()); + $this->assertEquals('', $decoded->getUserId()); + $this->assertEquals(API_KEY_ORGANIZATION, $decoded->getType()); + $this->assertEquals(User::ROLE_APPS, $decoded->getRole()); + $this->assertEquals($scopes, $decoded->getScopes()); + $this->assertEquals('Organization key', $decoded->getName()); } private static function generateKey( string $projectId, bool $usage, array $scopes, + int $maxAge = 86400, + ?int $timestamp = null, + array $extra = [] ): string { $jwt = new JWT( key: System::getEnv('_APP_OPENSSL_KEY_V1'), algo: 'HS256', - maxAge: 86400, + maxAge: $maxAge, leeway: 0, ); + $jwt->setTestTimestamp($timestamp); - $apiKey = $jwt->encode([ + $apiKey = $jwt->encode(\array_merge([ 'projectId' => $projectId, 'usage' => $usage, 'scopes' => $scopes, - ]); + ], $extra)); return API_KEY_DYNAMIC . '_' . $apiKey; } From eda189dbf18e4bc1bd42c70f8bf2fd1eaa649779 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 29 Dec 2025 13:24:26 +0100 Subject: [PATCH 29/60] AI review improvements --- app/config/scopes/account.php | 2 +- app/controllers/api/teams.php | 5 +++-- app/controllers/shared/api.php | 1 + tests/unit/Auth/KeyTest.php | 4 ++-- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/config/scopes/account.php b/app/config/scopes/account.php index 5041408b2d..7705dfca8a 100644 --- a/app/config/scopes/account.php +++ b/app/config/scopes/account.php @@ -10,6 +10,6 @@ return [ "description" => 'Access to read account\'s organizations.', ], "teams.write" => [ - "description" => 'Access to create, update and delete account\'s organizations and it\'s memberships.', + "description" => 'Access to create, update and delete account\'s organizations and its memberships.', ], ]; diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index 661e99ef1b..1ec33742fb 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -437,13 +437,14 @@ App::delete('/v1/teams/:teamId') $deletes = new Deletes(); $deletes->deleteMemberships($getProjectDB, $clone, $project); + // Async delete if ($project->getId() === 'console') { $queueForDeletes ->setType(DELETE_TYPE_TEAM_PROJECTS) - ->setDocument($clone); + ->setDocument($clone) + ->trigger(); } - // Async delete $queueForDeletes ->setType(DELETE_TYPE_DOCUMENT) ->setDocument($clone); diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index 58e81a4868..60d89df86b 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -330,6 +330,7 @@ App::init() // For standard keys, update last accessed time if (\in_array($apiKey->getType(), [API_KEY_STANDARD, API_KEY_ORGANIZATION, API_KEY_ACCOUNT])) { + $dbKey = null; if (!empty($apiKey->getProjectId())) { $dbKey = $project->find( key: 'secret', diff --git a/tests/unit/Auth/KeyTest.php b/tests/unit/Auth/KeyTest.php index 830ac29dd0..fc1779efad 100644 --- a/tests/unit/Auth/KeyTest.php +++ b/tests/unit/Auth/KeyTest.php @@ -41,7 +41,7 @@ class KeyTest extends TestCase $this->assertEquals(\array_merge($scopes, $roleScopes), $decoded->getScopes()); $this->assertEquals('Dynamic Key', $decoded->getName()); - // Decode dyamic key with extras + // Decode dynamic key with extras $extra = [ 'disabledMetrics' => ['metric123'], 'hostnameOverride' => true, @@ -127,7 +127,7 @@ class KeyTest extends TestCase $this->assertEquals(\array_merge($scopes, $roleScopes), $decoded->getScopes()); $this->assertEquals('Standard key', $decoded->getName()); - // Decode depricated standard key + // Decode deprecated standard key $scopes = ['custom.write']; $decoded = Key::decode( project: new Document(['$id' => $projectId, 'keys' => [ From 00b5236dea5b99fda9b2335bc7ffb34df50e5f1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 29 Dec 2025 18:41:35 +0100 Subject: [PATCH 30/60] simplify diff --- .../Projects/ProjectsConsoleClientTest.php | 236 +++++++++--------- 1 file changed, 118 insertions(+), 118 deletions(-) diff --git a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php index f2887d951b..7afb558c9b 100644 --- a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php +++ b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php @@ -1765,6 +1765,124 @@ class ProjectsConsoleClientTest extends Scope return $data; } + public function testUpdateProjectAuthSessionsLimit(): void + { + $id = $this->setupProject([ + 'projectId' => ID::unique(), + 'name' => 'testUpdateProjectAuthSessionsLimit', + 'region' => System::getEnv('_APP_REGION', 'default') + ]); + + /** + * Test for failure + */ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/max-sessions', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'limit' => 0, + ]); + + $this->assertEquals(400, $response['headers']['status-code']); + + /** + * Test for SUCCESS + */ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/max-sessions', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'limit' => 1, + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertNotEmpty($response['body']['$id']); + $this->assertEquals(1, $response['body']['authSessionsLimit']); + + $email = uniqid() . 'user@localhost.test'; + $password = 'password'; + $name = 'User Name'; + + /** + * Create new user + */ + $response = $this->client->call(Client::METHOD_POST, '/account', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $id, + ]), [ + 'userId' => ID::unique(), + 'email' => $email, + 'password' => $password, + 'name' => $name, + ]); + + $this->assertEquals(201, $response['headers']['status-code']); + + /** + * create new session + */ + $response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $id, + ]), [ + 'email' => $email, + 'password' => $password, + ]); + + + $this->assertEquals(201, $response['headers']['status-code']); + $sessionId1 = $response['body']['$id']; + + /** + * create new session + */ + $response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $id, + ]), [ + 'email' => $email, + 'password' => $password, + ]); + + + $this->assertEquals(201, $response['headers']['status-code']); + $sessionCookie = $response['headers']['set-cookie']; + $sessionId2 = $response['body']['$id']; + + /** + * List sessions + */ + $this->assertEventually(function () use ($id, $sessionCookie, $sessionId2) { + $response = $this->client->call(Client::METHOD_GET, '/account/sessions', [ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $id, + 'Cookie' => $sessionCookie, + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $sessions = $response['body']['sessions']; + + $this->assertEquals(1, count($sessions)); + $this->assertEquals($sessionId2, $sessions[0]['$id']); + }); + + /** + * Reset Limit + */ + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/max-sessions', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'limit' => 10, + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + } + /** * @depends testUpdateProjectAuthLimit */ @@ -2079,124 +2197,6 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(201, $response['headers']['status-code']); } - public function testUpdateProjectAuthSessionsLimit(): void - { - $id = $this->setupProject([ - 'projectId' => ID::unique(), - 'name' => 'testUpdateProjectAuthSessionsLimit', - 'region' => System::getEnv('_APP_REGION', 'default') - ]); - - /** - * Test for failure - */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/max-sessions', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'limit' => 0, - ]); - - $this->assertEquals(400, $response['headers']['status-code']); - - /** - * Test for SUCCESS - */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/max-sessions', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'limit' => 1, - ]); - - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertNotEmpty($response['body']['$id']); - $this->assertEquals(1, $response['body']['authSessionsLimit']); - - $email = uniqid() . 'user@localhost.test'; - $password = 'password'; - $name = 'User Name'; - - /** - * Create new user - */ - $response = $this->client->call(Client::METHOD_POST, '/account', array_merge([ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'x-appwrite-project' => $id, - ]), [ - 'userId' => ID::unique(), - 'email' => $email, - 'password' => $password, - 'name' => $name, - ]); - - $this->assertEquals(201, $response['headers']['status-code']); - - /** - * create new session - */ - $response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', array_merge([ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'x-appwrite-project' => $id, - ]), [ - 'email' => $email, - 'password' => $password, - ]); - - - $this->assertEquals(201, $response['headers']['status-code']); - $sessionId1 = $response['body']['$id']; - - /** - * create new session - */ - $response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', array_merge([ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'x-appwrite-project' => $id, - ]), [ - 'email' => $email, - 'password' => $password, - ]); - - - $this->assertEquals(201, $response['headers']['status-code']); - $sessionCookie = $response['headers']['set-cookie']; - $sessionId2 = $response['body']['$id']; - - /** - * List sessions - */ - $this->assertEventually(function () use ($id, $sessionCookie, $sessionId2) { - $response = $this->client->call(Client::METHOD_GET, '/account/sessions', [ - 'origin' => 'http://localhost', - 'content-type' => 'application/json', - 'x-appwrite-project' => $id, - 'Cookie' => $sessionCookie, - ]); - - $this->assertEquals(200, $response['headers']['status-code']); - $sessions = $response['body']['sessions']; - - $this->assertEquals(1, count($sessions)); - $this->assertEquals($sessionId2, $sessions[0]['$id']); - }); - - /** - * Reset Limit - */ - $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/max-sessions', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'limit' => 10, - ]); - - $this->assertEquals(200, $response['headers']['status-code']); - } - /** * @depends testUpdateProjectAuthLimit */ From 001d38caf51795a09cdf0c0efce97c9b64e3d454 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Mon, 5 Jan 2026 12:53:35 +0530 Subject: [PATCH 31/60] feat: sdk for md --- app/config/sdks.php | 20 +++++++++++++++++++ composer.json | 2 +- composer.lock | 29 ++++++++++++++-------------- docs/sdks/markdown/CHANGELOG.md | 5 +++++ src/Appwrite/Platform/Tasks/SDKs.php | 28 +++++++++++++++++++++++++++ 5 files changed, 69 insertions(+), 15 deletions(-) create mode 100644 docs/sdks/markdown/CHANGELOG.md diff --git a/app/config/sdks.php b/app/config/sdks.php index 9b5d17176f..4f626d9093 100644 --- a/app/config/sdks.php +++ b/app/config/sdks.php @@ -250,6 +250,26 @@ return [ ], ], ], + [ + 'key' => 'md', + 'name' => 'Markdown', + 'version' => '0.1.0', + 'url' => 'https://github.com/appwrite/sdk-for-md.git', + 'package' => 'https://www.npmjs.com/package/@appwrite.io/docs', + 'enabled' => true, + 'beta' => false, + 'dev' => false, + 'hidden' => false, + 'family' => APP_SDK_PLATFORM_CONSOLE, + 'prism' => 'markdown', + 'source' => \realpath(__DIR__ . '/../sdks/console-md'), + 'gitUrl' => 'git@github.com:appwrite/sdk-for-md.git', + 'gitRepoName' => 'sdk-for-md', + 'gitUserName' => 'appwrite', + 'gitBranch' => 'dev', + 'repoBranch' => 'main', + 'changelog' => \realpath(__DIR__ . '/../../docs/sdks/md/CHANGELOG.md'), + ], ], ], diff --git a/composer.json b/composer.json index 844a10d7e8..8b04dd247f 100644 --- a/composer.json +++ b/composer.json @@ -89,7 +89,7 @@ }, "require-dev": { "ext-fileinfo": "*", - "appwrite/sdk-generator": "*", + "appwrite/sdk-generator": "docs-sdk-dev", "phpunit/phpunit": "9.*", "swoole/ide-helper": "5.1.2", "phpstan/phpstan": "1.8.*", diff --git a/composer.lock b/composer.lock index c678d1c01e..5fcb2387d4 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": "b873febd2b03c32ec61a57b690cc44a2", + "content-hash": "6b901a04bee0c8fca7a48f222c52aea8", "packages": [ { "name": "adhocore/jwt", @@ -5438,16 +5438,16 @@ "packages-dev": [ { "name": "appwrite/sdk-generator", - "version": "1.8.6", + "version": "dev-docs-sdk", "source": { "type": "git", "url": "https://github.com/appwrite/sdk-generator.git", - "reference": "b6cc29d3bd247e193f3c06b4168dc69d884645f0" + "reference": "621cfc47d3edfc0ce0e45fa27b0a683be9cc4cc5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/b6cc29d3bd247e193f3c06b4168dc69d884645f0", - "reference": "b6cc29d3bd247e193f3c06b4168dc69d884645f0", + "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/621cfc47d3edfc0ce0e45fa27b0a683be9cc4cc5", + "reference": "621cfc47d3edfc0ce0e45fa27b0a683be9cc4cc5", "shasum": "" }, "require": { @@ -5483,9 +5483,9 @@ "description": "Appwrite PHP library for generating API SDKs for multiple programming languages and platforms", "support": { "issues": "https://github.com/appwrite/sdk-generator/issues", - "source": "https://github.com/appwrite/sdk-generator/tree/1.8.6" + "source": "https://github.com/appwrite/sdk-generator/tree/docs-sdk" }, - "time": "2025-12-31T10:22:17+00:00" + "time": "2026-01-05T06:12:51+00:00" }, { "name": "doctrine/annotations", @@ -8562,16 +8562,16 @@ }, { "name": "symfony/process", - "version": "v8.0.0", + "version": "v8.0.3", "source": { "type": "git", "url": "https://github.com/symfony/process.git", - "reference": "a0a750500c4ce900d69ba4e9faf16f82c10ee149" + "reference": "0cbbd88ec836f8757641c651bb995335846abb78" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/a0a750500c4ce900d69ba4e9faf16f82c10ee149", - "reference": "a0a750500c4ce900d69ba4e9faf16f82c10ee149", + "url": "https://api.github.com/repos/symfony/process/zipball/0cbbd88ec836f8757641c651bb995335846abb78", + "reference": "0cbbd88ec836f8757641c651bb995335846abb78", "shasum": "" }, "require": { @@ -8603,7 +8603,7 @@ "description": "Executes commands in sub-processes", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/process/tree/v8.0.0" + "source": "https://github.com/symfony/process/tree/v8.0.3" }, "funding": [ { @@ -8623,7 +8623,7 @@ "type": "tidelift" } ], - "time": "2025-10-16T16:25:44+00:00" + "time": "2025-12-19T10:01:18+00:00" }, { "name": "symfony/string", @@ -8946,6 +8946,7 @@ "aliases": [], "minimum-stability": "stable", "stability-flags": { + "appwrite/sdk-generator": 20, "utopia-php/audit": 5 }, "prefer-stable": false, @@ -8971,5 +8972,5 @@ "platform-overrides": { "php": "8.3" }, - "plugin-api-version": "2.9.0" + "plugin-api-version": "2.6.0" } diff --git a/docs/sdks/markdown/CHANGELOG.md b/docs/sdks/markdown/CHANGELOG.md new file mode 100644 index 0000000000..bbfc68354e --- /dev/null +++ b/docs/sdks/markdown/CHANGELOG.md @@ -0,0 +1,5 @@ +# Change Log + +## 0.1.0 + +* Initial release diff --git a/src/Appwrite/Platform/Tasks/SDKs.php b/src/Appwrite/Platform/Tasks/SDKs.php index c3a67d7fbb..6b44515fe4 100644 --- a/src/Appwrite/Platform/Tasks/SDKs.php +++ b/src/Appwrite/Platform/Tasks/SDKs.php @@ -12,6 +12,7 @@ use Appwrite\SDK\Language\Flutter; use Appwrite\SDK\Language\Go; use Appwrite\SDK\Language\GraphQL; use Appwrite\SDK\Language\Kotlin; +use Appwrite\SDK\Language\Markdown; use Appwrite\SDK\Language\Node; use Appwrite\SDK\Language\PHP; use Appwrite\SDK\Language\Python; @@ -31,6 +32,27 @@ use Utopia\Validator\WhiteList; class SDKs extends Action { + protected array $supportedSDKS = [ + 'web', + 'cli', + 'php', + 'nodejs', + 'deno', + 'python', + 'ruby', + 'flutter', + 'react-native', + 'dart', + 'go', + 'swift', + 'apple', + 'dotnet', + 'android', + 'graphql', + 'rest', + 'md', + ]; + public static function getName(): string { return 'sdks'; @@ -61,6 +83,9 @@ class SDKs extends Action if (!$sdks) { $selectedPlatform ??= Console::confirm('Choose Platform ("' . implode('", "', static::getPlatforms()) . '" or "*" for all):'); $selectedSDK ??= \strtolower(Console::confirm('Choose SDK ("*" for all):')); + if (!\in_array($selectedSDK, $this->supportedSDKS)) { + throw new \Exception('Unknown SDK "' . $selectedSDK . '" given. Options are: ' . implode(', ', $this->supportedSDKS)); + } } else { $sdks = explode(',', $sdks); } @@ -252,6 +277,9 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND case 'rest': $config = new REST(); break; + case 'md': + $config = new Markdown(); + break; default: throw new \Exception('Language "' . $language['key'] . '" not supported'); } From dad21a912e4f5638e6a51a756415c2a43a0ee740 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Sat, 10 Jan 2026 16:35:09 +0100 Subject: [PATCH 32/60] PR review changes --- app/config/collections/platform.php | 4 ++-- app/controllers/api/teams.php | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/app/config/collections/platform.php b/app/config/collections/platform.php index 395a1c5d3b..73c21ed408 100644 --- a/app/config/collections/platform.php +++ b/app/config/collections/platform.php @@ -726,8 +726,8 @@ $platformCollections = [ '$id' => ID::custom('_key_resource'), 'type' => Database::INDEX_KEY, 'attributes' => ['resourceType', 'resourceInternalId'], - 'lengths' => [Database::LENGTH_KEY], - 'orders' => [Database::ORDER_ASC], + 'lengths' => [], + 'orders' => [], ], [ '$id' => '_key_accessedAt', diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index 1ec33742fb..fe87c31dd6 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -431,8 +431,6 @@ App::delete('/v1/teams/:teamId') throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Failed to remove team from DB'); } - $clone = clone $team; - // Sync delete $deletes = new Deletes(); $deletes->deleteMemberships($getProjectDB, $clone, $project); From 60e1efb8cb47e339976c3b21382e60f2ddff9e7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Sat, 10 Jan 2026 16:42:45 +0100 Subject: [PATCH 33/60] Merge conflict fix --- app/init/models.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/init/models.php b/app/init/models.php index fdfa0271b4..5cd32e73eb 100644 --- a/app/init/models.php +++ b/app/init/models.php @@ -177,7 +177,7 @@ Response::setModel(new BaseList('Deployments List', Response::MODEL_DEPLOYMENT_L Response::setModel(new BaseList('Executions List', Response::MODEL_EXECUTION_LIST, 'executions', Response::MODEL_EXECUTION)); Response::setModel(new BaseList('Projects List', Response::MODEL_PROJECT_LIST, 'projects', Response::MODEL_PROJECT, true, false)); Response::setModel(new BaseList('Webhooks List', Response::MODEL_WEBHOOK_LIST, 'webhooks', Response::MODEL_WEBHOOK, true, false)); -Response::setModel(new BaseList('API Keys List', Response::MODEL_KEY_LIST, 'keys', Response::MODEL_KEY, true, false)); +Response::setModel(new BaseList('API Keys List', Response::MODEL_KEY_LIST, 'keys', Response::MODEL_KEY, true, true)); Response::setModel(new BaseList('Dev Keys List', Response::MODEL_DEV_KEY_LIST, 'devKeys', Response::MODEL_DEV_KEY, true, false)); Response::setModel(new BaseList('Auth Providers List', Response::MODEL_AUTH_PROVIDER_LIST, 'platforms', Response::MODEL_AUTH_PROVIDER, true, false)); Response::setModel(new BaseList('Platforms List', Response::MODEL_PLATFORM_LIST, 'platforms', Response::MODEL_PLATFORM, true, false)); From 497e5f8d0036adf056038868dbe637c0c89e0c39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Sat, 10 Jan 2026 16:57:23 +0100 Subject: [PATCH 34/60] tests fixes --- app/config/collections/platform.php | 24 ++++++++++++++++++++++++ app/controllers/api/teams.php | 6 +++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/app/config/collections/platform.php b/app/config/collections/platform.php index 2fb3168c5b..39960f37b3 100644 --- a/app/config/collections/platform.php +++ b/app/config/collections/platform.php @@ -632,6 +632,30 @@ $platformCollections = [ '$id' => ID::custom('keys'), 'name' => 'keys', 'attributes' => [ + // Delete eventuelly, when removing dual-write too + [ + '$id' => ID::custom('projectInternalId'), + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => Database::LENGTH_KEY, + 'signed' => true, + 'required' => true, + 'default' => null, + 'array' => false, + 'filters' => [], + ], + // Delete eventuelly, when removing dual-write too + [ + '$id' => ID::custom('projectId'), + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => Database::LENGTH_KEY, + 'signed' => true, + 'required' => false, + 'default' => 0, + 'array' => false, + 'filters' => [], + ], [ '$id' => ID::custom('resourceType'), 'type' => Database::VAR_STRING, diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index 9bf4a75d83..f151194e07 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -433,19 +433,19 @@ App::delete('/v1/teams/:teamId') // Sync delete $deletes = new Deletes(); - $deletes->deleteMemberships($getProjectDB, $clone, $project); + $deletes->deleteMemberships($getProjectDB, $team, $project); // Async delete if ($project->getId() === 'console') { $queueForDeletes ->setType(DELETE_TYPE_TEAM_PROJECTS) - ->setDocument($clone) + ->setDocument($team) ->trigger(); } $queueForDeletes ->setType(DELETE_TYPE_DOCUMENT) - ->setDocument($clone); + ->setDocument($team); $queueForEvents ->setParam('teamId', $team->getId()) From cd0d6092299f5c3546a6bd17ebb2af9437039023 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Sat, 10 Jan 2026 17:01:31 +0100 Subject: [PATCH 35/60] quality improv --- app/config/errors.php | 5 +++++ app/init/resources.php | 7 ++----- src/Appwrite/Extend/Exception.php | 1 + 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/config/errors.php b/app/config/errors.php index e01d9064bf..50ba6b21e1 100644 --- a/app/config/errors.php +++ b/app/config/errors.php @@ -1074,6 +1074,11 @@ return [ 'description' => 'The project key has expired. Please generate a new key using the Appwrite console.', 'code' => 401, ], + Exception::ACCOUNT_KEY_EXPIRED => [ + 'name' => Exception::ACCOUNT_KEY_EXPIRED, + 'description' => 'The account key has expired. Please generate a new key using the Appwrite console.', + 'code' => 401, + ], Exception::ROUTER_HOST_NOT_FOUND => [ 'name' => Exception::ROUTER_HOST_NOT_FOUND, 'description' => 'Host is not trusted. This could occur because you have not configured a custom domain. Add a custom domain to your project first and try again.', diff --git a/app/init/resources.php b/app/init/resources.php index e627e444a1..4a6b0571eb 100644 --- a/app/init/resources.php +++ b/app/init/resources.php @@ -451,15 +451,12 @@ App::setResource('user', function (string $mode, Document $project, Document $co ); if (!empty($key)) { - $expired = false; $expire = $key->getAttribute('expire'); if (!empty($expire) && $expire < DatabaseDateTime::formatTz(DatabaseDateTime::now())) { - $expired = true; + throw new Exception(Exception::ACCOUNT_KEY_EXPIRED); } - if (!$expired) { - $user = $accountKeyUser; - } + $user = $accountKeyUser; } } } diff --git a/src/Appwrite/Extend/Exception.php b/src/Appwrite/Extend/Exception.php index 33c0942b2d..754b84599a 100644 --- a/src/Appwrite/Extend/Exception.php +++ b/src/Appwrite/Extend/Exception.php @@ -290,6 +290,7 @@ class Exception extends \Exception public const string PROJECT_INVALID_FAILURE_URL = 'project_invalid_failure_url'; public const string PROJECT_RESERVED_PROJECT = 'project_reserved_project'; public const string PROJECT_KEY_EXPIRED = 'project_key_expired'; + public const string ACCOUNT_KEY_EXPIRED = 'account_key_expired'; public const string PROJECT_SMTP_CONFIG_INVALID = 'project_smtp_config_invalid'; From 5d5a14bd77e3379c698337c48473cc42615f2c46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Thu, 15 Jan 2026 16:16:09 +0100 Subject: [PATCH 36/60] PR review fixes --- app/config/errors.php | 22 +++++++++++++++++- app/controllers/shared/api.php | 19 +++++++--------- app/init/resources.php | 37 +++++++++++++++++++++++++++++-- src/Appwrite/Extend/Exception.php | 7 +++++- 4 files changed, 70 insertions(+), 15 deletions(-) diff --git a/app/config/errors.php b/app/config/errors.php index 50ba6b21e1..62affd8101 100644 --- a/app/config/errors.php +++ b/app/config/errors.php @@ -357,6 +357,11 @@ return [ 'description' => 'API key and session used in the same request. Use either `setSession` or `setKey`. Learn about which authentication method to use in the SSR docs: https://appwrite.io/docs/products/auth/server-side-rendering', 'code' => 403, ], + Exception::USER_JWT_AND_COOKIE_SET => [ + 'name' => Exception::USER_JWT_AND_COOKIE_SET, + 'description' => 'JWT and cookie used in the same request. Use either `setJWT` or `setCookie`. Learn about which authentication method to use in the SSR docs: https://appwrite.io/docs/products/auth/server-side-rendering', + 'code' => 403, + ], Exception::API_KEY_EXPIRED => [ 'name' => Exception::API_KEY_EXPIRED, 'description' => 'The dynamic API key has expired. Please don\'t use dynamic API keys for more than duration of the execution.', @@ -1076,7 +1081,7 @@ return [ ], Exception::ACCOUNT_KEY_EXPIRED => [ 'name' => Exception::ACCOUNT_KEY_EXPIRED, - 'description' => 'The account key has expired. Please generate a new key using the Appwrite console.', + 'description' => 'The account API key has expired. Please generate a new key using the Appwrite console.', 'code' => 401, ], Exception::ROUTER_HOST_NOT_FOUND => [ @@ -1333,4 +1338,19 @@ return [ 'description' => 'Target has an invalid provider type.', 'code' => 400, ], + Exception::USER_ID_MISSING => [ + 'name' => Exception::USER_ID_MISSING, + 'description' => 'When using account API key, make sure to pass x-appwrite-user header with your user ID.', + 'code' => 403, + ], + Exception::ORGANIZATION_ID_MISSING => [ + 'name' => Exception::ORGANIZATION_ID_MISSING, + 'description' => 'When using organization API key, make sure to pass x-appwrite-organization header with your organization ID.', + 'code' => 403, + ], + Exception::PROJECT_ID_MISSING => [ + 'name' => Exception::PROJECT_ID_MISSING, + 'description' => 'When using project API key, make sure to pass x-appwrite-project header with your project ID.', + 'code' => 403, + ], ]; diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index 99bf3b7a50..73e04b2028 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -357,16 +357,6 @@ App::init() throw new Exception(Exception::USER_UNAUTHORIZED); } - $purgeResource = function () use ($apiKey, $dbForPlatform, $project, $user, $team) { - if (!empty($apiKey->getProjectId())) { - Authorization::skip(fn () => $dbForPlatform->purgeCachedDocument('projects', $project->getId())); - } elseif (!empty($apiKey->getUserId())) { - Authorization::skip(fn () => $dbForPlatform->purgeCachedDocument('users', $user->getId())); - } elseif (!empty($apiKey->getTeamId())) { - Authorization::skip(fn () => $dbForPlatform->purgeCachedDocument('teams', $team->getId())); - } - }; - $updates = new Document(); $accessedAt = $dbKey->getAttribute('accessedAt', 0); @@ -391,7 +381,14 @@ App::init() if (!$updates->isEmpty()) { Authorization::skip(fn () => $dbForPlatform->updateDocument('keys', $dbKey->getId(), $updates)); - $purgeResource(); + + if (!empty($apiKey->getProjectId())) { + Authorization::skip(fn () => $dbForPlatform->purgeCachedDocument('projects', $project->getId())); + } elseif (!empty($apiKey->getUserId())) { + Authorization::skip(fn () => $dbForPlatform->purgeCachedDocument('users', $user->getId())); + } elseif (!empty($apiKey->getTeamId())) { + Authorization::skip(fn () => $dbForPlatform->purgeCachedDocument('teams', $team->getId())); + } } $queueForAudits->setUser($user); diff --git a/app/init/resources.php b/app/init/resources.php index 7df966f93d..ac6c068b27 100644 --- a/app/init/resources.php +++ b/app/init/resources.php @@ -339,7 +339,7 @@ App::setResource('user', function (string $mode, Document $project, Document $co * 5. Regardless of the results from steps 1-4, attempts to fetch the JWT token. * 6. If the JWT user has a valid session ID, updates the user variable with the user from `projectDB`, * overwriting the previous value. - * 7. If account key is passed, use user of the account key as long as user ID header matches too + * 7. If account API key is passed, use user of the account API key as long as user ID header matches too */ $authorization->setDefaultStatus(true); @@ -416,12 +416,17 @@ App::setResource('user', function (string $mode, Document $project, Document $co // } $authJWT = $request->getHeader('x-appwrite-jwt', ''); if (!empty($authJWT) && !$project->isEmpty()) { // JWT authentication + if (!$user->isEmpty()) { + throw new Exception(Exception::USER_JWT_AND_COOKIE_SET); + } + $jwt = new JWT(System::getEnv('_APP_OPENSSL_KEY_V1'), 'HS256', 3600, 0); try { $payload = $jwt->decode($authJWT); } catch (JWTException $error) { throw new Exception(Exception::USER_JWT_INVALID, 'Failed to verify JWT. ' . $error->getMessage()); } + $jwtUserId = $payload['userId'] ?? ''; if (!empty($jwtUserId)) { if ($mode === APP_MODE_ADMIN) { @@ -442,6 +447,10 @@ App::setResource('user', function (string $mode, Document $project, Document $co $accountKey = $request->getHeader('x-appwrite-key', ''); $accountKeyUserId = $request->getHeader('x-appwrite-user', ''); if (!empty($accountKeyUserId) && !empty($accountKey)) { + if (!$user->isEmpty()) { + throw new Exception(Exception::USER_API_KEY_AND_SESSION_SET); + } + $accountKeyUser = Authorization::skip(fn () => $dbForPlatform->getDocument('users', $accountKeyUserId)); if (!$accountKeyUser->isEmpty()) { $key = $accountKeyUser->find( @@ -1109,7 +1118,31 @@ App::setResource('apiKey', function (Request $request, Document $project, Docume return null; } - return Key::decode($project, $team, $user, $key); + $key = Key::decode($project, $team, $user, $key); + + $userHeader = $request->getHeader('x-appwrite-user'); + $organizationHeader = $request->getHeader('x-appwrite-organization'); + $projectHeader = $request->getHeader('x-appwrite-project'); + + if (!empty($key->getProjectId())) { + if (empty($projectHeader) || $projectHeader !== $key->getProjectId()) { + throw new Exception(Exception::PROJECT_ID_MISSING); + } + } + + if (!empty($key->getUserId())) { + if (empty($userHeader) || $userHeader !== $key->getUserId()) { + throw new Exception(Exception::USER_ID_MISSING); + } + } + + if (!empty($key->getTeamId())) { + if (empty($organizationHeader) || $organizationHeader !== $key->getTeamId()) { + throw new Exception(Exception::ORGANIZATION_ID_MISSING); + } + } + + return $key; }, ['request', 'project', 'team', 'user']); App::setResource('executor', fn () => new Executor()); diff --git a/src/Appwrite/Extend/Exception.php b/src/Appwrite/Extend/Exception.php index 754b84599a..df123323ca 100644 --- a/src/Appwrite/Extend/Exception.php +++ b/src/Appwrite/Extend/Exception.php @@ -107,7 +107,9 @@ class Exception extends \Exception public const string USER_DELETION_PROHIBITED = 'user_deletion_prohibited'; public const string USER_TARGET_NOT_FOUND = 'user_target_not_found'; public const string USER_TARGET_ALREADY_EXISTS = 'user_target_already_exists'; - public const string USER_API_KEY_AND_SESSION_SET = 'user_key_and_session_set'; + public const string USER_API_KEY_AND_SESSION_SET = 'user_api_key_and_session_set'; + public const string USER_JWT_AND_COOKIE_SET = 'user_jwt_and_cookie_set'; + public const string USER_ID_MISSING = 'user_id_missing'; public const string API_KEY_EXPIRED = 'api_key_expired'; @@ -119,6 +121,8 @@ class Exception extends \Exception public const string TEAM_INVITE_MISMATCH = 'team_invite_mismatch'; public const string TEAM_ALREADY_EXISTS = 'team_already_exists'; + public const string ORGANIZATION_ID_MISSING = 'organization_id_missing'; + /** Console */ public const string RESOURCE_ALREADY_EXISTS = 'resource_already_exists'; @@ -283,6 +287,7 @@ class Exception extends \Exception /** Projects */ public const string PROJECT_NOT_FOUND = 'project_not_found'; + public const string PROJECT_ID_MISSING = 'project_id_missing'; public const string PROJECT_PROVIDER_DISABLED = 'project_provider_disabled'; public const string PROJECT_PROVIDER_UNSUPPORTED = 'project_provider_unsupported'; public const string PROJECT_ALREADY_EXISTS = 'project_already_exists'; From a66551863aec9294061d098983f4a05b11046f0d Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Wed, 21 Jan 2026 13:46:46 +0530 Subject: [PATCH 37/60] update composer --- composer.lock | 107 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 86 insertions(+), 21 deletions(-) diff --git a/composer.lock b/composer.lock index 10c5862285..e4b00c728d 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": "33da844fdf5648d1d1a027dfb6ae42bc", + "content-hash": "d899525d82512d6f8a8b5358b2555200", "packages": [ { "name": "adhocore/jwt", @@ -798,6 +798,68 @@ }, "time": "2026-01-12T17:58:43+00:00" }, + { + "name": "halaxa/json-machine", + "version": "1.2.6", + "source": { + "type": "git", + "url": "https://github.com/halaxa/json-machine.git", + "reference": "8bf0b0ff6ff60ab480778eaa5ad7d505b442c2d4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/halaxa/json-machine/zipball/8bf0b0ff6ff60ab480778eaa5ad7d505b442c2d4", + "reference": "8bf0b0ff6ff60ab480778eaa5ad7d505b442c2d4", + "shasum": "" + }, + "require": { + "php": "7.2 - 8.5" + }, + "require-dev": { + "ext-json": "*", + "friendsofphp/php-cs-fixer": "^3.0", + "phpstan/phpstan": "^1.10", + "phpunit/phpunit": "^8.0" + }, + "suggest": { + "ext-json": "To run JSON Machine out of the box without custom decoders.", + "guzzlehttp/guzzle": "To run example with GuzzleHttp" + }, + "type": "library", + "autoload": { + "files": [ + "src/functions.php" + ], + "psr-4": { + "JsonMachine\\": "src/" + }, + "exclude-from-classmap": [ + "src/autoloader.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "Filip Halaxa", + "email": "filip@halaxa.cz" + } + ], + "description": "Efficient, easy-to-use and fast JSON pull parser", + "support": { + "issues": "https://github.com/halaxa/json-machine/issues", + "source": "https://github.com/halaxa/json-machine/tree/1.2.6" + }, + "funding": [ + { + "url": "https://ko-fi.com/G2G57KTE4", + "type": "other" + } + ], + "time": "2025-12-05T14:53:09+00:00" + }, { "name": "league/csv", "version": "9.24.1", @@ -1589,16 +1651,16 @@ }, { "name": "open-telemetry/sem-conv", - "version": "1.37.0", + "version": "1.38.0", "source": { "type": "git", "url": "https://github.com/opentelemetry-php/sem-conv.git", - "reference": "8da7ec497c881e39afa6657d72586e27efbd29a1" + "reference": "e613bc640a407def4991b8a936a9b27edd9a3240" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/opentelemetry-php/sem-conv/zipball/8da7ec497c881e39afa6657d72586e27efbd29a1", - "reference": "8da7ec497c881e39afa6657d72586e27efbd29a1", + "url": "https://api.github.com/repos/opentelemetry-php/sem-conv/zipball/e613bc640a407def4991b8a936a9b27edd9a3240", + "reference": "e613bc640a407def4991b8a936a9b27edd9a3240", "shasum": "" }, "require": { @@ -1638,11 +1700,11 @@ ], "support": { "chat": "https://app.slack.com/client/T08PSQ7BQ/C01NFPCV44V", - "docs": "https://opentelemetry.io/docs/php", + "docs": "https://opentelemetry.io/docs/languages/php", "issues": "https://github.com/open-telemetry/opentelemetry-php/issues", "source": "https://github.com/open-telemetry/opentelemetry-php" }, - "time": "2025-09-03T12:08:10+00:00" + "time": "2026-01-21T04:14:03+00:00" }, { "name": "paragonie/constant_time_encoding", @@ -4516,22 +4578,23 @@ }, { "name": "utopia-php/migration", - "version": "1.4.4", + "version": "1.4.6", "source": { "type": "git", "url": "https://github.com/utopia-php/migration.git", - "reference": "3fe751902012d09d323420cd3523be1ed855e868" + "reference": "f358db6fb6a01d855bbed39e283387069e4f277d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/migration/zipball/3fe751902012d09d323420cd3523be1ed855e868", - "reference": "3fe751902012d09d323420cd3523be1ed855e868", + "url": "https://api.github.com/repos/utopia-php/migration/zipball/f358db6fb6a01d855bbed39e283387069e4f277d", + "reference": "f358db6fb6a01d855bbed39e283387069e4f277d", "shasum": "" }, "require": { "appwrite/appwrite": "19.*", "ext-curl": "*", "ext-openssl": "*", + "halaxa/json-machine": "^1.2", "php": ">=8.1", "utopia-php/console": "0.0.*", "utopia-php/database": "4.*", @@ -4565,9 +4628,9 @@ ], "support": { "issues": "https://github.com/utopia-php/migration/issues", - "source": "https://github.com/utopia-php/migration/tree/1.4.4" + "source": "https://github.com/utopia-php/migration/tree/1.4.6" }, - "time": "2026-01-16T10:00:07+00:00" + "time": "2026-01-20T11:07:17+00:00" }, { "name": "utopia-php/mongo", @@ -5482,16 +5545,16 @@ "packages-dev": [ { "name": "appwrite/sdk-generator", - "version": "1.8.17", + "version": "dev-docs-sdk", "source": { "type": "git", "url": "https://github.com/appwrite/sdk-generator.git", - "reference": "1bc5a39bf87d3c2064f2f8d45fa712340338bc41" + "reference": "27e1240728266c2a3f88651395b126f0b199e1c0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/1bc5a39bf87d3c2064f2f8d45fa712340338bc41", - "reference": "1bc5a39bf87d3c2064f2f8d45fa712340338bc41", + "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/27e1240728266c2a3f88651395b126f0b199e1c0", + "reference": "27e1240728266c2a3f88651395b126f0b199e1c0", "shasum": "" }, "require": { @@ -5527,9 +5590,9 @@ "description": "Appwrite PHP library for generating API SDKs for multiple programming languages and platforms", "support": { "issues": "https://github.com/appwrite/sdk-generator/issues", - "source": "https://github.com/appwrite/sdk-generator/tree/1.8.17" + "source": "https://github.com/appwrite/sdk-generator/tree/docs-sdk" }, - "time": "2026-01-19T12:13:41+00:00" + "time": "2026-01-21T08:15:45+00:00" }, { "name": "doctrine/annotations", @@ -8988,7 +9051,9 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": { + "appwrite/sdk-generator": 20 + }, "prefer-stable": false, "prefer-lowest": false, "platform": { @@ -9012,5 +9077,5 @@ "platform-overrides": { "php": "8.3" }, - "plugin-api-version": "2.2.0" + "plugin-api-version": "2.6.0" } From bfd34b3b15c7ce45880a5f062829b55a0c829ec5 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Wed, 21 Jan 2026 14:01:16 +0530 Subject: [PATCH 38/60] fix validation --- app/config/sdks.php | 2 +- composer.lock | 8 ++++---- src/Appwrite/Platform/Tasks/SDKs.php | 7 ++++--- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/config/sdks.php b/app/config/sdks.php index 52df61c0f0..5fa935b946 100644 --- a/app/config/sdks.php +++ b/app/config/sdks.php @@ -251,7 +251,7 @@ return [ ], ], [ - 'key' => 'md', + 'key' => 'markdown', 'name' => 'Markdown', 'version' => '0.1.0', 'url' => 'https://github.com/appwrite/sdk-for-md.git', diff --git a/composer.lock b/composer.lock index e4b00c728d..f8dbd51e08 100644 --- a/composer.lock +++ b/composer.lock @@ -5549,12 +5549,12 @@ "source": { "type": "git", "url": "https://github.com/appwrite/sdk-generator.git", - "reference": "27e1240728266c2a3f88651395b126f0b199e1c0" + "reference": "e6c700bac81d1f250a97edeeb2007f69e17f29ba" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/27e1240728266c2a3f88651395b126f0b199e1c0", - "reference": "27e1240728266c2a3f88651395b126f0b199e1c0", + "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/e6c700bac81d1f250a97edeeb2007f69e17f29ba", + "reference": "e6c700bac81d1f250a97edeeb2007f69e17f29ba", "shasum": "" }, "require": { @@ -5592,7 +5592,7 @@ "issues": "https://github.com/appwrite/sdk-generator/issues", "source": "https://github.com/appwrite/sdk-generator/tree/docs-sdk" }, - "time": "2026-01-21T08:15:45+00:00" + "time": "2026-01-21T08:21:48+00:00" }, { "name": "doctrine/annotations", diff --git a/src/Appwrite/Platform/Tasks/SDKs.php b/src/Appwrite/Platform/Tasks/SDKs.php index d1bdb9f7ce..013fae1193 100644 --- a/src/Appwrite/Platform/Tasks/SDKs.php +++ b/src/Appwrite/Platform/Tasks/SDKs.php @@ -50,7 +50,7 @@ class SDKs extends Action 'android', 'graphql', 'rest', - 'md', + 'markdown', ]; public static function getName(): string @@ -83,7 +83,7 @@ class SDKs extends Action if (!$sdks) { $selectedPlatform ??= Console::confirm('Choose Platform ("' . implode('", "', static::getPlatforms()) . '" or "*" for all):'); $selectedSDK ??= \strtolower(Console::confirm('Choose SDK ("*" for all):')); - if (!\in_array($selectedSDK, $this->supportedSDKS)) { + if ($selectedSDK !== '*' && !\in_array($selectedSDK, $this->supportedSDKS)) { throw new \Exception('Unknown SDK "' . $selectedSDK . '" given. Options are: ' . implode(', ', $this->supportedSDKS)); } } else { @@ -277,8 +277,9 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND case 'rest': $config = new REST(); break; - case 'md': + case 'markdown': $config = new Markdown(); + $config->setNPMPackage('@appwrite.io/docs'); break; default: throw new \Exception('Language "' . $language['key'] . '" not supported'); From 6ebc36d0f353053ce338c9f0bd8ac9a39b466b43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Wed, 21 Jan 2026 14:47:18 +0100 Subject: [PATCH 39/60] Fix merge conflict --- app/init/database/filters.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/init/database/filters.php b/app/init/database/filters.php index c9beb526e1..ce220392b6 100644 --- a/app/init/database/filters.php +++ b/app/init/database/filters.php @@ -441,7 +441,7 @@ Database::addFilter( return; }, function (mixed $value, Document $document, Database $database) { - return Authorization::skip(fn () => $database + return $database->getAuthorization()->skip(fn () => $database ->find('keys', [ Query::equal('resourceType', ['teams']), Query::equal('resourceInternalId', [$document->getSequence()]), @@ -456,7 +456,7 @@ Database::addFilter( return; }, function (mixed $value, Document $document, Database $database) { - return Authorization::skip(fn () => $database + return $database->getAuthorization()->skip(fn () => $database ->find('keys', [ Query::equal('resourceType', ['users']), Query::equal('resourceInternalId', [$document->getSequence()]), From 8e98c08a23e74738c2c391f2ef0e920082d65b71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Wed, 21 Jan 2026 16:05:43 +0100 Subject: [PATCH 40/60] Fix failing tests --- app/controllers/shared/api.php | 8 ++++---- app/init/resources.php | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index f679480ba5..2825ea3a74 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -234,14 +234,14 @@ App::init() } if (!$updates->isEmpty()) { - Authorization::skip(fn () => $dbForPlatform->updateDocument('keys', $dbKey->getId(), $updates)); + $dbForPlatform->getAuthorization()->skip(fn () => $dbForPlatform->updateDocument('keys', $dbKey->getId(), $updates)); if (!empty($apiKey->getProjectId())) { - Authorization::skip(fn () => $dbForPlatform->purgeCachedDocument('projects', $project->getId())); + $dbForPlatform->getAuthorization()->skip(fn () => $dbForPlatform->purgeCachedDocument('projects', $project->getId())); } elseif (!empty($apiKey->getUserId())) { - Authorization::skip(fn () => $dbForPlatform->purgeCachedDocument('users', $user->getId())); + $dbForPlatform->getAuthorization()->skip(fn () => $dbForPlatform->purgeCachedDocument('users', $user->getId())); } elseif (!empty($apiKey->getTeamId())) { - Authorization::skip(fn () => $dbForPlatform->purgeCachedDocument('teams', $team->getId())); + $dbForPlatform->getAuthorization()->skip(fn () => $dbForPlatform->purgeCachedDocument('teams', $team->getId())); } } diff --git a/app/init/resources.php b/app/init/resources.php index e08d83743e..46f6ae05a0 100644 --- a/app/init/resources.php +++ b/app/init/resources.php @@ -455,7 +455,7 @@ App::setResource('user', function (string $mode, Document $project, Document $co throw new Exception(Exception::USER_API_KEY_AND_SESSION_SET); } - $accountKeyUser = Authorization::skip(fn () => $dbForPlatform->getDocument('users', $accountKeyUserId)); + $accountKeyUser = $dbForPlatform->getAuthorization()->skip(fn () => $dbForPlatform->getDocument('users', $accountKeyUserId)); if (!$accountKeyUser->isEmpty()) { $key = $accountKeyUser->find( key: 'secret', From b317f85fb6f4ff25b6b875233cf6928543a86673 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Wed, 21 Jan 2026 16:27:09 +0100 Subject: [PATCH 41/60] Fix depricated schema --- app/config/collections/platform.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/config/collections/platform.php b/app/config/collections/platform.php index 39960f37b3..73c9eea870 100644 --- a/app/config/collections/platform.php +++ b/app/config/collections/platform.php @@ -639,7 +639,7 @@ $platformCollections = [ 'format' => '', 'size' => Database::LENGTH_KEY, 'signed' => true, - 'required' => true, + 'required' => false, 'default' => null, 'array' => false, 'filters' => [], From 7e994f8db584bf4d9c5d418a79db3da786a5b0db Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Wed, 21 Jan 2026 10:36:25 +0530 Subject: [PATCH 42/60] release cli sdk 13.1.0 --- app/config/sdks.php | 2 +- composer.lock | 115 ++++++++++++++++++++++++++++--------- docs/sdks/cli/CHANGELOG.md | 11 ++++ 3 files changed, 101 insertions(+), 27 deletions(-) diff --git a/app/config/sdks.php b/app/config/sdks.php index 0d18f45569..757c7e8332 100644 --- a/app/config/sdks.php +++ b/app/config/sdks.php @@ -227,7 +227,7 @@ return [ [ 'key' => 'cli', 'name' => 'Command Line', - 'version' => '13.0.1', + 'version' => '13.1.0-rc.2', 'url' => 'https://github.com/appwrite/sdk-for-cli', 'package' => 'https://www.npmjs.com/package/appwrite-cli', 'enabled' => true, diff --git a/composer.lock b/composer.lock index 10c5862285..e35d56b5f4 100644 --- a/composer.lock +++ b/composer.lock @@ -798,6 +798,68 @@ }, "time": "2026-01-12T17:58:43+00:00" }, + { + "name": "halaxa/json-machine", + "version": "1.2.6", + "source": { + "type": "git", + "url": "https://github.com/halaxa/json-machine.git", + "reference": "8bf0b0ff6ff60ab480778eaa5ad7d505b442c2d4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/halaxa/json-machine/zipball/8bf0b0ff6ff60ab480778eaa5ad7d505b442c2d4", + "reference": "8bf0b0ff6ff60ab480778eaa5ad7d505b442c2d4", + "shasum": "" + }, + "require": { + "php": "7.2 - 8.5" + }, + "require-dev": { + "ext-json": "*", + "friendsofphp/php-cs-fixer": "^3.0", + "phpstan/phpstan": "^1.10", + "phpunit/phpunit": "^8.0" + }, + "suggest": { + "ext-json": "To run JSON Machine out of the box without custom decoders.", + "guzzlehttp/guzzle": "To run example with GuzzleHttp" + }, + "type": "library", + "autoload": { + "files": [ + "src/functions.php" + ], + "psr-4": { + "JsonMachine\\": "src/" + }, + "exclude-from-classmap": [ + "src/autoloader.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "Filip Halaxa", + "email": "filip@halaxa.cz" + } + ], + "description": "Efficient, easy-to-use and fast JSON pull parser", + "support": { + "issues": "https://github.com/halaxa/json-machine/issues", + "source": "https://github.com/halaxa/json-machine/tree/1.2.6" + }, + "funding": [ + { + "url": "https://ko-fi.com/G2G57KTE4", + "type": "other" + } + ], + "time": "2025-12-05T14:53:09+00:00" + }, { "name": "league/csv", "version": "9.24.1", @@ -1589,16 +1651,16 @@ }, { "name": "open-telemetry/sem-conv", - "version": "1.37.0", + "version": "1.38.0", "source": { "type": "git", "url": "https://github.com/opentelemetry-php/sem-conv.git", - "reference": "8da7ec497c881e39afa6657d72586e27efbd29a1" + "reference": "e613bc640a407def4991b8a936a9b27edd9a3240" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/opentelemetry-php/sem-conv/zipball/8da7ec497c881e39afa6657d72586e27efbd29a1", - "reference": "8da7ec497c881e39afa6657d72586e27efbd29a1", + "url": "https://api.github.com/repos/opentelemetry-php/sem-conv/zipball/e613bc640a407def4991b8a936a9b27edd9a3240", + "reference": "e613bc640a407def4991b8a936a9b27edd9a3240", "shasum": "" }, "require": { @@ -1638,11 +1700,11 @@ ], "support": { "chat": "https://app.slack.com/client/T08PSQ7BQ/C01NFPCV44V", - "docs": "https://opentelemetry.io/docs/php", + "docs": "https://opentelemetry.io/docs/languages/php", "issues": "https://github.com/open-telemetry/opentelemetry-php/issues", "source": "https://github.com/open-telemetry/opentelemetry-php" }, - "time": "2025-09-03T12:08:10+00:00" + "time": "2026-01-21T04:14:03+00:00" }, { "name": "paragonie/constant_time_encoding", @@ -3899,16 +3961,16 @@ }, { "name": "utopia-php/database", - "version": "4.5.2", + "version": "4.6.2", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "8e6a033d4da09a2f2ac1f79fd85fcfa2da018d23" + "reference": "53394759c44067e9db4660635765e2056f83788c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/8e6a033d4da09a2f2ac1f79fd85fcfa2da018d23", - "reference": "8e6a033d4da09a2f2ac1f79fd85fcfa2da018d23", + "url": "https://api.github.com/repos/utopia-php/database/zipball/53394759c44067e9db4660635765e2056f83788c", + "reference": "53394759c44067e9db4660635765e2056f83788c", "shasum": "" }, "require": { @@ -3951,9 +4013,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/4.5.2" + "source": "https://github.com/utopia-php/database/tree/4.6.2" }, - "time": "2026-01-15T04:23:30+00:00" + "time": "2026-01-22T07:14:12+00:00" }, { "name": "utopia-php/detector", @@ -4516,22 +4578,23 @@ }, { "name": "utopia-php/migration", - "version": "1.4.4", + "version": "1.4.6", "source": { "type": "git", "url": "https://github.com/utopia-php/migration.git", - "reference": "3fe751902012d09d323420cd3523be1ed855e868" + "reference": "f358db6fb6a01d855bbed39e283387069e4f277d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/migration/zipball/3fe751902012d09d323420cd3523be1ed855e868", - "reference": "3fe751902012d09d323420cd3523be1ed855e868", + "url": "https://api.github.com/repos/utopia-php/migration/zipball/f358db6fb6a01d855bbed39e283387069e4f277d", + "reference": "f358db6fb6a01d855bbed39e283387069e4f277d", "shasum": "" }, "require": { "appwrite/appwrite": "19.*", "ext-curl": "*", "ext-openssl": "*", + "halaxa/json-machine": "^1.2", "php": ">=8.1", "utopia-php/console": "0.0.*", "utopia-php/database": "4.*", @@ -4565,9 +4628,9 @@ ], "support": { "issues": "https://github.com/utopia-php/migration/issues", - "source": "https://github.com/utopia-php/migration/tree/1.4.4" + "source": "https://github.com/utopia-php/migration/tree/1.4.6" }, - "time": "2026-01-16T10:00:07+00:00" + "time": "2026-01-20T11:07:17+00:00" }, { "name": "utopia-php/mongo", @@ -5482,16 +5545,16 @@ "packages-dev": [ { "name": "appwrite/sdk-generator", - "version": "1.8.17", + "version": "1.8.19", "source": { "type": "git", "url": "https://github.com/appwrite/sdk-generator.git", - "reference": "1bc5a39bf87d3c2064f2f8d45fa712340338bc41" + "reference": "d4f54ca109bb8126769940a14ed87cbc330f4f1f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/1bc5a39bf87d3c2064f2f8d45fa712340338bc41", - "reference": "1bc5a39bf87d3c2064f2f8d45fa712340338bc41", + "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/d4f54ca109bb8126769940a14ed87cbc330f4f1f", + "reference": "d4f54ca109bb8126769940a14ed87cbc330f4f1f", "shasum": "" }, "require": { @@ -5527,9 +5590,9 @@ "description": "Appwrite PHP library for generating API SDKs for multiple programming languages and platforms", "support": { "issues": "https://github.com/appwrite/sdk-generator/issues", - "source": "https://github.com/appwrite/sdk-generator/tree/1.8.17" + "source": "https://github.com/appwrite/sdk-generator/tree/1.8.19" }, - "time": "2026-01-19T12:13:41+00:00" + "time": "2026-01-22T06:02:42+00:00" }, { "name": "doctrine/annotations", @@ -8988,7 +9051,7 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": {}, "prefer-stable": false, "prefer-lowest": false, "platform": { @@ -9012,5 +9075,5 @@ "platform-overrides": { "php": "8.3" }, - "plugin-api-version": "2.2.0" + "plugin-api-version": "2.6.0" } diff --git a/docs/sdks/cli/CHANGELOG.md b/docs/sdks/cli/CHANGELOG.md index 1de6ffa88d..3adf988ecc 100644 --- a/docs/sdks/cli/CHANGELOG.md +++ b/docs/sdks/cli/CHANGELOG.md @@ -1,5 +1,16 @@ # Change Log +## 13.1.0-rc.2 + +- Update generated `databases` services to automatically initialize a client instance +- Update generator to use handlebars templates + +## 13.1.0-rc.1 + +- Feat: `appwrite generate` command to create a fully typesafe SDK for your Appwrite project +- Chore: improve creation of columns during table creation by passing them directly instead of creating them one by one +- Improved config validation by adding extra rules in zod schema + ## 13.0.1 - Fix `project init` command leading to Cannot convert to BigInt error From e894eca201d86bfc11ef37d5d12998a4131782d1 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Fri, 23 Jan 2026 15:25:05 +0530 Subject: [PATCH 43/60] add rc3 --- app/config/sdks.php | 2 +- composer.lock | 24 +++++++++---------- .../examples/health/get-queue-audits.md | 1 + docs/sdks/cli/CHANGELOG.md | 5 ++++ 4 files changed, 19 insertions(+), 13 deletions(-) create mode 100644 docs/examples/1.8.x/console-cli/examples/health/get-queue-audits.md diff --git a/app/config/sdks.php b/app/config/sdks.php index 757c7e8332..be2108e074 100644 --- a/app/config/sdks.php +++ b/app/config/sdks.php @@ -227,7 +227,7 @@ return [ [ 'key' => 'cli', 'name' => 'Command Line', - 'version' => '13.1.0-rc.2', + 'version' => '13.1.0-rc.3', 'url' => 'https://github.com/appwrite/sdk-for-cli', 'package' => 'https://www.npmjs.com/package/appwrite-cli', 'enabled' => true, diff --git a/composer.lock b/composer.lock index e35d56b5f4..bb64ef63a3 100644 --- a/composer.lock +++ b/composer.lock @@ -3615,16 +3615,16 @@ }, { "name": "utopia-php/audit", - "version": "2.0.4", + "version": "2.1.0", "source": { "type": "git", "url": "https://github.com/utopia-php/audit.git", - "reference": "1301ab2607667b9f86456f86895f3e26f8c0c9a7" + "reference": "8e0540aa939968418ee3ad2b2c305992a771e142" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/audit/zipball/1301ab2607667b9f86456f86895f3e26f8c0c9a7", - "reference": "1301ab2607667b9f86456f86895f3e26f8c0c9a7", + "url": "https://api.github.com/repos/utopia-php/audit/zipball/8e0540aa939968418ee3ad2b2c305992a771e142", + "reference": "8e0540aa939968418ee3ad2b2c305992a771e142", "shasum": "" }, "require": { @@ -3658,9 +3658,9 @@ ], "support": { "issues": "https://github.com/utopia-php/audit/issues", - "source": "https://github.com/utopia-php/audit/tree/2.0.4" + "source": "https://github.com/utopia-php/audit/tree/2.1.0" }, - "time": "2026-01-14T07:22:46+00:00" + "time": "2026-01-22T12:40:48+00:00" }, { "name": "utopia-php/auth", @@ -5545,16 +5545,16 @@ "packages-dev": [ { "name": "appwrite/sdk-generator", - "version": "1.8.19", + "version": "1.8.20", "source": { "type": "git", "url": "https://github.com/appwrite/sdk-generator.git", - "reference": "d4f54ca109bb8126769940a14ed87cbc330f4f1f" + "reference": "b2bb03a83244df933c4d6333215e0d480d9a1b6a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/d4f54ca109bb8126769940a14ed87cbc330f4f1f", - "reference": "d4f54ca109bb8126769940a14ed87cbc330f4f1f", + "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/b2bb03a83244df933c4d6333215e0d480d9a1b6a", + "reference": "b2bb03a83244df933c4d6333215e0d480d9a1b6a", "shasum": "" }, "require": { @@ -5590,9 +5590,9 @@ "description": "Appwrite PHP library for generating API SDKs for multiple programming languages and platforms", "support": { "issues": "https://github.com/appwrite/sdk-generator/issues", - "source": "https://github.com/appwrite/sdk-generator/tree/1.8.19" + "source": "https://github.com/appwrite/sdk-generator/tree/1.8.20" }, - "time": "2026-01-22T06:02:42+00:00" + "time": "2026-01-23T08:11:20+00:00" }, { "name": "doctrine/annotations", diff --git a/docs/examples/1.8.x/console-cli/examples/health/get-queue-audits.md b/docs/examples/1.8.x/console-cli/examples/health/get-queue-audits.md new file mode 100644 index 0000000000..f228f092a5 --- /dev/null +++ b/docs/examples/1.8.x/console-cli/examples/health/get-queue-audits.md @@ -0,0 +1 @@ +appwrite health get-queue-audits diff --git a/docs/sdks/cli/CHANGELOG.md b/docs/sdks/cli/CHANGELOG.md index 3adf988ecc..596a58f6c3 100644 --- a/docs/sdks/cli/CHANGELOG.md +++ b/docs/sdks/cli/CHANGELOG.md @@ -1,5 +1,10 @@ # Change Log +## 13.1.0-rc.3 + +- Allow generation of server side CRUD operations on databases and tables +- Fix npm distribution failing due to missing template files in bundle + ## 13.1.0-rc.2 - Update generated `databases` services to automatically initialize a client instance From 785efa335546e64304221ac1954a5f016c1a10e6 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Mon, 26 Jan 2026 10:40:29 +0530 Subject: [PATCH 44/60] stable release --- app/config/sdks.php | 2 +- composer.lock | 134 ++++++++++++++++++------------------- docs/sdks/cli/CHANGELOG.md | 8 +++ 3 files changed, 76 insertions(+), 68 deletions(-) diff --git a/app/config/sdks.php b/app/config/sdks.php index be2108e074..aca85036d0 100644 --- a/app/config/sdks.php +++ b/app/config/sdks.php @@ -227,7 +227,7 @@ return [ [ 'key' => 'cli', 'name' => 'Command Line', - 'version' => '13.1.0-rc.3', + 'version' => '13.1.0', 'url' => 'https://github.com/appwrite/sdk-for-cli', 'package' => 'https://www.npmjs.com/package/appwrite-cli', 'enabled' => true, diff --git a/composer.lock b/composer.lock index bb64ef63a3..bd56277819 100644 --- a/composer.lock +++ b/composer.lock @@ -1298,16 +1298,16 @@ }, { "name": "open-telemetry/api", - "version": "1.7.1", + "version": "1.8.0", "source": { "type": "git", "url": "https://github.com/opentelemetry-php/api.git", - "reference": "45bda7efa8fcdd9bdb0daa2f26c8e31f062f49d4" + "reference": "df5197c6fd0ddd8e9883b87de042d9341300e2ad" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/opentelemetry-php/api/zipball/45bda7efa8fcdd9bdb0daa2f26c8e31f062f49d4", - "reference": "45bda7efa8fcdd9bdb0daa2f26c8e31f062f49d4", + "url": "https://api.github.com/repos/opentelemetry-php/api/zipball/df5197c6fd0ddd8e9883b87de042d9341300e2ad", + "reference": "df5197c6fd0ddd8e9883b87de042d9341300e2ad", "shasum": "" }, "require": { @@ -1317,7 +1317,7 @@ "symfony/polyfill-php82": "^1.26" }, "conflict": { - "open-telemetry/sdk": "<=1.0.8" + "open-telemetry/sdk": "<=1.11" }, "type": "library", "extra": { @@ -1364,7 +1364,7 @@ "issues": "https://github.com/open-telemetry/opentelemetry-php/issues", "source": "https://github.com/open-telemetry/opentelemetry-php" }, - "time": "2025-10-19T10:49:48+00:00" + "time": "2026-01-21T04:14:03+00:00" }, { "name": "open-telemetry/context", @@ -1554,16 +1554,16 @@ }, { "name": "open-telemetry/sdk", - "version": "1.11.0", + "version": "1.12.0", "source": { "type": "git", "url": "https://github.com/opentelemetry-php/sdk.git", - "reference": "d91f21addcdb42da9a451c002777f8318432461a" + "reference": "7f1bd524465c1ca42755a9ef1143ba09913f5be0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/opentelemetry-php/sdk/zipball/d91f21addcdb42da9a451c002777f8318432461a", - "reference": "d91f21addcdb42da9a451c002777f8318432461a", + "url": "https://api.github.com/repos/opentelemetry-php/sdk/zipball/7f1bd524465c1ca42755a9ef1143ba09913f5be0", + "reference": "7f1bd524465c1ca42755a9ef1143ba09913f5be0", "shasum": "" }, "require": { @@ -1604,7 +1604,7 @@ ] }, "branch-alias": { - "dev-main": "1.9.x-dev" + "dev-main": "1.12.x-dev" } }, "autoload": { @@ -1647,7 +1647,7 @@ "issues": "https://github.com/open-telemetry/opentelemetry-php/issues", "source": "https://github.com/open-telemetry/opentelemetry-php" }, - "time": "2026-01-15T11:21:03+00:00" + "time": "2026-01-21T04:14:03+00:00" }, { "name": "open-telemetry/sem-conv", @@ -2735,16 +2735,16 @@ }, { "name": "symfony/http-client", - "version": "v7.4.3", + "version": "v7.4.4", "source": { "type": "git", "url": "https://github.com/symfony/http-client.git", - "reference": "d01dfac1e0dc99f18da48b18101c23ce57929616" + "reference": "d63c23357d74715a589454c141c843f0172bec6c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-client/zipball/d01dfac1e0dc99f18da48b18101c23ce57929616", - "reference": "d01dfac1e0dc99f18da48b18101c23ce57929616", + "url": "https://api.github.com/repos/symfony/http-client/zipball/d63c23357d74715a589454c141c843f0172bec6c", + "reference": "d63c23357d74715a589454c141c843f0172bec6c", "shasum": "" }, "require": { @@ -2812,7 +2812,7 @@ "http" ], "support": { - "source": "https://github.com/symfony/http-client/tree/v7.4.3" + "source": "https://github.com/symfony/http-client/tree/v7.4.4" }, "funding": [ { @@ -2832,7 +2832,7 @@ "type": "tidelift" } ], - "time": "2025-12-23T14:50:43+00:00" + "time": "2026-01-23T16:34:22+00:00" }, { "name": "symfony/http-client-contracts", @@ -4121,16 +4121,16 @@ }, { "name": "utopia-php/domains", - "version": "0.11.0", + "version": "0.11.1", "source": { "type": "git", "url": "https://github.com/utopia-php/domains.git", - "reference": "f333e23e721ca5cd3bd21063fa88304114b0467d" + "reference": "63fc5b9b58a32a5efd426510bbab4199db24593b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/domains/zipball/f333e23e721ca5cd3bd21063fa88304114b0467d", - "reference": "f333e23e721ca5cd3bd21063fa88304114b0467d", + "url": "https://api.github.com/repos/utopia-php/domains/zipball/63fc5b9b58a32a5efd426510bbab4199db24593b", + "reference": "63fc5b9b58a32a5efd426510bbab4199db24593b", "shasum": "" }, "require": { @@ -4177,9 +4177,9 @@ ], "support": { "issues": "https://github.com/utopia-php/domains/issues", - "source": "https://github.com/utopia-php/domains/tree/0.11.0" + "source": "https://github.com/utopia-php/domains/tree/0.11.1" }, - "time": "2026-01-13T09:40:08+00:00" + "time": "2026-01-23T09:28:08+00:00" }, { "name": "utopia-php/dsn", @@ -5545,16 +5545,16 @@ "packages-dev": [ { "name": "appwrite/sdk-generator", - "version": "1.8.20", + "version": "1.8.21", "source": { "type": "git", "url": "https://github.com/appwrite/sdk-generator.git", - "reference": "b2bb03a83244df933c4d6333215e0d480d9a1b6a" + "reference": "1b47b2c794811c565f8b5e7eeaa19f749bcbeb6b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/b2bb03a83244df933c4d6333215e0d480d9a1b6a", - "reference": "b2bb03a83244df933c4d6333215e0d480d9a1b6a", + "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/1b47b2c794811c565f8b5e7eeaa19f749bcbeb6b", + "reference": "1b47b2c794811c565f8b5e7eeaa19f749bcbeb6b", "shasum": "" }, "require": { @@ -5590,9 +5590,9 @@ "description": "Appwrite PHP library for generating API SDKs for multiple programming languages and platforms", "support": { "issues": "https://github.com/appwrite/sdk-generator/issues", - "source": "https://github.com/appwrite/sdk-generator/tree/1.8.20" + "source": "https://github.com/appwrite/sdk-generator/tree/1.8.21" }, - "time": "2026-01-23T08:11:20+00:00" + "time": "2026-01-26T04:42:33+00:00" }, { "name": "doctrine/annotations", @@ -6772,16 +6772,16 @@ }, { "name": "phpunit/phpunit", - "version": "9.6.31", + "version": "9.6.32", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "945d0b7f346a084ce5549e95289962972c4272e5" + "reference": "492ee10a8369a1c1ac390a3b46e0c846e384c5a4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/945d0b7f346a084ce5549e95289962972c4272e5", - "reference": "945d0b7f346a084ce5549e95289962972c4272e5", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/492ee10a8369a1c1ac390a3b46e0c846e384c5a4", + "reference": "492ee10a8369a1c1ac390a3b46e0c846e384c5a4", "shasum": "" }, "require": { @@ -6803,7 +6803,7 @@ "phpunit/php-timer": "^5.0.3", "sebastian/cli-parser": "^1.0.2", "sebastian/code-unit": "^1.0.8", - "sebastian/comparator": "^4.0.9", + "sebastian/comparator": "^4.0.10", "sebastian/diff": "^4.0.6", "sebastian/environment": "^5.1.5", "sebastian/exporter": "^4.0.8", @@ -6855,7 +6855,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.31" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.32" }, "funding": [ { @@ -6879,7 +6879,7 @@ "type": "tidelift" } ], - "time": "2025-12-06T07:45:52+00:00" + "time": "2026-01-24T16:04:20+00:00" }, { "name": "psr/cache", @@ -7099,16 +7099,16 @@ }, { "name": "sebastian/comparator", - "version": "4.0.9", + "version": "4.0.10", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/comparator.git", - "reference": "67a2df3a62639eab2cc5906065e9805d4fd5dfc5" + "reference": "e4df00b9b3571187db2831ae9aada2c6efbd715d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/67a2df3a62639eab2cc5906065e9805d4fd5dfc5", - "reference": "67a2df3a62639eab2cc5906065e9805d4fd5dfc5", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/e4df00b9b3571187db2831ae9aada2c6efbd715d", + "reference": "e4df00b9b3571187db2831ae9aada2c6efbd715d", "shasum": "" }, "require": { @@ -7161,7 +7161,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/comparator/issues", - "source": "https://github.com/sebastianbergmann/comparator/tree/4.0.9" + "source": "https://github.com/sebastianbergmann/comparator/tree/4.0.10" }, "funding": [ { @@ -7181,7 +7181,7 @@ "type": "tidelift" } ], - "time": "2025-08-10T06:51:50+00:00" + "time": "2026-01-24T09:22:56+00:00" }, { "name": "sebastian/complexity", @@ -8039,16 +8039,16 @@ }, { "name": "symfony/console", - "version": "v8.0.3", + "version": "v8.0.4", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "6145b304a5c1ea0bdbd0b04d297a5864f9a7d587" + "reference": "ace03c4cf9805080ff40cbeec69fca180c339a3b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/6145b304a5c1ea0bdbd0b04d297a5864f9a7d587", - "reference": "6145b304a5c1ea0bdbd0b04d297a5864f9a7d587", + "url": "https://api.github.com/repos/symfony/console/zipball/ace03c4cf9805080ff40cbeec69fca180c339a3b", + "reference": "ace03c4cf9805080ff40cbeec69fca180c339a3b", "shasum": "" }, "require": { @@ -8105,7 +8105,7 @@ "terminal" ], "support": { - "source": "https://github.com/symfony/console/tree/v8.0.3" + "source": "https://github.com/symfony/console/tree/v8.0.4" }, "funding": [ { @@ -8125,7 +8125,7 @@ "type": "tidelift" } ], - "time": "2025-12-23T14:52:06+00:00" + "time": "2026-01-13T13:06:50+00:00" }, { "name": "symfony/filesystem", @@ -8199,16 +8199,16 @@ }, { "name": "symfony/finder", - "version": "v8.0.3", + "version": "v8.0.4", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", - "reference": "dd3a2953570a283a2ba4e17063bb98c734cf5b12" + "reference": "42e48eb02e07d5f3771d194d67da117eb824c8c1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/dd3a2953570a283a2ba4e17063bb98c734cf5b12", - "reference": "dd3a2953570a283a2ba4e17063bb98c734cf5b12", + "url": "https://api.github.com/repos/symfony/finder/zipball/42e48eb02e07d5f3771d194d67da117eb824c8c1", + "reference": "42e48eb02e07d5f3771d194d67da117eb824c8c1", "shasum": "" }, "require": { @@ -8243,7 +8243,7 @@ "description": "Finds files and directories via an intuitive fluent interface", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/finder/tree/v8.0.3" + "source": "https://github.com/symfony/finder/tree/v8.0.4" }, "funding": [ { @@ -8263,7 +8263,7 @@ "type": "tidelift" } ], - "time": "2025-12-23T14:52:06+00:00" + "time": "2026-01-12T12:37:40+00:00" }, { "name": "symfony/options-resolver", @@ -8668,16 +8668,16 @@ }, { "name": "symfony/process", - "version": "v8.0.3", + "version": "v8.0.4", "source": { "type": "git", "url": "https://github.com/symfony/process.git", - "reference": "0cbbd88ec836f8757641c651bb995335846abb78" + "reference": "10df72602d88c0a3fa685b822976a052611dd607" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/0cbbd88ec836f8757641c651bb995335846abb78", - "reference": "0cbbd88ec836f8757641c651bb995335846abb78", + "url": "https://api.github.com/repos/symfony/process/zipball/10df72602d88c0a3fa685b822976a052611dd607", + "reference": "10df72602d88c0a3fa685b822976a052611dd607", "shasum": "" }, "require": { @@ -8709,7 +8709,7 @@ "description": "Executes commands in sub-processes", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/process/tree/v8.0.3" + "source": "https://github.com/symfony/process/tree/v8.0.4" }, "funding": [ { @@ -8729,20 +8729,20 @@ "type": "tidelift" } ], - "time": "2025-12-19T10:01:18+00:00" + "time": "2026-01-23T11:07:10+00:00" }, { "name": "symfony/string", - "version": "v8.0.1", + "version": "v8.0.4", "source": { "type": "git", "url": "https://github.com/symfony/string.git", - "reference": "ba65a969ac918ce0cc3edfac6cdde847eba231dc" + "reference": "758b372d6882506821ed666032e43020c4f57194" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/string/zipball/ba65a969ac918ce0cc3edfac6cdde847eba231dc", - "reference": "ba65a969ac918ce0cc3edfac6cdde847eba231dc", + "url": "https://api.github.com/repos/symfony/string/zipball/758b372d6882506821ed666032e43020c4f57194", + "reference": "758b372d6882506821ed666032e43020c4f57194", "shasum": "" }, "require": { @@ -8799,7 +8799,7 @@ "utf8" ], "support": { - "source": "https://github.com/symfony/string/tree/v8.0.1" + "source": "https://github.com/symfony/string/tree/v8.0.4" }, "funding": [ { @@ -8819,7 +8819,7 @@ "type": "tidelift" } ], - "time": "2025-12-01T09:13:36+00:00" + "time": "2026-01-12T12:37:40+00:00" }, { "name": "textalk/websocket", diff --git a/docs/sdks/cli/CHANGELOG.md b/docs/sdks/cli/CHANGELOG.md index 596a58f6c3..342761e070 100644 --- a/docs/sdks/cli/CHANGELOG.md +++ b/docs/sdks/cli/CHANGELOG.md @@ -1,5 +1,13 @@ # Change Log +## 13.1.0 + +- Mark `appwrite generate` command as stable +- Improve permissions param to be a typesafe callback +- Fix relationship handling in generated code +- Fix `appwrite client` properly hanlding `--key` parameter +- Fix `init site` not working on Windows + ## 13.1.0-rc.3 - Allow generation of server side CRUD operations on databases and tables From aed9816d1e8d2d92ca27d2717934f4195395e3ad Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Mon, 26 Jan 2026 12:53:40 +0000 Subject: [PATCH 45/60] fix: validate relationship document ID --- .../Collections/Documents/Action.php | 31 +++ .../Collections/Documents/Create.php | 10 +- .../Collections/Documents/Update.php | 11 +- .../Collections/Documents/Upsert.php | 11 +- .../Databases/TablesDB/DatabasesBase.php | 251 ++++++++++++++++++ 5 files changed, 288 insertions(+), 26 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 14b09777a8..03236471db 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 @@ -5,8 +5,10 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Documen use Appwrite\Event\Event; use Appwrite\Extend\Exception; use Appwrite\Platform\Modules\Databases\Http\Databases\Action as DatabasesAction; +use Appwrite\Utopia\Database\Validator\CustomId; use Utopia\Database\Database; use Utopia\Database\Document; +use Utopia\Database\Helpers\ID; use Utopia\Database\Validator\Authorization; abstract class Action extends DatabasesAction @@ -249,6 +251,35 @@ abstract class Action extends DatabasesAction return $document; } + /** + * Validate and normalize a relationship value. + * Returns the relation ID and normalized relation as an array. + */ + protected function validateRelationship(mixed $relation): array + { + $relationId = null; + + if ($relation instanceof Document) { + $relationId = $relation->getAttribute('$id'); + } elseif (\is_string($relation)) { + $relationId = $relation; + } elseif (\is_array($relation) && \array_values($relation) !== $relation) { + $relation['$id'] = ID::unique(); + $relation = new Document($relation); + } else { + throw new Exception(Exception::RELATIONSHIP_VALUE_INVALID, 'Relationship value must be an object or document ID string, not ' . \gettype($relation)); + } + + if ($relationId !== null) { + $validator = new CustomId(); + if (!$validator->isValid($relationId)) { + throw new Exception(Exception::GENERAL_BAD_REQUEST, $validator->getDescription()); + } + } + + return [$relationId, $relation]; + } + /** * Resolves relationships in a document and attaches metadata. */ 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 d871abae8e..5244efc2ab 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 @@ -309,14 +309,8 @@ class Create extends Action ); foreach ($relations as &$relation) { - if ( - \is_array($relation) - && \array_values($relation) !== $relation - && !isset($relation['$id']) - ) { - $relation['$id'] = ID::unique(); - $relation = new Document($relation); - } + [$relationId, $relation] = $this->validateRelationship($relation); + if ($relation instanceof Document) { $relation = $this->removeReadonlyAttributes($relation, $isAPIKey || $isPrivilegedUser); 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 a92d8ec180..f6fa6a95cc 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 @@ -201,15 +201,8 @@ class Update extends Action ); foreach ($relations as &$relation) { - // If the relation is an array it can be either update or create a child document. - if ( - \is_array($relation) - && \array_values($relation) !== $relation - && !isset($relation['$id']) - ) { - $relation['$id'] = ID::unique(); - $relation = new Document($relation); - } + [$relationId, $relation] = $this->validateRelationship($relation); + if ($relation instanceof Document) { $relation = $this->removeReadonlyAttributes($relation, $isAPIKey || $isPrivilegedUser); 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 62e59dd010..9cc38050c4 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 @@ -211,15 +211,8 @@ class Upsert extends Action ); foreach ($relations as &$relation) { - // If the relation is an array it can be either update or create a child document. - if ( - \is_array($relation) - && \array_values($relation) !== $relation - && !isset($relation['$id']) - ) { - $relation['$id'] = ID::unique(); - $relation = new Document($relation); - } + [$relationId, $relation] = $this->validateRelationship($relation); + if ($relation instanceof Document) { $relation = $this->removeReadonlyAttributes($relation, $isAPIKey || $isPrivilegedUser); diff --git a/tests/e2e/Services/Databases/TablesDB/DatabasesBase.php b/tests/e2e/Services/Databases/TablesDB/DatabasesBase.php index ba111e5923..4d0e9e76a2 100644 --- a/tests/e2e/Services/Databases/TablesDB/DatabasesBase.php +++ b/tests/e2e/Services/Databases/TablesDB/DatabasesBase.php @@ -7626,6 +7626,257 @@ trait DatabasesBase $this->assertEquals(200, $update['headers']['status-code']); } + /** + * @depends testCreateDatabase + */ + public function testInvalidRelationshipDocumentId(array $data): void + { + $databaseId = $data['databaseId']; + + // Create parent table + $parentTable = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'tableId' => ID::unique(), + 'name' => 'ParentTable', + ]); + $this->assertEquals(201, $parentTable['headers']['status-code']); + $parentTableId = $parentTable['body']['$id']; + + // Create child table + $childTable = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'tableId' => ID::unique(), + 'name' => 'ChildTable', + ]); + $this->assertEquals(201, $childTable['headers']['status-code']); + $childTableId = $childTable['body']['$id']; + + // Add string column to parent + $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $parentTableId . '/columns/string', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'name', + 'size' => 255, + 'required' => false, + ]); + + // Add string column to child + $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $childTableId . '/columns/string', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'key' => 'title', + 'size' => 255, + 'required' => false, + ]); + + // Create one-to-many relationship + $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $parentTableId . '/columns/relationship', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'relatedTableId' => $childTableId, + 'type' => Database::RELATION_ONE_TO_MANY, + 'twoWay' => false, + 'key' => 'children', + ]); + + sleep(1); + + // ID too long (>36 chars) should fail + $response = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $parentTableId . '/rows', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'rowId' => ID::unique(), + 'data' => [ + 'name' => 'Parent 1', + 'children' => [ + [ + '$id' => 'this_id_is_way_too_long_and_should_fail_validation_check', + 'title' => 'Child 1', + ], + ], + ], + ]); + $this->assertEquals(400, $response['headers']['status-code']); + + // ID with invalid characters should fail + $response = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $parentTableId . '/rows', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'rowId' => ID::unique(), + 'data' => [ + 'name' => 'Parent 2', + 'children' => [ + [ + '$id' => 'invalid@id#with$special%chars', + 'title' => 'Child 2', + ], + ], + ], + ]); + $this->assertEquals(400, $response['headers']['status-code']); + + // ID starting with underscore should fail + $response = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $parentTableId . '/rows', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'rowId' => ID::unique(), + 'data' => [ + 'name' => 'Parent 3', + 'children' => [ + [ + '$id' => '_startsWithUnderscore', + 'title' => 'Child 3', + ], + ], + ], + ]); + $this->assertEquals(400, $response['headers']['status-code']); + + // Valid ID should succeed + $response = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $parentTableId . '/rows', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'rowId' => ID::unique(), + 'data' => [ + 'name' => 'Parent 4', + 'children' => [ + [ + '$id' => 'valid-id-123', + 'title' => 'Child 4', + ], + ], + ], + ]); + $this->assertEquals(201, $response['headers']['status-code']); + $parentRowId = $response['body']['$id']; + + // Update with invalid relationship ID should fail + $response = $this->client->call(Client::METHOD_PATCH, '/tablesdb/' . $databaseId . '/tables/' . $parentTableId . '/rows/' . $parentRowId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'data' => [ + 'children' => [ + [ + '$id' => 'another@invalid#id', + 'title' => 'Child 5', + ], + ], + ], + ]); + $this->assertEquals(400, $response['headers']['status-code']); + + // Invalid string relation ID should fail + $response = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $parentTableId . '/rows', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'rowId' => ID::unique(), + 'data' => [ + 'name' => 'Parent 6', + 'children' => [ + 'invalid@string#id', + ], + ], + ]); + $this->assertEquals(400, $response['headers']['status-code']); + + // Integer as relation value should fail + $response = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $parentTableId . '/rows', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'rowId' => ID::unique(), + 'data' => [ + 'name' => 'Parent 7', + 'children' => [ + 12345, + ], + ], + ]); + $this->assertEquals(400, $response['headers']['status-code']); + + // unique() as $id should succeed + $response = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $parentTableId . '/rows', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'rowId' => ID::unique(), + 'data' => [ + 'name' => 'Parent 8', + 'children' => [ + [ + '$id' => 'unique()', + 'title' => 'Child 8', + ], + ], + ], + ]); + $this->assertEquals(201, $response['headers']['status-code']); + + // Empty string as $id should fail + $response = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $parentTableId . '/rows', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'rowId' => ID::unique(), + 'data' => [ + 'name' => 'Parent 9', + 'children' => [ + [ + '$id' => '', + 'title' => 'Child 9', + ], + ], + ], + ]); + $this->assertEquals(400, $response['headers']['status-code']); + + // Valid ID with allowed special chars (hyphen, period) should succeed + $response = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $parentTableId . '/rows', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'rowId' => ID::unique(), + 'data' => [ + 'name' => 'Parent 10', + 'children' => [ + [ + '$id' => 'valid.id-with_chars', + 'title' => 'Child 10', + ], + ], + ], + ]); + $this->assertEquals(201, $response['headers']['status-code']); + } + /** * @depends testCreateDatabase */ From f66e0c2ff57b7dbae8d473d8b6b638abf489926f Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Mon, 26 Jan 2026 14:05:56 +0000 Subject: [PATCH 46/60] refactor: separate validation from normalization in validateRelationship --- .../Http/Databases/Collections/Documents/Action.php | 13 +++---------- .../Http/Databases/Collections/Documents/Create.php | 7 ++++++- .../Http/Databases/Collections/Documents/Update.php | 7 ++++++- .../Http/Databases/Collections/Documents/Upsert.php | 7 ++++++- 4 files changed, 21 insertions(+), 13 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 03236471db..2a34c8979b 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 @@ -8,7 +8,6 @@ use Appwrite\Platform\Modules\Databases\Http\Databases\Action as DatabasesAction use Appwrite\Utopia\Database\Validator\CustomId; use Utopia\Database\Database; use Utopia\Database\Document; -use Utopia\Database\Helpers\ID; use Utopia\Database\Validator\Authorization; abstract class Action extends DatabasesAction @@ -252,10 +251,9 @@ abstract class Action extends DatabasesAction } /** - * Validate and normalize a relationship value. - * Returns the relation ID and normalized relation as an array. + * Validate a relationship value and its document ID. */ - protected function validateRelationship(mixed $relation): array + protected function validateRelationship(mixed $relation): void { $relationId = null; @@ -263,10 +261,7 @@ abstract class Action extends DatabasesAction $relationId = $relation->getAttribute('$id'); } elseif (\is_string($relation)) { $relationId = $relation; - } elseif (\is_array($relation) && \array_values($relation) !== $relation) { - $relation['$id'] = ID::unique(); - $relation = new Document($relation); - } else { + } elseif (!(\is_array($relation) && \array_values($relation) !== $relation)) { throw new Exception(Exception::RELATIONSHIP_VALUE_INVALID, 'Relationship value must be an object or document ID string, not ' . \gettype($relation)); } @@ -276,8 +271,6 @@ abstract class Action extends DatabasesAction throw new Exception(Exception::GENERAL_BAD_REQUEST, $validator->getDescription()); } } - - return [$relationId, $relation]; } /** 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 5244efc2ab..8927c6b27b 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 @@ -309,7 +309,12 @@ class Create extends Action ); foreach ($relations as &$relation) { - [$relationId, $relation] = $this->validateRelationship($relation); + $this->validateRelationship($relation); + + if (\is_array($relation) && \array_values($relation) !== $relation) { + $relation['$id'] = ID::unique(); + $relation = new Document($relation); + } if ($relation instanceof Document) { $relation = $this->removeReadonlyAttributes($relation, $isAPIKey || $isPrivilegedUser); 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 f6fa6a95cc..0f3eb9e026 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 @@ -201,7 +201,12 @@ class Update extends Action ); foreach ($relations as &$relation) { - [$relationId, $relation] = $this->validateRelationship($relation); + $this->validateRelationship($relation); + + if (\is_array($relation) && \array_values($relation) !== $relation) { + $relation['$id'] = ID::unique(); + $relation = new Document($relation); + } if ($relation instanceof Document) { $relation = $this->removeReadonlyAttributes($relation, $isAPIKey || $isPrivilegedUser); 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 9cc38050c4..cdff15c5ab 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 @@ -211,7 +211,12 @@ class Upsert extends Action ); foreach ($relations as &$relation) { - [$relationId, $relation] = $this->validateRelationship($relation); + $this->validateRelationship($relation); + + if (\is_array($relation) && \array_values($relation) !== $relation) { + $relation['$id'] = ID::unique(); + $relation = new Document($relation); + } if ($relation instanceof Document) { $relation = $this->removeReadonlyAttributes($relation, $isAPIKey || $isPrivilegedUser); From 1ee2539ce0d8a247341aa0ca6481b63d98dad1fe Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Mon, 26 Jan 2026 14:49:43 +0000 Subject: [PATCH 47/60] fix: generate unique ID before validation per coderabbit suggestion --- .../Databases/Collections/Documents/Action.php | 4 +++- .../Databases/Collections/Documents/Create.php | 11 ++++++++++- .../Databases/Collections/Documents/Update.php | 11 ++++++++++- .../Databases/Collections/Documents/Upsert.php | 11 ++++++++++- .../Databases/TablesDB/DatabasesBase.php | 18 ++++++++++++++++-- 5 files changed, 49 insertions(+), 6 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 2a34c8979b..efd3f4ed6f 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 @@ -261,7 +261,9 @@ abstract class Action extends DatabasesAction $relationId = $relation->getAttribute('$id'); } elseif (\is_string($relation)) { $relationId = $relation; - } elseif (!(\is_array($relation) && \array_values($relation) !== $relation)) { + } elseif (\is_array($relation) && \array_values($relation) !== $relation) { + $relationId = $relation['$id'] ?? null; + } else { throw new Exception(Exception::RELATIONSHIP_VALUE_INVALID, 'Relationship value must be an object or document ID string, not ' . \gettype($relation)); } 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 8927c6b27b..253cf8ec3c 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 @@ -309,10 +309,19 @@ class Create extends Action ); foreach ($relations as &$relation) { + // Generate unique ID for new relation without $id + if ( + \is_array($relation) + && \array_values($relation) !== $relation + && !isset($relation['$id']) + ) { + $relation['$id'] = ID::unique(); + } + $this->validateRelationship($relation); + // If the relation is an array it can be either update or create a child document. if (\is_array($relation) && \array_values($relation) !== $relation) { - $relation['$id'] = ID::unique(); $relation = new Document($relation); } 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 0f3eb9e026..34f2a45e15 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 @@ -201,10 +201,19 @@ class Update extends Action ); foreach ($relations as &$relation) { + // Generate unique ID for new relation without $id + if ( + \is_array($relation) + && \array_values($relation) !== $relation + && !isset($relation['$id']) + ) { + $relation['$id'] = ID::unique(); + } + $this->validateRelationship($relation); + // If the relation is an array it can be either update or create a child document. if (\is_array($relation) && \array_values($relation) !== $relation) { - $relation['$id'] = ID::unique(); $relation = new Document($relation); } 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 cdff15c5ab..8b500a9e61 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 @@ -211,10 +211,19 @@ class Upsert extends Action ); foreach ($relations as &$relation) { + // Generate unique ID for new relation without $id + if ( + \is_array($relation) + && \array_values($relation) !== $relation + && !isset($relation['$id']) + ) { + $relation['$id'] = ID::unique(); + } + $this->validateRelationship($relation); + // If the relation is an array it can be either update or create a child document. if (\is_array($relation) && \array_values($relation) !== $relation) { - $relation['$id'] = ID::unique(); $relation = new Document($relation); } diff --git a/tests/e2e/Services/Databases/TablesDB/DatabasesBase.php b/tests/e2e/Services/Databases/TablesDB/DatabasesBase.php index 4d0e9e76a2..2ea0c8c108 100644 --- a/tests/e2e/Services/Databases/TablesDB/DatabasesBase.php +++ b/tests/e2e/Services/Databases/TablesDB/DatabasesBase.php @@ -7680,7 +7680,7 @@ trait DatabasesBase ]); // Create one-to-many relationship - $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $parentTableId . '/columns/relationship', array_merge([ + $relationship = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $parentTableId . '/columns/relationship', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'] @@ -7690,8 +7690,22 @@ trait DatabasesBase 'twoWay' => false, 'key' => 'children', ]); + $this->assertEquals(202, $relationship['headers']['status-code']); - sleep(1); + // Wait for relationship column to be available + $maxAttempts = 10; + for ($i = 0; $i < $maxAttempts; $i++) { + $columns = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $parentTableId . '/columns', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ])); + $columnKeys = array_column($columns['body']['columns'], 'key'); + if (in_array('children', $columnKeys)) { + break; + } + usleep(200000); + } // ID too long (>36 chars) should fail $response = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $parentTableId . '/rows', array_merge([ From 63e6a51af1185f27116909619ec1b08db4935fce Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Mon, 26 Jan 2026 15:31:41 +0000 Subject: [PATCH 48/60] test: add assertion for relationship column polling --- tests/e2e/Services/Databases/TablesDB/DatabasesBase.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/e2e/Services/Databases/TablesDB/DatabasesBase.php b/tests/e2e/Services/Databases/TablesDB/DatabasesBase.php index 2ea0c8c108..8d8133241b 100644 --- a/tests/e2e/Services/Databases/TablesDB/DatabasesBase.php +++ b/tests/e2e/Services/Databases/TablesDB/DatabasesBase.php @@ -7694,6 +7694,7 @@ trait DatabasesBase // Wait for relationship column to be available $maxAttempts = 10; + $childrenFound = false; for ($i = 0; $i < $maxAttempts; $i++) { $columns = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $parentTableId . '/columns', array_merge([ 'content-type' => 'application/json', @@ -7702,10 +7703,12 @@ trait DatabasesBase ])); $columnKeys = array_column($columns['body']['columns'], 'key'); if (in_array('children', $columnKeys)) { + $childrenFound = true; break; } usleep(200000); } + $this->assertTrue($childrenFound, "Relationship column 'children' not found in table {$parentTableId} of database {$databaseId}"); // ID too long (>36 chars) should fail $response = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $parentTableId . '/rows', array_merge([ From 00d091513d7d748a50ac77bd5e8b065a51f24ffb Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Tue, 27 Jan 2026 06:59:53 +0000 Subject: [PATCH 49/60] refactor: simplify relationship validation code --- .../Http/Databases/Collections/Documents/Action.php | 5 ++--- .../Http/Databases/Collections/Documents/Create.php | 7 +------ .../Http/Databases/Collections/Documents/Update.php | 8 ++------ .../Http/Databases/Collections/Documents/Upsert.php | 8 ++------ 4 files changed, 7 insertions(+), 21 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 efd3f4ed6f..c43c6114ef 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 @@ -251,7 +251,8 @@ abstract class Action extends DatabasesAction } /** - * Validate a relationship value and its document ID. + * Validate relationship values. + * Handles Document objects, ID strings, and associative arrays. */ protected function validateRelationship(mixed $relation): void { @@ -263,8 +264,6 @@ abstract class Action extends DatabasesAction $relationId = $relation; } elseif (\is_array($relation) && \array_values($relation) !== $relation) { $relationId = $relation['$id'] ?? null; - } else { - throw new Exception(Exception::RELATIONSHIP_VALUE_INVALID, 'Relationship value must be an object or document ID string, not ' . \gettype($relation)); } if ($relationId !== null) { 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 253cf8ec3c..eebe59796e 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 @@ -309,22 +309,17 @@ class Create extends Action ); foreach ($relations as &$relation) { - // Generate unique ID for new relation without $id if ( \is_array($relation) && \array_values($relation) !== $relation && !isset($relation['$id']) ) { $relation['$id'] = ID::unique(); + $relation = new Document($relation); } $this->validateRelationship($relation); - // If the relation is an array it can be either update or create a child document. - if (\is_array($relation) && \array_values($relation) !== $relation) { - $relation = new Document($relation); - } - if ($relation instanceof Document) { $relation = $this->removeReadonlyAttributes($relation, $isAPIKey || $isPrivilegedUser); 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 34f2a45e15..ff3ab6e23c 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 @@ -201,22 +201,18 @@ class Update extends Action ); foreach ($relations as &$relation) { - // Generate unique ID for new relation without $id + // If the relation is an array it can be either update or create a child document. if ( \is_array($relation) && \array_values($relation) !== $relation && !isset($relation['$id']) ) { $relation['$id'] = ID::unique(); + $relation = new Document($relation); } $this->validateRelationship($relation); - // If the relation is an array it can be either update or create a child document. - if (\is_array($relation) && \array_values($relation) !== $relation) { - $relation = new Document($relation); - } - if ($relation instanceof Document) { $relation = $this->removeReadonlyAttributes($relation, $isAPIKey || $isPrivilegedUser); 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 8b500a9e61..d0536b65ef 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 @@ -211,22 +211,18 @@ class Upsert extends Action ); foreach ($relations as &$relation) { - // Generate unique ID for new relation without $id + // If the relation is an array it can be either update or create a child document. if ( \is_array($relation) && \array_values($relation) !== $relation && !isset($relation['$id']) ) { $relation['$id'] = ID::unique(); + $relation = new Document($relation); } $this->validateRelationship($relation); - // If the relation is an array it can be either update or create a child document. - if (\is_array($relation) && \array_values($relation) !== $relation) { - $relation = new Document($relation); - } - if ($relation instanceof Document) { $relation = $this->removeReadonlyAttributes($relation, $isAPIKey || $isPrivilegedUser); From d792d3bbeaae56a29e94e2191e0188ffb2ac2224 Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Tue, 27 Jan 2026 09:25:39 +0000 Subject: [PATCH 50/60] refactor: use getId() instead of getAttribute('$id') --- .../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 c43c6114ef..65b3be2130 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 @@ -259,7 +259,7 @@ abstract class Action extends DatabasesAction $relationId = null; if ($relation instanceof Document) { - $relationId = $relation->getAttribute('$id'); + $relationId = $relation->getId(); } elseif (\is_string($relation)) { $relationId = $relation; } elseif (\is_array($relation) && \array_values($relation) !== $relation) { From d182c853302e6e717eb7d291e6b1d4dd88bb9b1d Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Tue, 27 Jan 2026 09:35:45 +0000 Subject: [PATCH 51/60] fix: reject unsupported relationship value types --- .../Databases/Http/Databases/Collections/Documents/Action.php | 2 ++ 1 file changed, 2 insertions(+) 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 65b3be2130..7cac57bfa7 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 @@ -264,6 +264,8 @@ abstract class Action extends DatabasesAction $relationId = $relation; } elseif (\is_array($relation) && \array_values($relation) !== $relation) { $relationId = $relation['$id'] ?? null; + } else { + throw new Exception(Exception::GENERAL_BAD_REQUEST, 'Relationship value must be an object, document ID string, or associative array'); } if ($relationId !== null) { From 99dc31062de115ba65f76009bef6dc6de6d23cf3 Mon Sep 17 00:00:00 2001 From: Hemachandar <132386067+hmacr@users.noreply.github.com> Date: Tue, 27 Jan 2026 15:36:50 +0530 Subject: [PATCH 52/60] Fix rule status check (#11195) --- src/Appwrite/Platform/Workers/Certificates.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Workers/Certificates.php b/src/Appwrite/Platform/Workers/Certificates.php index 33ebd39092..bfa6bf87c7 100644 --- a/src/Appwrite/Platform/Workers/Certificates.php +++ b/src/Appwrite/Platform/Workers/Certificates.php @@ -276,7 +276,7 @@ class Certificates extends Action ])); // Rule not found (or) not in the expected state - if ($rule->isEmpty() || $rule->getAttribute('status') !== RULE_STATUS_CERTIFICATE_GENERATING) { + if ($rule->isEmpty() || !\in_array($rule->getAttribute('status'), [RULE_STATUS_CERTIFICATE_GENERATING, RULE_STATUS_VERIFIED])) { Console::warning('Certificate generation for ' . $domain->get() . ' is skipped as the associated rule is either empty or not in the expected state.'); return; } From cb66e5061252f4873d1f4f2cb0f84c68e38bc2f8 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Tue, 27 Jan 2026 11:58:34 +0000 Subject: [PATCH 53/60] refactor: remove magic class strings --- app/controllers/general.php | 6 +- src/Appwrite/GraphQL/Types/Mapper.php | 106 +++++++-------- .../SDK/Specification/Format/OpenAPI3.php | 122 +++++++++--------- .../SDK/Specification/Format/Swagger2.php | 78 +++++------ 4 files changed, 156 insertions(+), 156 deletions(-) diff --git a/app/controllers/general.php b/app/controllers/general.php index 8fc5a11503..2bd0a6d54c 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -1228,7 +1228,7 @@ App::error() } switch ($class) { - case 'Utopia\Exception': + case Utopia\Exception::class: $error = new AppwriteException(AppwriteException::GENERAL_UNKNOWN, $message, $code, $error); switch ($code) { case 400: @@ -1239,10 +1239,10 @@ App::error() break; } break; - case 'Utopia\Database\Exception\Authorization': + case Utopia\Database\Exception\Authorization::class: $error = new AppwriteException(AppwriteException::USER_UNAUTHORIZED); break; - case 'Utopia\Database\Exception\Timeout': + case Utopia\Database\Exception\Timeout::class: $error = new AppwriteException(AppwriteException::DATABASE_TIMEOUT, previous: $error); break; } diff --git a/src/Appwrite/GraphQL/Types/Mapper.php b/src/Appwrite/GraphQL/Types/Mapper.php index c9ae84f1c3..8935e67c0b 100644 --- a/src/Appwrite/GraphQL/Types/Mapper.php +++ b/src/Appwrite/GraphQL/Types/Mapper.php @@ -269,59 +269,59 @@ class Mapper } switch ((!empty($validator)) ? $validator::class : '') { - case 'Appwrite\Auth\Validator\Password': - case 'Appwrite\Event\Validator\Event': - case 'Appwrite\Event\Validator\FunctionEvent': - case 'Appwrite\Network\Validator\CNAME': - case 'Appwrite\Network\Validator\Email': - case 'Appwrite\Network\Validator\Redirect': - case 'Appwrite\Network\Validator\DNS': - case 'Appwrite\Network\Validator\Origin': - case 'Appwrite\Task\Validator\Cron': - case 'Appwrite\Utopia\Database\Validator\CustomId': - case 'Utopia\Database\Validator\Key': - case 'Utopia\Database\Validator\UID': - case 'Utopia\Validator\Domain': - case 'Utopia\Validator\HexColor': - case 'Utopia\Validator\Host': - case 'Utopia\Validator\IP': - case 'Utopia\Validator\Origin': - case 'Utopia\Validator\Text': - case 'Utopia\Validator\URL': - case 'Utopia\Validator\WhiteList': + case \Appwrite\Auth\Validator\Password::class: + case \Appwrite\Event\Validator\Event::class: + case \Appwrite\Event\Validator\FunctionEvent::class: + case \Appwrite\Network\Validator\CNAME::class: + case \Appwrite\Network\Validator\Email::class: + case \Appwrite\Network\Validator\Redirect::class: + case \Appwrite\Network\Validator\DNS::class: + case \Appwrite\Network\Validator\Origin::class: + case \Appwrite\Task\Validator\Cron::class: + case \Appwrite\Utopia\Database\Validator\CustomId::class: + case \Utopia\Database\Validator\Key::class: + case \Utopia\Database\Validator\UID::class: + case \Utopia\Validator\Domain::class: + case \Utopia\Validator\HexColor::class: + case \Utopia\Validator\Host::class: + case \Utopia\Validator\IP::class: + case \Utopia\Validator\Origin::class: + case \Utopia\Validator\Text::class: + case \Utopia\Validator\URL::class: + case \Utopia\Validator\WhiteList::class: default: $type = Type::string(); break; - case 'Appwrite\Utopia\Database\Validator\Queries\Attributes': - case 'Appwrite\Utopia\Database\Validator\Queries\Base': - case 'Appwrite\Utopia\Database\Validator\Queries\Buckets': - case 'Appwrite\Utopia\Database\Validator\Queries\Tables': - case 'Appwrite\Utopia\Database\Validator\Queries\Collections': - case 'Appwrite\Utopia\Database\Validator\Queries\Columns': - case 'Appwrite\Utopia\Database\Validator\Queries\Databases': - case 'Appwrite\Utopia\Database\Validator\Queries\Deployments': - case 'Appwrite\Utopia\Database\Validator\Queries\Executions': - case 'Appwrite\Utopia\Database\Validator\Queries\Files': - case 'Appwrite\Utopia\Database\Validator\Queries\Functions': - case 'Appwrite\Utopia\Database\Validator\Queries\Indexes': - case 'Appwrite\Utopia\Database\Validator\Queries\Installations': - case 'Appwrite\Utopia\Database\Validator\Queries\Memberships': - case 'Appwrite\Utopia\Database\Validator\Queries\Projects': - case 'Appwrite\Utopia\Database\Validator\Queries\Rules': - case 'Appwrite\Utopia\Database\Validator\Queries\Teams': - case 'Appwrite\Utopia\Database\Validator\Queries\Users': - case 'Appwrite\Utopia\Database\Validator\Queries\Variables': - case 'Utopia\Database\Validator\Authorization': - case 'Utopia\Database\Validator\Permissions': - case 'Utopia\Database\Validator\Queries': - case 'Utopia\Database\Validator\Queries\Documents': - case 'Utopia\Database\Validator\Roles': + case \Appwrite\Utopia\Database\Validator\Queries\Attributes::class: + case \Appwrite\Utopia\Database\Validator\Queries\Base::class: + case \Appwrite\Utopia\Database\Validator\Queries\Buckets::class: + case \Appwrite\Utopia\Database\Validator\Queries\Tables::class: + case \Appwrite\Utopia\Database\Validator\Queries\Collections::class: + case \Appwrite\Utopia\Database\Validator\Queries\Columns::class: + case \Appwrite\Utopia\Database\Validator\Queries\Databases::class: + case \Appwrite\Utopia\Database\Validator\Queries\Deployments::class: + case \Appwrite\Utopia\Database\Validator\Queries\Executions::class: + case \Appwrite\Utopia\Database\Validator\Queries\Files::class: + case \Appwrite\Utopia\Database\Validator\Queries\Functions::class: + case \Appwrite\Utopia\Database\Validator\Queries\Indexes::class: + case \Appwrite\Utopia\Database\Validator\Queries\Installations::class: + case \Appwrite\Utopia\Database\Validator\Queries\Memberships::class: + case \Appwrite\Utopia\Database\Validator\Queries\Projects::class: + case \Appwrite\Utopia\Database\Validator\Queries\Rules::class: + case \Appwrite\Utopia\Database\Validator\Queries\Teams::class: + case \Appwrite\Utopia\Database\Validator\Queries\Users::class: + case \Appwrite\Utopia\Database\Validator\Queries\Variables::class: + case \Utopia\Database\Validator\Authorization::class: + case \Utopia\Database\Validator\Permissions::class: + case \Utopia\Database\Validator\Queries::class: + case \Utopia\Database\Validator\Queries\Documents::class: + case \Utopia\Database\Validator\Roles::class: $type = Type::listOf(Type::string()); break; - case 'Utopia\Validator\Boolean': + case \Utopia\Validator\Boolean::class: $type = Type::boolean(); break; - case 'Utopia\Validator\ArrayList': + case \Utopia\Validator\ArrayList::class: $type = Type::listOf(self::param( $utopia, $validator->getValidator(), @@ -329,11 +329,11 @@ class Mapper $injections )); break; - case 'Utopia\Validator\Integer': - case 'Utopia\Validator\Numeric': + case \Utopia\Validator\Integer::class: + case \Utopia\Validator\Numeric::class: $type = Type::int(); break; - case 'Utopia\Validator\Range': + case \Utopia\Validator\Range::class: // Check if the Range validator is for float or integer if ($validator instanceof \Utopia\Validator\Range && $validator->getType() === \Utopia\Validator\Range::TYPE_FLOAT) { $type = Type::float(); @@ -341,16 +341,16 @@ class Mapper $type = Type::int(); } break; - case 'Utopia\Validator\FloatValidator': + case \Utopia\Validator\FloatValidator::class: $type = Type::float(); break; - case 'Utopia\Validator\Assoc': + case \Utopia\Validator\Assoc::class: $type = Types::assoc(); break; - case 'Utopia\Validator\JSON': + case \Utopia\Validator\JSON::class: $type = Types::json(); break; - case 'Utopia\Storage\Validator\File': + case \Utopia\Storage\Validator\File::class: $type = Types::inputFile(); break; } diff --git a/src/Appwrite/SDK/Specification/Format/OpenAPI3.php b/src/Appwrite/SDK/Specification/Format/OpenAPI3.php index 8171a45db4..8e710cd0ac 100644 --- a/src/Appwrite/SDK/Specification/Format/OpenAPI3.php +++ b/src/Appwrite/SDK/Specification/Format/OpenAPI3.php @@ -392,51 +392,51 @@ class OpenAPI3 extends Format : ''; switch ($base) { - case 'Appwrite\Utopia\Database\Validator\Queries\Base': + case \Appwrite\Utopia\Database\Validator\Queries\Base::class: $class = $base; break; } - if ($class === 'Utopia\Validator\AnyOf') { + if ($class === \Utopia\Validator\AnyOf::class) { $validator = $param['validator']->getValidators()[0]; $class = \get_class($validator); } $array = false; - if ($class === 'Utopia\Validator\ArrayList') { + if ($class === \Utopia\Validator\ArrayList::class) { $array = true; $subclass = \get_class($validator->getValidator()); switch ($subclass) { - case 'Appwrite\Utopia\Database\Validator\Operation': - case 'Utopia\Validator\WhiteList': + case \Appwrite\Utopia\Database\Validator\Operation::class: + case \Utopia\Validator\WhiteList::class: $class = $subclass; break; } } switch ($class) { - case 'Utopia\Database\Validator\UID': - case 'Utopia\Validator\Text': + case \Utopia\Database\Validator\UID::class: + case \Utopia\Validator\Text::class: $node['schema']['type'] = $validator->getType(); $node['schema']['x-example'] = ($param['example'] ?? '') ?: '<' . \strtoupper(Template::fromCamelCaseToSnake($node['name'])) . '>'; break; - case 'Utopia\Validator\Boolean': + case \Utopia\Validator\Boolean::class: $node['schema']['type'] = $validator->getType(); $node['schema']['x-example'] = ($param['example'] ?? '') ?: false; break; - case 'Appwrite\Utopia\Database\Validator\CustomId': + case \Appwrite\Utopia\Database\Validator\CustomId::class: if ($sdk->getType() === MethodType::UPLOAD) { $node['schema']['x-upload-id'] = true; } $node['schema']['type'] = $validator->getType(); $node['schema']['x-example'] = ($param['example'] ?? '') ?: '<' . \strtoupper(Template::fromCamelCaseToSnake($node['name'])) . '>'; break; - case 'Utopia\Database\Validator\DatetimeValidator': + case \Utopia\Database\Validator\DatetimeValidator::class: $node['schema']['type'] = $validator->getType(); $node['schema']['format'] = 'datetime'; $node['schema']['x-example'] = ($param['example'] ?? '') ?: Model::TYPE_DATETIME_EXAMPLE; break; - case 'Utopia\Database\Validator\Spatial': + case \Utopia\Database\Validator\Spatial::class: /** @var Spatial $validator */ $node['schema']['type'] = 'array'; $node['schema']['items'] = [ @@ -450,31 +450,31 @@ class OpenAPI3 extends Format Database::VAR_POLYGON => '[[[1, 2], [3, 4], [5, 6], [1, 2]]]', }; break; - case 'Appwrite\Network\Validator\Email': + case \Appwrite\Network\Validator\Email::class: $node['schema']['type'] = $validator->getType(); $node['schema']['format'] = 'email'; $node['schema']['x-example'] = ($param['example'] ?? '') ?: 'email@example.com'; break; - case 'Utopia\Validator\Host': - case 'Utopia\Validator\URL': - case 'Appwrite\Network\Validator\Redirect': + case \Utopia\Validator\Host::class: + case \Utopia\Validator\URL::class: + case \Appwrite\Network\Validator\Redirect::class: $node['schema']['type'] = $validator->getType(); $node['schema']['format'] = 'url'; $node['schema']['x-example'] = ($param['example'] ?? '') ?: 'https://example.com'; break; - case 'Utopia\Validator\JSON': - case 'Utopia\Validator\Mock': - case 'Utopia\Validator\Assoc': + case \Utopia\Validator\JSON::class: + case \Utopia\Validator\Mock::class: + case \Utopia\Validator\Assoc::class: $param['default'] = (empty($param['default'])) ? new \stdClass() : $param['default']; $node['schema']['type'] = 'object'; $node['schema']['x-example'] = ($param['example'] ?? '') ?: '{}'; break; - case 'Utopia\Storage\Validator\File': + case \Utopia\Storage\Validator\File::class: $consumes = ['multipart/form-data']; $node['schema']['type'] = $validator->getType(); $node['schema']['format'] = 'binary'; break; - case 'Utopia\Validator\ArrayList': + case \Utopia\Validator\ArrayList::class: /** @var ArrayList $validator */ $node['schema']['type'] = 'array'; $node['schema']['items'] = [ @@ -484,92 +484,92 @@ class OpenAPI3 extends Format $node['schema']['x-example'] = $param['example']; } break; - case 'Appwrite\Utopia\Database\Validator\Queries\Base': - case 'Appwrite\Utopia\Database\Validator\Queries\Columns': - case 'Appwrite\Utopia\Database\Validator\Queries\Attributes': - case 'Appwrite\Utopia\Database\Validator\Queries\Buckets': - case 'Appwrite\Utopia\Database\Validator\Queries\Tables': - case 'Appwrite\Utopia\Database\Validator\Queries\Collections': - case 'Appwrite\Utopia\Database\Validator\Queries\Databases': - case 'Appwrite\Utopia\Database\Validator\Queries\Deployments': - case 'Appwrite\Utopia\Database\Validator\Queries\Executions': - case 'Appwrite\Utopia\Database\Validator\Queries\Files': - case 'Appwrite\Utopia\Database\Validator\Queries\Functions': - case 'Appwrite\Utopia\Database\Validator\Queries\Identities': - case 'Appwrite\Utopia\Database\Validator\Queries\Indexes': - case 'Appwrite\Utopia\Database\Validator\Queries\Installations': - case 'Appwrite\Utopia\Database\Validator\Queries\Memberships': - case 'Appwrite\Utopia\Database\Validator\Queries\Messages': - case 'Appwrite\Utopia\Database\Validator\Queries\Migrations': - case 'Appwrite\Utopia\Database\Validator\Queries\Projects': - case 'Appwrite\Utopia\Database\Validator\Queries\Providers': - case 'Appwrite\Utopia\Database\Validator\Queries\Rules': - case 'Appwrite\Utopia\Database\Validator\Queries\Subscribers': - case 'Appwrite\Utopia\Database\Validator\Queries\Targets': - case 'Appwrite\Utopia\Database\Validator\Queries\Teams': - case 'Appwrite\Utopia\Database\Validator\Queries\Topics': - case 'Appwrite\Utopia\Database\Validator\Queries\Users': - case 'Appwrite\Utopia\Database\Validator\Queries\Variables': - case 'Utopia\Database\Validator\Queries': - case 'Utopia\Database\Validator\Queries\Document': - case 'Utopia\Database\Validator\Queries\Documents': + case \Appwrite\Utopia\Database\Validator\Queries\Base::class: + case \Appwrite\Utopia\Database\Validator\Queries\Columns::class: + case \Appwrite\Utopia\Database\Validator\Queries\Attributes::class: + case \Appwrite\Utopia\Database\Validator\Queries\Buckets::class: + case \Appwrite\Utopia\Database\Validator\Queries\Tables::class: + case \Appwrite\Utopia\Database\Validator\Queries\Collections::class: + case \Appwrite\Utopia\Database\Validator\Queries\Databases::class: + case \Appwrite\Utopia\Database\Validator\Queries\Deployments::class: + case \Appwrite\Utopia\Database\Validator\Queries\Executions::class: + case \Appwrite\Utopia\Database\Validator\Queries\Files::class: + case \Appwrite\Utopia\Database\Validator\Queries\Functions::class: + case \Appwrite\Utopia\Database\Validator\Queries\Identities::class: + case \Appwrite\Utopia\Database\Validator\Queries\Indexes::class: + case \Appwrite\Utopia\Database\Validator\Queries\Installations::class: + case \Appwrite\Utopia\Database\Validator\Queries\Memberships::class: + case \Appwrite\Utopia\Database\Validator\Queries\Messages::class: + case \Appwrite\Utopia\Database\Validator\Queries\Migrations::class: + case \Appwrite\Utopia\Database\Validator\Queries\Projects::class: + case \Appwrite\Utopia\Database\Validator\Queries\Providers::class: + case \Appwrite\Utopia\Database\Validator\Queries\Rules::class: + case \Appwrite\Utopia\Database\Validator\Queries\Subscribers::class: + case \Appwrite\Utopia\Database\Validator\Queries\Targets::class: + case \Appwrite\Utopia\Database\Validator\Queries\Teams::class: + case \Appwrite\Utopia\Database\Validator\Queries\Topics::class: + case \Appwrite\Utopia\Database\Validator\Queries\Users::class: + case \Appwrite\Utopia\Database\Validator\Queries\Variables::class: + case \Utopia\Database\Validator\Queries::class: + case \Utopia\Database\Validator\Queries\Document::class: + case \Utopia\Database\Validator\Queries\Documents::class: $node['schema']['type'] = 'array'; $node['schema']['items'] = [ 'type' => 'string', ]; break; - case 'Utopia\Database\Validator\Permissions': + case \Utopia\Database\Validator\Permissions::class: $node['schema']['type'] = $validator->getType(); $node['schema']['items'] = [ 'type' => 'string', ]; $node['schema']['x-example'] = ($param['example'] ?? '') ?: '["' . Permission::read(Role::any()) . '"]'; break; - case 'Utopia\Database\Validator\Roles': + case \Utopia\Database\Validator\Roles::class: $node['schema']['type'] = $validator->getType(); $node['schema']['items'] = [ 'type' => 'string', ]; $node['schema']['x-example'] = ($param['example'] ?? '') ?: '["' . Role::any()->toString() . '"]'; break; - case 'Appwrite\Auth\Validator\Password': + case \Appwrite\Auth\Validator\Password::class: $node['schema']['type'] = $validator->getType(); $node['schema']['format'] = 'password'; $node['schema']['x-example'] = ($param['example'] ?? '') ?: 'password'; break; - case 'Appwrite\Auth\Validator\Phone': + case \Appwrite\Auth\Validator\Phone::class: $node['schema']['type'] = $validator->getType(); $node['schema']['format'] = 'phone'; $node['schema']['x-example'] = ($param['example'] ?? '') ?: '+12065550100'; // In the US, 555 is reserved like example.com break; - case 'Utopia\Validator\Range': + case \Utopia\Validator\Range::class: /** @var Range $validator */ $node['schema']['type'] = $validator->getType() === Validator::TYPE_FLOAT ? 'number' : $validator->getType(); $node['schema']['format'] = $validator->getType() == Validator::TYPE_INTEGER ? 'int32' : 'float'; $node['schema']['x-example'] = ($param['example'] ?? '') ?: $validator->getMin(); break; - case 'Utopia\Validator\Integer': + case \Utopia\Validator\Integer::class: $node['schema']['type'] = $validator->getType(); $node['schema']['format'] = $validator->getFormat(); if (!empty($param['example'])) { $node['schema']['x-example'] = $param['example']; } break; - case 'Utopia\Validator\Numeric': - case 'Utopia\Validator\FloatValidator': + case \Utopia\Validator\Numeric::class: + case \Utopia\Validator\FloatValidator::class: $node['schema']['type'] = 'number'; $node['schema']['format'] = 'float'; if (!empty($param['example'])) { $node['schema']['x-example'] = $param['example']; } break; - case 'Utopia\Validator\Length': + case \Utopia\Validator\Length::class: $node['schema']['type'] = $validator->getType(); if (!empty($param['example'])) { $node['schema']['x-example'] = $param['example']; } break; - case 'Utopia\Validator\WhiteList': + case \Utopia\Validator\WhiteList::class: if ($array) { $validator = $validator->getValidator(); @@ -687,11 +687,11 @@ class OpenAPI3 extends Format } } break; - case 'Appwrite\Utopia\Database\Validator\CompoundUID': + case \Appwrite\Utopia\Database\Validator\CompoundUID::class: $node['schema']['type'] = $validator->getType(); $node['schema']['x-example'] = ($param['example'] ?? '') ?: ''; break; - case 'Appwrite\Utopia\Database\Validator\Operation': + case \Appwrite\Utopia\Database\Validator\Operation::class: if ($array) { $validator = $validator->getValidator(); } diff --git a/src/Appwrite/SDK/Specification/Format/Swagger2.php b/src/Appwrite/SDK/Specification/Format/Swagger2.php index 990c456851..0d66e4d725 100644 --- a/src/Appwrite/SDK/Specification/Format/Swagger2.php +++ b/src/Appwrite/SDK/Specification/Format/Swagger2.php @@ -397,51 +397,51 @@ class Swagger2 extends Format : ''; switch ($base) { - case 'Appwrite\Utopia\Database\Validator\Queries\Base': + case \Appwrite\Utopia\Database\Validator\Queries\Base::class: $class = $base; break; } - if ($class === 'Utopia\Validator\AnyOf') { + if ($class === \Utopia\Validator\AnyOf::class) { $validator = $param['validator']->getValidators()[0]; $class = \get_class($validator); } $array = false; - if ($class === 'Utopia\Validator\ArrayList') { + if ($class === \Utopia\Validator\ArrayList::class) { $array = true; $subclass = \get_class($validator->getValidator()); switch ($subclass) { - case 'Appwrite\Utopia\Database\Validator\Operation': - case 'Utopia\Validator\WhiteList': + case \Appwrite\Utopia\Database\Validator\Operation::class: + case \Utopia\Validator\WhiteList::class: $class = $subclass; break; } } switch ($class) { - case 'Utopia\Validator\Text': - case 'Utopia\Database\Validator\UID': + case \Utopia\Validator\Text::class: + case \Utopia\Database\Validator\UID::class: $node['type'] = $validator->getType(); $node['x-example'] = ($param['example'] ?? '') ?: '<' . \strtoupper(Template::fromCamelCaseToSnake($node['name'])) . '>'; break; - case 'Utopia\Validator\Boolean': + case \Utopia\Validator\Boolean::class: $node['type'] = $validator->getType(); $node['x-example'] = ($param['example'] ?? '') ?: false; break; - case 'Appwrite\Utopia\Database\Validator\CustomId': + case \Appwrite\Utopia\Database\Validator\CustomId::class: if ($sdk->getType() === MethodType::UPLOAD) { $node['x-upload-id'] = true; } $node['type'] = $validator->getType(); $node['x-example'] = ($param['example'] ?? '') ?: '<' . \strtoupper(Template::fromCamelCaseToSnake($node['name'])) . '>'; break; - case 'Utopia\Database\Validator\DatetimeValidator': + case \Utopia\Database\Validator\DatetimeValidator::class: $node['type'] = $validator->getType(); $node['format'] = 'datetime'; $node['x-example'] = ($param['example'] ?? '') ?: Model::TYPE_DATETIME_EXAMPLE; break; - case 'Utopia\Database\Validator\Spatial': + case \Utopia\Database\Validator\Spatial::class: /** @var Spatial $validator */ $node['type'] = 'array'; $node['schema']['items'] = [ @@ -455,19 +455,19 @@ class Swagger2 extends Format Database::VAR_POLYGON => '[[[1, 2], [3, 4], [5, 6], [1, 2]]]', }; break; - case 'Appwrite\Network\Validator\Email': + case \Appwrite\Network\Validator\Email::class: $node['type'] = $validator->getType(); $node['format'] = 'email'; $node['x-example'] = ($param['example'] ?? '') ?: 'email@example.com'; break; - case 'Utopia\Validator\Host': - case 'Utopia\Validator\URL': - case 'Appwrite\Network\Validator\Redirect': + case \Utopia\Validator\Host::class: + case \Utopia\Validator\URL::class: + case \Appwrite\Network\Validator\Redirect::class: $node['type'] = $validator->getType(); $node['format'] = 'url'; $node['x-example'] = ($param['example'] ?? '') ?: 'https://example.com'; break; - case 'Utopia\Validator\ArrayList': + case \Utopia\Validator\ArrayList::class: /** @var ArrayList $validator */ $node['type'] = 'array'; $node['collectionFormat'] = 'multi'; @@ -478,34 +478,34 @@ class Swagger2 extends Format $node['x-example'] = $param['example']; } break; - case 'Utopia\Validator\JSON': - case 'Utopia\Validator\Mock': - case 'Utopia\Validator\Assoc': + case \Utopia\Validator\JSON::class: + case \Utopia\Validator\Mock::class: + case \Utopia\Validator\Assoc::class: $node['type'] = 'object'; $node['default'] = (empty($param['default'])) ? new \stdClass() : $param['default']; $node['x-example'] = ($param['example'] ?? '') ?: '{}'; break; - case 'Utopia\Storage\Validator\File': + case \Utopia\Storage\Validator\File::class: $consumes = ['multipart/form-data']; $node['type'] = 'file'; break; - case 'Appwrite\Functions\Validator\Payload': + case \Appwrite\Functions\Validator\Payload::class: $consumes = ['multipart/form-data']; $node['type'] = 'payload'; break; - case 'Appwrite\Utopia\Database\Validator\Queries\Base': - case 'Utopia\Database\Validator\Queries': - case 'Utopia\Database\Validator\Queries\Document': - case 'Utopia\Database\Validator\Queries\Documents': - case 'Appwrite\Utopia\Database\Validator\Queries\Columns': - case 'Appwrite\Utopia\Database\Validator\Queries\Tables': + case \Appwrite\Utopia\Database\Validator\Queries\Base::class: + case \Utopia\Database\Validator\Queries::class: + case \Utopia\Database\Validator\Queries\Document::class: + case \Utopia\Database\Validator\Queries\Documents::class: + case \Appwrite\Utopia\Database\Validator\Queries\Columns::class: + case \Appwrite\Utopia\Database\Validator\Queries\Tables::class: $node['type'] = 'array'; $node['collectionFormat'] = 'multi'; $node['items'] = [ 'type' => 'string', ]; break; - case 'Utopia\Database\Validator\Permissions': + case \Utopia\Database\Validator\Permissions::class: $node['type'] = $validator->getType(); $node['collectionFormat'] = 'multi'; $node['items'] = [ @@ -513,7 +513,7 @@ class Swagger2 extends Format ]; $node['x-example'] = ($param['example'] ?? '') ?: '["' . Permission::read(Role::any()) . '"]'; break; - case 'Utopia\Database\Validator\Roles': + case \Utopia\Database\Validator\Roles::class: $node['type'] = $validator->getType(); $node['collectionFormat'] = 'multi'; $node['items'] = [ @@ -521,44 +521,44 @@ class Swagger2 extends Format ]; $node['x-example'] = ($param['example'] ?? '') ?: '["' . Role::any()->toString() . '"]'; break; - case 'Appwrite\Auth\Validator\Password': + case \Appwrite\Auth\Validator\Password::class: $node['type'] = $validator->getType(); $node['format'] = 'password'; $node['x-example'] = ($param['example'] ?? '') ?: 'password'; break; - case 'Appwrite\Auth\Validator\Phone': + case \Appwrite\Auth\Validator\Phone::class: $node['type'] = $validator->getType(); $node['format'] = 'phone'; $node['x-example'] = ($param['example'] ?? '') ?: '+12065550100'; break; - case 'Utopia\Validator\Range': + case \Utopia\Validator\Range::class: /** @var Range $validator */ $node['type'] = $validator->getType() === Validator::TYPE_FLOAT ? 'number' : $validator->getType(); $node['format'] = $validator->getType() == Validator::TYPE_INTEGER ? 'int32' : 'float'; $node['x-example'] = ($param['example'] ?? '') ?: $validator->getMin(); break; - case 'Utopia\Validator\Integer': + case \Utopia\Validator\Integer::class: $node['type'] = $validator->getType(); $node['format'] = $validator->getFormat(); if (!empty($param['example'])) { $node['x-example'] = $param['example']; } break; - case 'Utopia\Validator\Numeric': - case 'Utopia\Validator\FloatValidator': + case \Utopia\Validator\Numeric::class: + case \Utopia\Validator\FloatValidator::class: $node['type'] = 'number'; $node['format'] = 'float'; if (!empty($param['example'])) { $node['x-example'] = $param['example']; } break; - case 'Utopia\Validator\Length': + case \Utopia\Validator\Length::class: $node['type'] = $validator->getType(); if (!empty($param['example'])) { $node['x-example'] = $param['example']; } break; - case 'Utopia\Validator\WhiteList': + case \Utopia\Validator\WhiteList::class: if ($array) { $validator = $validator->getValidator(); @@ -665,11 +665,11 @@ class Swagger2 extends Format } } break; - case 'Appwrite\Utopia\Database\Validator\CompoundUID': + case \Appwrite\Utopia\Database\Validator\CompoundUID::class: $node['type'] = $validator->getType(); $node['x-example'] = ($param['example'] ?? '') ?: ''; break; - case 'Appwrite\Utopia\Database\Validator\Operation': + case \Appwrite\Utopia\Database\Validator\Operation::class: if ($array) { $validator = $validator->getValidator(); } From 7f3ea98924c6aa9977f9eee9182f3c3d01a8feb1 Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Tue, 27 Jan 2026 13:00:29 +0000 Subject: [PATCH 54/60] refactor: use array_is_list() and assertEventually helper --- .../Http/Databases/Collections/Documents/Action.php | 2 +- .../Services/Databases/TablesDB/DatabasesBase.php | 13 +++---------- 2 files changed, 4 insertions(+), 11 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 7cac57bfa7..c0a95ce0bd 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 @@ -262,7 +262,7 @@ abstract class Action extends DatabasesAction $relationId = $relation->getId(); } elseif (\is_string($relation)) { $relationId = $relation; - } elseif (\is_array($relation) && \array_values($relation) !== $relation) { + } elseif (\is_array($relation) && !\array_is_list($relation)) { $relationId = $relation['$id'] ?? null; } else { throw new Exception(Exception::GENERAL_BAD_REQUEST, 'Relationship value must be an object, document ID string, or associative array'); diff --git a/tests/e2e/Services/Databases/TablesDB/DatabasesBase.php b/tests/e2e/Services/Databases/TablesDB/DatabasesBase.php index 8d8133241b..62b7851271 100644 --- a/tests/e2e/Services/Databases/TablesDB/DatabasesBase.php +++ b/tests/e2e/Services/Databases/TablesDB/DatabasesBase.php @@ -7693,22 +7693,15 @@ trait DatabasesBase $this->assertEquals(202, $relationship['headers']['status-code']); // Wait for relationship column to be available - $maxAttempts = 10; - $childrenFound = false; - for ($i = 0; $i < $maxAttempts; $i++) { + $this->assertEventually(function () use ($databaseId, $parentTableId) { $columns = $this->client->call(Client::METHOD_GET, '/tablesdb/' . $databaseId . '/tables/' . $parentTableId . '/columns', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], 'x-appwrite-key' => $this->getProject()['apiKey'] ])); $columnKeys = array_column($columns['body']['columns'], 'key'); - if (in_array('children', $columnKeys)) { - $childrenFound = true; - break; - } - usleep(200000); - } - $this->assertTrue($childrenFound, "Relationship column 'children' not found in table {$parentTableId} of database {$databaseId}"); + $this->assertContains('children', $columnKeys, "Relationship column 'children' not found in table {$parentTableId} of database {$databaseId}"); + }, 2000, 200); // ID too long (>36 chars) should fail $response = $this->client->call(Client::METHOD_POST, '/tablesdb/' . $databaseId . '/tables/' . $parentTableId . '/rows', array_merge([ From aef7b8df38e1760bee332cb9d64c101ce7b94e18 Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Wed, 28 Jan 2026 08:41:10 +0000 Subject: [PATCH 55/60] fix: use RELATIONSHIP_VALUE_INVALID exception for validation errors --- .../Http/Databases/Collections/Documents/Action.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 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 c0a95ce0bd..1df947f8c3 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 @@ -265,13 +265,16 @@ abstract class Action extends DatabasesAction } elseif (\is_array($relation) && !\array_is_list($relation)) { $relationId = $relation['$id'] ?? null; } else { - throw new Exception(Exception::GENERAL_BAD_REQUEST, 'Relationship value must be an object, document ID string, or associative array'); + throw new Exception(Exception::RELATIONSHIP_VALUE_INVALID, 'Relationship value must be an object, document ID string, or associative array'); } if ($relationId !== null) { + if (!\is_string($relationId)) { + throw new Exception(Exception::RELATIONSHIP_VALUE_INVALID, 'Relationship $id must be a string'); + } $validator = new CustomId(); if (!$validator->isValid($relationId)) { - throw new Exception(Exception::GENERAL_BAD_REQUEST, $validator->getDescription()); + throw new Exception(Exception::RELATIONSHIP_VALUE_INVALID, $validator->getDescription()); } } } From cbe2d2383d1310c55d94b2fe7c9692aac5b2f2e7 Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Wed, 28 Jan 2026 10:22:00 +0000 Subject: [PATCH 56/60] chore: update phpunit to 9.6.34 (security fix) --- composer.lock | 53 +++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/composer.lock b/composer.lock index db1096fee8..0ac488570a 100644 --- a/composer.lock +++ b/composer.lock @@ -5564,30 +5564,29 @@ }, { "name": "doctrine/instantiator", - "version": "2.0.0", + "version": "2.1.0", "source": { "type": "git", "url": "https://github.com/doctrine/instantiator.git", - "reference": "c6222283fa3f4ac679f8b9ced9a4e23f163e80d0" + "reference": "23da848e1a2308728fe5fdddabf4be17ff9720c7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/instantiator/zipball/c6222283fa3f4ac679f8b9ced9a4e23f163e80d0", - "reference": "c6222283fa3f4ac679f8b9ced9a4e23f163e80d0", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/23da848e1a2308728fe5fdddabf4be17ff9720c7", + "reference": "23da848e1a2308728fe5fdddabf4be17ff9720c7", "shasum": "" }, "require": { - "php": "^8.1" + "php": "^8.4" }, "require-dev": { - "doctrine/coding-standard": "^11", + "doctrine/coding-standard": "^14", "ext-pdo": "*", "ext-phar": "*", "phpbench/phpbench": "^1.2", - "phpstan/phpstan": "^1.9.4", - "phpstan/phpstan-phpunit": "^1.3", - "phpunit/phpunit": "^9.5.27", - "vimeo/psalm": "^5.4" + "phpstan/phpstan": "^2.1", + "phpstan/phpstan-phpunit": "^2.0", + "phpunit/phpunit": "^10.5.58" }, "type": "library", "autoload": { @@ -5614,7 +5613,7 @@ ], "support": { "issues": "https://github.com/doctrine/instantiator/issues", - "source": "https://github.com/doctrine/instantiator/tree/2.0.0" + "source": "https://github.com/doctrine/instantiator/tree/2.1.0" }, "funding": [ { @@ -5630,7 +5629,7 @@ "type": "tidelift" } ], - "time": "2022-12-30T00:23:10+00:00" + "time": "2026-01-05T06:47:08+00:00" }, { "name": "doctrine/lexer", @@ -6664,16 +6663,16 @@ }, { "name": "phpunit/phpunit", - "version": "9.6.31", + "version": "9.6.34", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "945d0b7f346a084ce5549e95289962972c4272e5" + "reference": "b36f02317466907a230d3aa1d34467041271ef4a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/945d0b7f346a084ce5549e95289962972c4272e5", - "reference": "945d0b7f346a084ce5549e95289962972c4272e5", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/b36f02317466907a230d3aa1d34467041271ef4a", + "reference": "b36f02317466907a230d3aa1d34467041271ef4a", "shasum": "" }, "require": { @@ -6695,7 +6694,7 @@ "phpunit/php-timer": "^5.0.3", "sebastian/cli-parser": "^1.0.2", "sebastian/code-unit": "^1.0.8", - "sebastian/comparator": "^4.0.9", + "sebastian/comparator": "^4.0.10", "sebastian/diff": "^4.0.6", "sebastian/environment": "^5.1.5", "sebastian/exporter": "^4.0.8", @@ -6747,7 +6746,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.31" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.34" }, "funding": [ { @@ -6771,7 +6770,7 @@ "type": "tidelift" } ], - "time": "2025-12-06T07:45:52+00:00" + "time": "2026-01-27T05:45:00+00:00" }, { "name": "psr/cache", @@ -6991,16 +6990,16 @@ }, { "name": "sebastian/comparator", - "version": "4.0.9", + "version": "4.0.10", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/comparator.git", - "reference": "67a2df3a62639eab2cc5906065e9805d4fd5dfc5" + "reference": "e4df00b9b3571187db2831ae9aada2c6efbd715d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/67a2df3a62639eab2cc5906065e9805d4fd5dfc5", - "reference": "67a2df3a62639eab2cc5906065e9805d4fd5dfc5", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/e4df00b9b3571187db2831ae9aada2c6efbd715d", + "reference": "e4df00b9b3571187db2831ae9aada2c6efbd715d", "shasum": "" }, "require": { @@ -7053,7 +7052,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/comparator/issues", - "source": "https://github.com/sebastianbergmann/comparator/tree/4.0.9" + "source": "https://github.com/sebastianbergmann/comparator/tree/4.0.10" }, "funding": [ { @@ -7073,7 +7072,7 @@ "type": "tidelift" } ], - "time": "2025-08-10T06:51:50+00:00" + "time": "2026-01-24T09:22:56+00:00" }, { "name": "sebastian/complexity", @@ -8943,7 +8942,7 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": {}, + "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, "platform": { @@ -8967,5 +8966,5 @@ "platform-overrides": { "php": "8.3" }, - "plugin-api-version": "2.9.0" + "plugin-api-version": "2.6.0" } From 2f3fa9e0d3138704b48e7c09a5aa4adc61377348 Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Wed, 28 Jan 2026 11:42:51 +0000 Subject: [PATCH 57/60] sync CONTRIBUTING.md with 1.8.x --- CONTRIBUTING.md | 78 ++++++++++++++++++------------------------------- 1 file changed, 28 insertions(+), 50 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 96b0614165..c6837673d5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -222,73 +222,51 @@ Appwrite's current structure is a combination of both [Monolithic](https://en.wi ```bash . ├── app # Main application -│ ├── assets -│ │ ├── dbip -│ │ ├── fonts -│ │ └── security │ ├── config # Config files -│ │ ├── avatars -│ │ ├── collections -│ │ ├── locale -│ │ ├── specs -│ │ ├── storage -│ │ └── templates │ ├── controllers # API & dashboard controllers │ │ ├── api │ │ ├── shared │ │ └── web -│ ├── init # DB schemas -│ │ └── database -│ └── views # HTML server-side templates -│ ├── general -│ └── install +│ ├── db # DB schemas +│ ├── sdks # SDKs generated copies (used for generating code examples) +│ ├── tasks # Server CLI commands +│ ├── views # HTML server-side templates +│ └── workers # Background workers ├── bin # Server executables (tasks & workers) -├── dev # Debugger config +├── docker # Docker related resources and configs ├── docs # Docs and tutorials │ ├── examples -│ ├── lists │ ├── references -│ ├── sdks │ ├── services │ ├── specs │ └── tutorials ├── public # Public files +│ ├── dist │ ├── fonts │ ├── images -│ ├── sdk-console -│ ├── sdk-project -│ └── sdk-web -├── src # Supporting libraries (each lib has one role, common libs are released as -│ ├── Appwrite -│ │ ├── Auth -│ │ ├── Certificates -│ │ ├── Deletes -│ │ ├── Detector -│ │ ├── Docker -│ │ ├── Event -│ │ ├── Extend -│ │ ├── Functions/Validator -│ │ ├── GraphQL -│ │ ├── Hooks -│ │ ├── Messaging -│ │ ├── Migration -│ │ ├── Network -│ │ ├── OpenSSL -│ │ ├── Platform -│ │ ├── Promises -│ │ ├── PubSub -│ │ ├── SDK -│ │ ├── Task/Validator -│ │ ├── Template -│ │ ├── Transformation -│ │ ├── URL -│ │ ├── Utopia -│ │ └── Vcs -│ └── Executor +│ ├── scripts +│ └── styles +├── src # Supporting libraries (each lib has one role, common libs are released as individual projects) +│ └── Appwrite +│ ├── Auth +│ ├── Detector +│ ├── Docker +| ├── DSN +│ ├── Event +│ ├── Extend +│ ├── GraphQL +│ ├── Messaging +│ ├── Migration +│ ├── Network +│ ├── OpenSSL +│ ├── Promises +│ ├── Specification +│ ├── Task +│ ├── Template +│ ├── URL +│ └── Utopia └── tests # End to end & unit tests - ├── benchmarks ├── e2e - ├── extensions ├── resources └── unit ``` From 14a96a2b56a79c665de8bc4a9f5e75d9864fd02f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Wed, 28 Jan 2026 14:50:17 +0100 Subject: [PATCH 58/60] Remove unnessessary attributes --- app/config/collections/platform.php | 24 ------------------------ app/controllers/api/projects.php | 3 --- app/controllers/mock.php | 3 --- 3 files changed, 30 deletions(-) diff --git a/app/config/collections/platform.php b/app/config/collections/platform.php index 73c9eea870..2fb3168c5b 100644 --- a/app/config/collections/platform.php +++ b/app/config/collections/platform.php @@ -632,30 +632,6 @@ $platformCollections = [ '$id' => ID::custom('keys'), 'name' => 'keys', 'attributes' => [ - // Delete eventuelly, when removing dual-write too - [ - '$id' => ID::custom('projectInternalId'), - 'type' => Database::VAR_STRING, - 'format' => '', - 'size' => Database::LENGTH_KEY, - 'signed' => true, - 'required' => false, - 'default' => null, - 'array' => false, - 'filters' => [], - ], - // Delete eventuelly, when removing dual-write too - [ - '$id' => ID::custom('projectId'), - 'type' => Database::VAR_STRING, - 'format' => '', - 'size' => Database::LENGTH_KEY, - 'signed' => true, - 'required' => false, - 'default' => 0, - 'array' => false, - 'filters' => [], - ], [ '$id' => ID::custom('resourceType'), 'type' => Database::VAR_STRING, diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 1e03c861d1..57ad3030d9 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -1502,9 +1502,6 @@ App::post('/v1/projects/:projectId/keys') Permission::update(Role::any()), Permission::delete(Role::any()), ], - // TODO: @hmacr Remove `projectInternalId` and `projectId` column writes before deleting the column. - 'projectInternalId' => $project->getSequence(), - 'projectId' => $project->getId(), 'resourceInternalId' => $project->getSequence(), 'resourceId' => $project->getId(), 'resourceType' => 'projects', diff --git a/app/controllers/mock.php b/app/controllers/mock.php index 16d6d72de7..42b300e410 100644 --- a/app/controllers/mock.php +++ b/app/controllers/mock.php @@ -200,9 +200,6 @@ App::post('/v1/mock/api-key-unprefixed') Permission::update(Role::any()), Permission::delete(Role::any()), ], - // TODO: @hmacr Remove `projectInternalId` and `projectId` column writes before deleting the column. - 'projectInternalId' => $project->getSequence(), - 'projectId' => $project->getId(), 'resourceInternalId' => $project->getSequence(), 'resourceId' => $project->getId(), 'resourceType' => 'projects', From e22e8d6a5fe617ed76d53d2d5565854c36addcac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Wed, 28 Jan 2026 14:55:13 +0100 Subject: [PATCH 59/60] Upgrade phpunit for vuln --- composer.lock | 80 +++++++++++++++++++++++++-------------------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/composer.lock b/composer.lock index bd56277819..1c7e6c2a5b 100644 --- a/composer.lock +++ b/composer.lock @@ -2066,16 +2066,16 @@ }, { "name": "phpseclib/phpseclib", - "version": "3.0.48", + "version": "3.0.49", "source": { "type": "git", "url": "https://github.com/phpseclib/phpseclib.git", - "reference": "64065a5679c50acb886e82c07aa139b0f757bb89" + "reference": "6233a1e12584754e6b5daa69fe1289b47775c1b9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/64065a5679c50acb886e82c07aa139b0f757bb89", - "reference": "64065a5679c50acb886e82c07aa139b0f757bb89", + "url": "https://api.github.com/repos/phpseclib/phpseclib/zipball/6233a1e12584754e6b5daa69fe1289b47775c1b9", + "reference": "6233a1e12584754e6b5daa69fe1289b47775c1b9", "shasum": "" }, "require": { @@ -2156,7 +2156,7 @@ ], "support": { "issues": "https://github.com/phpseclib/phpseclib/issues", - "source": "https://github.com/phpseclib/phpseclib/tree/3.0.48" + "source": "https://github.com/phpseclib/phpseclib/tree/3.0.49" }, "funding": [ { @@ -2172,7 +2172,7 @@ "type": "tidelift" } ], - "time": "2025-12-15T11:51:42+00:00" + "time": "2026-01-27T09:17:28+00:00" }, { "name": "psr/container", @@ -2735,16 +2735,16 @@ }, { "name": "symfony/http-client", - "version": "v7.4.4", + "version": "v7.4.5", "source": { "type": "git", "url": "https://github.com/symfony/http-client.git", - "reference": "d63c23357d74715a589454c141c843f0172bec6c" + "reference": "84bb634857a893cc146cceb467e31b3f02c5fe9f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-client/zipball/d63c23357d74715a589454c141c843f0172bec6c", - "reference": "d63c23357d74715a589454c141c843f0172bec6c", + "url": "https://api.github.com/repos/symfony/http-client/zipball/84bb634857a893cc146cceb467e31b3f02c5fe9f", + "reference": "84bb634857a893cc146cceb467e31b3f02c5fe9f", "shasum": "" }, "require": { @@ -2812,7 +2812,7 @@ "http" ], "support": { - "source": "https://github.com/symfony/http-client/tree/v7.4.4" + "source": "https://github.com/symfony/http-client/tree/v7.4.5" }, "funding": [ { @@ -2832,7 +2832,7 @@ "type": "tidelift" } ], - "time": "2026-01-23T16:34:22+00:00" + "time": "2026-01-27T16:16:02+00:00" }, { "name": "symfony/http-client-contracts", @@ -5120,28 +5120,28 @@ }, { "name": "utopia-php/swoole", - "version": "1.0.0", + "version": "1.0.1", "source": { "type": "git", "url": "https://github.com/utopia-php/swoole.git", - "reference": "95a937acb393dbf95cccba239d55886e2848ab0b" + "reference": "c5ce710dfffc4df09bf3e7aea2d1e55c53e77a95" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/swoole/zipball/95a937acb393dbf95cccba239d55886e2848ab0b", - "reference": "95a937acb393dbf95cccba239d55886e2848ab0b", + "url": "https://api.github.com/repos/utopia-php/swoole/zipball/c5ce710dfffc4df09bf3e7aea2d1e55c53e77a95", + "reference": "c5ce710dfffc4df09bf3e7aea2d1e55c53e77a95", "shasum": "" }, "require": { - "ext-swoole": "*", - "php": ">=8.0", + "ext-swoole": "6.*", + "php": ">=8.1", "utopia-php/framework": "0.33.37" }, "require-dev": { "laravel/pint": "1.2.*", "phpstan/phpstan": "^1.10", "phpunit/phpunit": "^9.3", - "swoole/ide-helper": "5.0.2" + "swoole/ide-helper": "6.0.2" }, "type": "library", "autoload": { @@ -5165,9 +5165,9 @@ ], "support": { "issues": "https://github.com/utopia-php/swoole/issues", - "source": "https://github.com/utopia-php/swoole/tree/1.0.0" + "source": "https://github.com/utopia-php/swoole/tree/1.0.1" }, - "time": "2026-01-14T14:00:11+00:00" + "time": "2026-01-28T12:43:38+00:00" }, { "name": "utopia-php/system", @@ -6772,16 +6772,16 @@ }, { "name": "phpunit/phpunit", - "version": "9.6.32", + "version": "9.6.34", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "492ee10a8369a1c1ac390a3b46e0c846e384c5a4" + "reference": "b36f02317466907a230d3aa1d34467041271ef4a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/492ee10a8369a1c1ac390a3b46e0c846e384c5a4", - "reference": "492ee10a8369a1c1ac390a3b46e0c846e384c5a4", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/b36f02317466907a230d3aa1d34467041271ef4a", + "reference": "b36f02317466907a230d3aa1d34467041271ef4a", "shasum": "" }, "require": { @@ -6855,7 +6855,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.32" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.34" }, "funding": [ { @@ -6879,7 +6879,7 @@ "type": "tidelift" } ], - "time": "2026-01-24T16:04:20+00:00" + "time": "2026-01-27T05:45:00+00:00" }, { "name": "psr/cache", @@ -8199,16 +8199,16 @@ }, { "name": "symfony/finder", - "version": "v8.0.4", + "version": "v8.0.5", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", - "reference": "42e48eb02e07d5f3771d194d67da117eb824c8c1" + "reference": "8bd576e97c67d45941365bf824e18dc8538e6eb0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/42e48eb02e07d5f3771d194d67da117eb824c8c1", - "reference": "42e48eb02e07d5f3771d194d67da117eb824c8c1", + "url": "https://api.github.com/repos/symfony/finder/zipball/8bd576e97c67d45941365bf824e18dc8538e6eb0", + "reference": "8bd576e97c67d45941365bf824e18dc8538e6eb0", "shasum": "" }, "require": { @@ -8243,7 +8243,7 @@ "description": "Finds files and directories via an intuitive fluent interface", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/finder/tree/v8.0.4" + "source": "https://github.com/symfony/finder/tree/v8.0.5" }, "funding": [ { @@ -8263,7 +8263,7 @@ "type": "tidelift" } ], - "time": "2026-01-12T12:37:40+00:00" + "time": "2026-01-26T15:08:38+00:00" }, { "name": "symfony/options-resolver", @@ -8668,16 +8668,16 @@ }, { "name": "symfony/process", - "version": "v8.0.4", + "version": "v8.0.5", "source": { "type": "git", "url": "https://github.com/symfony/process.git", - "reference": "10df72602d88c0a3fa685b822976a052611dd607" + "reference": "b5f3aa6762e33fd95efbaa2ec4f4bc9fdd16d674" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/10df72602d88c0a3fa685b822976a052611dd607", - "reference": "10df72602d88c0a3fa685b822976a052611dd607", + "url": "https://api.github.com/repos/symfony/process/zipball/b5f3aa6762e33fd95efbaa2ec4f4bc9fdd16d674", + "reference": "b5f3aa6762e33fd95efbaa2ec4f4bc9fdd16d674", "shasum": "" }, "require": { @@ -8709,7 +8709,7 @@ "description": "Executes commands in sub-processes", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/process/tree/v8.0.4" + "source": "https://github.com/symfony/process/tree/v8.0.5" }, "funding": [ { @@ -8729,7 +8729,7 @@ "type": "tidelift" } ], - "time": "2026-01-23T11:07:10+00:00" + "time": "2026-01-26T15:08:38+00:00" }, { "name": "symfony/string", @@ -9075,5 +9075,5 @@ "platform-overrides": { "php": "8.3" }, - "plugin-api-version": "2.6.0" + "plugin-api-version": "2.9.0" } From 23dae85d2f409a2972207ffa3b17c969189e8be8 Mon Sep 17 00:00:00 2001 From: Prem Palanisamy Date: Wed, 28 Jan 2026 18:45:11 +0000 Subject: [PATCH 60/60] Sync composer.lock with 1.8.x --- composer.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.lock b/composer.lock index fa87eebe72..1c7e6c2a5b 100644 --- a/composer.lock +++ b/composer.lock @@ -9051,7 +9051,7 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": {}, "prefer-stable": false, "prefer-lowest": false, "platform": {