diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index cf1e55f7ec..766b295fff 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -145,7 +145,7 @@ jobs: Account, Avatars, Console, - Databases/Collections, + Databases/Legacy, Databases/Tables, Functions, FunctionsSchedule, @@ -214,7 +214,7 @@ jobs: Account, Avatars, Console, - Databases/Collections, + Databases/Legacy, Databases/Tables, Functions, FunctionsSchedule, diff --git a/app/config/collections/projects.php b/app/config/collections/projects.php index 48a0938a1c..ac14421382 100644 --- a/app/config/collections/projects.php +++ b/app/config/collections/projects.php @@ -1286,6 +1286,7 @@ return [ ] ], ], + 'deployments' => [ '$collection' => ID::custom(Database::METADATA), '$id' => ID::custom('deployments'), diff --git a/app/config/console.php b/app/config/console.php index 1de3a99370..aa7de13ba0 100644 --- a/app/config/console.php +++ b/app/config/console.php @@ -39,7 +39,8 @@ $console = [ 'invites' => System::getEnv('_APP_CONSOLE_INVITES', 'enabled') === 'enabled', 'limit' => (System::getEnv('_APP_CONSOLE_WHITELIST_ROOT', 'enabled') === 'enabled') ? 1 : 0, // limit signup to 1 user 'duration' => Auth::TOKEN_EXPIRATION_LOGIN_LONG, // 1 Year in seconds - 'sessionAlerts' => System::getEnv('_APP_CONSOLE_SESSION_ALERTS', 'disabled') === 'enabled' + 'sessionAlerts' => System::getEnv('_APP_CONSOLE_SESSION_ALERTS', 'disabled') === 'enabled', + 'invalidateSessions' => true ], 'authWhitelistEmails' => (!empty(System::getEnv('_APP_CONSOLE_WHITELIST_EMAILS', null))) ? \explode(',', System::getEnv('_APP_CONSOLE_WHITELIST_EMAILS', null)) : [], 'authWhitelistIPs' => (!empty(System::getEnv('_APP_CONSOLE_WHITELIST_IPS', null))) ? \explode(',', System::getEnv('_APP_CONSOLE_WHITELIST_IPS', null)) : [], diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 2d0d0eac40..2bb009cf61 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -2843,6 +2843,18 @@ App::patch('/v1/account/password') ->setAttribute('hash', Auth::DEFAULT_ALGO) ->setAttribute('hashOptions', Auth::DEFAULT_ALGO_OPTIONS); + $sessions = $user->getAttribute('sessions', []); + $current = Auth::sessionVerify($sessions, Auth::$secret); + $invalidate = $project->getAttribute('auths', default: [])['invalidateSessions'] ?? false; + if ($invalidate && !empty($current)) { + foreach ($sessions as $session) { + /** @var Document $session */ + if ($session->getId() !== $current) { + $dbForProject->deleteDocument('sessions', $session->getId()); + } + } + } + $user = $dbForProject->updateDocument('users', $user->getId(), $user); $queueForEvents->setParam('userId', $user->getId()); diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 3474f6ced0..5527a6bd18 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -127,6 +127,7 @@ App::post('/v1/projects') 'membershipsUserName' => false, 'membershipsUserEmail' => false, 'membershipsMfa' => false, + 'invalidateSessions' => true ]; foreach ($auth as $method) { @@ -2499,3 +2500,40 @@ App::delete('/v1/projects/:projectId/templates/email/:type/:locale') 'message' => $template['message'] ]), Response::MODEL_EMAIL_TEMPLATE); }); + +App::patch('/v1/projects/:projectId/auth/session-invalidation') + ->desc('Update invalidate session option of the project') + ->groups(['api', 'projects']) + ->label('scope', 'projects.write') + ->label('sdk', new Method( + namespace: 'projects', + group: 'auth', + name: 'updateSessionInvalidation', + description: '/docs/references/projects/update-session-invalidation.md', + auth: [AuthType::ADMIN], + responses: [ + new SDKResponse( + code: Response::STATUS_CODE_OK, + model: Response::MODEL_PROJECT, + ) + ] + )) + ->param('projectId', '', new UID(), 'Project unique ID.') + ->param('enabled', false, new Boolean(), 'Update authentication session invalidation status. Use this endpoint to enable or disable session invalidation on password change') + ->inject('response') + ->inject('dbForPlatform') + ->action(function (string $projectId, bool $invalidateSessions, Response $response, Database $dbForPlatform) { + + $project = $dbForPlatform->getDocument('projects', $projectId); + + if ($project->isEmpty()) { + throw new Exception(Exception::PROJECT_NOT_FOUND); + } + + $auths = $project->getAttribute('auths', []); + $auths['invalidateSessions'] = $invalidateSessions; + $dbForPlatform->updateDocument('projects', $project->getId(), $project + ->setAttribute('auths', $auths)); + + $response->dynamic($project, Response::MODEL_PROJECT); + }); diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index d7def69464..0b580170e1 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -1351,6 +1351,17 @@ App::patch('/v1/users/:userId/password') $user = $dbForProject->updateDocument('users', $user->getId(), $user); + $sessions = $user->getAttribute('sessions', []); + $invalidate = $project->getAttribute('auths', default: [])['invalidateSessions'] ?? false; + if ($invalidate) { + foreach ($sessions as $session) { + /** @var Document $session */ + $dbForProject->deleteDocument('sessions', $session->getId()); + } + } + + $dbForProject->purgeCachedDocument('users', $user->getId()); + $queueForEvents->setParam('userId', $user->getId()); $response->dynamic($user, Response::MODEL_USER); diff --git a/app/controllers/api/vcs.php b/app/controllers/api/vcs.php index 69d4c490d9..e8bbd2854c 100644 --- a/app/controllers/api/vcs.php +++ b/app/controllers/api/vcs.php @@ -363,6 +363,7 @@ $createGitDeployments = function (GitHub $github, string $providerInstallationId if (!empty($providerCommitHash) && $resource->getAttribute('providerSilentMode', false) === false) { $resourceName = $resource->getAttribute('name'); $projectName = $project->getAttribute('name'); + $region = $project->getAttribute('region', 'default'); $name = "{$resourceName} ({$projectName})"; $message = 'Starting...'; @@ -377,7 +378,7 @@ $createGitDeployments = function (GitHub $github, string $providerInstallationId } $owner = $github->getOwnerName($providerInstallationId); - $providerTargetUrl = $request->getProtocol() . '://' . $request->getHostname() . "/console/project-$projectId/$resourceCollection/$resourceType-$resourceId"; + $providerTargetUrl = $request->getProtocol() . '://' . $request->getHostname() . "/console/project-$region-$projectId/$resourceCollection/$resourceType-$resourceId"; $github->updateCommitStatus($repositoryName, $providerCommitHash, $owner, 'pending', $message, $providerTargetUrl, $name); } @@ -476,16 +477,6 @@ App::get('/v1/vcs/github/callback') $state = \json_decode($state, true); $projectId = $state['projectId'] ?? ''; - $defaultState = [ - 'success' => $request->getProtocol() . '://' . $request->getHostname() . "/console/project-$projectId/settings/git-installations", - 'failure' => $request->getProtocol() . '://' . $request->getHostname() . "/console/project-$projectId/settings/git-installations", - ]; - - $state = \array_merge($defaultState, $state ?? []); - - $redirectSuccess = $state['success'] ?? ''; - $redirectFailure = $state['failure'] ?? ''; - $project = $dbForPlatform->getDocument('projects', $projectId); if ($project->isEmpty()) { @@ -502,6 +493,18 @@ App::get('/v1/vcs/github/callback') throw new Exception(Exception::PROJECT_NOT_FOUND, $error); } + $region = $project->getAttribute('region', 'default'); + + $defaultState = [ + 'success' => $request->getProtocol() . '://' . $request->getHostname() . "/console/project-$region-$projectId/settings/git-installations", + 'failure' => $request->getProtocol() . '://' . $request->getHostname() . "/console/project-$region-$projectId/settings/git-installations", + ]; + + $state = \array_merge($defaultState, $state ?? []); + + $redirectSuccess = $state['success'] ?? ''; + $redirectFailure = $state['failure'] ?? ''; + // Create / Update installation if (!empty($providerInstallationId)) { $privateKey = System::getEnv('_APP_VCS_GITHUB_PRIVATE_KEY'); diff --git a/app/controllers/general.php b/app/controllers/general.php index 1872ba82e3..61a9cc9bfa 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -186,7 +186,7 @@ function router(App $utopia, Database $dbForPlatform, callable $getProjectDB, Sw $resourceId = $rule->getAttribute('deploymentResourceId', ''); $type = ($resourceType === 'site') ? 'sites' : 'functions'; $exception = new AppwriteException(AppwriteException::DEPLOYMENT_NOT_FOUND, view: $errorView); - $exception->addCTA('View deployments', $url . '/console/project-' . $projectId . '/' . $type . '/' . $resourceType . '-' . $resourceId); + $exception->addCTA('View deployments', $url . '/console/project-' . $project->getAttribute('region', 'default') . '-' . $projectId . '/' . $type . '/' . $resourceType . '-' . $resourceId); throw $exception; } @@ -319,21 +319,22 @@ function router(App $utopia, Database $dbForPlatform, callable $getProjectDB, Sw $allowAnyStatus = !\is_null($apiKey) && $apiKey->isDeploymentStatusIgnored(); if (!$allowAnyStatus && $deployment->getAttribute('status') !== 'ready') { $status = $deployment->getAttribute('status'); + $region = $project->getAttribute('region', 'default'); switch ($status) { case 'failed': $exception = new AppwriteException(AppwriteException::BUILD_FAILED, view: $errorView); - $ctaUrl = '/console/project-' . $project->getId() . '/sites/site-' . $resource->getId() . '/deployments/deployment-' . $deployment->getId(); + $ctaUrl = '/console/project-' . $region . '-' . $project->getId() . '/sites/site-' . $resource->getId() . '/deployments/deployment-' . $deployment->getId(); $exception->addCTA('View logs', $url . $ctaUrl); break; case 'canceled': $exception = new AppwriteException(AppwriteException::BUILD_CANCELED, view: $errorView); - $ctaUrl = '/console/project-' . $project->getId() . '/sites/site-' . $resource->getId() . '/deployments'; + $ctaUrl = '/console/project-' . $region . '-' . $project->getId() . '/sites/site-' . $resource->getId() . '/deployments'; $exception->addCTA('View deployments', $url . $ctaUrl); break; default: $exception = new AppwriteException(AppwriteException::BUILD_NOT_READY, view: $errorView); - $ctaUrl = '/console/project-' . $project->getId() . '/sites/site-' . $resource->getId() . '/deployments/deployment-' . $deployment->getId(); + $ctaUrl = '/console/project-' . $region . '-' . $project->getId() . '/sites/site-' . $resource->getId() . '/deployments/deployment-' . $deployment->getId(); $exception->addCTA('Reload', '/'); $exception->addCTA('View logs', $url . $ctaUrl); break; @@ -345,7 +346,7 @@ function router(App $utopia, Database $dbForPlatform, callable $getProjectDB, Sw $permissions = $resource->getAttribute('execute'); if (!(\in_array('any', $permissions)) && !(\in_array('guests', $permissions))) { $exception = new AppwriteException(AppwriteException::FUNCTION_EXECUTE_PERMISSION_MISSING, view: $errorView); - $exception->addCTA('View settings', $url . '/console/project-' . $project->getId() . '/functions/function-' . $resource->getId() . '/settings'); + $exception->addCTA('View settings', $url . '/console/project-' . $project->getAttribute('region', 'default') . '-' . $project->getId() . '/functions/function-' . $resource->getId() . '/settings'); throw $exception; } } @@ -1582,20 +1583,6 @@ foreach (Config::getParam('services', []) as $service) { } } -// legacy controller init hooks as the endpoint controller logic is now moved to a module structure. -// 1. databases -App::init() - ->groups(['api', 'database']) - ->inject('request') - ->inject('dbForProject') - ->action(function (Request $request, Database $dbForProject) { - $timeout = \intval($request->getHeader('x-appwrite-timeout')); - - if (!empty($timeout) && App::isDevelopment()) { - $dbForProject->setTimeout($timeout); - } - }); - // Check for any errors found while we were initialising the SDK Methods. if (!empty(Method::getErrors())) { throw new \Exception('Errors found during SDK initialization:' . PHP_EOL . implode(PHP_EOL, Method::getErrors())); diff --git a/docs/references/projects/update-session-invalidation.md b/docs/references/projects/update-session-invalidation.md new file mode 100644 index 0000000000..cbaf378624 --- /dev/null +++ b/docs/references/projects/update-session-invalidation.md @@ -0,0 +1 @@ +Invalidate all existing sessions. An optional auth security setting for projects, and enabled by default for console project. \ No newline at end of file diff --git a/src/Appwrite/Platform/Modules/Databases/Constants.php b/src/Appwrite/Platform/Modules/Databases/Constants.php new file mode 100644 index 0000000000..cfc297c3f4 --- /dev/null +++ b/src/Appwrite/Platform/Modules/Databases/Constants.php @@ -0,0 +1,24 @@ +context = TABLES; } - $this->context = $context; + return parent::setHttpPath($path); } /** @@ -53,7 +48,7 @@ abstract class Action extends UtopiaAction */ final protected function isCollectionsAPI(): bool { - return $this->getContext() === Context::DATABASE_COLLECTIONS; + return $this->getContext() === COLLECTIONS; } /** @@ -64,6 +59,14 @@ abstract class Action extends UtopiaAction return $this->isCollectionsAPI() ? 'collections' : 'tables'; } + /** + * Get the SDK namespace for the current action. + */ + final protected function getSdkNamespace(): string + { + return $this->isCollectionsAPI() ? 'databases' : 'tables'; + } + /** * Get the exception to throw when the resource already exists. */ diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Action.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Action.php index 2ee265a18d..3f331edc9a 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Action.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Action.php @@ -5,7 +5,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attribu use Appwrite\Event\Database as EventDatabase; use Appwrite\Event\Event; use Appwrite\Extend\Exception; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Utopia\Response; use Appwrite\Utopia\Response as UtopiaResponse; use Throwable; @@ -29,25 +28,20 @@ abstract class Action extends UtopiaAction /** * @var string|null The current context (either 'column' or 'attribute') */ - private ?string $context = Context::DATABASE_ATTRIBUTES; + private ?string $context = ATTRIBUTES; /** * Get the correct response model. */ abstract protected function getResponseModel(): string|array; - /** - * Set the context to either `column` or `attribute`. - * - * @throws \InvalidArgumentException If the context is invalid. - */ - final protected function setContext(string $context): void + public function setHttpPath(string $path): UtopiaAction { - if (!\in_array($context, [Context::DATABASE_COLUMNS, Context::DATABASE_ATTRIBUTES], true)) { - throw new \InvalidArgumentException("Invalid context '$context'. Use `Context::DATABASE_COLUMNS` or `Context::DATABASE_ATTRIBUTES`"); + if (str_contains($path, '/:databaseId/tables')) { + $this->context = COLUMNS; } - $this->context = $context; + return parent::setHttpPath($path); } /** @@ -65,7 +59,7 @@ abstract class Action extends UtopiaAction { // columns in tables context // attributes in collections context - return $this->getContext() === Context::DATABASE_ATTRIBUTES; + return $this->getContext() === ATTRIBUTES; } /** @@ -83,7 +77,7 @@ abstract class Action extends UtopiaAction */ final protected function getSdkNamespace(): string { - return $this->isCollectionsAPI() ? 'collections' : 'tables'; + return $this->isCollectionsAPI() ? 'databases' : 'tables'; } /** @@ -227,7 +221,7 @@ abstract class Action extends UtopiaAction /** * Get the proper column/attribute type based on set context. */ - final protected function getCorrectModel(string $type, string $format): string + final protected function getModel(string $type, string $format): string { $isCollections = $this->isCollectionsAPI(); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Boolean/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Boolean/Create.php index b1fddc0371..c38ef8d703 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Boolean/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Boolean/Create.php @@ -13,14 +13,11 @@ use Utopia\Database\Database; use Utopia\Database\Document; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; class Create extends Action { - use HTTP; - public static function getName(): string { return 'createBooleanAttribute'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Boolean/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Boolean/Update.php index 7aa2360fb8..9bb606edf5 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Boolean/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Boolean/Update.php @@ -12,15 +12,12 @@ use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\Nullable; class Update extends Action { - use HTTP; - public static function getName(): string { return 'updateBooleanAttribute'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Datetime/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Datetime/Create.php index fd54fe0843..ff8054abe4 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Datetime/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Datetime/Create.php @@ -14,14 +14,11 @@ use Utopia\Database\Document; use Utopia\Database\Validator\Datetime as DatetimeValidator; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; class Create extends Action { - use HTTP; - public static function getName(): string { return 'createDatetimeAttribute'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Datetime/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Datetime/Update.php index 17818fec2d..5f8909a294 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Datetime/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Datetime/Update.php @@ -13,15 +13,12 @@ use Utopia\Database\Database; use Utopia\Database\Validator\Datetime as DatetimeValidator; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\Nullable; class Update extends Action { - use HTTP; - public static function getName(): string { return 'updateDatetimeAttribute'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Delete.php index 4582500091..5816de31a2 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Delete.php @@ -15,13 +15,10 @@ use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\IndexDependency as IndexDependencyValidator; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; class Delete extends Action { - use HTTP; - public static function getName(): string { return 'deleteAttribute'; @@ -29,7 +26,6 @@ class Delete extends Action protected function getResponseModel(): string|array { - // we should correctly & carefully set the context later. return UtopiaResponse::MODEL_NONE; } @@ -141,7 +137,7 @@ class Delete extends Action $type = $attribute->getAttribute('type'); $format = $attribute->getAttribute('format'); - $model = $this->getCorrectModel($type, $format); + $model = $this->getModel($type, $format); $queueForEvents ->setContext('database', $db) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Email/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Email/Create.php index 80f0270ea3..3c703f23a7 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Email/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Email/Create.php @@ -14,14 +14,11 @@ use Utopia\Database\Database; use Utopia\Database\Document; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; class Create extends Action { - use HTTP; - public static function getName(): string { return 'createEmailAttribute'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Email/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Email/Update.php index 2f14d8a361..c8a34cf55c 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Email/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Email/Update.php @@ -13,15 +13,12 @@ use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\Nullable; class Update extends Action { - use HTTP; - public static function getName(): string { return 'updateEmailAttribute'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Enum/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Enum/Create.php index 620cd40d3a..76478a505f 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Enum/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Enum/Create.php @@ -14,7 +14,6 @@ use Utopia\Database\Database; use Utopia\Database\Document; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\ArrayList; use Utopia\Validator\Boolean; @@ -22,8 +21,6 @@ use Utopia\Validator\Text; class Create extends Action { - use HTTP; - public static function getName(): string { return 'createEnumAttribute'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Enum/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Enum/Update.php index c2f6d7696c..8624bde78d 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Enum/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Enum/Update.php @@ -12,7 +12,6 @@ use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\ArrayList; use Utopia\Validator\Boolean; @@ -21,8 +20,6 @@ use Utopia\Validator\Text; class Update extends Action { - use HTTP; - public static function getName(): string { return 'updateEnumAttribute'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Float/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Float/Create.php index 35e9bb68a1..520366f689 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Float/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Float/Create.php @@ -14,7 +14,6 @@ use Utopia\Database\Database; use Utopia\Database\Document; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\FloatValidator; @@ -22,8 +21,6 @@ use Utopia\Validator\Range; class Create extends Action { - use HTTP; - public static function getName(): string { return 'createFloatAttribute'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Float/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Float/Update.php index 2fdcf949f1..18a966d91d 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Float/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Float/Update.php @@ -12,7 +12,6 @@ use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\FloatValidator; @@ -20,8 +19,6 @@ use Utopia\Validator\Nullable; class Update extends Action { - use HTTP; - public static function getName(): string { return 'updateFloatAttribute'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Get.php index d49639e049..579f7883e0 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Get.php @@ -11,13 +11,10 @@ use Utopia\Database\Database; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; class Get extends Action { - use HTTP; - public static function getName(): string { return 'getAttribute'; @@ -94,7 +91,7 @@ class Get extends Action $attribute->setAttribute($key, $option); } - $model = $this->getCorrectModel($type, $format); + $model = $this->getModel($type, $format); $attribute->setAttribute('encrypt', in_array('encrypt', $filters)); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/IP/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/IP/Create.php index c62e2add01..e46e508bc6 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/IP/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/IP/Create.php @@ -13,15 +13,12 @@ use Utopia\Database\Database; use Utopia\Database\Document; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\IP; class Create extends Action { - use HTTP; - public static function getName(): string { return 'createIpAttribute'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/IP/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/IP/Update.php index a3e1ea5a61..e9d9404c17 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/IP/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/IP/Update.php @@ -12,7 +12,6 @@ use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\IP; @@ -20,8 +19,6 @@ use Utopia\Validator\Nullable; class Update extends Action { - use HTTP; - public static function getName(): string { return 'updateIpAttribute'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Integer/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Integer/Create.php index 69272b6aea..e348e9a2a6 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Integer/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Integer/Create.php @@ -14,7 +14,6 @@ use Utopia\Database\Database; use Utopia\Database\Document; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\Integer; @@ -22,8 +21,6 @@ use Utopia\Validator\Range; class Create extends Action { - use HTTP; - public static function getName(): string { return 'createIntegerAttribute'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Integer/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Integer/Update.php index 9c05382173..bbbf045115 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Integer/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Integer/Update.php @@ -12,7 +12,6 @@ use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\Integer; @@ -20,8 +19,6 @@ use Utopia\Validator\Nullable; class Update extends Action { - use HTTP; - public static function getName(): string { return 'updateIntegerAttribute'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Relationship/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Relationship/Create.php index fa8d0ad750..795ea445c8 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Relationship/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Relationship/Create.php @@ -15,15 +15,12 @@ use Utopia\Database\Document; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\WhiteList; class Create extends Action { - use HTTP; - public static function getName(): string { return 'createRelationshipAttribute'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Relationship/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Relationship/Update.php index da2d0b9b08..7202a3e4e6 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Relationship/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/Relationship/Update.php @@ -12,14 +12,11 @@ use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\WhiteList; class Update extends Action { - use HTTP; - public static function getName(): string { return 'updateRelationshipAttribute'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/String/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/String/Create.php index cc989f6687..8ce8626f3a 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/String/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/String/Create.php @@ -14,7 +14,6 @@ use Utopia\Database\Database; use Utopia\Database\Document; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator; use Utopia\Validator\Boolean; @@ -23,8 +22,6 @@ use Utopia\Validator\Text; class Create extends Action { - use HTTP; - public static function getName(): string { return 'createStringAttribute'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/String/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/String/Update.php index b3f4cf3f03..b359b83eaa 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/String/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/String/Update.php @@ -12,7 +12,6 @@ use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator; use Utopia\Validator\Boolean; @@ -22,8 +21,6 @@ use Utopia\Validator\Text; class Update extends Action { - use HTTP; - public static function getName(): string { return 'updateStringAttribute'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/URL/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/URL/Create.php index 2d72533cf1..27bc2d38c1 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/URL/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/URL/Create.php @@ -13,15 +13,12 @@ use Utopia\Database\Database; use Utopia\Database\Document; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\URL; class Create extends Action { - use HTTP; - public static function getName(): string { return 'createUrlAttribute'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/URL/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/URL/Update.php index e5c4288d92..ae48c43653 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/URL/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/URL/Update.php @@ -12,7 +12,6 @@ use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\Nullable; @@ -20,8 +19,6 @@ use Utopia\Validator\URL; class Update extends Action { - use HTTP; - public static function getName(): string { return 'updateUrlAttribute'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/XList.php index 2509115e13..e09420d7ce 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Attributes/XList.php @@ -16,13 +16,10 @@ use Utopia\Database\Query; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\Query\Cursor; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; class XList extends Action { - use HTTP; - public static function getName(): string { return 'listAttributes'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Create.php index 5edce7715f..176c3ca853 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Create.php @@ -21,15 +21,12 @@ use Utopia\Database\Helpers\Permission; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\Permissions; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\Text; class Create extends Action { - use HTTP; - public static function getName(): string { return 'createCollection'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Delete.php index b8080ab471..e4618a40b7 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Delete.php @@ -13,13 +13,10 @@ use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; class Delete extends Action { - use HTTP; - public static function getName(): string { return 'deleteCollection'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Action.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Action.php index c0e71d3730..bfebca4cf7 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Action.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Action.php @@ -3,7 +3,9 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Documents; use Appwrite\Extend\Exception; -use Appwrite\Platform\Modules\Databases\Context; +use Utopia\Database\Database; +use Utopia\Database\Document; +use Utopia\Database\Validator\Authorization; use Utopia\Platform\Action as UtopiaAction; abstract class Action extends UtopiaAction @@ -11,25 +13,20 @@ abstract class Action extends UtopiaAction /** * @var string|null The current context (either 'row' or 'document') */ - private ?string $context = Context::DATABASE_DOCUMENTS; + private ?string $context = DOCUMENTS; /** * Get the response model used in the SDK and HTTP responses. */ abstract protected function getResponseModel(): string; - /** - * Set the context to either `row` or `document`. - * - * @throws \InvalidArgumentException If the context is invalid. - */ - final protected function setContext(string $context): void + public function setHttpPath(string $path): UtopiaAction { - if (!\in_array($context, [Context::DATABASE_ROWS, Context::DATABASE_DOCUMENTS], true)) { - throw new \InvalidArgumentException("Invalid context '$context'. Use `Context::DATABASE_ROWS` or `Context::DATABASE_DOCUMENTS`"); + if (str_contains($path, '/:databaseId/tables')) { + $this->context = ROWS; } - $this->context = $context; + return parent::setHttpPath($path); } /** @@ -57,7 +54,7 @@ abstract class Action extends UtopiaAction { // rows in tables api context // documents in collections api context - return $this->getContext() === Context::DATABASE_DOCUMENTS; + return $this->getContext() === DOCUMENTS; } /** @@ -75,7 +72,7 @@ abstract class Action extends UtopiaAction */ final protected function getSdkNamespace(): string { - return $this->isCollectionsAPI() ? 'collections' : 'tables'; + return $this->isCollectionsAPI() ? 'databases' : 'tables'; } /** @@ -193,4 +190,93 @@ abstract class Action extends UtopiaAction { return $this->isCollectionsAPI() ? 'collection' : 'table'; } + + /** + * Resolves relationships in a document and attaches metadata. + */ + final protected function processDocument( + /* database */ + Document $database, + Document $collection, + Document $document, + Database $dbForProject, + + /* options */ + array &$collectionsCache, + ?int &$operations = null, + ): bool { + + if ($operations !== null && $document->isEmpty()) { + return false; + } + + if ($operations !== null) { + $operations++; + } + + $collectionId = $collection->getId(); + $document->removeAttribute('$collection'); + $document->setAttribute('$databaseId', $database->getId()); + $document->setAttribute('$collectionId', $collectionId); + + $relationships = $collectionsCache[$collectionId] ??= \array_filter( + $collection->getAttribute('attributes', []), + fn ($attr) => $attr->getAttribute('type') === Database::VAR_RELATIONSHIP + ); + + foreach ($relationships as $relationship) { + $key = $relationship->getAttribute('key'); + $related = $document->getAttribute($key); + + if (empty($related)) { + if (\in_array(\gettype($related), ['array', 'object']) && $operations !== null) { + $operations++; + } + continue; + } + + $relations = \is_array($related) ? $related : [$related]; + $relatedCollectionId = $relationship->getAttribute('relatedCollection'); + + if (!isset($collectionsCache[$relatedCollectionId])) { + $relatedCollectionDoc = Authorization::skip( + fn () => $dbForProject->getDocument( + 'database_' . $database->getSequence(), + $relatedCollectionId + ) + ); + + $collectionsCache[$relatedCollectionId] = \array_filter( + $relatedCollectionDoc->getAttribute('attributes', []), + fn ($attr) => $attr->getAttribute('type') === Database::VAR_RELATIONSHIP + ); + } + + foreach ($relations as $relation) { + if ($relation instanceof Document) { + $relatedCollection = new Document([ + '$id' => $relatedCollectionId, + 'attributes' => $collectionsCache[$relatedCollectionId], + ]); + + $this->processDocument( + database: $database, + collection: $relatedCollection, + document: $relation, + dbForProject: $dbForProject, + collectionsCache: $collectionsCache, + operations: $operations + ); + } + } + + if (\is_array($related)) { + $document->setAttribute($relationship->getAttribute('key'), \array_values($relations)); + } elseif (empty($relations)) { + $document->setAttribute($relationship->getAttribute('key'), null); + } + } + + return true; + } } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Decrement.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Decrement.php index 9a8da5858c..40035ac302 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Decrement.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Decrement.php @@ -19,14 +19,11 @@ use Utopia\Database\Exception\Type as TypeException; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Numeric; class Decrement extends Action { - use HTTP; - public static function getName(): string { return 'decrementDocumentAttribute'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Increment.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Increment.php index b65ca3c285..6755d313c0 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Increment.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Attribute/Increment.php @@ -19,14 +19,11 @@ use Utopia\Database\Exception\Type as TypeException; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Numeric; class Increment extends Action { - use HTTP; - public static function getName(): string { return 'incrementDocumentAttribute'; @@ -102,7 +99,6 @@ class Increment extends Action } catch (ConflictException) { throw new Exception($this->getConflictException()); } catch (NotFoundException) { - // todo: @itznotabug what do we name this exception now? throw new Exception($this->getStructureNotFoundException()); } catch (LimitException) { throw new Exception($this->getLimitException(), $this->getSdkNamespace() . ' "' . $attribute . '" has reached the maximum value of ' . $max); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Delete.php index bee3b35599..4ec852f7c5 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Delete.php @@ -17,15 +17,12 @@ use Utopia\Database\Exception\Query as QueryException; use Utopia\Database\Exception\Restricted as RestrictedException; use Utopia\Database\Query; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\ArrayList; use Utopia\Validator\Text; class Delete extends Action { - use HTTP; - public static function getName(): string { return 'deleteDocuments'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Update.php index 23c8d5d58e..d391c805fa 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Update.php @@ -19,7 +19,6 @@ use Utopia\Database\Exception\Structure as StructureException; use Utopia\Database\Query; use Utopia\Database\Validator\Permissions; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\ArrayList; use Utopia\Validator\JSON; @@ -27,8 +26,6 @@ use Utopia\Validator\Text; class Update extends Action { - use HTTP; - public static function getName(): string { return 'updateDocuments'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Upsert.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Upsert.php index 770f7a4d95..f4c8c2e6d2 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Upsert.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Upsert.php @@ -17,15 +17,12 @@ use Utopia\Database\Exception\Duplicate as DuplicateException; use Utopia\Database\Exception\Relationship as RelationshipException; use Utopia\Database\Exception\Structure as StructureException; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\ArrayList; use Utopia\Validator\JSON; class Upsert extends Action { - use HTTP; - public static function getName(): string { return 'upsertDocuments'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Create.php index 6005495a68..6c1fdae5e6 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Create.php @@ -25,15 +25,12 @@ use Utopia\Database\Helpers\Role; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\Permissions; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\ArrayList; use Utopia\Validator\JSON; class Create extends Action { - use HTTP; - public static function getName(): string { return 'createDocument'; @@ -373,42 +370,15 @@ class Create extends Action ->setParam('tableId', $collection->getId()) ->setContext($this->getCollectionsEventsContext(), $collection); - // Add $collectionId and $databaseId for all documents - $processDocument = function (Document $table, Document $document) use (&$processDocument, $dbForProject, $database) { - $document->removeAttribute('$collection'); - $document->setAttribute('$databaseId', $database->getId()); - $document->setAttribute('$collectionId', $table->getId()); - - $relationships = \array_filter( - $table->getAttribute('attributes', []), - fn ($attribute) => $attribute->getAttribute('type') === Database::VAR_RELATIONSHIP - ); - - foreach ($relationships as $relationship) { - $related = $document->getAttribute($relationship->getAttribute('key')); - - if (empty($related)) { - continue; - } - if (!\is_array($related)) { - $related = [$related]; - } - - $relatedCollectionId = $relationship->getAttribute('relatedCollection'); - $relatedCollection = Authorization::skip( - fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $relatedCollectionId) - ); - - foreach ($related as $relation) { - if ($relation instanceof Document) { - $processDocument($relatedCollection, $relation); - } - } - } - }; - + $collectionsCache = []; foreach ($documents as $document) { - $processDocument($collection, $document); + $this->processDocument( + database: $database, + collection: $collection, + document: $document, + dbForProject: $dbForProject, + collectionsCache: $collectionsCache, + ); } $queueForStatsUsage diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Delete.php index dc307071e4..8c8cec2986 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Delete.php @@ -12,18 +12,14 @@ use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; -use Utopia\Database\Document; use Utopia\Database\Exception\Conflict as ConflictException; use Utopia\Database\Exception\Restricted as RestrictedException; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; class Delete extends Action { - use HTTP; - public static function getName(): string { return 'deleteDocument'; @@ -115,40 +111,14 @@ class Delete extends Action throw new Exception($this->getRestrictedException()); } - // Add $collection and $databaseId for all documents - $processDocument = function (Document $collection, Document $document) use (&$processDocument, $dbForProject, $database) { - $document->setAttribute('$databaseId', $database->getId()); - $document->setAttribute('$collectionId', $collection->getId()); - - $relationships = \array_filter( - $collection->getAttribute('attributes', []), - fn ($attribute) => $attribute->getAttribute('type') === Database::VAR_RELATIONSHIP - ); - - foreach ($relationships as $relationship) { - $related = $document->getAttribute($relationship->getAttribute('key')); - - if (empty($related)) { - continue; - } - if (!\is_array($related)) { - $related = [$related]; - } - - $relatedCollectionId = $relationship->getAttribute('relatedCollection'); - $relatedCollection = Authorization::skip( - fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $relatedCollectionId) - ); - - foreach ($related as $relation) { - if ($relation instanceof Document) { - $processDocument($relatedCollection, $relation); - } - } - } - }; - - $processDocument($collection, $document); + $collectionsCache = []; + $this->processDocument( + database: $database, + collection: $collection, + document: $document, + dbForProject: $dbForProject, + collectionsCache: $collectionsCache, + ); $queueForStatsUsage ->addMetric(METRIC_DATABASES_OPERATIONS_WRITES, 1) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Get.php index 3f7f74ee75..7376fe770a 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Get.php @@ -11,20 +11,16 @@ use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; -use Utopia\Database\Document; use Utopia\Database\Exception\Query as QueryException; use Utopia\Database\Query; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\ArrayList; use Utopia\Validator\Text; class Get extends Action { - use HTTP; - public static function getName(): string { return 'getDocument'; @@ -101,52 +97,15 @@ class Get extends Action } $operations = 0; - - // Add $collectionId and $databaseId for all rows - $processDocument = function (Document $collection, Document $document) use (&$processDocument, $dbForProject, $database, &$operations) { - if ($document->isEmpty()) { - return; - } - - $operations++; - - $document->setAttribute('$databaseId', $database->getId()); - $document->setAttribute('$collectionId', $collection->getId()); - - $relationships = \array_filter( - $collection->getAttribute('attributes', []), - fn ($attribute) => $attribute->getAttribute('type') === Database::VAR_RELATIONSHIP - ); - - foreach ($relationships as $relationship) { - $related = $document->getAttribute($relationship->getAttribute('key')); - - if (empty($related)) { - if (\in_array(\gettype($related), ['array', 'object'])) { - $operations++; - } - - continue; - } - - if (!\is_array($related)) { - $related = [$related]; - } - - $relatedCollectionId = $relationship->getAttribute('relatedCollection'); - $relatedCollection = Authorization::skip( - fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $relatedCollectionId) - ); - - foreach ($related as $relation) { - if ($relation instanceof Document) { - $processDocument($relatedCollection, $relation); - } - } - } - }; - - $processDocument($collection, $document); + $collectionsCache = []; + $this->processDocument( + database: $database, + collection: $collection, + document: $document, + dbForProject: $dbForProject, + collectionsCache: $collectionsCache, + operations: $operations + ); $queueForStatsUsage ->addMetric(METRIC_DATABASES_OPERATIONS_READS, max($operations, 1)) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Logs/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Logs/XList.php index 4f4dad9882..3fe25b9441 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Logs/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Logs/XList.php @@ -23,13 +23,10 @@ use Utopia\Database\Validator\Query\Limit; use Utopia\Database\Validator\Query\Offset; use Utopia\Database\Validator\UID; use Utopia\Locale\Locale; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; class XList extends Action { - use HTTP; - public static function getName(): string { return 'listDocumentLogs'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Update.php index 3bc97e817b..ce822ca713 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Update.php @@ -23,14 +23,11 @@ use Utopia\Database\Helpers\Role; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\Permissions; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\JSON; class Update extends Action { - use HTTP; - public static function getName(): string { return 'updateDocument'; @@ -247,40 +244,14 @@ class Update extends Action throw new Exception($this->getInvalidStructureException(), $e->getMessage()); } - // Add $collectionId and $databaseId for all documents - $processDocument = function (Document $table, Document $row) use (&$processDocument, $dbForProject, $database) { - $row->setAttribute('$databaseId', $database->getId()); - $row->setAttribute('$collectionId', $table->getId()); - - $relationships = \array_filter( - $table->getAttribute('attributes', []), - fn ($attribute) => $attribute->getAttribute('type') === Database::VAR_RELATIONSHIP - ); - - foreach ($relationships as $relationship) { - $related = $row->getAttribute($relationship->getAttribute('key')); - - if (empty($related)) { - continue; - } - if (!\is_array($related)) { - $related = [$related]; - } - - $relatedCollectionId = $relationship->getAttribute('relatedCollection'); - $relatedCollection = Authorization::skip( - fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $relatedCollectionId) - ); - - foreach ($related as $relation) { - if ($relation instanceof Document) { - $processDocument($relatedCollection, $relation); - } - } - } - }; - - $processDocument($collection, $document); + $collectionsCache = []; + $this->processDocument( + database: $database, + collection: $collection, + document: $document, + dbForProject: $dbForProject, + collectionsCache: $collectionsCache, + ); $response->dynamic($document, $this->getResponseModel()); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Upsert.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Upsert.php index ebe30f6970..7a077fed0d 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Upsert.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Upsert.php @@ -24,14 +24,11 @@ use Utopia\Database\Helpers\Role; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\Permissions; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\JSON; class Upsert extends Action { - use HTTP; - public static function getName(): string { return 'upsertDocument'; @@ -235,41 +232,15 @@ class Upsert extends Action throw new Exception($this->getInvalidStructureException(), $e->getMessage()); } + $collectionsCache = []; $document = $upserted[0]; - // Add $collectionId and $databaseId for all documents - $processDocument = function (Document $table, Document $document) use (&$processDocument, $dbForProject, $database) { - $document->setAttribute('$databaseId', $database->getId()); - $document->setAttribute('$collectionId', $table->getId()); - - $relationships = \array_filter( - $table->getAttribute('attributes', []), - fn ($attribute) => $attribute->getAttribute('type') === Database::VAR_RELATIONSHIP - ); - - foreach ($relationships as $relationship) { - $related = $document->getAttribute($relationship->getAttribute('key')); - - if (empty($related)) { - continue; - } - if (!\is_array($related)) { - $related = [$related]; - } - - $relatedCollectionId = $relationship->getAttribute('relatedCollection'); - $relatedCollection = Authorization::skip( - fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $relatedCollectionId) - ); - - foreach ($related as $relation) { - if ($relation instanceof Document) { - $processDocument($relatedCollection, $relation); - } - } - } - }; - - $processDocument($collection, $document); + $this->processDocument( + database: $database, + collection: $collection, + document: $document, + dbForProject: $dbForProject, + collectionsCache: $collectionsCache, + ); $relationships = \array_map( fn ($document) => $document->getAttribute('key'), diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/XList.php index 0012b8339a..2e76942db1 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/XList.php @@ -18,15 +18,12 @@ use Utopia\Database\Query; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\Query\Cursor; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\ArrayList; use Utopia\Validator\Text; class XList extends Action { - use HTTP; - public static function getName(): string { return 'listDocuments'; @@ -130,65 +127,16 @@ class XList extends Action } $operations = 0; - - // Add $collectionId and $databaseId for all documents - $processDocument = (function (Document $collection, Document $document) use (&$processDocument, $dbForProject, $database, &$operations): bool { - if ($document->isEmpty()) { - return false; - } - - $operations++; - - $document->removeAttribute('$collection'); - $document->setAttribute('$databaseId', $database->getId()); - $document->setAttribute('$collectionId', $collection->getId()); - - $relationships = \array_filter( - $collection->getAttribute('attributes', []), - fn ($attribute) => $attribute->getAttribute('type') === Database::VAR_RELATIONSHIP + $collectionsCache = []; + foreach ($documents as $document) { + $this->processDocument( + database: $database, + collection: $collection, + document: $document, + dbForProject: $dbForProject, + collectionsCache: $collectionsCache, + operations: $operations, ); - - foreach ($relationships as $relationship) { - $related = $document->getAttribute($relationship->getAttribute('key')); - - if (empty($related)) { - if (\in_array(\gettype($related), ['array', 'object'])) { - $operations++; - } - - continue; - } - - if (!\is_array($related)) { - $relations = [$related]; - } else { - $relations = $related; - } - - $relatedCollectionId = $relationship->getAttribute('relatedCollection'); - // todo: Use local cache for this getDocument - $relatedCollection = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $relatedCollectionId)); - - foreach ($relations as $index => $doc) { - if ($doc instanceof Document) { - if (!$processDocument($relatedCollection, $doc)) { - unset($relations[$index]); - } - } - } - - if (\is_array($related)) { - $document->setAttribute($relationship->getAttribute('key'), \array_values($relations)); - } elseif (empty($relations)) { - $document->setAttribute($relationship->getAttribute('key'), null); - } - } - - return true; - }); - - foreach ($documents as $row) { - $processDocument($collection, $row); } $queueForStatsUsage diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Get.php index 0359025fc5..e35a924657 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Get.php @@ -11,13 +11,10 @@ use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; class Get extends Action { - use HTTP; - public static function getName(): string { return 'getCollection'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Action.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Action.php index 4a40ea6b5f..33c2977be5 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Action.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Action.php @@ -3,7 +3,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Indexes; use Appwrite\Extend\Exception; -use Appwrite\Platform\Modules\Databases\Context; use Utopia\Platform\Action as UtopiaAction; abstract class Action extends UtopiaAction @@ -11,25 +10,20 @@ abstract class Action extends UtopiaAction /** * The current API context (either 'columnIndex' or 'index'). */ - private ?string $context = Context::DATABASE_INDEX; + private ?string $context = INDEX; /** * Get the response model used in the SDK and HTTP responses. */ abstract protected function getResponseModel(): string; - /** - * Set the current API context. - * - * @param string $context Must be either `DATABASE_INDEX` or `DATABASE_COLUMN_INDEX`. - */ - final protected function setContext(string $context): void + public function setHttpPath(string $path): UtopiaAction { - if (!\in_array($context, [Context::DATABASE_INDEX, Context::DATABASE_COLUMN_INDEX], true)) { - throw new \InvalidArgumentException("Invalid context '$context'. Must be either `Context::DATABASE_COLUMN_INDEX` or `Context::DATABASE_INDEX`."); + if (str_contains($path, '/:databaseId/tables')) { + $this->context = COLUMN_INDEX; } - $this->context = $context; + return parent::setHttpPath($path); } /** @@ -37,9 +31,7 @@ abstract class Action extends UtopiaAction */ final protected function getParentContext(): string { - return $this->getContext() === Context::DATABASE_INDEX - ? Context::DATABASE_ATTRIBUTES - : Context::DATABASE_COLUMNS; + return $this->getContext() === INDEX ? ATTRIBUTES : COLUMNS; } /** @@ -55,7 +47,7 @@ abstract class Action extends UtopiaAction */ final protected function isCollectionsAPI(): bool { - return $this->getParentContext() === Context::DATABASE_ATTRIBUTES; + return $this->getParentContext() === ATTRIBUTES; } /** @@ -71,7 +63,7 @@ abstract class Action extends UtopiaAction */ final protected function getSdkNamespace(): string { - return $this->isCollectionsAPI() ? 'collections' : 'tables'; + return $this->isCollectionsAPI() ? 'databases' : 'tables'; } /** diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Create.php index 9dbd7924c6..9003fbb4a9 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Create.php @@ -19,7 +19,6 @@ use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\Index as IndexValidator; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\ArrayList; use Utopia\Validator\Integer; @@ -28,8 +27,6 @@ use Utopia\Validator\WhiteList; class Create extends Action { - use HTTP; - public static function getName(): string { return 'createIndex'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Delete.php index bb0b7bc4ca..701ab103ad 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Delete.php @@ -14,13 +14,10 @@ use Utopia\Database\Database; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; class Delete extends Action { - use HTTP; - public static function getName(): string { return 'deleteIndex'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Get.php index e29bbf6647..c5b81fe231 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/Get.php @@ -12,13 +12,10 @@ use Utopia\Database\Database; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; class Get extends Action { - use HTTP; - public static function getName(): string { return 'getIndex'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/XList.php index dae25a3335..36c52f711e 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Indexes/XList.php @@ -17,13 +17,10 @@ use Utopia\Database\Query; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\Query\Cursor; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; class XList extends Action { - use HTTP; - public static function getName(): string { return 'listIndexes'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Logs/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Logs/XList.php index 2f9ac2c8c0..70bb14e9d8 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Logs/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Logs/XList.php @@ -23,13 +23,10 @@ use Utopia\Database\Validator\Query\Limit; use Utopia\Database\Validator\Query\Offset; use Utopia\Database\Validator\UID; use Utopia\Locale\Locale; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; class XList extends Action { - use HTTP; - public static function getName(): string { return 'listCollectionLogs'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Update.php index cc41d716d4..fd3b1e8bda 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Update.php @@ -14,15 +14,12 @@ use Utopia\Database\Helpers\Permission; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\Permissions; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\Text; class Update extends Action { - use HTTP; - public static function getName(): string { return 'updateCollection'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Usage/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Usage/Get.php index 0c565806cc..e5335d6abf 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Usage/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Usage/Get.php @@ -15,14 +15,11 @@ use Utopia\Database\Document; use Utopia\Database\Query; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\WhiteList; class Get extends Action { - use HTTP; - public static function getName(): string { return 'getCollectionUsage'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/XList.php index d3ddb9301f..3a9868dec2 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/XList.php @@ -17,14 +17,11 @@ use Utopia\Database\Query; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\Query\Cursor; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Text; class XList extends Action { - use HTTP; - public static function getName(): string { return 'listCollections'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Create.php index 3b9efa2fca..38374402fb 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Create.php @@ -19,15 +19,12 @@ use Utopia\Database\Exception\Limit as LimitException; use Utopia\Database\Exception\Structure as StructureException; use Utopia\Database\Helpers\ID; use Utopia\Platform\Action; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\Text; class Create extends Action { - use HTTP; - public static function getName(): string { return 'createDatabase'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Delete.php index b9b475f699..56cf1a4296 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Delete.php @@ -13,13 +13,10 @@ use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; use Utopia\Database\Validator\UID; use Utopia\Platform\Action; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; class Delete extends Action { - use HTTP; - public static function getName(): string { return 'deleteDatabase'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Get.php index c2c6a57da1..f478dc7917 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Get.php @@ -11,13 +11,10 @@ use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; use Utopia\Database\Validator\UID; use Utopia\Platform\Action; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; class Get extends Action { - use HTTP; - public static function getName(): string { return 'getDatabase'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Logs/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Logs/XList.php index a531110398..52f2ad93b6 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Logs/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Logs/XList.php @@ -23,13 +23,10 @@ use Utopia\Database\Validator\Query\Offset; use Utopia\Database\Validator\UID; use Utopia\Locale\Locale; use Utopia\Platform\Action; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; class XList extends Action { - use HTTP; - public static function getName(): string { return 'listDatabaseLogs'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Boolean/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Boolean/Create.php index af6bf90696..b6417e929a 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Boolean/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Boolean/Create.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Columns\Boolean; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Boolean\Create as BooleanCreate; use Appwrite\SDK\AuthType; use Appwrite\SDK\Method; @@ -10,14 +9,11 @@ use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; class Create extends BooleanCreate { - use HTTP; - public static function getName(): string { return 'createBooleanColumn'; @@ -30,8 +26,6 @@ class Create extends BooleanCreate public function __construct() { - $this->setContext(Context::DATABASE_COLUMNS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/columns/boolean') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Boolean/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Boolean/Update.php index 4ce36915dc..534e514bdf 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Boolean/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Boolean/Update.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Columns\Boolean; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Boolean\Update as BooleanUpdate; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -11,15 +10,12 @@ use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\Nullable; class Update extends BooleanUpdate { - use HTTP; - public static function getName(): string { return 'updateBooleanColumn'; @@ -32,8 +28,6 @@ class Update extends BooleanUpdate public function __construct() { - $this->setContext(Context::DATABASE_COLUMNS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/columns/boolean/:key') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Datetime/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Datetime/Create.php index 7a3f77dbee..d29d8fd8b2 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Datetime/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Datetime/Create.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Columns\Datetime; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Datetime\Create as DatetimeCreate; use Appwrite\SDK\AuthType; use Appwrite\SDK\Method; @@ -12,14 +11,11 @@ use Utopia\Database\Database; use Utopia\Database\Validator\Datetime as DatetimeValidator; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; class Create extends DatetimeCreate { - use HTTP; - public static function getName(): string { return 'createDatetimeColumn'; @@ -32,8 +28,6 @@ class Create extends DatetimeCreate public function __construct() { - $this->setContext(Context::DATABASE_COLUMNS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/columns/datetime') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Datetime/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Datetime/Update.php index 305a0b4df2..f343b5f41d 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Datetime/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Datetime/Update.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Columns\Datetime; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Datetime\Update as DatetimeUpdate; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -13,15 +12,12 @@ use Utopia\Database\Database; use Utopia\Database\Validator\Datetime as DatetimeValidator; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\Nullable; class Update extends DatetimeUpdate { - use HTTP; - public static function getName(): string { return 'updateDatetimeColumn'; @@ -34,8 +30,6 @@ class Update extends DatetimeUpdate public function __construct() { - $this->setContext(Context::DATABASE_COLUMNS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/columns/datetime/:key') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Delete.php index fadbd2b165..97f5443bc8 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Delete.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Columns; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Delete as AttributesDelete; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -11,13 +10,10 @@ use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; class Delete extends AttributesDelete { - use HTTP; - public static function getName(): string { return 'deleteColumn'; @@ -31,8 +27,6 @@ class Delete extends AttributesDelete public function __construct() { - $this->setContext(Context::DATABASE_COLUMNS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_DELETE) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/columns/:key') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Email/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Email/Create.php index b8dc7b7ec8..3052e63149 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Email/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Email/Create.php @@ -3,7 +3,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Columns\Email; use Appwrite\Network\Validator\Email; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Email\Create as EmailCreate; use Appwrite\SDK\AuthType; use Appwrite\SDK\Method; @@ -11,14 +10,11 @@ use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; class Create extends EmailCreate { - use HTTP; - public static function getName(): string { return 'createEmailColumn'; @@ -31,8 +27,6 @@ class Create extends EmailCreate public function __construct() { - $this->setContext(Context::DATABASE_COLUMNS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/columns/email') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Email/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Email/Update.php index c006e53a41..82895f6cf1 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Email/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Email/Update.php @@ -3,7 +3,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Columns\Email; use Appwrite\Network\Validator\Email; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Email\Update as EmailUpdate; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -12,15 +11,12 @@ use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\Nullable; class Update extends EmailUpdate { - use HTTP; - public static function getName(): string { return 'updateEmailColumn'; @@ -33,8 +29,6 @@ class Update extends EmailUpdate public function __construct() { - $this->setContext(Context::DATABASE_COLUMNS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/columns/email/:key') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Enum/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Enum/Create.php index b85fae15dc..25414fa91d 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Enum/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Enum/Create.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Columns\Enum; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Enum\Create as EnumCreate; use Appwrite\SDK\AuthType; use Appwrite\SDK\Method; @@ -11,7 +10,6 @@ use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\ArrayList; use Utopia\Validator\Boolean; @@ -19,8 +17,6 @@ use Utopia\Validator\Text; class Create extends EnumCreate { - use HTTP; - public static function getName(): string { return 'createEnumColumn'; @@ -33,8 +29,6 @@ class Create extends EnumCreate public function __construct() { - $this->setContext(Context::DATABASE_COLUMNS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/columns/enum') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Enum/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Enum/Update.php index f4ffb53bd7..6bc8df63e4 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Enum/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Enum/Update.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Columns\Enum; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Enum\Update as EnumUpdate; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -12,7 +11,6 @@ use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\ArrayList; use Utopia\Validator\Boolean; @@ -21,8 +19,6 @@ use Utopia\Validator\Text; class Update extends EnumUpdate { - use HTTP; - public static function getName(): string { return 'updateEnumColumn'; @@ -35,8 +31,6 @@ class Update extends EnumUpdate public function __construct() { - $this->setContext(Context::DATABASE_COLUMNS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/columns/enum/:key') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Float/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Float/Create.php index 5dd7fb6a3b..c7e102699e 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Float/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Float/Create.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Columns\Float; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Float\Create as FloatCreate; use Appwrite\SDK\AuthType; use Appwrite\SDK\Method; @@ -10,15 +9,12 @@ use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\FloatValidator; class Create extends FloatCreate { - use HTTP; - public static function getName(): string { return 'createFloatColumn'; @@ -31,8 +27,6 @@ class Create extends FloatCreate public function __construct() { - $this->setContext(Context::DATABASE_COLUMNS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/columns/float') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Float/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Float/Update.php index 5946f16e75..ec2467cf96 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Float/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Float/Update.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Columns\Float; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Float\Update as FloatUpdate; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -11,7 +10,6 @@ use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\FloatValidator; @@ -19,8 +17,6 @@ use Utopia\Validator\Nullable; class Update extends FloatUpdate { - use HTTP; - public static function getName(): string { return 'updateFloatColumn'; @@ -33,8 +29,6 @@ class Update extends FloatUpdate public function __construct() { - $this->setContext(Context::DATABASE_COLUMNS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/columns/float/:key') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Get.php index 488b41a27c..2409468e56 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Get.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Columns; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Get as AttributesGet; use Appwrite\SDK\AuthType; use Appwrite\SDK\Method; @@ -10,13 +9,10 @@ use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; class Get extends AttributesGet { - use HTTP; - public static function getName(): string { return 'getColumn'; @@ -40,8 +36,6 @@ class Get extends AttributesGet public function __construct() { - $this->setContext(Context::DATABASE_COLUMNS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_GET) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/columns/:key') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/IP/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/IP/Create.php index b889526d2c..48ebd3c300 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/IP/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/IP/Create.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Columns\IP; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\IP\Create as IPCreate; use Appwrite\SDK\AuthType; use Appwrite\SDK\Method; @@ -10,15 +9,12 @@ use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\IP; class Create extends IPCreate { - use HTTP; - public static function getName(): string { return 'createIpColumn'; @@ -31,8 +27,6 @@ class Create extends IPCreate public function __construct() { - $this->setContext(Context::DATABASE_COLUMNS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/columns/ip') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/IP/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/IP/Update.php index 496ee34a53..83609fbf6f 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/IP/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/IP/Update.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Columns\IP; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\IP\Update as IPUpdate; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -11,7 +10,6 @@ use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\IP; @@ -19,8 +17,6 @@ use Utopia\Validator\Nullable; class Update extends IPUpdate { - use HTTP; - public static function getName(): string { return 'updateIpColumn'; @@ -33,8 +29,6 @@ class Update extends IPUpdate public function __construct() { - $this->setContext(Context::DATABASE_COLUMNS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/columns/ip/:key') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Integer/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Integer/Create.php index 8f2e826052..b7f50d3ca4 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Integer/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Integer/Create.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Columns\Integer; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Integer\Create as IntegerCreate; use Appwrite\SDK\AuthType; use Appwrite\SDK\Method; @@ -10,15 +9,12 @@ use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\Integer; class Create extends IntegerCreate { - use HTTP; - public static function getName(): string { return 'createIntegerColumn'; @@ -31,8 +27,6 @@ class Create extends IntegerCreate public function __construct() { - $this->setContext(Context::DATABASE_COLUMNS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/columns/integer') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Integer/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Integer/Update.php index 5b406a95ed..ef92d242e5 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Integer/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Integer/Update.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Columns\Integer; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Integer\Update as IntegerUpdate; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -11,7 +10,6 @@ use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\Integer; @@ -19,8 +17,6 @@ use Utopia\Validator\Nullable; class Update extends IntegerUpdate { - use HTTP; - public static function getName(): string { return 'updateIntegerColumn'; @@ -33,8 +29,6 @@ class Update extends IntegerUpdate public function __construct() { - $this->setContext(Context::DATABASE_COLUMNS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/columns/integer/:key') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Relationship/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Relationship/Create.php index a374e3f520..bdbf136bfc 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Relationship/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Relationship/Create.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Columns\Relationship; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Relationship\Create as RelationshipCreate; use Appwrite\SDK\AuthType; use Appwrite\SDK\Method; @@ -11,15 +10,12 @@ use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\WhiteList; class Create extends RelationshipCreate { - use HTTP; - public static function getName(): string { return 'createRelationshipColumn'; @@ -32,8 +28,6 @@ class Create extends RelationshipCreate public function __construct() { - $this->setContext(Context::DATABASE_COLUMNS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/columns/relationship') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Relationship/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Relationship/Update.php index c7325b922e..98a5db3758 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Relationship/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/Relationship/Update.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Columns\Relationship; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\Relationship\Update as RelationshipUpdate; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -12,14 +11,11 @@ use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\WhiteList; class Update extends RelationshipUpdate { - use HTTP; - public static function getName(): string { return 'updateRelationshipColumn'; @@ -32,8 +28,6 @@ class Update extends RelationshipUpdate public function __construct() { - $this->setContext(Context::DATABASE_COLUMNS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/columns/:key/relationship') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/String/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/String/Create.php index e281a3d475..c61b3e465a 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/String/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/String/Create.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Columns\String; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\String\Create as StringCreate; use Appwrite\SDK\AuthType; use Appwrite\SDK\Method; @@ -10,7 +9,6 @@ use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator; use Utopia\Validator\Boolean; @@ -19,8 +17,6 @@ use Utopia\Validator\Text; class Create extends StringCreate { - use HTTP; - public static function getName(): string { return 'createStringColumn'; @@ -33,8 +29,6 @@ class Create extends StringCreate public function __construct() { - $this->setContext(Context::DATABASE_COLUMNS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/columns/string') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/String/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/String/Update.php index 6f1512bab4..b8c52d15cb 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/String/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/String/Update.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Columns\String; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\String\Update as StringUpdate; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -11,7 +10,6 @@ use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator; use Utopia\Validator\Boolean; @@ -21,8 +19,6 @@ use Utopia\Validator\Text; class Update extends StringUpdate { - use HTTP; - public static function getName(): string { return 'updateStringColumn'; @@ -35,8 +31,6 @@ class Update extends StringUpdate public function __construct() { - $this->setContext(Context::DATABASE_COLUMNS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/columns/string/:key') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/URL/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/URL/Create.php index b33ee6e4c8..6fdf0f6e2b 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/URL/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/URL/Create.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Columns\URL; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\URL\Create as URLCreate; use Appwrite\SDK\AuthType; use Appwrite\SDK\Method; @@ -10,15 +9,12 @@ use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\URL; class Create extends URLCreate { - use HTTP; - public static function getName(): string { return 'createUrlColumn'; @@ -31,8 +27,6 @@ class Create extends URLCreate public function __construct() { - $this->setContext(Context::DATABASE_COLUMNS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/columns/url') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/URL/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/URL/Update.php index 4404d98c6e..79207338b4 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/URL/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/URL/Update.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Columns\URL; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\URL\Update as URLUpdate; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -11,7 +10,6 @@ use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\Nullable; @@ -19,8 +17,6 @@ use Utopia\Validator\URL; class Update extends URLUpdate { - use HTTP; - public static function getName(): string { return 'updateUrlColumn'; @@ -33,8 +29,6 @@ class Update extends URLUpdate public function __construct() { - $this->setContext(Context::DATABASE_COLUMNS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/columns/url/:key') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/XList.php index c6ceb35f48..8190f2ec71 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Columns/XList.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Columns; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Attributes\XList as AttributesXList; use Appwrite\SDK\AuthType; use Appwrite\SDK\Method; @@ -10,13 +9,10 @@ use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Database\Validator\Queries\Columns; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; class XList extends AttributesXList { - use HTTP; - public static function getName(): string { return 'listColumns'; @@ -29,8 +25,6 @@ class XList extends AttributesXList public function __construct() { - $this->setContext(Context::DATABASE_COLUMNS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_GET) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/columns') @@ -53,7 +47,7 @@ class XList extends AttributesXList )) ->param('databaseId', '', new UID(), 'Database ID.') ->param('tableId', '', new UID(), 'Table ID.') - ->param('queries', [], new Columns(), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' queries are allowed, each ' . APP_LIMIT_ARRAY_ELEMENT_SIZE . ' characters long. You may filter on the following attributes: ' . implode(', ', Columns::ALLOWED_ATTRIBUTES), true) + ->param('queries', [], new Columns(), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' queries are allowed, each ' . APP_LIMIT_ARRAY_ELEMENT_SIZE . ' characters long. You may filter on the following attributes: ' . implode(', ', Columns::ALLOWED_COLUMNS), true) ->inject('response') ->inject('dbForProject') ->callback($this->action(...)); diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Create.php index 3fafa6c970..ed31333dac 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Create.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Create as CollectionCreate; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -12,18 +11,15 @@ use Appwrite\Utopia\Database\Validator\CustomId; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\Permissions; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\Text; class Create extends CollectionCreate { - use HTTP; - public static function getName(): string { - return 'createTable'; + return 'create'; } protected function getResponseModel(): string @@ -33,8 +29,6 @@ class Create extends CollectionCreate public function __construct() { - $this->setContext(Context::DATABASE_TABLES); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) ->setHttpPath('/v1/databases/:databaseId/tables') @@ -46,8 +40,8 @@ class Create extends CollectionCreate ->label('audits.event', 'table.create') ->label('audits.resource', 'database/{request.databaseId}/table/{response.$id}') ->label('sdk', new Method( - namespace: 'databases', - group: $this->getSdkGroup(), + namespace: $this->getSdkNamespace(), + group: null, name: self::getName(), description: '/docs/references/databases/create-table.md', auth: [AuthType::KEY], @@ -63,7 +57,7 @@ class Create extends CollectionCreate ->param('tableId', '', new CustomId(), 'Unique Id. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.') ->param('name', '', new Text(128), 'Table name. Max length: 128 chars.') ->param('permissions', null, new Permissions(APP_LIMIT_ARRAY_PARAMS_SIZE), 'An array of permissions strings. By default, no user is granted with any permissions. [Learn more about permissions](https://appwrite.io/docs/permissions).', true) - ->param('rowSecurity', false, new Boolean(true), 'Enables configuring permissions for individual rows. A user needs one of row or table level permissions to access a document. [Learn more about permissions](https://appwrite.io/docs/permissions).', true) + ->param('rowSecurity', false, new Boolean(true), 'Enables configuring permissions for individual rows. A user needs one of row or table level permissions to access a row. [Learn more about permissions](https://appwrite.io/docs/permissions).', true) ->param('enabled', true, new Boolean(), 'Is table enabled? When set to \'disabled\', users cannot access the table but Server SDKs with and API key can still read and write to the table. No data is lost when this is toggled.', true) ->inject('response') ->inject('dbForProject') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Delete.php index d4c6bb6f7c..3e30013176 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Delete.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Delete as CollectionDelete; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -10,16 +9,13 @@ use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; class Delete extends CollectionDelete { - use HTTP; - public static function getName(): string { - return 'deleteTable'; + return 'delete'; } protected function getResponseModel(): string @@ -29,8 +25,6 @@ class Delete extends CollectionDelete public function __construct() { - $this->setContext(Context::DATABASE_TABLES); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_DELETE) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId') @@ -42,8 +36,8 @@ class Delete extends CollectionDelete ->label('audits.event', 'table.delete') ->label('audits.resource', 'database/{request.databaseId}/table/{request.tableId}') ->label('sdk', new Method( - namespace: 'databases', - group: $this->getSdkGroup(), + namespace: $this->getSdkNamespace(), + group: null, name: self::getName(), description: '/docs/references/databases/delete-table.md', auth: [AuthType::KEY], diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Get.php index 5fe6ac216b..30d3f95477 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Get.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Get as CollectionGet; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -10,16 +9,13 @@ use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; class Get extends CollectionGet { - use HTTP; - public static function getName(): string { - return 'getTable'; + return 'get'; } protected function getResponseModel(): string @@ -29,8 +25,6 @@ class Get extends CollectionGet public function __construct() { - $this->setContext(Context::DATABASE_TABLES); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_GET) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId') @@ -39,8 +33,8 @@ class Get extends CollectionGet ->label('scope', 'collections.read') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( - namespace: 'databases', - group: $this->getSdkGroup(), + namespace: $this->getSdkNamespace(), + group: null, name: self::getName(), description: '/docs/references/databases/get-table.md', auth: [AuthType::KEY], diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Indexes/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Indexes/Create.php index e57e962e87..b11892e0f9 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Indexes/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Indexes/Create.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Indexes; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Indexes\Create as IndexCreate; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -12,7 +11,6 @@ use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\ArrayList; use Utopia\Validator\Integer; @@ -21,8 +19,6 @@ use Utopia\Validator\WhiteList; class Create extends IndexCreate { - use HTTP; - public static function getName(): string { return 'createColumnIndex'; @@ -35,8 +31,6 @@ class Create extends IndexCreate public function __construct() { - $this->setContext(Context::DATABASE_COLUMN_INDEX); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/indexes') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Indexes/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Indexes/Delete.php index 7cda1ce471..4ff9638f27 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Indexes/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Indexes/Delete.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Indexes; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Indexes\Delete as IndexDelete; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -11,13 +10,10 @@ use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; class Delete extends IndexDelete { - use HTTP; - public static function getName(): string { return 'updateColumnIndex'; @@ -34,8 +30,6 @@ class Delete extends IndexDelete public function __construct() { - $this->setContext(Context::DATABASE_COLUMN_INDEX); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_DELETE) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/indexes/:key') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Indexes/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Indexes/Get.php index 3bee87de4a..79529fda66 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Indexes/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Indexes/Get.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Indexes; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Indexes\Get as IndexGet; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -11,13 +10,10 @@ use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; class Get extends IndexGet { - use HTTP; - public static function getName(): string { return 'getColumnIndex'; @@ -30,8 +26,6 @@ class Get extends IndexGet public function __construct() { - $this->setContext(Context::DATABASE_COLUMN_INDEX); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_GET) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/indexes/:key') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Indexes/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Indexes/XList.php index 1af13dc82e..12581a4fc3 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Indexes/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Indexes/XList.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Indexes; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Indexes\XList as IndexXList; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -11,13 +10,10 @@ use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Database\Validator\Queries\Indexes; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; class XList extends IndexXList { - use HTTP; - public static function getName(): string { return 'listColumnIndexes'; @@ -30,8 +26,6 @@ class XList extends IndexXList public function __construct() { - $this->setContext(Context::DATABASE_COLUMN_INDEX); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_GET) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/indexes') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Logs/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Logs/XList.php index 011583ebca..f879e01abb 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Logs/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Logs/XList.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Logs; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Logs\XList as CollectionLogXList; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -12,13 +11,10 @@ use Utopia\Database\Validator\Queries; use Utopia\Database\Validator\Query\Limit; use Utopia\Database\Validator\Query\Offset; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; class XList extends CollectionLogXList { - use HTTP; - public static function getName(): string { return 'listTableLogs'; @@ -26,8 +22,6 @@ class XList extends CollectionLogXList public function __construct() { - $this->setContext(Context::DATABASE_TABLES); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_GET) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/logs') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Bulk/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Bulk/Delete.php index 204dfde5d4..d854bebe4c 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Bulk/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Bulk/Delete.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Rows\Bulk; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Documents\Bulk\Delete as DocumentsDelete; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -10,15 +9,12 @@ use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\ArrayList; use Utopia\Validator\Text; class Delete extends DocumentsDelete { - use HTTP; - public static function getName(): string { return 'deleteRows'; @@ -31,8 +27,6 @@ class Delete extends DocumentsDelete public function __construct() { - $this->setContext(Context::DATABASE_ROWS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_DELETE) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/rows') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Bulk/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Bulk/Update.php index e5e9a9806c..6a678fd237 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Bulk/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Bulk/Update.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Rows\Bulk; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Documents\Bulk\Update as DocumentsUpdate; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -10,7 +9,6 @@ use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\ArrayList; use Utopia\Validator\JSON; @@ -18,8 +16,6 @@ use Utopia\Validator\Text; class Update extends DocumentsUpdate { - use HTTP; - public static function getName(): string { return 'updateRows'; @@ -32,8 +28,6 @@ class Update extends DocumentsUpdate public function __construct() { - $this->setContext(Context::DATABASE_ROWS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/rows') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Bulk/Upsert.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Bulk/Upsert.php index 8f0a8da91e..97e3769750 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Bulk/Upsert.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Bulk/Upsert.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Rows\Bulk; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Documents\Bulk\Upsert as DocumentsUpsert; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -10,15 +9,12 @@ use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\ArrayList; use Utopia\Validator\JSON; class Upsert extends DocumentsUpsert { - use HTTP; - public static function getName(): string { return 'upsertRows'; @@ -31,8 +27,6 @@ class Upsert extends DocumentsUpsert public function __construct() { - $this->setContext(Context::DATABASE_ROWS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_PUT) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/rows') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Column/Decrement.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Column/Decrement.php index 3d3247680b..37d46cee97 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Column/Decrement.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Column/Decrement.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Rows\Column; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Documents\Attribute\Decrement as DecrementDocumentAttribute; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -11,14 +10,11 @@ use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Numeric; class Decrement extends DecrementDocumentAttribute { - use HTTP; - public static function getName(): string { return 'decrementRowColumn'; @@ -31,8 +27,6 @@ class Decrement extends DecrementDocumentAttribute public function __construct() { - $this->setContext(Context::DATABASE_ROWS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/rows/:rowId/:column/decrement') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Column/Increment.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Column/Increment.php index 59e49e20e9..e953824e58 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Column/Increment.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Column/Increment.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Rows\Column; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Documents\Attribute\Increment as IncrementDocumentAttribute; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -11,14 +10,11 @@ use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\Key; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Numeric; class Increment extends IncrementDocumentAttribute { - use HTTP; - public static function getName(): string { return 'incrementRowColumn'; @@ -31,8 +27,6 @@ class Increment extends IncrementDocumentAttribute public function __construct() { - $this->setContext(Context::DATABASE_ROWS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/rows/:rowId/:column/increment') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Create.php index 928287971c..c49cf2d4bc 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Create.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Rows; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Documents\Create as DocumentCreate; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -14,15 +13,12 @@ use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; use Utopia\Database\Validator\Permissions; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\ArrayList; use Utopia\Validator\JSON; class Create extends DocumentCreate { - use HTTP; - public static function getName(): string { return 'createRow'; @@ -40,8 +36,6 @@ class Create extends DocumentCreate public function __construct() { - $this->setContext(Context::DATABASE_ROWS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_POST) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/rows') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Delete.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Delete.php index 45ffa88082..56133814ee 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Delete.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Delete.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Rows; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Documents\Delete as DocumentDelete; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -10,13 +9,10 @@ use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; class Delete extends DocumentDelete { - use HTTP; - public static function getName(): string { return 'deleteRow'; @@ -35,8 +31,6 @@ class Delete extends DocumentDelete public function __construct() { - $this->setContext(Context::DATABASE_ROWS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_DELETE) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/rows/:rowId') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Get.php index d89ca52551..9fcb155105 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Get.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Rows; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Documents\Get as DocumentGet; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -10,15 +9,12 @@ use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\ArrayList; use Utopia\Validator\Text; class Get extends DocumentGet { - use HTTP; - public static function getName(): string { return 'getRow'; @@ -31,8 +27,6 @@ class Get extends DocumentGet public function __construct() { - $this->setContext(Context::DATABASE_ROWS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_GET) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/rows/:rowId') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Logs/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Logs/XList.php index b00817225e..51f0259431 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Logs/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Logs/XList.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Rows\Logs; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Documents\Logs\XList as DocumentLogXList; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -12,13 +11,10 @@ use Utopia\Database\Validator\Queries; use Utopia\Database\Validator\Query\Limit; use Utopia\Database\Validator\Query\Offset; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; class XList extends DocumentLogXList { - use HTTP; - public static function getName(): string { return 'listRowLogs'; @@ -26,8 +22,6 @@ class XList extends DocumentLogXList public function __construct() { - $this->setContext(Context::DATABASE_ROWS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_GET) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/rows/:rowId/logs') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Update.php index dd256a3fa6..a3992143c3 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Update.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Rows; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Documents\Update as DocumentUpdate; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -12,14 +11,11 @@ use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; use Utopia\Database\Validator\Permissions; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\JSON; class Update extends DocumentUpdate { - use HTTP; - public static function getName(): string { return 'updateRow'; @@ -32,8 +28,6 @@ class Update extends DocumentUpdate public function __construct() { - $this->setContext(Context::DATABASE_ROWS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_PATCH) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/rows/:rowId') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Upsert.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Upsert.php index 1337f75874..0b67d0b533 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Upsert.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/Upsert.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Rows; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Documents\Upsert as DocumentUpsert; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -12,14 +11,11 @@ use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; use Utopia\Database\Validator\Permissions; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\JSON; class Upsert extends DocumentUpsert { - use HTTP; - public static function getName(): string { return 'upsertRow'; @@ -32,8 +28,6 @@ class Upsert extends DocumentUpsert public function __construct() { - $this->setContext(Context::DATABASE_ROWS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_PUT) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/rows/:rowId') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/XList.php index 096b29d6d5..3ecbed1d6f 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Rows/XList.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Rows; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Documents\XList as DocumentXList; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -10,15 +9,12 @@ use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\ArrayList; use Utopia\Validator\Text; class XList extends DocumentXList { - use HTTP; - public static function getName(): string { return 'listRows'; @@ -31,8 +27,6 @@ class XList extends DocumentXList public function __construct() { - $this->setContext(Context::DATABASE_ROWS); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_GET) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/rows') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Update.php index 3160b34ec6..c0e1b32f78 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Update.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Update as CollectionUpdate; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -11,18 +10,15 @@ use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\Permissions; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\Text; class Update extends CollectionUpdate { - use HTTP; - public static function getName(): string { - return 'updateTable'; + return 'update'; } protected function getResponseModel(): string @@ -32,8 +28,6 @@ class Update extends CollectionUpdate public function __construct() { - $this->setContext(Context::DATABASE_TABLES); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_PUT) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId') @@ -45,8 +39,8 @@ class Update extends CollectionUpdate ->label('audits.event', 'table.update') ->label('audits.resource', 'database/{request.databaseId}/table/{request.tableId}') ->label('sdk', new Method( - namespace: 'databases', - group: $this->getSdkGroup(), + namespace: $this->getSdkNamespace(), + group: null, name: self::getName(), description: '/docs/references/databases/update-table.md', auth: [AuthType::KEY], @@ -60,7 +54,7 @@ class Update extends CollectionUpdate )) ->param('databaseId', '', new UID(), 'Database ID.') ->param('tableId', '', new UID(), 'Table ID.') - ->param('name', null, new Text(128), 'Collection name. Max length: 128 chars.') + ->param('name', null, new Text(128), 'Table name. Max length: 128 chars.') ->param('permissions', null, new Permissions(APP_LIMIT_ARRAY_PARAMS_SIZE), 'An array of permission strings. By default, the current permissions are inherited. [Learn more about permissions](https://appwrite.io/docs/permissions).', true) ->param('rowSecurity', false, new Boolean(true), 'Enables configuring permissions for individual rows. A user needs one of row or table level permissions to access a document. [Learn more about permissions](https://appwrite.io/docs/permissions).', true) ->param('enabled', true, new Boolean(), 'Is table enabled? When set to \'disabled\', users cannot access the table but Server SDKs with and API key can still read and write to the table. No data is lost when this is toggled.', true) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Usage/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Usage/Get.php index d9660b1147..99146d1dd0 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Usage/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/Usage/Get.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables\Usage; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Usage\Get as CollectionUsageGet; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -10,14 +9,11 @@ use Appwrite\SDK\Method; use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\WhiteList; class Get extends CollectionUsageGet { - use HTTP; - public static function getName(): string { return 'getTableUsage'; @@ -30,8 +26,6 @@ class Get extends CollectionUsageGet public function __construct() { - $this->setContext(Context::DATABASE_TABLES); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_GET) ->setHttpPath('/v1/databases/:databaseId/tables/:tableId/usage') @@ -40,7 +34,7 @@ class Get extends CollectionUsageGet ->label('scope', 'collections.read') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( - namespace: 'databases', + namespace: $this->getSdkNamespace(), group: null, name: self::getName(), description: '/docs/references/databases/get-table-usage.md', diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/XList.php index 96e0626e58..427e2a085a 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Tables/XList.php @@ -2,7 +2,6 @@ namespace Appwrite\Platform\Modules\Databases\Http\Databases\Tables; -use Appwrite\Platform\Modules\Databases\Context; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\XList as CollectionXList; use Appwrite\SDK\AuthType; use Appwrite\SDK\ContentType; @@ -11,17 +10,14 @@ use Appwrite\SDK\Response as SDKResponse; use Appwrite\Utopia\Database\Validator\Queries\Tables; use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Validator\UID; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Text; class XList extends CollectionXList { - use HTTP; - public static function getName(): string { - return 'listTables'; + return 'list'; } protected function getResponseModel(): string @@ -31,8 +27,6 @@ class XList extends CollectionXList public function __construct() { - $this->setContext(Context::DATABASE_TABLES); - $this ->setHttpMethod(self::HTTP_REQUEST_METHOD_GET) ->setHttpPath('/v1/databases/:databaseId/tables') @@ -41,8 +35,8 @@ class XList extends CollectionXList ->label('scope', 'collections.read') ->label('resourceType', RESOURCE_TYPE_DATABASES) ->label('sdk', new Method( - namespace: 'databases', - group: $this->getSdkGroup(), + namespace: $this->getSdkNamespace(), + group: null, name: self::getName(), description: '/docs/references/databases/list-tables.md', auth: [AuthType::KEY], @@ -55,7 +49,7 @@ class XList extends CollectionXList contentType: ContentType::JSON )) ->param('databaseId', '', new UID(), 'Database ID.') - ->param('queries', [], new Tables(), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' queries are allowed, each ' . APP_LIMIT_ARRAY_ELEMENT_SIZE . ' characters long. You may filter on the following attributes: ' . implode(', ', Tables::ALLOWED_ATTRIBUTES), true) + ->param('queries', [], new Tables(), 'Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' queries are allowed, each ' . APP_LIMIT_ARRAY_ELEMENT_SIZE . ' characters long. You may filter on the following attributes: ' . implode(', ', Tables::ALLOWED_COLUMNS), true) ->param('search', '', new Text(256), 'Search term to filter your list results. Max length: 256 chars.', true) ->inject('response') ->inject('dbForProject') diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Update.php index a0e440c657..a746f4ce4c 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Update.php @@ -12,15 +12,12 @@ use Appwrite\Utopia\Response as UtopiaResponse; use Utopia\Database\Database; use Utopia\Database\Validator\UID; use Utopia\Platform\Action; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Boolean; use Utopia\Validator\Text; class Update extends Action { - use HTTP; - public static function getName(): string { return 'updateDatabase'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Usage/Get.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Usage/Get.php index 1a85380767..5482d25269 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Usage/Get.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Usage/Get.php @@ -15,14 +15,11 @@ use Utopia\Database\Query; use Utopia\Database\Validator\Authorization; use Utopia\Database\Validator\UID; use Utopia\Platform\Action; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\WhiteList; class Get extends Action { - use HTTP; - public static function getName(): string { return 'getUsage'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Usage/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Usage/XList.php index 2d551465db..fd3a95cd24 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Usage/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Usage/XList.php @@ -13,14 +13,11 @@ use Utopia\Database\Document; use Utopia\Database\Query; use Utopia\Database\Validator\Authorization; use Utopia\Platform\Action; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\WhiteList; class XList extends Action { - use HTTP; - public static function getName(): string { return 'listUsages'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/XList.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/XList.php index 7179be90ec..52f3fd2b55 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/XList.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/XList.php @@ -16,14 +16,11 @@ use Utopia\Database\Exception\Query as QueryException; use Utopia\Database\Query; use Utopia\Database\Validator\Query\Cursor; use Utopia\Platform\Action; -use Utopia\Platform\Scope\HTTP; use Utopia\Swoole\Response as SwooleResponse; use Utopia\Validator\Text; class XList extends Action { - use HTTP; - public static function getName(): string { return 'listDatabases'; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Init/Timeout.php b/src/Appwrite/Platform/Modules/Databases/Http/Init/Timeout.php new file mode 100644 index 0000000000..19e202981b --- /dev/null +++ b/src/Appwrite/Platform/Modules/Databases/Http/Init/Timeout.php @@ -0,0 +1,35 @@ +setType(Action::TYPE_INIT) + ->groups(['api', 'database']) + ->inject('request') + ->inject('dbForProject') + ->callback(function (Request $request, Database $dbForProject) { + $timeout = \intval($request->getHeader('x-appwrite-timeout')); + + if (!empty($timeout) && App::isDevelopment()) { + $dbForProject->setTimeout($timeout); + } + }); + } +} diff --git a/src/Appwrite/Platform/Modules/Databases/Module.php b/src/Appwrite/Platform/Modules/Databases/Module.php index f8686999dd..bf336413d4 100644 --- a/src/Appwrite/Platform/Modules/Databases/Module.php +++ b/src/Appwrite/Platform/Modules/Databases/Module.php @@ -2,6 +2,8 @@ namespace Appwrite\Platform\Modules\Databases; +require_once __DIR__ . '/Constants.php'; + use Appwrite\Platform\Modules\Databases\Services\Http; use Appwrite\Platform\Modules\Databases\Services\Workers; use Utopia\Platform; diff --git a/src/Appwrite/Platform/Modules/Databases/Services/Http.php b/src/Appwrite/Platform/Modules/Databases/Services/Http.php index 6c1361b0b1..d2f66f3657 100644 --- a/src/Appwrite/Platform/Modules/Databases/Services/Http.php +++ b/src/Appwrite/Platform/Modules/Databases/Services/Http.php @@ -2,6 +2,7 @@ namespace Appwrite\Platform\Modules\Databases\Services; +use Appwrite\Platform\Modules\Databases\Http\Init\Timeout; use Appwrite\Platform\Modules\Databases\Services\Registry\Collections as CollectionsRegistry; use Appwrite\Platform\Modules\Databases\Services\Registry\Databases as DatabasesRegistry; use Appwrite\Platform\Modules\Databases\Services\Registry\Tables as TablesRegistry; @@ -13,6 +14,9 @@ class Http extends Service { $this->type = Service::TYPE_HTTP; + // Project database timeout init hook! + $this->addAction(Timeout::getName(), new Timeout()); + foreach ([ DatabasesRegistry::class, CollectionsRegistry::class, diff --git a/src/Appwrite/Platform/Modules/Databases/Services/Registry/Collections.php b/src/Appwrite/Platform/Modules/Databases/Services/Registry/Collections.php index d036d2fd7b..bb0002ed47 100644 --- a/src/Appwrite/Platform/Modules/Databases/Services/Registry/Collections.php +++ b/src/Appwrite/Platform/Modules/Databases/Services/Registry/Collections.php @@ -35,6 +35,7 @@ use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Documents\Bul use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Documents\Create as CreateDocument; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Documents\Delete as DeleteDocument; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Documents\Get as GetDocument; +use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Documents\Logs\XList as ListDocumentLogs; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Documents\Update as UpdateDocument; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Documents\Upsert as UpsertDocument; use Appwrite\Platform\Modules\Databases\Http\Databases\Collections\Documents\XList as ListDocuments; @@ -90,6 +91,7 @@ class Collections extends Base $service->addAction(DeleteDocument::getName(), new DeleteDocument()); $service->addAction(DeleteDocuments::getName(), new DeleteDocuments()); $service->addAction(ListDocuments::getName(), new ListDocuments()); + $service->addAction(ListDocumentLogs::getName(), new ListDocumentLogs()); $service->addAction(IncrementDocumentAttribute::getName(), new IncrementDocumentAttribute()); $service->addAction(DecrementDocumentAttribute::getName(), new DecrementDocumentAttribute()); diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index 048d9f83b8..bbe1e1f004 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -1441,10 +1441,11 @@ class Builds extends Action $hostname = System::getEnv('_APP_DOMAIN'); $projectId = $project->getId(); + $region = $project->getAttribute('region', 'default'); $resourceId = $resource->getId(); $providerTargetUrl = match ($resource->getCollection()) { - 'functions' => "{$protocol}://{$hostname}/console/project-{$projectId}/functions/function-{$resourceId}", - 'sites' => "{$protocol}://{$hostname}/console/project-{$projectId}/sites/site-{$resourceId}", + 'functions' => "{$protocol}://{$hostname}/console/project-{$region}-{$projectId}/functions/function-{$resourceId}", + 'sites' => "{$protocol}://{$hostname}/console/project-{$region}-{$projectId}/sites/site-{$resourceId}", default => throw new \Exception('Invalid resource type') }; diff --git a/src/Appwrite/Platform/Workers/Deletes.php b/src/Appwrite/Platform/Workers/Deletes.php index 2f41001b58..8ed96c76a2 100644 --- a/src/Appwrite/Platform/Workers/Deletes.php +++ b/src/Appwrite/Platform/Workers/Deletes.php @@ -495,7 +495,7 @@ class Deletes extends Action * @throws Authorization * @throws DatabaseException */ - protected function deleteProject(Database $dbForPlatform, callable $getProjectDB, Device $deviceForFiles, Device $deviceForSites, Device $deviceForFunctions, Device $deviceForBuilds, Device $deviceForCache, CertificatesAdapter $certificates, Document $document): void + private function deleteProject(Database $dbForPlatform, callable $getProjectDB, Device $deviceForFiles, Device $deviceForSites, Device $deviceForFunctions, Device $deviceForBuilds, Device $deviceForCache, CertificatesAdapter $certificates, Document $document): void { $projectInternalId = $document->getSequence(); $projectId = $document->getId(); diff --git a/src/Appwrite/Platform/Workers/Migrations.php b/src/Appwrite/Platform/Workers/Migrations.php index f8e302089e..b59308c288 100644 --- a/src/Appwrite/Platform/Workers/Migrations.php +++ b/src/Appwrite/Platform/Workers/Migrations.php @@ -185,13 +185,33 @@ class Migrations extends Action */ protected function updateMigrationDocument(Document $migration, Document $project, Realtime $queueForRealtime): Document { + $errorMessages = []; + $clonedMigrationDocument = clone $migration; + + // we cannot use #sensitive because + // `errors` is nested which requires an override. + $errors = $clonedMigrationDocument->getAttribute('errors', []); + + foreach ($errors as $error) { + $decoded = json_decode($error, true); + + if (is_array($decoded) && isset($decoded['trace'])) { + unset($decoded['trace']); + $errorMessages[] = json_encode($decoded); + } + } + + // set the errors back without trace + $clonedMigrationDocument->setAttribute('errors', $errorMessages); + + /** Trigger Realtime Events */ $queueForRealtime ->setProject($project) ->setSubscribers(['console', $project->getId()]) ->setEvent('migrations.[migrationId].update') ->setParam('migrationId', $migration->getId()) - ->setPayload($migration->getArrayCopy()) + ->setPayload($clonedMigrationDocument->getArrayCopy(), ['options', 'credentials']) ->trigger(); return $this->dbForProject->updateDocument('migrations', $migration->getId(), $migration); @@ -306,26 +326,13 @@ class Migrations extends Action $errorMessages = []; foreach ($sourceErrors as $error) { - $message = "Error occurred while fetching '{$error->getResourceName()}:{$error->getResourceId()}' from source with message: '{$error->getMessage()}'"; - if ($error->getPrevious()) { - $message .= " Message: ".$error->getPrevious()->getMessage() . " File: ".$error->getPrevious()->getFile() . " Line: ".$error->getPrevious()->getLine(); - } - - $errorMessages[] = $message; + $errorMessages[] = json_encode($error); } foreach ($destinationErrors as $error) { - $message = "Error occurred while pushing '{$error->getResourceName()}:{$error->getResourceId()}' to destination with message: '{$error->getMessage()}'"; - - if ($error->getPrevious()) { - $message .= " Message: ".$error->getPrevious()->getMessage() . " File: ".$error->getPrevious()->getFile() . " Line: ".$error->getPrevious()->getLine(); - } - - /** @var MigrationException $error */ - $errorMessages[] = $message; + $errorMessages[] = json_encode($error); } $migration->setAttribute('errors', $errorMessages); - $this->updateMigrationDocument($migration, $projectDocument, $queueForRealtime); return; } @@ -355,12 +362,10 @@ class Migrations extends Action $errorMessages = []; foreach ($sourceErrors as $error) { - /** @var MigrationException $error */ - $errorMessages[] = "Error occurred while fetching '{$error->getResourceName()}:{$error->getResourceId()}' from source with message '{$error->getMessage()}'"; + $errorMessages[] = json_encode($error); } foreach ($destinationErrors as $error) { - /** @var MigrationException $error */ - $errorMessages[] = "Error occurred while pushing '{$error->getResourceName()}:{$error->getResourceId()}' to destination with message '{$error->getMessage()}'"; + $errorMessages[] = json_encode($error); } $migration->setAttribute('errors', $errorMessages); diff --git a/src/Appwrite/Platform/Workers/Webhooks.php b/src/Appwrite/Platform/Workers/Webhooks.php index 4c081aaa13..2ce39f8aaa 100644 --- a/src/Appwrite/Platform/Workers/Webhooks.php +++ b/src/Appwrite/Platform/Workers/Webhooks.php @@ -219,6 +219,7 @@ class Webhooks extends Action ]); $projectId = $project->getId(); + $region = $project->getAttribute('region', 'default'); $webhookId = $webhook->getId(); $template = Template::fromFile(__DIR__ . '/../../../../app/config/locale/templates/email-webhook-failed.tpl'); @@ -227,7 +228,7 @@ class Webhooks extends Action $template->setParam('{{project}}', $project->getAttribute('name')); $template->setParam('{{url}}', $webhook->getAttribute('url')); $template->setParam('{{error}}', $curlError ?? 'The server returned ' . $statusCode . ' status code'); - $template->setParam('{{path}}', "/console/project-$projectId/settings/webhooks/$webhookId"); + $template->setParam('{{path}}', "/console/project-$region-$projectId/settings/webhooks/$webhookId"); $template->setParam('{{attempts}}', $attempts); $template->setParam('{{logoUrl}}', $plan['logoUrl'] ?? APP_EMAIL_LOGO_URL); diff --git a/src/Appwrite/Utopia/Database/Validator/Queries/Attributes.php b/src/Appwrite/Utopia/Database/Validator/Queries/Attributes.php index 4a35c82b73..953948c045 100644 --- a/src/Appwrite/Utopia/Database/Validator/Queries/Attributes.php +++ b/src/Appwrite/Utopia/Database/Validator/Queries/Attributes.php @@ -4,7 +4,7 @@ namespace Appwrite\Utopia\Database\Validator\Queries; class Attributes extends Base { - public const ALLOWED_ATTRIBUTES = [ + public const array ALLOWED_ATTRIBUTES = [ 'key', 'type', 'size', diff --git a/src/Appwrite/Utopia/Database/Validator/Queries/Collections.php b/src/Appwrite/Utopia/Database/Validator/Queries/Collections.php index 6e8fcb8339..cdaaa104dc 100644 --- a/src/Appwrite/Utopia/Database/Validator/Queries/Collections.php +++ b/src/Appwrite/Utopia/Database/Validator/Queries/Collections.php @@ -4,7 +4,7 @@ namespace Appwrite\Utopia\Database\Validator\Queries; class Collections extends Base { - public const ALLOWED_ATTRIBUTES = [ + public const array ALLOWED_ATTRIBUTES = [ 'name', 'enabled', 'documentSecurity' diff --git a/src/Appwrite/Utopia/Database/Validator/Queries/Columns.php b/src/Appwrite/Utopia/Database/Validator/Queries/Columns.php index 3c2742bfdd..c990dfc18a 100644 --- a/src/Appwrite/Utopia/Database/Validator/Queries/Columns.php +++ b/src/Appwrite/Utopia/Database/Validator/Queries/Columns.php @@ -4,7 +4,7 @@ namespace Appwrite\Utopia\Database\Validator\Queries; class Columns extends Base { - public const ALLOWED_ATTRIBUTES = [ + public const array ALLOWED_COLUMNS = [ 'key', 'type', 'size', @@ -20,6 +20,6 @@ class Columns extends Base */ public function __construct() { - parent::__construct('attributes', self::ALLOWED_ATTRIBUTES); + parent::__construct('attributes', self::ALLOWED_COLUMNS); } } diff --git a/src/Appwrite/Utopia/Database/Validator/Queries/Tables.php b/src/Appwrite/Utopia/Database/Validator/Queries/Tables.php index 5a1fc4ec6d..f3aadb69ac 100644 --- a/src/Appwrite/Utopia/Database/Validator/Queries/Tables.php +++ b/src/Appwrite/Utopia/Database/Validator/Queries/Tables.php @@ -4,10 +4,10 @@ namespace Appwrite\Utopia\Database\Validator\Queries; class Tables extends Base { - public const ALLOWED_ATTRIBUTES = [ + public const array ALLOWED_COLUMNS = [ 'name', 'enabled', - 'documentSecurity' + 'rowSecurity' ]; /** @@ -16,6 +16,6 @@ class Tables extends Base */ public function __construct() { - parent::__construct('collections', self::ALLOWED_ATTRIBUTES); + parent::__construct('collections', self::ALLOWED_COLUMNS); } } diff --git a/src/Appwrite/Utopia/Response/Model/Migration.php b/src/Appwrite/Utopia/Response/Model/Migration.php index 3be1d519a6..76e00b3097 100644 --- a/src/Appwrite/Utopia/Response/Model/Migration.php +++ b/src/Appwrite/Utopia/Response/Model/Migration.php @@ -4,6 +4,7 @@ namespace Appwrite\Utopia\Response\Model; use Appwrite\Utopia\Response; use Appwrite\Utopia\Response\Model; +use Utopia\Database\Document; class Migration extends Model { @@ -107,4 +108,29 @@ class Migration extends Model { return Response::MODEL_MIGRATION; } + + public function filter(Document $document): Document + { + $errors = $document->getAttribute('errors', []); + if (empty($errors)) { + return $document; + } + + foreach ($errors as $index => $error) { + $decoded = json_decode($error, true); + + // frontend doesn't need too many details. + if (is_array($decoded)) { + $errors[$index] = json_encode([ + 'code' => $decoded['code'] ?? 0, + 'message' => $decoded['message'] ?? null, + ]); + } + } + + // errors now only have code and message. + $document->setAttribute('errors', $errors); + + return $document; + } } diff --git a/src/Appwrite/Utopia/Response/Model/Project.php b/src/Appwrite/Utopia/Response/Model/Project.php index efd002654e..abe67e7e86 100644 --- a/src/Appwrite/Utopia/Response/Model/Project.php +++ b/src/Appwrite/Utopia/Response/Model/Project.php @@ -169,6 +169,12 @@ class Project extends Model 'default' => false, 'example' => true, ]) + ->addRule('authInvalidateSessions', [ + 'type' => self::TYPE_BOOLEAN, + 'description' => 'Whether or not all existing sessions should be invalidated on password change', + 'default' => false, + 'example' => true, + ]) ->addRule('oAuthProviders', [ 'type' => Response::MODEL_AUTH_PROVIDER, 'description' => 'List of Auth Providers.', @@ -376,6 +382,7 @@ class Project extends Model $document->setAttribute('authMembershipsUserName', $authValues['membershipsUserName'] ?? true); $document->setAttribute('authMembershipsUserEmail', $authValues['membershipsUserEmail'] ?? true); $document->setAttribute('authMembershipsMfa', $authValues['membershipsMfa'] ?? true); + $document->setAttribute('authInvalidateSessions', $authValues['invalidateSessions'] ?? false); foreach ($auth as $index => $method) { $key = $method['key']; diff --git a/tests/e2e/Scopes/ProjectCustom.php b/tests/e2e/Scopes/ProjectCustom.php index a354696f53..51aebeaef7 100644 --- a/tests/e2e/Scopes/ProjectCustom.php +++ b/tests/e2e/Scopes/ProjectCustom.php @@ -200,4 +200,17 @@ trait ProjectCustom return $key['body']['secret']; } + public function updateProjectinvalidateSessionsProperty(bool $value) + { + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . self::$project['$id'] . '/auth/session-invalidation', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'cookie' => 'a_session_console=' . $this->getRoot()['session'], + 'x-appwrite-project' => 'console', + ]), [ + 'enabled' => $value, + ]); + + return $response['headers']['status-code']; + } } diff --git a/tests/e2e/Services/Account/AccountCustomClientTest.php b/tests/e2e/Services/Account/AccountCustomClientTest.php index 0cc2eb893a..b114a54c30 100644 --- a/tests/e2e/Services/Account/AccountCustomClientTest.php +++ b/tests/e2e/Services/Account/AccountCustomClientTest.php @@ -480,6 +480,29 @@ class AccountCustomClientTest extends Scope $password = $data['password'] ?? ''; $session = $data['session'] ?? ''; + for ($i = 0; $i < 5; $i++) { + $response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ]), [ + 'email' => $email, + 'password' => $password, + ]); + + $this->assertEquals(201, $response['headers']['status-code']); + sleep(1); + } + + $response = $this->client->call(Client::METHOD_GET, '/account/sessions', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session, + ])); + + $allSessions = array_map(fn ($sessionDetails) => $sessionDetails['$id'], $response['body']['sessions']); + /** * Test for SUCCESS */ @@ -500,17 +523,140 @@ class AccountCustomClientTest extends Scope $this->assertTrue((new DatetimeValidator())->isValid($response['body']['registration'])); $this->assertEquals($response['body']['email'], $email); + $currentSessionId = $data['sessionId'] ?? ''; + $response = $this->client->call(Client::METHOD_GET, '/account/sessions', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session, + ])); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals(1, $response['body']['total']); + // checking the current session or not + $this->assertEquals($currentSessionId, $response['body']['sessions'][0]['$id']); + $this->assertTrue($response['body']['sessions'][0]['current']); + + // checking for all non active sessions are cleared + foreach ($allSessions as $sessionId) { + if ($currentSessionId === $sessionId) { + $response = $this->client->call(Client::METHOD_GET, '/account/sessions/current', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session, + ])); + + $this->assertEquals(200, $response['headers']['status-code']); + } else { + $response = $this->client->call(Client::METHOD_GET, '/account/sessions/'.$sessionId, array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session, + ])); + + $this->assertEquals(404, $response['headers']['status-code']); + } + } + + $newPassword = 'new-password'; + // updating the invalidateSession to false to check sessions are not invalidated + $this->updateProjectinvalidateSessionsProperty(false); + for ($i = 0; $i < 5; $i++) { + $response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ]), [ + 'email' => $email, + 'password' => $newPassword, + ]); + + $this->assertEquals(201, $response['headers']['status-code']); + sleep(1); + } + + $response = $this->client->call(Client::METHOD_GET, '/account/sessions', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session, + ])); + + $allSessions = array_map(fn ($sessionDetails) => $sessionDetails['$id'], $response['body']['sessions']); + + $response = $this->client->call(Client::METHOD_PATCH, '/account/password', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session, + ]), [ + 'password' => $newPassword, + 'oldPassword' => $newPassword, + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + + foreach ($allSessions as $sessionId) { + $response = $this->client->call(Client::METHOD_GET, '/account/sessions/'.$sessionId, headers: array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session, + ])); + + $this->assertEquals(200, $response['headers']['status-code']); + } + + // setting invalidateSession to true to check the sessions are cleared or not + $this->updateProjectinvalidateSessionsProperty(true); + $response = $this->client->call(Client::METHOD_PATCH, '/account/password', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session, + ]), [ + 'password' => $newPassword, + 'oldPassword' => $newPassword, + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_GET, '/account/sessions', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session, + ])); + + $allSessions = array_map(fn ($sessionDetails) => $sessionDetails['$id'], $response['body']['sessions']); + + foreach ($allSessions as $sessionId) { + if ($currentSessionId !== $sessionId) { + $response = $this->client->call(Client::METHOD_GET, '/account/sessions/'.$sessionId, array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'cookie' => 'a_session_' . $this->getProject()['$id'] . '=' . $session, + ])); + + $this->assertEquals(404, $response['headers']['status-code']); + } + } + $response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], ]), [ 'email' => $email, - 'password' => 'new-password', + 'password' => $newPassword, ]); $this->assertEquals(201, $response['headers']['status-code']); + /** * Test for FAILURE */ diff --git a/tests/e2e/Services/Databases/Collections/DatabasesBase.php b/tests/e2e/Services/Databases/Legacy/DatabasesBase.php similarity index 99% rename from tests/e2e/Services/Databases/Collections/DatabasesBase.php rename to tests/e2e/Services/Databases/Legacy/DatabasesBase.php index 6b0aca1512..69b24d5052 100644 --- a/tests/e2e/Services/Databases/Collections/DatabasesBase.php +++ b/tests/e2e/Services/Databases/Legacy/DatabasesBase.php @@ -1,6 +1,6 @@ [ 'databaseId' => $this->database['body']['data']['databasesCreate']['_id'], 'collectionId' => $this->collection['body']['data']['databasesCreateCollection']['_id'], - 'documentId' => $document['body']['data']['collectionsCreateDocument']['_id'], + 'documentId' => $document['body']['data']['databasesCreateDocument']['_id'], ] ]; $document = $this->client->call(Client::METHOD_POST, '/graphql', [ @@ -188,7 +188,7 @@ class AuthTest extends Scope 'cookie' => 'a_session_' . $projectId . '=' . $this->token1, ], $gqlPayload); - $this->assertIsArray($document['body']['data']['collectionsGetDocument']); + $this->assertIsArray($document['body']['data']['databasesGetDocument']); $this->assertArrayNotHasKey('errors', $document['body']); // Try to read as account 2 @@ -238,7 +238,7 @@ class AuthTest extends Scope 'variables' => [ 'databaseId' => $this->database['body']['data']['databasesCreate']['_id'], 'collectionId' => $this->collection['body']['data']['databasesCreateCollection']['_id'], - 'documentId' => $document['body']['data']['collectionsCreateDocument']['_id'], + 'documentId' => $document['body']['data']['databasesCreateDocument']['_id'], ] ]; $document = $this->client->call(Client::METHOD_POST, '/graphql', [ diff --git a/tests/e2e/Services/GraphQL/Collections/DatabaseClientTest.php b/tests/e2e/Services/GraphQL/Legacy/DatabaseClientTest.php similarity index 94% rename from tests/e2e/Services/GraphQL/Collections/DatabaseClientTest.php rename to tests/e2e/Services/GraphQL/Legacy/DatabaseClientTest.php index 349d580d64..c2c63e41c0 100644 --- a/tests/e2e/Services/GraphQL/Collections/DatabaseClientTest.php +++ b/tests/e2e/Services/GraphQL/Legacy/DatabaseClientTest.php @@ -1,6 +1,6 @@ assertArrayNotHasKey('errors', $attribute['body']); $this->assertIsArray($attribute['body']['data']); - $this->assertIsArray($attribute['body']['data']['collectionsCreateStringAttribute']); + $this->assertIsArray($attribute['body']['data']['databasesCreateStringAttribute']); return $data; } @@ -141,7 +141,7 @@ class DatabaseClientTest extends Scope $this->assertArrayNotHasKey('errors', $attribute['body']); $this->assertIsArray($attribute['body']['data']); - $this->assertIsArray($attribute['body']['data']['collectionsCreateIntegerAttribute']); + $this->assertIsArray($attribute['body']['data']['databasesCreateIntegerAttribute']); return $data; } @@ -182,7 +182,7 @@ class DatabaseClientTest extends Scope $this->assertArrayNotHasKey('errors', $document['body']); $this->assertIsArray($document['body']['data']); - $document = $document['body']['data']['collectionsCreateDocument']; + $document = $document['body']['data']['databasesCreateDocument']; $this->assertIsArray($document); return [ @@ -215,7 +215,7 @@ class DatabaseClientTest extends Scope $this->assertArrayNotHasKey('errors', $documents['body']); $this->assertIsArray($documents['body']['data']); - $this->assertIsArray($documents['body']['data']['collectionsListDocuments']); + $this->assertIsArray($documents['body']['data']['databasesListDocuments']); } /** @@ -242,7 +242,7 @@ class DatabaseClientTest extends Scope $this->assertArrayNotHasKey('errors', $document['body']); $this->assertIsArray($document['body']['data']); - $this->assertIsArray($document['body']['data']['collectionsGetDocument']); + $this->assertIsArray($document['body']['data']['databasesGetDocument']); } /** @@ -272,7 +272,7 @@ class DatabaseClientTest extends Scope $this->assertArrayNotHasKey('errors', $document['body']); $this->assertIsArray($document['body']['data']); - $document = $document['body']['data']['collectionsUpdateDocument']; + $document = $document['body']['data']['databasesUpdateDocument']; $this->assertIsArray($document); $this->assertStringContainsString('New Document Name', $document['data']); @@ -377,7 +377,7 @@ class DatabaseClientTest extends Scope ]; $res = $this->client->call(Client::METHOD_POST, '/graphql', $headers, $payload); $this->assertArrayNotHasKey('errors', $res['body']); - $this->assertCount(10, $res['body']['data']['collectionsCreateDocuments']['documents']); + $this->assertCount(10, $res['body']['data']['databasesCreateDocuments']['documents']); return [ 'databaseId' => $databaseId, @@ -418,7 +418,7 @@ class DatabaseClientTest extends Scope ]; $res = $this->client->call(Client::METHOD_POST, '/graphql', $headers, $payload); $this->assertArrayNotHasKey('errors', $res['body']); - $this->assertCount(10, $res['body']['data']['collectionsUpdateDocuments']['documents']); + $this->assertCount(10, $res['body']['data']['databasesUpdateDocuments']['documents']); return $data; } @@ -449,7 +449,7 @@ class DatabaseClientTest extends Scope ]; $res = $this->client->call(Client::METHOD_POST, '/graphql', $headers, $payload); $this->assertArrayNotHasKey('errors', $res['body']); - $this->assertCount(2, $res['body']['data']['collectionsUpsertDocuments']['documents']); + $this->assertCount(2, $res['body']['data']['databasesUpsertDocuments']['documents']); return $data; } @@ -475,7 +475,7 @@ class DatabaseClientTest extends Scope ]; $res = $this->client->call(Client::METHOD_POST, '/graphql', $headers, $payload); $this->assertArrayNotHasKey('errors', $res['body']); - $this->assertCount(11, $res['body']['data']['collectionsDeleteDocuments']['documents']); + $this->assertCount(11, $res['body']['data']['databasesDeleteDocuments']['documents']); return $data; } diff --git a/tests/e2e/Services/GraphQL/Collections/DatabaseServerTest.php b/tests/e2e/Services/GraphQL/Legacy/DatabaseServerTest.php similarity index 91% rename from tests/e2e/Services/GraphQL/Collections/DatabaseServerTest.php rename to tests/e2e/Services/GraphQL/Legacy/DatabaseServerTest.php index 3e5b457308..3ecc96eaa0 100644 --- a/tests/e2e/Services/GraphQL/Collections/DatabaseServerTest.php +++ b/tests/e2e/Services/GraphQL/Legacy/DatabaseServerTest.php @@ -1,6 +1,6 @@ assertArrayNotHasKey('errors', $attribute['body']); $this->assertIsArray($attribute['body']['data']); - $this->assertIsArray($attribute['body']['data']['collectionsCreateStringAttribute']); + $this->assertIsArray($attribute['body']['data']['databasesCreateStringAttribute']); return $data; } @@ -170,9 +170,9 @@ class DatabaseServerTest extends Scope ], $this->getHeaders()), $gqlPayload); $this->assertIsArray($attribute['body']['data']); - $this->assertIsArray($attribute['body']['data']['collectionsUpdateStringAttribute']); - $this->assertFalse($attribute['body']['data']['collectionsUpdateStringAttribute']['required']); - $this->assertEquals('Default Value', $attribute['body']['data']['collectionsUpdateStringAttribute']['default']); + $this->assertIsArray($attribute['body']['data']['databasesUpdateStringAttribute']); + $this->assertFalse($attribute['body']['data']['databasesUpdateStringAttribute']['required']); + $this->assertEquals('Default Value', $attribute['body']['data']['databasesUpdateStringAttribute']['default']); $this->assertEquals(200, $attribute['headers']['status-code']); return $data; @@ -205,7 +205,7 @@ class DatabaseServerTest extends Scope $this->assertArrayNotHasKey('errors', $attribute['body']); $this->assertIsArray($attribute['body']['data']); - $this->assertIsArray($attribute['body']['data']['collectionsCreateIntegerAttribute']); + $this->assertIsArray($attribute['body']['data']['databasesCreateIntegerAttribute']); return $data; } @@ -240,11 +240,11 @@ class DatabaseServerTest extends Scope ], $this->getHeaders()), $gqlPayload); $this->assertIsArray($attribute['body']['data']); - $this->assertIsArray($attribute['body']['data']['collectionsUpdateIntegerAttribute']); - $this->assertFalse($attribute['body']['data']['collectionsUpdateIntegerAttribute']['required']); - $this->assertEquals(12, $attribute['body']['data']['collectionsUpdateIntegerAttribute']['min']); - $this->assertEquals(160, $attribute['body']['data']['collectionsUpdateIntegerAttribute']['max']); - $this->assertEquals(50, $attribute['body']['data']['collectionsUpdateIntegerAttribute']['default']); + $this->assertIsArray($attribute['body']['data']['databasesUpdateIntegerAttribute']); + $this->assertFalse($attribute['body']['data']['databasesUpdateIntegerAttribute']['required']); + $this->assertEquals(12, $attribute['body']['data']['databasesUpdateIntegerAttribute']['min']); + $this->assertEquals(160, $attribute['body']['data']['databasesUpdateIntegerAttribute']['max']); + $this->assertEquals(50, $attribute['body']['data']['databasesUpdateIntegerAttribute']['default']); $this->assertEquals(200, $attribute['headers']['status-code']); return $data; @@ -275,7 +275,7 @@ class DatabaseServerTest extends Scope $this->assertArrayNotHasKey('errors', $attribute['body']); $this->assertIsArray($attribute['body']['data']); - $this->assertIsArray($attribute['body']['data']['collectionsCreateBooleanAttribute']); + $this->assertIsArray($attribute['body']['data']['databasesCreateBooleanAttribute']); return $data; } @@ -308,9 +308,9 @@ class DatabaseServerTest extends Scope ], $this->getHeaders()), $gqlPayload); $this->assertIsArray($attribute['body']['data']); - $this->assertIsArray($attribute['body']['data']['collectionsUpdateBooleanAttribute']); - $this->assertFalse($attribute['body']['data']['collectionsUpdateBooleanAttribute']['required']); - $this->assertTrue($attribute['body']['data']['collectionsUpdateBooleanAttribute']['default']); + $this->assertIsArray($attribute['body']['data']['databasesUpdateBooleanAttribute']); + $this->assertFalse($attribute['body']['data']['databasesUpdateBooleanAttribute']['required']); + $this->assertTrue($attribute['body']['data']['databasesUpdateBooleanAttribute']['default']); $this->assertEquals(200, $attribute['headers']['status-code']); return $data; @@ -344,7 +344,7 @@ class DatabaseServerTest extends Scope $this->assertArrayNotHasKey('errors', $attribute['body']); $this->assertIsArray($attribute['body']['data']); - $this->assertIsArray($attribute['body']['data']['collectionsCreateFloatAttribute']); + $this->assertIsArray($attribute['body']['data']['databasesCreateFloatAttribute']); return $data; } @@ -379,11 +379,11 @@ class DatabaseServerTest extends Scope ], $this->getHeaders()), $gqlPayload); $this->assertIsArray($attribute['body']['data']); - $this->assertIsArray($attribute['body']['data']['collectionsUpdateFloatAttribute']); - $this->assertFalse($attribute['body']['data']['collectionsUpdateFloatAttribute']['required']); - $this->assertEquals(100.0, $attribute['body']['data']['collectionsUpdateFloatAttribute']['min']); - $this->assertEquals(1000000.0, $attribute['body']['data']['collectionsUpdateFloatAttribute']['max']); - $this->assertEquals(2500.0, $attribute['body']['data']['collectionsUpdateFloatAttribute']['default']); + $this->assertIsArray($attribute['body']['data']['databasesUpdateFloatAttribute']); + $this->assertFalse($attribute['body']['data']['databasesUpdateFloatAttribute']['required']); + $this->assertEquals(100.0, $attribute['body']['data']['databasesUpdateFloatAttribute']['min']); + $this->assertEquals(1000000.0, $attribute['body']['data']['databasesUpdateFloatAttribute']['max']); + $this->assertEquals(2500.0, $attribute['body']['data']['databasesUpdateFloatAttribute']['default']); $this->assertEquals(200, $attribute['headers']['status-code']); return $data; @@ -414,7 +414,7 @@ class DatabaseServerTest extends Scope $this->assertArrayNotHasKey('errors', $attribute['body']); $this->assertIsArray($attribute['body']['data']); - $this->assertIsArray($attribute['body']['data']['collectionsCreateEmailAttribute']); + $this->assertIsArray($attribute['body']['data']['databasesCreateEmailAttribute']); return $data; } @@ -447,9 +447,9 @@ class DatabaseServerTest extends Scope ], $this->getHeaders()), $gqlPayload); $this->assertIsArray($attribute['body']['data']); - $this->assertIsArray($attribute['body']['data']['collectionsUpdateEmailAttribute']); - $this->assertFalse($attribute['body']['data']['collectionsUpdateEmailAttribute']['required']); - $this->assertEquals('torsten@appwrite.io', $attribute['body']['data']['collectionsUpdateEmailAttribute']['default']); + $this->assertIsArray($attribute['body']['data']['databasesUpdateEmailAttribute']); + $this->assertFalse($attribute['body']['data']['databasesUpdateEmailAttribute']['required']); + $this->assertEquals('torsten@appwrite.io', $attribute['body']['data']['databasesUpdateEmailAttribute']['default']); $this->assertEquals(200, $attribute['headers']['status-code']); return $data; @@ -485,7 +485,7 @@ class DatabaseServerTest extends Scope $this->assertArrayNotHasKey('errors', $attribute['body']); $this->assertIsArray($attribute['body']['data']); - $this->assertIsArray($attribute['body']['data']['collectionsCreateEnumAttribute']); + $this->assertIsArray($attribute['body']['data']['databasesCreateEnumAttribute']); return $data; } @@ -524,11 +524,11 @@ class DatabaseServerTest extends Scope ], $this->getHeaders()), $gqlPayload); $this->assertIsArray($attribute['body']['data']); - $this->assertIsArray($attribute['body']['data']['collectionsUpdateEnumAttribute']); - $this->assertFalse($attribute['body']['data']['collectionsUpdateEnumAttribute']['required']); - $this->assertEquals('tech', $attribute['body']['data']['collectionsUpdateEnumAttribute']['default']); - $this->assertContains('tech', $attribute['body']['data']['collectionsUpdateEnumAttribute']['elements']); - $this->assertNotContains('guest', $attribute['body']['data']['collectionsUpdateEnumAttribute']['elements']); + $this->assertIsArray($attribute['body']['data']['databasesUpdateEnumAttribute']); + $this->assertFalse($attribute['body']['data']['databasesUpdateEnumAttribute']['required']); + $this->assertEquals('tech', $attribute['body']['data']['databasesUpdateEnumAttribute']['default']); + $this->assertContains('tech', $attribute['body']['data']['databasesUpdateEnumAttribute']['elements']); + $this->assertNotContains('guest', $attribute['body']['data']['databasesUpdateEnumAttribute']['elements']); $this->assertEquals(200, $attribute['headers']['status-code']); return $data; @@ -559,7 +559,7 @@ class DatabaseServerTest extends Scope $this->assertArrayNotHasKey('errors', $attribute['body']); $this->assertIsArray($attribute['body']['data']); - $this->assertIsArray($attribute['body']['data']['collectionsCreateDatetimeAttribute']); + $this->assertIsArray($attribute['body']['data']['databasesCreateDatetimeAttribute']); return $data; } @@ -592,9 +592,9 @@ class DatabaseServerTest extends Scope ], $this->getHeaders()), $gqlPayload); $this->assertIsArray($attribute['body']['data']); - $this->assertIsArray($attribute['body']['data']['collectionsUpdateDatetimeAttribute']); - $this->assertFalse($attribute['body']['data']['collectionsUpdateDatetimeAttribute']['required']); - $this->assertEquals('2000-01-01T00:00:00Z', $attribute['body']['data']['collectionsUpdateDatetimeAttribute']['default']); + $this->assertIsArray($attribute['body']['data']['databasesUpdateDatetimeAttribute']); + $this->assertFalse($attribute['body']['data']['databasesUpdateDatetimeAttribute']['required']); + $this->assertEquals('2000-01-01T00:00:00Z', $attribute['body']['data']['databasesUpdateDatetimeAttribute']['default']); $this->assertEquals(200, $attribute['headers']['status-code']); return $data; @@ -627,7 +627,7 @@ class DatabaseServerTest extends Scope $this->assertArrayNotHasKey('errors', $attribute['body']); $this->assertIsArray($attribute['body']['data']); - $this->assertIsArray($attribute['body']['data']['collectionsCreateRelationshipAttribute']); + $this->assertIsArray($attribute['body']['data']['databasesCreateRelationshipAttribute']); return $data; } @@ -658,7 +658,7 @@ class DatabaseServerTest extends Scope $this->assertArrayNotHasKey('errors', $attribute['body']); $this->assertIsArray($attribute['body']['data']); - $this->assertIsArray($attribute['body']['data']['collectionsUpdateRelationshipAttribute']); + $this->assertIsArray($attribute['body']['data']['databasesUpdateRelationshipAttribute']); return $data; } @@ -689,7 +689,7 @@ class DatabaseServerTest extends Scope $this->assertArrayNotHasKey('errors', $attribute['body']); $this->assertIsArray($attribute['body']['data']); - $this->assertIsArray($attribute['body']['data']['collectionsCreateIpAttribute']); + $this->assertIsArray($attribute['body']['data']['databasesCreateIpAttribute']); return $data; } @@ -722,9 +722,9 @@ class DatabaseServerTest extends Scope ], $this->getHeaders()), $gqlPayload); $this->assertIsArray($attribute['body']['data']); - $this->assertIsArray($attribute['body']['data']['collectionsUpdateIpAttribute']); - $this->assertFalse($attribute['body']['data']['collectionsUpdateIpAttribute']['required']); - $this->assertEquals('127.0.0.1', $attribute['body']['data']['collectionsUpdateIpAttribute']['default']); + $this->assertIsArray($attribute['body']['data']['databasesUpdateIpAttribute']); + $this->assertFalse($attribute['body']['data']['databasesUpdateIpAttribute']['required']); + $this->assertEquals('127.0.0.1', $attribute['body']['data']['databasesUpdateIpAttribute']['default']); $this->assertEquals(200, $attribute['headers']['status-code']); return $data; @@ -756,7 +756,7 @@ class DatabaseServerTest extends Scope $this->assertArrayNotHasKey('errors', $attribute['body']); $this->assertIsArray($attribute['body']['data']); - $this->assertIsArray($attribute['body']['data']['collectionsCreateUrlAttribute']); + $this->assertIsArray($attribute['body']['data']['databasesCreateUrlAttribute']); return $data; } @@ -789,9 +789,9 @@ class DatabaseServerTest extends Scope ], $this->getHeaders()), $gqlPayload); $this->assertIsArray($attribute['body']['data']); - $this->assertIsArray($attribute['body']['data']['collectionsUpdateUrlAttribute']); - $this->assertFalse($attribute['body']['data']['collectionsUpdateUrlAttribute']['required']); - $this->assertEquals('https://cloud.appwrite.io', $attribute['body']['data']['collectionsUpdateUrlAttribute']['default']); + $this->assertIsArray($attribute['body']['data']['databasesUpdateUrlAttribute']); + $this->assertFalse($attribute['body']['data']['databasesUpdateUrlAttribute']['required']); + $this->assertEquals('https://cloud.appwrite.io', $attribute['body']['data']['databasesUpdateUrlAttribute']['default']); $this->assertEquals(200, $attribute['headers']['status-code']); } @@ -825,12 +825,12 @@ class DatabaseServerTest extends Scope $this->assertArrayNotHasKey('errors', $index['body']); $this->assertIsArray($index['body']['data']); - $this->assertIsArray($index['body']['data']['collectionsCreateIndex']); + $this->assertIsArray($index['body']['data']['databasesCreateIndex']); return [ 'database' => $data['database'], 'collection' => $data['collection'], - 'index' => $index['body']['data']['collectionsCreateIndex'], + 'index' => $index['body']['data']['databasesCreateIndex'], ]; } @@ -876,7 +876,7 @@ class DatabaseServerTest extends Scope $this->assertArrayNotHasKey('errors', $document['body']); $this->assertIsArray($document['body']['data']); - $document = $document['body']['data']['collectionsCreateDocument']; + $document = $document['body']['data']['databasesCreateDocument']; $this->assertIsArray($document); return [ @@ -1044,7 +1044,7 @@ class DatabaseServerTest extends Scope $this->assertArrayNotHasKey('errors', $attributes['body']); $this->assertIsArray($attributes['body']['data']); - $this->assertIsArray($attributes['body']['data']['collectionsListAttributes']); + $this->assertIsArray($attributes['body']['data']['databasesListAttributes']); } /** @@ -1071,7 +1071,7 @@ class DatabaseServerTest extends Scope $this->assertArrayNotHasKey('errors', $attribute['body']); $this->assertIsArray($attribute['body']['data']); - $this->assertIsArray($attribute['body']['data']['collectionsGetAttribute']); + $this->assertIsArray($attribute['body']['data']['databasesGetAttribute']); } /** @@ -1097,7 +1097,7 @@ class DatabaseServerTest extends Scope $this->assertArrayNotHasKey('errors', $indices['body']); $this->assertIsArray($indices['body']['data']); - $this->assertIsArray($indices['body']['data']['collectionsListIndexes']); + $this->assertIsArray($indices['body']['data']['databasesListIndexes']); } /** @@ -1124,7 +1124,7 @@ class DatabaseServerTest extends Scope $this->assertArrayNotHasKey('errors', $index['body']); $this->assertIsArray($index['body']['data']); - $this->assertIsArray($index['body']['data']['collectionsGetIndex']); + $this->assertIsArray($index['body']['data']['databasesGetIndex']); } /** @@ -1150,7 +1150,7 @@ class DatabaseServerTest extends Scope $this->assertArrayNotHasKey('errors', $documents['body']); $this->assertIsArray($documents['body']['data']); - $this->assertIsArray($documents['body']['data']['collectionsListDocuments']); + $this->assertIsArray($documents['body']['data']['databasesListDocuments']); } /** @@ -1177,7 +1177,7 @@ class DatabaseServerTest extends Scope $this->assertArrayNotHasKey('errors', $document['body']); $this->assertIsArray($document['body']['data']); - $this->assertIsArray($document['body']['data']['collectionsGetDocument']); + $this->assertIsArray($document['body']['data']['databasesGetDocument']); } // /** @@ -1308,7 +1308,7 @@ class DatabaseServerTest extends Scope $this->assertArrayNotHasKey('errors', $document['body']); $this->assertIsArray($document['body']['data']); - $document = $document['body']['data']['collectionsUpdateDocument']; + $document = $document['body']['data']['databasesUpdateDocument']; $this->assertIsArray($document); $this->assertStringContainsString('New Document Name', $document['data']); } @@ -1538,7 +1538,7 @@ class DatabaseServerTest extends Scope ]; $res = $this->client->call(Client::METHOD_POST, '/graphql', $headers, $payload); $this->assertArrayNotHasKey('errors', $res['body']); - $this->assertCount(10, $res['body']['data']['collectionsCreateDocuments']['documents']); + $this->assertCount(10, $res['body']['data']['databasesCreateDocuments']['documents']); return [ 'databaseId' => $databaseId, @@ -1578,7 +1578,7 @@ class DatabaseServerTest extends Scope ]; $res = $this->client->call(Client::METHOD_POST, '/graphql', $headers, $payload); $this->assertArrayNotHasKey('errors', $res['body']); - $this->assertCount(10, $res['body']['data']['collectionsUpdateDocuments']['documents']); + $this->assertCount(10, $res['body']['data']['databasesUpdateDocuments']['documents']); return $data; } @@ -1608,7 +1608,7 @@ class DatabaseServerTest extends Scope ]; $res = $this->client->call(Client::METHOD_POST, '/graphql', $headers, $payload); $this->assertArrayNotHasKey('errors', $res['body']); - $this->assertCount(2, $res['body']['data']['collectionsUpsertDocuments']['documents']); + $this->assertCount(2, $res['body']['data']['databasesUpsertDocuments']['documents']); return $data; } @@ -1633,7 +1633,7 @@ class DatabaseServerTest extends Scope ]; $res = $this->client->call(Client::METHOD_POST, '/graphql', $headers, $payload); $this->assertArrayNotHasKey('errors', $res['body']); - $this->assertCount(11, $res['body']['data']['collectionsDeleteDocuments']['documents']); + $this->assertCount(11, $res['body']['data']['databasesDeleteDocuments']['documents']); return $data; } diff --git a/tests/e2e/Services/GraphQL/Tables/AbuseTest.php b/tests/e2e/Services/GraphQL/Tables/AbuseTest.php index abb5019d55..8b759aa1ce 100644 --- a/tests/e2e/Services/GraphQL/Tables/AbuseTest.php +++ b/tests/e2e/Services/GraphQL/Tables/AbuseTest.php @@ -132,7 +132,7 @@ class AbuseTest extends Scope 'x-appwrite-key' => $this->getProject()['apiKey'], ], $gqlPayload); - $databaseId = $response['body']['data']['databasesCreate']['_id']; + $databaseId = $response['body']['data']['tablesCreate']['_id']; $query = $this->getQuery(self::$CREATE_TABLE); $gqlPayload = [ @@ -155,7 +155,7 @@ class AbuseTest extends Scope 'x-appwrite-key' => $this->getProject()['apiKey'], ], $gqlPayload); - $tableId = $response['body']['data']['databasesCreateTable']['_id']; + $tableId = $response['body']['data']['tablesCreate']['_id']; $query = $this->getQuery(self::$CREATE_STRING_COLUMN); $gqlPayload = [ diff --git a/tests/e2e/Services/GraphQL/Tables/AuthTest.php b/tests/e2e/Services/GraphQL/Tables/AuthTest.php index 681607d599..21d581d207 100644 --- a/tests/e2e/Services/GraphQL/Tables/AuthTest.php +++ b/tests/e2e/Services/GraphQL/Tables/AuthTest.php @@ -128,7 +128,7 @@ class AuthTest extends Scope 'query' => $query, 'variables' => [ 'databaseId' => $this->database['body']['data']['databasesCreate']['_id'], - 'tableId' => $this->table['body']['data']['databasesCreateTable']['_id'], + 'tableId' => $this->table['body']['data']['tablesCreate']['_id'], 'key' => 'name', 'size' => 256, 'required' => true, @@ -154,7 +154,7 @@ class AuthTest extends Scope 'query' => $query, 'variables' => [ 'databaseId' => $this->database['body']['data']['databasesCreate']['_id'], - 'tableId' => $this->table['body']['data']['databasesCreateTable']['_id'], + 'tableId' => $this->table['body']['data']['tablesCreate']['_id'], 'rowId' => ID::unique(), 'data' => [ 'name' => 'John Doe', @@ -178,7 +178,7 @@ class AuthTest extends Scope 'query' => $query, 'variables' => [ 'databaseId' => $this->database['body']['data']['databasesCreate']['_id'], - 'tableId' => $this->table['body']['data']['databasesCreateTable']['_id'], + 'tableId' => $this->table['body']['data']['tablesCreate']['_id'], 'rowId' => $row['body']['data']['tablesCreateRow']['_id'], ] ]; @@ -213,7 +213,7 @@ class AuthTest extends Scope 'query' => $query, 'variables' => [ 'databaseId' => $this->database['body']['data']['databasesCreate']['_id'], - 'tableId' => $this->table['body']['data']['databasesCreateTable']['_id'], + 'tableId' => $this->table['body']['data']['tablesCreate']['_id'], 'rowId' => ID::unique(), 'data' => [ 'name' => 'John Doe', @@ -237,7 +237,7 @@ class AuthTest extends Scope 'query' => $query, 'variables' => [ 'databaseId' => $this->database['body']['data']['databasesCreate']['_id'], - 'tableId' => $this->table['body']['data']['databasesCreateTable']['_id'], + 'tableId' => $this->table['body']['data']['tablesCreate']['_id'], 'rowId' => $row['body']['data']['tablesCreateRow']['_id'], ] ]; diff --git a/tests/e2e/Services/GraphQL/Tables/DatabaseClientTest.php b/tests/e2e/Services/GraphQL/Tables/DatabaseClientTest.php index c5cba6c47f..5ff8e65922 100644 --- a/tests/e2e/Services/GraphQL/Tables/DatabaseClientTest.php +++ b/tests/e2e/Services/GraphQL/Tables/DatabaseClientTest.php @@ -75,7 +75,7 @@ class DatabaseClientTest extends Scope $this->assertIsArray($table['body']['data']); $this->assertArrayNotHasKey('errors', $table['body']); - $table = $table['body']['data']['databasesCreateTable']; + $table = $table['body']['data']['tablesCreate']; $this->assertEquals('Actors', $table['name']); return [ @@ -349,7 +349,7 @@ class DatabaseClientTest extends Scope $res = $this->client->call(Client::METHOD_POST, '/graphql', $headers, $payload); $this->assertArrayNotHasKey('errors', $res['body']); - $tableId = $res['body']['data']['databasesCreateTable']['_id']; + $tableId = $res['body']['data']['tablesCreate']['_id']; // Step 3: Create column $query = $this->getQuery(self::$CREATE_STRING_COLUMN); diff --git a/tests/e2e/Services/GraphQL/Tables/DatabaseServerTest.php b/tests/e2e/Services/GraphQL/Tables/DatabaseServerTest.php index 61cb57911a..e4e9b34f35 100644 --- a/tests/e2e/Services/GraphQL/Tables/DatabaseServerTest.php +++ b/tests/e2e/Services/GraphQL/Tables/DatabaseServerTest.php @@ -75,7 +75,7 @@ class DatabaseServerTest extends Scope $this->assertIsArray($table['body']['data']); $this->assertArrayNotHasKey('errors', $table['body']); - $table = $table['body']['data']['databasesCreateTable']; + $table = $table['body']['data']['tablesCreate']; $this->assertEquals('Actors', $table['name']); $gqlPayload = [ @@ -101,7 +101,7 @@ class DatabaseServerTest extends Scope $this->assertIsArray($table2['body']['data']); $this->assertArrayNotHasKey('errors', $table2['body']); - $table2 = $table2['body']['data']['databasesCreateTable']; + $table2 = $table2['body']['data']['tablesCreate']; $this->assertEquals('Movies', $table2['name']); return [ @@ -992,7 +992,7 @@ class DatabaseServerTest extends Scope $this->assertArrayNotHasKey('errors', $tables['body']); $this->assertIsArray($tables['body']['data']); - $this->assertIsArray($tables['body']['data']['databasesListTables']); + $this->assertIsArray($tables['body']['data']['tablesList']); } /** @@ -1018,7 +1018,7 @@ class DatabaseServerTest extends Scope $this->assertArrayNotHasKey('errors', $table['body']); $this->assertIsArray($table['body']['data']); - $this->assertIsArray($table['body']['data']['databasesGetTable']); + $this->assertIsArray($table['body']['data']['tablesGet']); } /** @@ -1279,7 +1279,7 @@ class DatabaseServerTest extends Scope $this->assertArrayNotHasKey('errors', $table['body']); $this->assertIsArray($table['body']['data']); - $this->assertIsArray($table['body']['data']['databasesUpdateTable']); + $this->assertIsArray($table['body']['data']['tablesUpdate']); } /** @@ -1510,7 +1510,7 @@ class DatabaseServerTest extends Scope $res = $this->client->call(Client::METHOD_POST, '/graphql', $headers, $payload); $this->assertArrayNotHasKey('errors', $res['body']); - $tableId = $res['body']['data']['databasesCreateTable']['_id']; + $tableId = $res['body']['data']['tablesCreate']['_id']; // Step 3: Create column $query = $this->getQuery(self::$CREATE_STRING_COLUMN); diff --git a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php index dda041d1ed..8b34d552f5 100644 --- a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php +++ b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php @@ -951,6 +951,55 @@ class ProjectsConsoleClientTest extends Scope return ['projectId' => $projectId]; } + /** @depends testCreateProject */ + public function testUpdateProjectInvalidateSessions($data): array + { + $id = $data['projectId']; + + // Check defaults + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => 'console', + ], $this->getHeaders())); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertTrue($response['body']['authInvalidateSessions']); + + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/session-invalidation', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'enabled' => false, + ]); + $this->assertFalse($response['body']['authInvalidateSessions']); + + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => 'console', + ], $this->getHeaders())); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertFalse($response['body']['authInvalidateSessions']); + + $response = $this->client->call(Client::METHOD_PATCH, '/projects/' . $id . '/auth/session-invalidation', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'enabled' => true, + ]); + $this->assertTrue($response['body']['authInvalidateSessions']); + + $response = $this->client->call(Client::METHOD_GET, '/projects/' . $id, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => 'console', + ], $this->getHeaders())); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertTrue($response['body']['authInvalidateSessions']); + + return $data; + } + /** * @depends testCreateProject */ diff --git a/tests/e2e/Services/Users/UsersBase.php b/tests/e2e/Services/Users/UsersBase.php index 00e999672f..0aa5784930 100644 --- a/tests/e2e/Services/Users/UsersBase.php +++ b/tests/e2e/Services/Users/UsersBase.php @@ -1117,7 +1117,7 @@ trait UsersBase ]); $this->assertEquals(401, $session['headers']['status-code']); - + $this->updateProjectinvalidateSessionsProperty(true); $user = $this->client->call(Client::METHOD_PATCH, '/users/' . $data['userId'] . '/password', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], @@ -1129,6 +1129,15 @@ trait UsersBase $this->assertNotEmpty($user['body']['$id']); $this->assertNotEmpty($user['body']['password']); + $sessions = $this->client->call(Client::METHOD_GET, '/users/' . $data['userId'] . '/sessions', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + + $this->assertEquals($sessions['headers']['status-code'], 200); + $this->assertIsArray($sessions['body']); + $this->assertEmpty($sessions['body']['sessions']); + $session = $this->client->call(Client::METHOD_POST, '/account/sessions/email', [ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], @@ -1138,7 +1147,7 @@ trait UsersBase ]); $this->assertEquals($session['headers']['status-code'], 201); - + $this->updateProjectinvalidateSessionsProperty(false); return $data; }