From adcfecfa0e65a7f968c2f772cfe02331aec2adb5 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Wed, 5 Apr 2023 02:33:38 +0000 Subject: [PATCH] remove paused and introduce enable-disable all services --- app/config/errors.php | 5 ---- app/controllers/api/projects.php | 39 ++++++++++++++++++++++++++++---- app/controllers/general.php | 5 ---- 3 files changed, 35 insertions(+), 14 deletions(-) diff --git a/app/config/errors.php b/app/config/errors.php index 97ac6d1a45..a6cf0c4afd 100644 --- a/app/config/errors.php +++ b/app/config/errors.php @@ -28,11 +28,6 @@ return [ 'description' => 'The request originated from an unknown origin. If you trust this domain, please list it as a trusted platform in the Appwrite console.', 'code' => 403, ], - Exception::GENERAL_PROJECT_PAUSED => [ - 'name' => Exception::GENERAL_PROJECT_PAUSED, - 'description' => 'The requested project is paused. You can resume the project from the Appwrite console.', - 'code' => 503, - ], Exception::GENERAL_SERVICE_DISABLED => [ 'name' => Exception::GENERAL_SERVICE_DISABLED, 'description' => 'The requested service is disabled. You can enable the service from the Appwrite console.', diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 9dc0da6d5f..269ddb586c 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -108,7 +108,6 @@ App::post('/v1/projects') 'logo' => $logo, 'url' => $url, 'version' => APP_VERSION_STABLE, - 'paused' => false, 'legalName' => $legalName, 'legalCountry' => $legalCountry, 'legalState' => $legalState, @@ -370,7 +369,6 @@ App::patch('/v1/projects/:projectId') ->label('sdk.response.model', Response::MODEL_PROJECT) ->param('projectId', '', new UID(), 'Project unique ID.') ->param('name', null, new Text(128), 'Project name. Max length: 128 chars.') - ->param('paused', null, new Boolean(), 'Pause project', true) ->param('description', '', new Text(256), 'Project description. Max length: 256 chars.', true) ->param('logo', '', new Text(1024), 'Project logo.', true) ->param('url', '', new URL(), 'Project URL.', true) @@ -382,7 +380,7 @@ App::patch('/v1/projects/:projectId') ->param('legalTaxId', '', new Text(256), 'Project legal tax ID. Max length: 256 chars.', true) ->inject('response') ->inject('dbForConsole') - ->action(function (string $projectId, string $name, ?bool $paused, string $description, string $logo, string $url, string $legalName, string $legalCountry, string $legalState, string $legalCity, string $legalAddress, string $legalTaxId, Response $response, Database $dbForConsole) { + ->action(function (string $projectId, string $name, string $description, string $logo, string $url, string $legalName, string $legalCountry, string $legalState, string $legalCity, string $legalAddress, string $legalTaxId, Response $response, Database $dbForConsole) { $project = $dbForConsole->getDocument('projects', $projectId); @@ -392,7 +390,6 @@ App::patch('/v1/projects/:projectId') $project = $dbForConsole->updateDocument('projects', $project->getId(), $project ->setAttribute('name', $name) - ->setAttribute('paused', $paused ?? $project->getAttribute('paused', false)) ->setAttribute('description', $description) ->setAttribute('logo', $logo) ->setAttribute('url', $url) @@ -438,6 +435,40 @@ App::patch('/v1/projects/:projectId/service') $response->dynamic($project, Response::MODEL_PROJECT); }); +App::patch('/v1/projects/:projectId/service/all') + ->desc('Update all service status') + ->groups(['api', 'projects']) + ->label('scope', 'projects.write') + ->label('sdk.auth', [APP_AUTH_TYPE_ADMIN]) + ->label('sdk.namespace', 'projects') + ->label('sdk.method', 'updateServiceStatusAll') + ->label('sdk.response.code', Response::STATUS_CODE_OK) + ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) + ->label('sdk.response.model', Response::MODEL_PROJECT) + ->param('projectId', '', new UID(), 'Project unique ID.') + ->param('status', null, new Boolean(), 'Service status.') + ->inject('response') + ->inject('dbForConsole') + ->action(function (string $projectId, bool $status, Response $response, Database $dbForConsole) { + + $project = $dbForConsole->getDocument('projects', $projectId); + + if ($project->isEmpty()) { + throw new Exception(Exception::PROJECT_NOT_FOUND); + } + + $allServices = array_keys(array_filter(Config::getParam('services'), fn($element) => $element['optional'])); + + $services = []; + foreach($allServices as $service) { + $services[$service] = $status; + } + + $project = $dbForConsole->updateDocument('projects', $project->getId(), $project->setAttribute('services', $services)); + + $response->dynamic($project, Response::MODEL_PROJECT); + }); + App::patch('/v1/projects/:projectId/oauth2') ->desc('Update Project OAuth2') ->groups(['api', 'projects']) diff --git a/app/controllers/general.php b/app/controllers/general.php index 0fdfe28d05..c1b8457d12 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -346,11 +346,6 @@ App::init() Authorization::setRole($authRole); } - $paused = $project->getAttribute('paused', false); - if ($paused && !(Auth::isPrivilegedUser(Authorization::getRoles()) || Auth::isAppUser(Authorization::getRoles()))) { - throw new AppwriteException(AppwriteException::GENERAL_PROJECT_PAUSED); - } - $service = $route->getLabel('sdk.namespace', ''); if (!empty($service)) { if (