From f6b7e0392bd237fa46343b31904f1b5c486f5f58 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Mon, 14 Nov 2022 09:15:55 +0000 Subject: [PATCH] Give auth duration it's own endpoint --- app/controllers/api/projects.php | 33 +++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index eaa113055..b06a7ea9e 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -376,10 +376,9 @@ App::patch('/v1/projects/:projectId') ->param('legalCity', '', new Text(256), 'Project legal city. Max length: 256 chars.', true) ->param('legalAddress', '', new Text(256), 'Project legal address. Max length: 256 chars.', true) ->param('legalTaxId', '', new Text(256), 'Project legal tax ID. Max length: 256 chars.', true) - ->param('authDuration', 525600, new Range(0, 525600), 'Project session length in minutes. Max length: 525600 minutes.', true) ->inject('response') ->inject('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, int $authDuration, 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); @@ -398,7 +397,6 @@ App::patch('/v1/projects/:projectId') ->setAttribute('legalCity', $legalCity) ->setAttribute('legalAddress', $legalAddress) ->setAttribute('legalTaxId', $legalTaxId) - ->setAttribute('authDuration', $authDuration * 60) ->setAttribute('search', implode(' ', [$projectId, $name]))); $response->dynamic($project, Response::MODEL_PROJECT); @@ -498,6 +496,35 @@ App::patch('/v1/projects/:projectId/auth/limit') $response->dynamic($project, Response::MODEL_PROJECT); }); + + +App::patch('/v1/projects/:projectId/auth/authDuration') + ->desc('Update Project Authentication Duration') + ->groups(['api', 'projects']) + ->label('scope', 'projects.write') + ->label('sdk.auth', [APP_AUTH_TYPE_ADMIN]) + ->label('sdk.namespace', 'projects') + ->label('sdk.method', 'updateAuthDuration') + ->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('authDuration', 525600, new Range(0, 525600), 'Project session length in minutes. Max length: 525600 minutes.') + ->inject('response') + ->inject('dbForConsole') + ->action(function (string $projectId, int $authDuration, Response $response, Database $dbForConsole) { + + $project = $dbForConsole->getDocument('projects', $projectId); + + if ($project->isEmpty()) { + throw new Exception(Exception::PROJECT_NOT_FOUND); + } + + $dbForConsole->updateDocument('projects', $project->getId(), $project + ->setAttribute('authDuration', $authDuration * 60)); + + $response->dynamic($project, Response::MODEL_PROJECT); + }); App::patch('/v1/projects/:projectId/auth/:method') ->desc('Update Project auth method status. Use this endpoint to enable or disable a given auth method for this project.')