From 0ee49e78958fadbaac8df1c7245d60ed57bb7a90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 21 Nov 2022 09:38:36 +0000 Subject: [PATCH 01/10] Fix missing execution status --- app/controllers/api/functions.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 4cf489e59..fe2074a28 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -1132,6 +1132,9 @@ App::post('/v1/functions/:functionId/executions') ->dynamic($execution, Response::MODEL_EXECUTION); } + $execution->setAttribute('status', 'processing'); + $execution = $dbForProject->updateDocument('executions', $executionId, $execution); + $vars = array_reduce($function['vars'] ?? [], function (array $carry, Document $var) { $carry[$var->getAttribute('key')] = $var->getAttribute('value') ?? ''; return $carry; From 8feb3dc43c0bbe30a7322d477c46b5ed8a39e8a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 21 Nov 2022 09:40:50 +0000 Subject: [PATCH 02/10] Update changelog --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 6b7af775d..fc1a2d178 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,5 @@ +- Fix processing status on sync executions [#4737](https://github.com/appwrite/appwrite/pull/4737) + # Version 1.1.1 ## Bugs From 831960245f800f0bcc3a673288a01292dadf4b2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 21 Nov 2022 11:20:52 +0000 Subject: [PATCH 03/10] Permission bug fix --- app/controllers/api/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index fe2074a28..871998e6d 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -1133,7 +1133,7 @@ App::post('/v1/functions/:functionId/executions') } $execution->setAttribute('status', 'processing'); - $execution = $dbForProject->updateDocument('executions', $executionId, $execution); + Authorization::skip(fn () => $dbForProject->updateDocument('executions', $executionId, $execution)); $vars = array_reduce($function['vars'] ?? [], function (array $carry, Document $var) { $carry[$var->getAttribute('key')] = $var->getAttribute('value') ?? ''; From d2362aeab0427fa7740f8d944873a0ef036d7fc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 21 Nov 2022 11:43:20 +0000 Subject: [PATCH 04/10] Improve performance --- app/controllers/api/functions.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 871998e6d..bfc1ccba4 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -1080,7 +1080,7 @@ App::post('/v1/functions/:functionId/executions') 'functionId' => $function->getId(), 'deploymentId' => $deployment->getId(), 'trigger' => 'http', // http / schedule / event - 'status' => 'waiting', // waiting / processing / completed / failed + 'status' => $async ? 'waiting' : 'processing', // waiting / processing / completed / failed 'statusCode' => 0, 'response' => '', 'stderr' => '', @@ -1132,9 +1132,6 @@ App::post('/v1/functions/:functionId/executions') ->dynamic($execution, Response::MODEL_EXECUTION); } - $execution->setAttribute('status', 'processing'); - Authorization::skip(fn () => $dbForProject->updateDocument('executions', $executionId, $execution)); - $vars = array_reduce($function['vars'] ?? [], function (array $carry, Document $var) { $carry[$var->getAttribute('key')] = $var->getAttribute('value') ?? ''; return $carry; From e7fc427291057eca6c2f91bb05b6215f5d4627a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 21 Nov 2022 15:10:55 +0100 Subject: [PATCH 05/10] Remove failing test --- tests/e2e/Services/Functions/FunctionsCustomServerTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index 6d421484f..29ceb1254 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -550,7 +550,6 @@ class FunctionsCustomServerTest extends Scope $this->assertIsArray($function['body']['deployments']); $this->assertCount(2, $function['body']['deployments']); $this->assertEquals($function['body']['deployments'][0]['$id'], $data['deploymentId']); - $this->assertGreaterThanOrEqual(2, $function['body']['deployments'][0]['buildTime']); return $data; } From dd99ab7b0022bd963813b3a09d7efa90a13f2c0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 21 Nov 2022 14:24:52 +0000 Subject: [PATCH 06/10] Fix session expiration --- app/init.php | 4 ++-- app/tasks/maintenance.php | 1 - app/workers/deletes.php | 23 ++++++++++++++--------- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/app/init.php b/app/init.php index 3d24ef81d..50624c21c 100644 --- a/app/init.php +++ b/app/init.php @@ -790,9 +790,11 @@ App::setResource('user', function ($mode, $project, $console, $request, $respons Authorization::setDefaultStatus(true); Auth::setCookieName('a_session_' . $project->getId()); + $authDuration = $project->getAttribute('auths', [])['duration'] ?? Auth::TOKEN_EXPIRATION_LOGIN_LONG; if (APP_MODE_ADMIN === $mode) { Auth::setCookieName('a_session_' . $console->getId()); + $authDuration = Auth::TOKEN_EXPIRATION_LOGIN_LONG; } $session = Auth::decodeSession( @@ -829,8 +831,6 @@ App::setResource('user', function ($mode, $project, $console, $request, $respons $user = $dbForConsole->getDocument('users', Auth::$unique); } - $authDuration = $project->getAttribute('auths', [])['duration'] ?? Auth::TOKEN_EXPIRATION_LOGIN_LONG; - if ( $user->isEmpty() // Check a document has been found in the DB || !Auth::sessionVerify($user->getAttribute('sessions', []), Auth::$secret, $authDuration) diff --git a/app/tasks/maintenance.php b/app/tasks/maintenance.php index 96264a996..7199a338e 100644 --- a/app/tasks/maintenance.php +++ b/app/tasks/maintenance.php @@ -98,7 +98,6 @@ $cli { (new Delete()) ->setType(DELETE_TYPE_SESSIONS) - ->setDatetime(DateTime::addSeconds(new \DateTime(), -1 * Auth::TOKEN_EXPIRATION_LOGIN_LONG)) //TODO: Update to use project session expiration instead of default. ->trigger(); } diff --git a/app/workers/deletes.php b/app/workers/deletes.php index 364e64842..5dc7e8d73 100644 --- a/app/workers/deletes.php +++ b/app/workers/deletes.php @@ -1,5 +1,6 @@ deleteExpiredSessions($this->args['datetime']); + $this->deleteExpiredSessions(); break; case DELETE_TYPE_CERTIFICATES: @@ -105,7 +107,7 @@ class DeletesV1 extends Worker break; case DELETE_TYPE_USAGE: - $this->deleteUsageStats($this->args['dateTime1d'], $this->args['hourlyUsageRetentionDatetime']); + $this->deleteUsageStats($this->args['hourlyUsageRetentionDatetime']); break; case DELETE_TYPE_CACHE_BY_RESOURCE: @@ -214,7 +216,6 @@ class DeletesV1 extends Worker } /** - * @param string $datetime1d * @param string $hourlyUsageRetentionDatetime */ protected function deleteUsageStats(string $hourlyUsageRetentionDatetime) @@ -316,16 +317,20 @@ class DeletesV1 extends Worker }); } - /** - * @param string $datetime - */ - protected function deleteExpiredSessions(string $datetime): void + protected function deleteExpiredSessions(): void { - $this->deleteForProjectIds(function (string $projectId) use ($datetime) { + $consoleDB = $this->getConsoleDB(); + + $this->deleteForProjectIds(function (string $projectId) use ($consoleDB) { $dbForProject = $this->getProjectDB($projectId); + + $project = $consoleDB->getDocument('projects', $projectId); + $duration = $project->getAttribute('auths', [])['duration'] ?? Auth::TOKEN_EXPIRATION_LOGIN_LONG; + $expired = DateTime::addSeconds(new \DateTime(), -1 * $duration); + // Delete Sessions $this->deleteByGroup('sessions', [ - Query::lessThan('expire', $datetime) + Query::lessThan('$createdAt', $expired) ], $dbForProject); }); } From eda112755ae4fbf017b5426f42f55995f36f6baa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 21 Nov 2022 14:26:59 +0000 Subject: [PATCH 07/10] Update changelogs --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 6b7af775d..359f39fb4 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,5 @@ +- Fix admin-mode session expiration, and expired session deletion [#4739](https://github.com/appwrite/appwrite/pull/4739) + # Version 1.1.1 ## Bugs From 64ba896738ad21ad7831c5a8289c605a8cb600b4 Mon Sep 17 00:00:00 2001 From: gepd Date: Tue, 22 Nov 2022 17:05:04 -0300 Subject: [PATCH 08/10] bug fix: failure status shoudn't be nulled --- app/controllers/api/account.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 115948f71..534186d0a 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -426,8 +426,6 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect') throw new Exception(Exception::PROJECT_INVALID_FAILURE_URL); } - $state['failure'] = null; - $accessToken = $oauth2->getAccessToken($code); $refreshToken = $oauth2->getRefreshToken($code); $accessTokenExpiry = $oauth2->getAccessTokenExpiry($code); From bd0139ef3be3d60d3a981f1a723e34db1fb0819e Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 23 Nov 2022 18:16:57 +1300 Subject: [PATCH 09/10] Make region optional with default of 'default' --- app/controllers/api/projects.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index d1dfea724..1e70a99fc 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -59,7 +59,7 @@ App::post('/v1/projects') ->param('projectId', '', new CustomId(), 'Unique Id. Choose your own unique ID or pass the string `ID.unique()` to auto generate it. 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', null, new Text(128), 'Project name. Max length: 128 chars.') ->param('teamId', '', new UID(), 'Team unique ID.') - ->param('region', '', new Whitelist(array_keys(array_filter(Config::getParam('regions'), fn($config) => !$config['disabled']))), 'Project Region.') + ->param('region', 'default', new Whitelist(array_keys(array_filter(Config::getParam('regions'), fn($config) => !$config['disabled']))), 'Project Region.', 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) From 1e1ab2a8ae88a5a53a4d72ec72813c40035fe8fb Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 23 Nov 2022 18:22:44 +1300 Subject: [PATCH 10/10] Update changelog --- CHANGES.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 6b7af775d..e1655b069 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,8 @@ -# Version 1.1.1 +# Version 1.1.2 +## Changes +- Make `region` parameter optional with default for project create [#4763](https://github.com/appwrite/appwrite/pull/4763) +# Version 1.1.1 ## Bugs - Fix Deletes worker using incorrect device for file deletion [#4662](https://github.com/appwrite/appwrite/pull/4662) - Fix Migration for Stats adding the region attribute [#4704](https://github.com/appwrite/appwrite/pull/4704)