remove paused and introduce enable-disable all services

This commit is contained in:
Damodar Lohani
2023-04-05 02:33:38 +00:00
parent a1df37e168
commit adcfecfa0e
3 changed files with 35 additions and 14 deletions
-5
View File
@@ -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.',
+35 -4
View File
@@ -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'])
-5
View File
@@ -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 (