From 447b47592c22ac8dfe17954dd79eb26f759b9b0d Mon Sep 17 00:00:00 2001 From: Matej Baco Date: Mon, 13 Dec 2021 13:42:40 +0100 Subject: [PATCH 01/37] Updated docs --- docs/references/account/update-prefs.md | 2 +- docs/references/users/update-user-prefs.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/references/account/update-prefs.md b/docs/references/account/update-prefs.md index cdfbdf9f0..8283f2f7c 100644 --- a/docs/references/account/update-prefs.md +++ b/docs/references/account/update-prefs.md @@ -1 +1 @@ -Update currently logged in user account preferences. You can pass only the specific settings you wish to update. \ No newline at end of file +Update currently logged in user account preferences. The object you pass is stored as is, and replaces any previous value. \ No newline at end of file diff --git a/docs/references/users/update-user-prefs.md b/docs/references/users/update-user-prefs.md index cb06d4a7f..392736367 100644 --- a/docs/references/users/update-user-prefs.md +++ b/docs/references/users/update-user-prefs.md @@ -1 +1 @@ -Update the user preferences by its unique ID. You can pass only the specific settings you wish to update. \ No newline at end of file +Update the user preferences by its unique ID. The object you pass is stored as is, and replaces any previous value. \ No newline at end of file From 72625158422f0eeda9f8939c351d3fc0787a7be9 Mon Sep 17 00:00:00 2001 From: Matej Baco Date: Mon, 13 Dec 2021 13:53:30 +0100 Subject: [PATCH 02/37] Added prefs max size limit --- app/controllers/api/account.php | 4 ++++ app/controllers/api/users.php | 4 ++++ docs/references/account/update-prefs.md | 2 +- docs/references/users/update-user-prefs.md | 2 +- 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index d2e68b114..c41564549 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -1494,6 +1494,10 @@ App::patch('/v1/account/prefs') /** @var Appwrite\Event\Event $audits */ /** @var Appwrite\Stats\Stats $usage */ + if(\strlen($prefs) > 16384) { + throw new Exception('Maximum allowed prefs size exceeded.', 400); + } + $user = $dbForInternal->updateDocument('users', $user->getId(), $user->setAttribute('prefs', $prefs)); $audits diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index a5d412d5b..124ae14c6 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -591,6 +591,10 @@ App::patch('/v1/users/:userId/prefs') /** @var Utopia\Database\Database $dbForInternal */ /** @var Appwrite\Stats\Stats $usage */ + if(\strlen($prefs) > 16384) { + throw new Exception('Maximum allowed prefs size exceeded.', 400); + } + $user = $dbForInternal->getDocument('users', $userId); if ($user->isEmpty() || $user->getAttribute('deleted')) { diff --git a/docs/references/account/update-prefs.md b/docs/references/account/update-prefs.md index 8283f2f7c..3f8c12da5 100644 --- a/docs/references/account/update-prefs.md +++ b/docs/references/account/update-prefs.md @@ -1 +1 @@ -Update currently logged in user account preferences. The object you pass is stored as is, and replaces any previous value. \ No newline at end of file +Update currently logged in user account preferences. The object you pass is stored as is, and replaces any previous value. The maximum allowed prefs size is 16384 characters and throws error if exceeded. \ No newline at end of file diff --git a/docs/references/users/update-user-prefs.md b/docs/references/users/update-user-prefs.md index 392736367..b0ea7a864 100644 --- a/docs/references/users/update-user-prefs.md +++ b/docs/references/users/update-user-prefs.md @@ -1 +1 @@ -Update the user preferences by its unique ID. The object you pass is stored as is, and replaces any previous value. \ No newline at end of file +Update the user preferences by its unique ID. The object you pass is stored as is, and replaces any previous value. The maximum allowed prefs size is 16384 characters and throws error if exceeded. \ No newline at end of file From e3716ab2b846d777ea75e87816993c9294ade78d Mon Sep 17 00:00:00 2001 From: Matej Baco Date: Mon, 13 Dec 2021 14:09:23 +0100 Subject: [PATCH 03/37] Included prefs size exceeded test --- composer.json | 2 +- tests/e2e/Services/Account/AccountBase.php | 24 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index f534615f2..01ba42c71 100644 --- a/composer.json +++ b/composer.json @@ -38,7 +38,7 @@ "appwrite/php-clamav": "1.1.*", "appwrite/php-runtimes": "0.6.*", - "utopia-php/framework": "0.19.*", + "utopia-php/framework": "0.19.1", "utopia-php/abuse": "0.6.*", "utopia-php/analytics": "0.2.*", "utopia-php/audit": "0.7.*", diff --git a/tests/e2e/Services/Account/AccountBase.php b/tests/e2e/Services/Account/AccountBase.php index fc615fef8..0e2b5f7ae 100644 --- a/tests/e2e/Services/Account/AccountBase.php +++ b/tests/e2e/Services/Account/AccountBase.php @@ -3,6 +3,7 @@ namespace Tests\E2E\Services\Account; use Tests\E2E\Client; +use function array_merge; trait AccountBase { @@ -751,6 +752,29 @@ trait AccountBase $this->assertEquals($response['headers']['status-code'], 400); + /** + * Prefs size exceeded + */ + + $prefsObject = []; + // Add 1000 keys + for($i = 1000; $i < 2000; $i++) { + $prefsObject["key" + $i] = "HelloWorld"; + // Each key is 7 characters and value is 10 characters + } + // That makes total size minimum of 17 000, plus any JSON stuff. Max supported is 16384, so this should exceed. + + $response = $this->client->call(Client::METHOD_PATCH, '/account/prefs', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'cookie' => 'a_session_'.$this->getProject()['$id'].'=' . $session, + ]), [ + 'prefs' => $prefsObject + ]); + + $this->assertEquals($response['headers']['status-code'], 400); + return $data; } From 198382a60a42be7b48f02c95a011393a1d6ec49d Mon Sep 17 00:00:00 2001 From: Matej Baco Date: Mon, 13 Dec 2021 14:18:44 +0100 Subject: [PATCH 04/37] Removed unnecessary use --- tests/e2e/Services/Account/AccountBase.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/e2e/Services/Account/AccountBase.php b/tests/e2e/Services/Account/AccountBase.php index 0e2b5f7ae..bca0ecfe0 100644 --- a/tests/e2e/Services/Account/AccountBase.php +++ b/tests/e2e/Services/Account/AccountBase.php @@ -3,7 +3,6 @@ namespace Tests\E2E\Services\Account; use Tests\E2E\Client; -use function array_merge; trait AccountBase { From 44721f840f96fd46d9aef025cbf5013eca95bd9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Tue, 14 Dec 2021 10:34:51 +0100 Subject: [PATCH 05/37] Reverted version limitation --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 01ba42c71..f534615f2 100644 --- a/composer.json +++ b/composer.json @@ -38,7 +38,7 @@ "appwrite/php-clamav": "1.1.*", "appwrite/php-runtimes": "0.6.*", - "utopia-php/framework": "0.19.1", + "utopia-php/framework": "0.19.*", "utopia-php/abuse": "0.6.*", "utopia-php/analytics": "0.2.*", "utopia-php/audit": "0.7.*", From e46b99b0a61bb044080f2c659cb2d1fde8849087 Mon Sep 17 00:00:00 2001 From: Matej Baco Date: Mon, 20 Dec 2021 16:21:01 +0100 Subject: [PATCH 06/37] Implemented limit in a new way; second iteration --- app/config/collections.php | 2 +- app/controllers/api/account.php | 4 ---- app/controllers/api/users.php | 4 ---- docs/references/account/update-prefs.md | 2 +- docs/references/users/update-user-prefs.md | 2 +- tests/e2e/Services/Account/AccountBase.php | 10 +++++----- 6 files changed, 8 insertions(+), 16 deletions(-) diff --git a/app/config/collections.php b/app/config/collections.php index 30d9b79fb..1916ac671 100644 --- a/app/config/collections.php +++ b/app/config/collections.php @@ -998,7 +998,7 @@ $collections = [ '$id' => 'prefs', 'type' => Database::VAR_STRING, 'format' => '', - 'size' => 16384, + 'size' => 65535, 'signed' => true, 'required' => false, 'default' => null, diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 291ddc0a0..775604152 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -1480,10 +1480,6 @@ App::patch('/v1/account/prefs') /** @var Appwrite\Event\Event $audits */ /** @var Appwrite\Stats\Stats $usage */ - if(\strlen($prefs) > 16384) { - throw new Exception('Maximum allowed prefs size exceeded.', 400); - } - $user = $dbForInternal->updateDocument('users', $user->getId(), $user->setAttribute('prefs', $prefs)); $audits diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index baa4e2bd7..5cef36f6c 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -578,10 +578,6 @@ App::patch('/v1/users/:userId/prefs') /** @var Utopia\Database\Database $dbForInternal */ /** @var Appwrite\Stats\Stats $usage */ - if(\strlen($prefs) > 16384) { - throw new Exception('Maximum allowed prefs size exceeded.', 400); - } - $user = $dbForInternal->getDocument('users', $userId); if ($user->isEmpty() || $user->getAttribute('deleted')) { diff --git a/docs/references/account/update-prefs.md b/docs/references/account/update-prefs.md index 3f8c12da5..53f58cb5b 100644 --- a/docs/references/account/update-prefs.md +++ b/docs/references/account/update-prefs.md @@ -1 +1 @@ -Update currently logged in user account preferences. The object you pass is stored as is, and replaces any previous value. The maximum allowed prefs size is 16384 characters and throws error if exceeded. \ No newline at end of file +Update currently logged in user account preferences. The object you pass is stored as is, and replaces any previous value. The maximum allowed prefs size is 64kB and throws error if exceeded. \ No newline at end of file diff --git a/docs/references/users/update-user-prefs.md b/docs/references/users/update-user-prefs.md index b0ea7a864..11b63efa4 100644 --- a/docs/references/users/update-user-prefs.md +++ b/docs/references/users/update-user-prefs.md @@ -1 +1 @@ -Update the user preferences by its unique ID. The object you pass is stored as is, and replaces any previous value. The maximum allowed prefs size is 16384 characters and throws error if exceeded. \ No newline at end of file +Update the user preferences by its unique ID. The object you pass is stored as is, and replaces any previous value. The maximum allowed prefs size is 64kB and throws error if exceeded. \ No newline at end of file diff --git a/tests/e2e/Services/Account/AccountBase.php b/tests/e2e/Services/Account/AccountBase.php index bca0ecfe0..eb7f14d29 100644 --- a/tests/e2e/Services/Account/AccountBase.php +++ b/tests/e2e/Services/Account/AccountBase.php @@ -756,12 +756,12 @@ trait AccountBase */ $prefsObject = []; - // Add 1000 keys - for($i = 1000; $i < 2000; $i++) { - $prefsObject["key" + $i] = "HelloWorld"; - // Each key is 7 characters and value is 10 characters + // Add 1024 keys + for($i = 1000; $i < 2024; $i++) { + $prefsObject["key" + $i] = "HelloWorldHelloWorldHelloWorldHelloWorldHelloWorldHelloWorldHel"; + // Each key is 7 characters and value is 63 characters } - // That makes total size minimum of 17 000, plus any JSON stuff. Max supported is 16384, so this should exceed. + // That makes total size minimum of 70kB, plus any JSON stuff. Max supported is 64kB, so this should exceed. $response = $this->client->call(Client::METHOD_PATCH, '/account/prefs', array_merge([ 'origin' => 'http://localhost', From 27a43beddc6dbec2b989a1216c9f375ddc55dfe5 Mon Sep 17 00:00:00 2001 From: Matej Baco Date: Mon, 20 Dec 2021 16:37:17 +0100 Subject: [PATCH 07/37] Test bug fix --- tests/e2e/Services/Account/AccountBase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/Services/Account/AccountBase.php b/tests/e2e/Services/Account/AccountBase.php index eb7f14d29..57a9d9699 100644 --- a/tests/e2e/Services/Account/AccountBase.php +++ b/tests/e2e/Services/Account/AccountBase.php @@ -758,7 +758,7 @@ trait AccountBase $prefsObject = []; // Add 1024 keys for($i = 1000; $i < 2024; $i++) { - $prefsObject["key" + $i] = "HelloWorldHelloWorldHelloWorldHelloWorldHelloWorldHelloWorldHel"; + $prefsObject["key" . $i] = "HelloWorldHelloWorldHelloWorldHelloWorldHelloWorldHelloWorldHel"; // Each key is 7 characters and value is 63 characters } // That makes total size minimum of 70kB, plus any JSON stuff. Max supported is 64kB, so this should exceed. From 5757a853f5798fe1828eb6c551b64d07f650333a Mon Sep 17 00:00:00 2001 From: Matej Baco Date: Mon, 20 Dec 2021 16:56:58 +0100 Subject: [PATCH 08/37] Tests fixed, I hope --- tests/e2e/Services/Account/AccountBase.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/tests/e2e/Services/Account/AccountBase.php b/tests/e2e/Services/Account/AccountBase.php index 57a9d9699..040d7da3d 100644 --- a/tests/e2e/Services/Account/AccountBase.php +++ b/tests/e2e/Services/Account/AccountBase.php @@ -756,12 +756,17 @@ trait AccountBase */ $prefsObject = []; - // Add 1024 keys - for($i = 1000; $i < 2024; $i++) { - $prefsObject["key" . $i] = "HelloWorldHelloWorldHelloWorldHelloWorldHelloWorldHelloWorldHel"; - // Each key is 7 characters and value is 63 characters + + $text1Kb = ""; + for($i = 0; $i < 1024; $i++) { + $text1Kb .= "🍰"; } - // That makes total size minimum of 70kB, plus any JSON stuff. Max supported is 64kB, so this should exceed. + + // Add 100 keys, each is 1kB + for($i = 0; $i < 100; $i++) { + $prefsObject["key" . $i] = $text1Kb; + } + // That makes total size minimum of 100kB, plus any JSON stuff. Max supported is 64kB, so this should exceed. $response = $this->client->call(Client::METHOD_PATCH, '/account/prefs', array_merge([ 'origin' => 'http://localhost', @@ -772,7 +777,7 @@ trait AccountBase 'prefs' => $prefsObject ]); - $this->assertEquals($response['headers']['status-code'], 400); + $this->assertEquals(400, $response['headers']['status-code']); return $data; } From 491b163b273ead4109e424994f6aa06dc7c9515b Mon Sep 17 00:00:00 2001 From: Matej Baco Date: Wed, 22 Dec 2021 09:08:37 +0100 Subject: [PATCH 09/37] Update text to HTTP response changes --- tests/e2e/Services/Account/AccountBase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/Services/Account/AccountBase.php b/tests/e2e/Services/Account/AccountBase.php index 040d7da3d..9f4069061 100644 --- a/tests/e2e/Services/Account/AccountBase.php +++ b/tests/e2e/Services/Account/AccountBase.php @@ -777,7 +777,7 @@ trait AccountBase 'prefs' => $prefsObject ]); - $this->assertEquals(400, $response['headers']['status-code']); + $this->assertEquals(500, $response['headers']['status-code']); return $data; } From 628b3fc805f2dcb5bf30e6a9c1cf8bdf24d77231 Mon Sep 17 00:00:00 2001 From: Matej Baco Date: Wed, 22 Dec 2021 09:34:31 +0100 Subject: [PATCH 10/37] Added non-multi-byte test --- tests/e2e/Services/Account/AccountBase.php | 28 +++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/tests/e2e/Services/Account/AccountBase.php b/tests/e2e/Services/Account/AccountBase.php index 9f4069061..8fe3610cf 100644 --- a/tests/e2e/Services/Account/AccountBase.php +++ b/tests/e2e/Services/Account/AccountBase.php @@ -3,6 +3,7 @@ namespace Tests\E2E\Services\Account; use Tests\E2E\Client; +use function array_merge; trait AccountBase { @@ -764,9 +765,9 @@ trait AccountBase // Add 100 keys, each is 1kB for($i = 0; $i < 100; $i++) { - $prefsObject["key" . $i] = $text1Kb; + $prefsObject["k" . $i] = $text1Kb; } - // That makes total size minimum of 100kB, plus any JSON stuff. Max supported is 64kB, so this should exceed. + // That makes total size minimum of 100kB, plus key size, plus any JSON syntax stuff. Max supported is 64kB, so this should exceed. $response = $this->client->call(Client::METHOD_PATCH, '/account/prefs', array_merge([ 'origin' => 'http://localhost', @@ -777,7 +778,28 @@ trait AccountBase 'prefs' => $prefsObject ]); - $this->assertEquals(500, $response['headers']['status-code']); + $this->assertEquals(400, $response['headers']['status-code']); + + // Now let's test the same thing, but with normal symbol instead of multi-byte cake emoji + $prefsObject = []; + $text1Kb = ""; + for($i = 0; $i < 1024; $i++) { + $text1Kb .= "A"; + } + for($i = 0; $i < 100; $i++) { + $prefsObject["key" . $i] = $text1Kb; + } + + $response = $this->client->call(Client::METHOD_PATCH, '/account/prefs', array_merge([ + 'origin' => 'http://localhost', + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'cookie' => 'a_session_'.$this->getProject()['$id'].'=' . $session, + ]), [ + 'prefs' => $prefsObject + ]); + + $this->assertEquals(400, $response['headers']['status-code']); return $data; } From 9b749db89be29cd0490c85aa7620a7ca6d0da1cc Mon Sep 17 00:00:00 2001 From: Matej Baco Date: Thu, 30 Dec 2021 10:25:43 +0100 Subject: [PATCH 11/37] Draft commit with POC --- app/controllers/general.php | 30 +++++++++++++---- composer.lock | 36 ++++++++++----------- docker-compose.yml | 2 +- src/Appwrite/Utopia/Request/Filter.php | 17 ++++++++++ src/Appwrite/Utopia/Request/Filters/V11.php | 35 ++++++++++++++++++++ 5 files changed, 95 insertions(+), 25 deletions(-) create mode 100644 src/Appwrite/Utopia/Request/Filter.php create mode 100644 src/Appwrite/Utopia/Request/Filters/V11.php diff --git a/app/controllers/general.php b/app/controllers/general.php index deb36a1b4..a808517c5 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -2,6 +2,7 @@ require_once __DIR__.'/../init.php'; +use Appwrite\Utopia\Request\Filters\V11; use Utopia\App; use Utopia\Swoole\Request; use Appwrite\Utopia\Response; @@ -23,7 +24,7 @@ Config::setParam('domainVerification', false); Config::setParam('cookieDomain', 'localhost'); Config::setParam('cookieSamesite', Response::COOKIE_SAMESITE_NONE); -App::init(function ($utopia, $request, $response, $console, $project, $dbForConsole, $user, $locale, $clients) { +App::init(function ($args, $utopia, $request, $response, $console, $project, $dbForConsole, $user, $locale, $clients) { /** @var Utopia\App $utopia */ /** @var Utopia\Swoole\Request $request */ /** @var Appwrite\Utopia\Response $response */ @@ -79,13 +80,30 @@ App::init(function ($utopia, $request, $response, $console, $project, $dbForCons Config::setParam('domains', $domains); } - $localeParam = (string) $request->getParam('locale', $request->getHeader('x-appwrite-locale', '')); + $route = $utopia->match($request); + /* + * Request format + */ + $requestFormat = $request->getHeader('x-appwrite-response-format', App::getEnv('_APP_SYSTEM_RESPONSE_FORMAT', '')); + if ($requestFormat) { + switch($requestFormat) { + // TODO: For some reason console is still on 0.12. We dont want this filter logic in console, console uses 0.12 SDK + case version_compare ($requestFormat , '0.11.0', '<=') : + $requestFilter = new V11(); + break; + } + } + if(isset($requestFilter)) { + $endpointIdentifier = $route->getLabel('sdk.namespace', 'unknown') . '.' . $route->getLabel('sdk.method', 'unknown'); + $newParams = $requestFilter->parse($args->get(), $endpointIdentifier); + $args->set($newParams); + } + + $localeParam = (string) $request->getParam('locale', $request->getHeader('x-appwrite-locale', '')); if (\in_array($localeParam, Config::getParam('locale-codes'))) { $locale->setDefault($localeParam); - }; - - $route = $utopia->match($request); + } if ($project->isEmpty()) { throw new Exception('Project not found', 404); @@ -280,7 +298,7 @@ App::init(function ($utopia, $request, $response, $console, $project, $dbForCons throw new Exception('Password reset is required', 412); } -}, ['utopia', 'request', 'response', 'console', 'project', 'dbForConsole', 'user', 'locale', 'clients']); +}, ['args', 'utopia', 'request', 'response', 'console', 'project', 'dbForConsole', 'user', 'locale', 'clients']); App::options(function ($request, $response) { /** @var Utopia\Swoole\Request $request */ diff --git a/composer.lock b/composer.lock index 00e3ca58f..347db5efb 100644 --- a/composer.lock +++ b/composer.lock @@ -2138,16 +2138,16 @@ }, { "name": "utopia-php/database", - "version": "0.13.0", + "version": "0.13.1", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "2e13987364f4966ec8a36784d4fb5df3a84e4e78" + "reference": "a1b2849c991b6384fe70e3c2d0633256a4fb795b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/2e13987364f4966ec8a36784d4fb5df3a84e4e78", - "reference": "2e13987364f4966ec8a36784d4fb5df3a84e4e78", + "url": "https://api.github.com/repos/utopia-php/database/zipball/a1b2849c991b6384fe70e3c2d0633256a4fb795b", + "reference": "a1b2849c991b6384fe70e3c2d0633256a4fb795b", "shasum": "" }, "require": { @@ -2195,9 +2195,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/0.13.0" + "source": "https://github.com/utopia-php/database/tree/0.13.1" }, - "time": "2021-12-27T12:59:50+00:00" + "time": "2021-12-29T14:04:55+00:00" }, { "name": "utopia-php/domains", @@ -5655,16 +5655,16 @@ }, { "name": "symfony/console", - "version": "v6.0.1", + "version": "v6.0.2", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "fafd9802d386bf1c267e0249ddb7ceb14dcfdad4" + "reference": "dd434fa8d69325e5d210f63070014d889511fcb3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/fafd9802d386bf1c267e0249ddb7ceb14dcfdad4", - "reference": "fafd9802d386bf1c267e0249ddb7ceb14dcfdad4", + "url": "https://api.github.com/repos/symfony/console/zipball/dd434fa8d69325e5d210f63070014d889511fcb3", + "reference": "dd434fa8d69325e5d210f63070014d889511fcb3", "shasum": "" }, "require": { @@ -5730,7 +5730,7 @@ "terminal" ], "support": { - "source": "https://github.com/symfony/console/tree/v6.0.1" + "source": "https://github.com/symfony/console/tree/v6.0.2" }, "funding": [ { @@ -5746,7 +5746,7 @@ "type": "tidelift" } ], - "time": "2021-12-09T12:47:37+00:00" + "time": "2021-12-27T21:05:08+00:00" }, { "name": "symfony/polyfill-intl-grapheme", @@ -6077,16 +6077,16 @@ }, { "name": "symfony/string", - "version": "v6.0.1", + "version": "v6.0.2", "source": { "type": "git", "url": "https://github.com/symfony/string.git", - "reference": "0cfed595758ec6e0a25591bdc8ca733c1896af32" + "reference": "bae261d0c3ac38a1f802b4dfed42094296100631" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/string/zipball/0cfed595758ec6e0a25591bdc8ca733c1896af32", - "reference": "0cfed595758ec6e0a25591bdc8ca733c1896af32", + "url": "https://api.github.com/repos/symfony/string/zipball/bae261d0c3ac38a1f802b4dfed42094296100631", + "reference": "bae261d0c3ac38a1f802b4dfed42094296100631", "shasum": "" }, "require": { @@ -6142,7 +6142,7 @@ "utf8" ], "support": { - "source": "https://github.com/symfony/string/tree/v6.0.1" + "source": "https://github.com/symfony/string/tree/v6.0.2" }, "funding": [ { @@ -6158,7 +6158,7 @@ "type": "tidelift" } ], - "time": "2021-12-08T15:13:44+00:00" + "time": "2021-12-16T22:13:01+00:00" }, { "name": "textalk/websocket", diff --git a/docker-compose.yml b/docker-compose.yml index 2efed94a4..313665829 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -71,7 +71,7 @@ services: - ./psalm.xml:/usr/src/code/psalm.xml - ./tests:/usr/src/code/tests - ./app:/usr/src/code/app - # - ./vendor:/usr/src/code/vendor + - ./vendor/utopia-php/framework:/usr/src/code/vendor/utopia-php/framework - ./docs:/usr/src/code/docs - ./src:/usr/src/code/src # - ./debug:/tmp diff --git a/src/Appwrite/Utopia/Request/Filter.php b/src/Appwrite/Utopia/Request/Filter.php new file mode 100644 index 000000000..9f3e94bb3 --- /dev/null +++ b/src/Appwrite/Utopia/Request/Filter.php @@ -0,0 +1,17 @@ +addUserId($content); + break; + } + + if(empty($parsedResponse)) { + // TODO: Do we need execption? We dont need to find, right? Not found means no changes + // throw new Exception('Received invalid request model : '. $model); + $parsedResponse = $content; + } + + return $parsedResponse; + } + + protected function addUserId(array $content): array + { + $content['userId'] = 'unique()'; + return $content; + } +} From 592ab3ab00f8e344e7bfe6b2512aba0355a78ab0 Mon Sep 17 00:00:00 2001 From: Matej Baco Date: Thu, 30 Dec 2021 17:17:01 +0100 Subject: [PATCH 12/37] WIP: Request filters refactor (into HTTP.php) --- app/controllers/general.php | 24 +---- app/http.php | 20 +++- app/realtime.php | 2 +- composer.lock | 12 +-- src/Appwrite/Utopia/Request.php | 145 +++++++++++++++++++++++++++++ src/Appwrite/Utopia/Response.php | 4 +- tests/unit/Utopia/ResponseTest.php | 4 +- 7 files changed, 178 insertions(+), 33 deletions(-) create mode 100644 src/Appwrite/Utopia/Request.php diff --git a/app/controllers/general.php b/app/controllers/general.php index a808517c5..ea8b79346 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -4,7 +4,7 @@ require_once __DIR__.'/../init.php'; use Appwrite\Utopia\Request\Filters\V11; use Utopia\App; -use Utopia\Swoole\Request; +use Appwrite\Utopia\Request; use Appwrite\Utopia\Response; use Appwrite\Utopia\View; use Utopia\Exception; @@ -24,7 +24,7 @@ Config::setParam('domainVerification', false); Config::setParam('cookieDomain', 'localhost'); Config::setParam('cookieSamesite', Response::COOKIE_SAMESITE_NONE); -App::init(function ($args, $utopia, $request, $response, $console, $project, $dbForConsole, $user, $locale, $clients) { +App::init(function ($utopia, $request, $response, $console, $project, $dbForConsole, $user, $locale, $clients) { /** @var Utopia\App $utopia */ /** @var Utopia\Swoole\Request $request */ /** @var Appwrite\Utopia\Response $response */ @@ -82,24 +82,6 @@ App::init(function ($args, $utopia, $request, $response, $console, $project, $db $route = $utopia->match($request); - /* - * Request format - */ - $requestFormat = $request->getHeader('x-appwrite-response-format', App::getEnv('_APP_SYSTEM_RESPONSE_FORMAT', '')); - if ($requestFormat) { - switch($requestFormat) { - // TODO: For some reason console is still on 0.12. We dont want this filter logic in console, console uses 0.12 SDK - case version_compare ($requestFormat , '0.11.0', '<=') : - $requestFilter = new V11(); - break; - } - } - if(isset($requestFilter)) { - $endpointIdentifier = $route->getLabel('sdk.namespace', 'unknown') . '.' . $route->getLabel('sdk.method', 'unknown'); - $newParams = $requestFilter->parse($args->get(), $endpointIdentifier); - $args->set($newParams); - } - $localeParam = (string) $request->getParam('locale', $request->getHeader('x-appwrite-locale', '')); if (\in_array($localeParam, Config::getParam('locale-codes'))) { $locale->setDefault($localeParam); @@ -298,7 +280,7 @@ App::init(function ($args, $utopia, $request, $response, $console, $project, $db throw new Exception('Password reset is required', 412); } -}, ['args', 'utopia', 'request', 'response', 'console', 'project', 'dbForConsole', 'user', 'locale', 'clients']); +}, ['utopia', 'request', 'response', 'console', 'project', 'dbForConsole', 'user', 'locale', 'clients']); App::options(function ($request, $response) { /** @var Utopia\Swoole\Request $request */ diff --git a/app/http.php b/app/http.php index 13223edfb..74fbe1d1b 100644 --- a/app/http.php +++ b/app/http.php @@ -2,6 +2,7 @@ require_once __DIR__.'/../vendor/autoload.php'; +use Appwrite\Utopia\Request\Filters\V11; use Appwrite\Utopia\Response; use Swoole\Process; use Swoole\Http\Server; @@ -15,7 +16,7 @@ use Utopia\Audit\Audit; use Utopia\Abuse\Adapters\TimeLimit; use Utopia\Database\Document; use Utopia\Swoole\Files; -use Utopia\Swoole\Request; +use Appwrite\Utopia\Request; $http = new Server("0.0.0.0", App::getEnv('PORT', 80)); @@ -184,6 +185,23 @@ $http->on('request', function (SwooleRequest $swooleRequest, SwooleResponse $swo Authorization::cleanRoles(); Authorization::setRole('role:all'); + /* + * Request format + */ + $route = $app->match($request); + Request::setRoute($route); + + $requestFormat = $request->getHeader('x-appwrite-response-format', App::getEnv('_APP_SYSTEM_RESPONSE_FORMAT', '')); + if ($requestFormat) { + switch($requestFormat) { + // TODO: For some reason console is still on 0.12. We dont want this filter logic in console, console uses 0.12 SDK + case version_compare ($requestFormat , '0.11.0', '<=') : + \var_dump("Matches 0.11"); + Request::setFilter(new V11()); + break; + } + } + $app->run($request, $response); } catch (\Throwable $th) { Console::error('[Error] Type: '.get_class($th)); diff --git a/app/realtime.php b/app/realtime.php index a671e149a..f3361ab89 100644 --- a/app/realtime.php +++ b/app/realtime.php @@ -22,7 +22,7 @@ use Utopia\Database\Document; use Utopia\Database\Query; use Utopia\Database\Validator\Authorization; use Utopia\Registry\Registry; -use Utopia\Swoole\Request; +use Appwrite\Utopia\Request; use Utopia\WebSocket\Server; use Utopia\WebSocket\Adapter; diff --git a/composer.lock b/composer.lock index 347db5efb..778756ca3 100644 --- a/composer.lock +++ b/composer.lock @@ -2255,16 +2255,16 @@ }, { "name": "utopia-php/framework", - "version": "0.19.3", + "version": "0.19.4", "source": { "type": "git", "url": "https://github.com/utopia-php/framework.git", - "reference": "4c6c841d738cec458b73fec5aedd40fd43bd41a7" + "reference": "b1c79f199a6adbf8526cea272d931213a8eb511d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/framework/zipball/4c6c841d738cec458b73fec5aedd40fd43bd41a7", - "reference": "4c6c841d738cec458b73fec5aedd40fd43bd41a7", + "url": "https://api.github.com/repos/utopia-php/framework/zipball/b1c79f199a6adbf8526cea272d931213a8eb511d", + "reference": "b1c79f199a6adbf8526cea272d931213a8eb511d", "shasum": "" }, "require": { @@ -2298,9 +2298,9 @@ ], "support": { "issues": "https://github.com/utopia-php/framework/issues", - "source": "https://github.com/utopia-php/framework/tree/0.19.3" + "source": "https://github.com/utopia-php/framework/tree/0.19.4" }, - "time": "2021-12-17T13:04:13+00:00" + "time": "2021-12-29T15:05:19+00:00" }, { "name": "utopia-php/image", diff --git a/src/Appwrite/Utopia/Request.php b/src/Appwrite/Utopia/Request.php new file mode 100644 index 000000000..a3533bddf --- /dev/null +++ b/src/Appwrite/Utopia/Request.php @@ -0,0 +1,145 @@ +getMethod()) { + case self::METHOD_GET: + return $this->getQuery($key, $default); + break; + case self::METHOD_POST: + case self::METHOD_PUT: + case self::METHOD_PATCH: + case self::METHOD_DELETE: + return $this->getPayload($key, $default); + break; + default: + return $this->getQuery($key, $default); + } + } + + /** + * Get Params + * + * Get all params of current method + * + * @return array + */ + public function getParams(): array + { + $requestParameters = []; + + switch($this->getMethod()) { + case self::METHOD_GET: + $requestParameters = (!empty($this->swoole->get)) ? $this->swoole->get : []; + break; + case self::METHOD_POST: + case self::METHOD_PUT: + case self::METHOD_PATCH: + case self::METHOD_DELETE: + $requestParameters = $this->generateInput(); + break; + default: + $requestParameters = (!empty($this->swoole->get)) ? $this->swoole->get : []; + } + + if (self::hasFilter() && self::hasRoute()) { + $endpointIdentifier = self::getRoute()->getLabel('sdk.namespace', 'unknown') . '.' . self::getRoute()->getLabel('sdk.method', 'unknown'); + return self::getFilter()->parse($requestParameters, $endpointIdentifier); + } else { + return $requestParameters; + } + } + + + /** + * Function to set a response filter + * + * @param $filter the response filter to set + * + * @return void + */ + public static function setFilter(?Filter $filter) + { + self::$filter = $filter; + } + + /** + * Return the currently set filter + * + * @return Filter + */ + public static function getFilter(): ?Filter + { + return self::$filter; + } + + /** + * Check if a filter has been set + * + * @return bool + */ + public static function hasFilter(): bool + { + return self::$filter != null; + } + + /** + * Function to set a request route + * + * @param Route $route the request route to set + * + * @return void + */ + public static function setRoute(?Route $route) + { + self::$route = $route; + } + + /** + * Return the currently get route + * + * @return Route + */ + public static function getRoute(): ?Route + { + return self::$route; + } + + /** + * Check if a route has been set + * + * @return bool + */ + public static function hasRoute(): bool + { + return self::$route != null; + } +} \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response.php b/src/Appwrite/Utopia/Response.php index 8bf8b52ee..047ccb965 100644 --- a/src/Appwrite/Utopia/Response.php +++ b/src/Appwrite/Utopia/Response.php @@ -349,7 +349,7 @@ class Response extends SwooleResponse $output = $this->output($document, $model); // If filter is set, parse the output - if (self::isFilter()) { + if (self::hasFilter()) { $output = self::getFilter()->parse($output, $model); } @@ -488,7 +488,7 @@ class Response extends SwooleResponse * * @return bool */ - public static function isFilter(): bool + public static function hasFilter(): bool { return self::$filter != null; } diff --git a/tests/unit/Utopia/ResponseTest.php b/tests/unit/Utopia/ResponseTest.php index e8d99630f..da555fde0 100644 --- a/tests/unit/Utopia/ResponseTest.php +++ b/tests/unit/Utopia/ResponseTest.php @@ -22,13 +22,13 @@ class ResponseTest extends TestCase public function testSetFilter() { - $this->assertEquals($this->object->isFilter(), false); + $this->assertEquals($this->object->hasFilter(), false); $this->assertEquals($this->object->getFilter(), null); $filter = new V06(); $this->object->setFilter($filter); - $this->assertEquals($this->object->isFilter(), true); + $this->assertEquals($this->object->hasFilter(), true); $this->assertEquals($this->object->getFilter(), $filter); } } \ No newline at end of file From ae4d02c0f0720bb9fc05950071fb7deeb9c665ed Mon Sep 17 00:00:00 2001 From: Matej Baco Date: Fri, 31 Dec 2021 09:40:35 +0100 Subject: [PATCH 13/37] Cleanup of POC --- app/controllers/general.php | 5 ++--- app/http.php | 11 +++++++---- docker-compose.yml | 2 +- src/Appwrite/Utopia/Request.php | 7 +++++++ .../Utopia/Request/Filters/{V11.php => V12.php} | 6 ++---- 5 files changed, 19 insertions(+), 12 deletions(-) rename src/Appwrite/Utopia/Request/Filters/{V11.php => V12.php} (71%) diff --git a/app/controllers/general.php b/app/controllers/general.php index ea8b79346..f5d3b5b67 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -2,7 +2,6 @@ require_once __DIR__.'/../init.php'; -use Appwrite\Utopia\Request\Filters\V11; use Utopia\App; use Appwrite\Utopia\Request; use Appwrite\Utopia\Response; @@ -80,13 +79,13 @@ App::init(function ($utopia, $request, $response, $console, $project, $dbForCons Config::setParam('domains', $domains); } - $route = $utopia->match($request); - $localeParam = (string) $request->getParam('locale', $request->getHeader('x-appwrite-locale', '')); if (\in_array($localeParam, Config::getParam('locale-codes'))) { $locale->setDefault($localeParam); } + $route = $utopia->match($request); + if ($project->isEmpty()) { throw new Exception('Project not found', 404); } diff --git a/app/http.php b/app/http.php index 74fbe1d1b..e7dd0f1ec 100644 --- a/app/http.php +++ b/app/http.php @@ -2,7 +2,7 @@ require_once __DIR__.'/../vendor/autoload.php'; -use Appwrite\Utopia\Request\Filters\V11; +use Appwrite\Utopia\Request\Filters\V12; use Appwrite\Utopia\Response; use Swoole\Process; use Swoole\Http\Server; @@ -194,12 +194,15 @@ $http->on('request', function (SwooleRequest $swooleRequest, SwooleResponse $swo $requestFormat = $request->getHeader('x-appwrite-response-format', App::getEnv('_APP_SYSTEM_RESPONSE_FORMAT', '')); if ($requestFormat) { switch($requestFormat) { - // TODO: For some reason console is still on 0.12. We dont want this filter logic in console, console uses 0.12 SDK + // TODO: For some reason console is still on 0.11. We dont want this filter logic in console, console uses 0.12 SDK case version_compare ($requestFormat , '0.11.0', '<=') : - \var_dump("Matches 0.11"); - Request::setFilter(new V11()); + Request::setFilter(new V12()); break; + default: + Request::setFilter(null); } + } else { + Request::setFilter(null); } $app->run($request, $response); diff --git a/docker-compose.yml b/docker-compose.yml index 313665829..2efed94a4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -71,7 +71,7 @@ services: - ./psalm.xml:/usr/src/code/psalm.xml - ./tests:/usr/src/code/tests - ./app:/usr/src/code/app - - ./vendor/utopia-php/framework:/usr/src/code/vendor/utopia-php/framework + # - ./vendor:/usr/src/code/vendor - ./docs:/usr/src/code/docs - ./src:/usr/src/code/src # - ./debug:/tmp diff --git a/src/Appwrite/Utopia/Request.php b/src/Appwrite/Utopia/Request.php index a3533bddf..cd4ad0f99 100644 --- a/src/Appwrite/Utopia/Request.php +++ b/src/Appwrite/Utopia/Request.php @@ -43,6 +43,13 @@ class Request extends UtopiaRequest default: return $this->getQuery($key, $default); } + + if (self::hasFilter() && self::hasRoute()) { + $endpointIdentifier = self::getRoute()->getLabel('sdk.namespace', 'unknown') . '.' . self::getRoute()->getLabel('sdk.method', 'unknown'); + return self::getFilter()->parse($requestParameters, $endpointIdentifier); + } else { + return $requestParameters; + } } /** diff --git a/src/Appwrite/Utopia/Request/Filters/V11.php b/src/Appwrite/Utopia/Request/Filters/V12.php similarity index 71% rename from src/Appwrite/Utopia/Request/Filters/V11.php rename to src/Appwrite/Utopia/Request/Filters/V12.php index eb5c338af..b4d6d0e2e 100644 --- a/src/Appwrite/Utopia/Request/Filters/V11.php +++ b/src/Appwrite/Utopia/Request/Filters/V12.php @@ -4,9 +4,8 @@ namespace Appwrite\Utopia\Request\Filters; use Appwrite\Utopia\Request\Filter; -class V11 extends Filter +class V12 extends Filter { - // TODO: Should this class be called be V11 or V12? // Convert 0.11 params format to 0.12 format public function parse(array $content, string $model): array { @@ -19,8 +18,7 @@ class V11 extends Filter } if(empty($parsedResponse)) { - // TODO: Do we need execption? We dont need to find, right? Not found means no changes - // throw new Exception('Received invalid request model : '. $model); + // No changes between current version and the one user requested $parsedResponse = $content; } From ba06f1ff614364b02dcb152cb23ad5b3a2a7d09f Mon Sep 17 00:00:00 2001 From: Matej Baco Date: Fri, 31 Dec 2021 13:00:07 +0100 Subject: [PATCH 14/37] Added custom IDs request filters --- src/Appwrite/Utopia/Request/Filters/V12.php | 34 +++++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/src/Appwrite/Utopia/Request/Filters/V12.php b/src/Appwrite/Utopia/Request/Filters/V12.php index b4d6d0e2e..4f40ee47d 100644 --- a/src/Appwrite/Utopia/Request/Filters/V12.php +++ b/src/Appwrite/Utopia/Request/Filters/V12.php @@ -12,8 +12,30 @@ class V12 extends Filter $parsedResponse = []; switch ($model) { + // No IDs -> Custom IDs case "account.create": - $parsedResponse = $this->addUserId($content); + case "account.createMagicURLSession": + case "users.create": + $parsedResponse = $this->addId('userId', $content); + break; + case "functions.create": + $parsedResponse = $this->addId('functionId', $content); + break; + case "teams.create": + $parsedResponse = $this->addId('teamId', $content); + break; + + // Status integer -> boolean + case "users.updateStatus": + $parsedResponse = $this->convertStatus($content); + break; + + // The rest (more complex) formats + case "database.createDocument": + $parsedResponse = $this->addId('documentId', $content); + break; + case "database.createCollection": + $parsedResponse = $this->addId('collectionId', $content); break; } @@ -25,9 +47,15 @@ class V12 extends Filter return $parsedResponse; } - protected function addUserId(array $content): array + protected function addUserId(string $key, array $content): array { - $content['userId'] = 'unique()'; + $content[$key] = 'unique()'; + return $content; + } + + protected function convertStatus(array $content): array + { + $content['status'] = 'false'; // TODO: True or false. original is integer return $content; } } From 457cb18be1ea36ad539871a6bcd5472ab42aad05 Mon Sep 17 00:00:00 2001 From: Matej Baco Date: Fri, 31 Dec 2021 14:30:50 +0100 Subject: [PATCH 15/37] Improved request filters --- src/Appwrite/Utopia/Request/Filters/V12.php | 98 +++++++++++++++++---- 1 file changed, 83 insertions(+), 15 deletions(-) diff --git a/src/Appwrite/Utopia/Request/Filters/V12.php b/src/Appwrite/Utopia/Request/Filters/V12.php index 4f40ee47d..63a713dd6 100644 --- a/src/Appwrite/Utopia/Request/Filters/V12.php +++ b/src/Appwrite/Utopia/Request/Filters/V12.php @@ -9,53 +9,121 @@ class V12 extends Filter // Convert 0.11 params format to 0.12 format public function parse(array $content, string $model): array { - $parsedResponse = []; + // TODO: Double-check! switch ($model) { // No IDs -> Custom IDs case "account.create": case "account.createMagicURLSession": case "users.create": - $parsedResponse = $this->addId('userId', $content); + $content = $this->addId($content, 'userId'); break; case "functions.create": - $parsedResponse = $this->addId('functionId', $content); + $content = $this->addId($content, 'functionId'); break; case "teams.create": - $parsedResponse = $this->addId('teamId', $content); + $content = $this->addId($content, 'teamId'); break; // Status integer -> boolean case "users.updateStatus": - $parsedResponse = $this->convertStatus($content); + $content = $this->convertStatus($content); + break; + + // Deprecating order type + case "functions.listExecutions": + $content = $this->removeOrderType($content); break; // The rest (more complex) formats case "database.createDocument": - $parsedResponse = $this->addId('documentId', $content); + $content = $this->addId($content, 'documentId'); + $content = $this->removeParentProperties($content); + break; + case "database.listDocuments": + $content = $this->removeOrderCast($content); + $content = $this->convertOrder($content); + $content = $this->convertQueries($content); break; case "database.createCollection": - $parsedResponse = $this->addId('collectionId', $content); + $content = $this->addId($content, 'collectionId'); + $content = $this->removeRules($content); + $content = $this->addCollectionPermissionLevel($content); + break; + case "database.updateCollection": + $content = $this->removeRules($content); + $content = $this->addCollectionPermissionLevel($content); break; } - if(empty($parsedResponse)) { - // No changes between current version and the one user requested - $parsedResponse = $content; - } - - return $parsedResponse; + return $content; } - protected function addUserId(string $key, array $content): array + // New parameters + + protected function addUserId(array $content, string $key): array { $content[$key] = 'unique()'; return $content; } + protected function addCollectionPermissionLevel(array $content): array + { + $content['permission'] = 'document'; + return $content; + } + + // Deprecated parameters + + protected function removeRules(array $content): array + { + unset($content['rules']); + return $content; + } + + protected function removeOrderType(array $content): array + { + unset($content['orderType']); + return $content; + } + + protected function removeOrderCast(array $content): array + { + unset($content['orderCast']); + return $content; + } + + protected function removeParentProperties(array $content): array + { + unset($content['parentDocument']); + unset($content['parentProperty']); + unset($content['parentPropertyType']); + return $content; + } + + // Modified parameters + protected function convertStatus(array $content): array { - $content['status'] = 'false'; // TODO: True or false. original is integer + $content['status'] = $content['status'] === 2 ? false : true; + return $content; + } + + protected function convertOrder(array $content): array + { + $content['orderAttributes'] = [ $content['orderField'] ]; + $content['orderTypes'] = [ $content['orderType'] ]; + + unset($content['orderField']); + unset($content['orderType']); + + return $content; + } + + protected function convertQueries(array $content): array + { + // TODO: remove filters, search; add queries + return $content; } } From 551021085a717d0f92b20e06301b4af63dd1a274 Mon Sep 17 00:00:00 2001 From: Matej Baco Date: Fri, 31 Dec 2021 16:17:57 +0100 Subject: [PATCH 16/37] Bug fixes for request parser --- src/Appwrite/Utopia/Request/Filters/V12.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Appwrite/Utopia/Request/Filters/V12.php b/src/Appwrite/Utopia/Request/Filters/V12.php index 63a713dd6..ad346f3d3 100644 --- a/src/Appwrite/Utopia/Request/Filters/V12.php +++ b/src/Appwrite/Utopia/Request/Filters/V12.php @@ -9,8 +9,6 @@ class V12 extends Filter // Convert 0.11 params format to 0.12 format public function parse(array $content, string $model): array { - // TODO: Double-check! - switch ($model) { // No IDs -> Custom IDs case "account.create": @@ -61,7 +59,7 @@ class V12 extends Filter // New parameters - protected function addUserId(array $content, string $key): array + protected function addId(array $content, string $key): array { $content[$key] = 'unique()'; return $content; From 577eb107da4294f483e2cbc4526fe43731879311 Mon Sep 17 00:00:00 2001 From: Matej Baco Date: Fri, 31 Dec 2021 16:45:49 +0100 Subject: [PATCH 17/37] Added request filters for queries --- src/Appwrite/Utopia/Request/Filters/V12.php | 31 ++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/Appwrite/Utopia/Request/Filters/V12.php b/src/Appwrite/Utopia/Request/Filters/V12.php index ad346f3d3..392d62aee 100644 --- a/src/Appwrite/Utopia/Request/Filters/V12.php +++ b/src/Appwrite/Utopia/Request/Filters/V12.php @@ -120,7 +120,36 @@ class V12 extends Filter protected function convertQueries(array $content): array { - // TODO: remove filters, search; add queries + $queries = []; + + if(!empty($content['filters'])) { + foreach ($content['filters'] as $filter) { + $operators = ['=' => 'equal', '!=' => 'notEqual', '>' => 'greater', '<' => 'lesser', '<=' => 'lesserEqual', '>=' => 'greaterEqual']; + foreach ($operators as $operator => $operatorVerbose) { + if (\str_contains($filter, $operator)) { + $usedOperator = $operator; + break; + } + } + + if(isset($usedOperator)) { + [ $attributeKey, $filterValue ] = \explode($usedOperator, $filter); + // TODO: String or not? Any way to figure out? + $query = $attributeKey . '.' . $operators[$usedOperator] . '("' . $filterValue . '")'; + \array_push($queries, $query); + } + } + } + + // TODO: Can we even migrate search? Which key? Is $id key OK? + // TODO: What's difference between !empty and isset? + if(!empty($content['search'])) { + \array_push($queries, '$id.search("' . $content['search'] . '")'); + } + + unset($content['filters']); + unset($content['search']); + $content['queries'] = $queries; return $content; } From 69b4d074f5654cc2a9d2775de50474dccb374c63 Mon Sep 17 00:00:00 2001 From: Matej Baco Date: Fri, 31 Dec 2021 16:50:07 +0100 Subject: [PATCH 18/37] Migrated all imports to new request class --- app/controllers/api/account.php | 28 ++++++++++++++-------------- app/controllers/api/functions.php | 2 +- app/controllers/api/locale.php | 2 +- app/controllers/api/storage.php | 4 ++-- app/controllers/api/teams.php | 4 ++-- app/controllers/general.php | 6 +++--- app/controllers/mock.php | 8 ++++---- app/controllers/shared/api.php | 6 +++--- app/controllers/shared/web.php | 2 +- app/controllers/web/home.php | 2 +- app/init.php | 6 +++--- src/Appwrite/Utopia/Request.php | 2 +- 12 files changed, 36 insertions(+), 36 deletions(-) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index ef00af00e..07f45b380 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -55,7 +55,7 @@ App::post('/v1/account') ->inject('audits') ->inject('usage') ->action(function ($userId, $email, $password, $name, $request, $response, $project, $dbForProject, $audits, $usage) { - /** @var Utopia\Swoole\Request $request */ + /** @var Appwrite\Utopia\Request $request */ /** @var Appwrite\Utopia\Response $response */ /** @var Utopia\Database\Document $project */ /** @var Utopia\Database\Database $dbForProject */ @@ -155,7 +155,7 @@ App::post('/v1/account/sessions') ->inject('audits') ->inject('usage') ->action(function ($email, $password, $request, $response, $dbForProject, $locale, $geodb, $audits, $usage) { - /** @var Utopia\Swoole\Request $request */ + /** @var Appwrite\Utopia\Request $request */ /** @var Appwrite\Utopia\Response $response */ /** @var Utopia\Database\Database $dbForProject */ /** @var Utopia\Locale\Locale $locale */ @@ -267,7 +267,7 @@ App::get('/v1/account/sessions/oauth2/:provider') ->inject('response') ->inject('project') ->action(function ($provider, $success, $failure, $scopes, $request, $response, $project) use ($oauthDefaultSuccess, $oauthDefaultFailure) { - /** @var Utopia\Swoole\Request $request */ + /** @var Appwrite\Utopia\Request $request */ /** @var Appwrite\Utopia\Response $response */ /** @var Utopia\Database\Document $project */ @@ -320,7 +320,7 @@ App::get('/v1/account/sessions/oauth2/callback/:provider/:projectId') ->inject('request') ->inject('response') ->action(function ($projectId, $provider, $code, $state, $request, $response) { - /** @var Utopia\Swoole\Request $request */ + /** @var Appwrite\Utopia\Request $request */ /** @var Appwrite\Utopia\Response $response */ $domain = $request->getHostname(); @@ -347,7 +347,7 @@ App::post('/v1/account/sessions/oauth2/callback/:provider/:projectId') ->inject('request') ->inject('response') ->action(function ($projectId, $provider, $code, $state, $request, $response) { - /** @var Utopia\Swoole\Request $request */ + /** @var Appwrite\Utopia\Request $request */ /** @var Appwrite\Utopia\Response $response */ $domain = $request->getHostname(); @@ -382,7 +382,7 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect') ->inject('events') ->inject('usage') ->action(function ($provider, $code, $state, $request, $response, $project, $user, $dbForProject, $geodb, $audits, $events, $usage) use ($oauthDefaultSuccess) { - /** @var Utopia\Swoole\Request $request */ + /** @var Appwrite\Utopia\Request $request */ /** @var Appwrite\Utopia\Response $response */ /** @var Utopia\Database\Document $project */ /** @var Utopia\Database\Document $user */ @@ -627,7 +627,7 @@ App::post('/v1/account/sessions/magic-url') ->inject('events') ->inject('mails') ->action(function ($userId, $email, $url, $request, $response, $project, $dbForProject, $locale, $audits, $events, $mails) { - /** @var Utopia\Swoole\Request $request */ + /** @var Appwrite\Utopia\Request $request */ /** @var Appwrite\Utopia\Response $response */ /** @var Utopia\Database\Document $project */ /** @var Utopia\Database\Database $dbForProject */ @@ -773,7 +773,7 @@ App::put('/v1/account/sessions/magic-url') ->action(function ($userId, $secret, $request, $response, $dbForProject, $locale, $geodb, $audits) { /** @var string $userId */ /** @var string $secret */ - /** @var Utopia\Swoole\Request $request */ + /** @var Appwrite\Utopia\Request $request */ /** @var Appwrite\Utopia\Response $response */ /** @var Utopia\Database\Database $dbForProject */ /** @var Utopia\Locale\Locale $locale */ @@ -899,7 +899,7 @@ App::post('/v1/account/sessions/anonymous') ->inject('audits') ->inject('usage') ->action(function ($request, $response, $locale, $user, $project, $dbForProject, $geodb, $audits, $usage) { - /** @var Utopia\Swoole\Request $request */ + /** @var Appwrite\Utopia\Request $request */ /** @var Appwrite\Utopia\Response $response */ /** @var Utopia\Locale\Locale $locale */ /** @var Utopia\Database\Document $user */ @@ -1512,7 +1512,7 @@ App::delete('/v1/account') ->inject('events') ->inject('usage') ->action(function ($request, $response, $user, $dbForProject, $audits, $events, $usage) { - /** @var Utopia\Swoole\Request $request */ + /** @var Appwrite\Utopia\Request $request */ /** @var Appwrite\Utopia\Response $response */ /** @var Utopia\Database\Document $user */ /** @var Utopia\Database\Database $dbForProject */ @@ -1582,7 +1582,7 @@ App::delete('/v1/account/sessions/:sessionId') ->inject('events') ->inject('usage') ->action(function ($sessionId, $request, $response, $user, $dbForProject, $locale, $audits, $events, $usage) { - /** @var Utopia\Swoole\Request $request */ + /** @var Appwrite\Utopia\Request $request */ /** @var Appwrite\Utopia\Response $response */ /** @var Utopia\Database\Document $user */ /** @var Utopia\Database\Database $dbForProject */ @@ -1668,7 +1668,7 @@ App::delete('/v1/account/sessions') ->inject('events') ->inject('usage') ->action(function ($request, $response, $user, $dbForProject, $locale, $audits, $events, $usage) { - /** @var Utopia\Swoole\Request $request */ + /** @var Appwrite\Utopia\Request $request */ /** @var Appwrite\Utopia\Response $response */ /** @var Utopia\Database\Document $user */ /** @var Utopia\Database\Database $dbForProject */ @@ -1753,7 +1753,7 @@ App::post('/v1/account/recovery') ->inject('events') ->inject('usage') ->action(function ($email, $url, $request, $response, $dbForProject, $project, $locale, $mails, $audits, $events, $usage) { - /** @var Utopia\Swoole\Request $request */ + /** @var Appwrite\Utopia\Request $request */ /** @var Appwrite\Utopia\Response $response */ /** @var Utopia\Database\Database $dbForProject */ /** @var Utopia\Database\Document $project */ @@ -1945,7 +1945,7 @@ App::post('/v1/account/verification') ->inject('mails') ->inject('usage') ->action(function ($url, $request, $response, $project, $user, $dbForProject, $locale, $audits, $events, $mails, $usage) { - /** @var Utopia\Swoole\Request $request */ + /** @var Appwrite\Utopia\Request $request */ /** @var Appwrite\Utopia\Response $response */ /** @var Utopia\Database\Document $project */ /** @var Utopia\Database\Document $user */ diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 673d84ba4..eab8f322a 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -453,7 +453,7 @@ App::post('/v1/functions/:functionId/tags') ->inject('dbForProject') ->inject('usage') ->action(function ($functionId, $command, $file, $request, $response, $dbForProject, $usage) { - /** @var Utopia\Swoole\Request $request */ + /** @var Appwrite\Utopia\Request $request */ /** @var Appwrite\Utopia\Response $response */ /** @var Utopia\Database\Database $dbForProject */ /** @var Appwrite\Event\Event $usage */ diff --git a/app/controllers/api/locale.php b/app/controllers/api/locale.php index d5e2feb17..9c9e152e5 100644 --- a/app/controllers/api/locale.php +++ b/app/controllers/api/locale.php @@ -21,7 +21,7 @@ App::get('/v1/locale') ->inject('locale') ->inject('geodb') ->action(function ($request, $response, $locale, $geodb) { - /** @var Utopia\Swoole\Request $request */ + /** @var Appwrite\Utopia\Request $request */ /** @var Appwrite\Utopia\Response $response */ /** @var Utopia\Locale\Locale $locale */ /** @var MaxMind\Db\Reader $geodb */ diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index 39d18e3d3..4a5fb7cfe 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -52,7 +52,7 @@ App::post('/v1/storage/files') ->inject('audits') ->inject('usage') ->action(function ($fileId, $file, $read, $write, $request, $response, $dbForProject, $user, $audits, $usage) { - /** @var Utopia\Swoole\Request $request */ + /** @var Appwrite\Utopia\Request $request */ /** @var Appwrite\Utopia\Response $response */ /** @var Utopia\Database\Database $dbForProject */ /** @var Utopia\Database\Document $user */ @@ -295,7 +295,7 @@ App::get('/v1/storage/files/:fileId/preview') ->inject('dbForProject') ->inject('usage') ->action(function ($fileId, $width, $height, $gravity, $quality, $borderWidth, $borderColor, $borderRadius, $opacity, $rotation, $background, $output, $request, $response, $project, $dbForProject, $usage) { - /** @var Utopia\Swoole\Request $request */ + /** @var Appwrite\Utopia\Request $request */ /** @var Appwrite\Utopia\Response $response */ /** @var Utopia\Database\Document $project */ /** @var Utopia\Database\Database $dbForProject */ diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index c2f26159b..ab5534edc 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -541,7 +541,7 @@ App::patch('/v1/teams/:teamId/memberships/:membershipId') ->inject('dbForProject') ->inject('audits') ->action(function ($teamId, $membershipId, $roles, $request, $response, $user, $dbForProject, $audits) { - /** @var Utopia\Swoole\Request $request */ + /** @var Appwrite\Utopia\Request $request */ /** @var Appwrite\Utopia\Response $response */ /** @var Utopia\Database\Document $user */ /** @var Utopia\Database\Database $dbForProject */ @@ -608,7 +608,7 @@ App::patch('/v1/teams/:teamId/memberships/:membershipId/status') ->inject('geodb') ->inject('audits') ->action(function ($teamId, $membershipId, $userId, $secret, $request, $response, $user, $dbForProject, $geodb, $audits) { - /** @var Utopia\Swoole\Request $request */ + /** @var Appwrite\Utopia\Request $request */ /** @var Appwrite\Utopia\Response $response */ /** @var Utopia\Database\Document $user */ /** @var Utopia\Database\Database $dbForProject */ diff --git a/app/controllers/general.php b/app/controllers/general.php index 27ee03d7a..26d389bad 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -27,7 +27,7 @@ Config::setParam('cookieSamesite', Response::COOKIE_SAMESITE_NONE); App::init(function ($utopia, $request, $response, $console, $project, $dbForConsole, $user, $locale, $clients) { /** @var Utopia\App $utopia */ - /** @var Utopia\Swoole\Request $request */ + /** @var Appwrite\Utopia\Request $request */ /** @var Appwrite\Utopia\Response $response */ /** @var Utopia\Database\Document $console */ /** @var Utopia\Database\Document $project */ @@ -284,7 +284,7 @@ App::init(function ($utopia, $request, $response, $console, $project, $dbForCons }, ['utopia', 'request', 'response', 'console', 'project', 'dbForConsole', 'user', 'locale', 'clients']); App::options(function ($request, $response) { - /** @var Utopia\Swoole\Request $request */ + /** @var Appwrite\Utopia\Request $request */ /** @var Appwrite\Utopia\Response $response */ $origin = $request->getOrigin(); @@ -302,7 +302,7 @@ App::options(function ($request, $response) { App::error(function ($error, $utopia, $request, $response, $layout, $project, $logger, $loggerBreadcrumbs) { /** @var Exception $error */ /** @var Utopia\App $utopia */ - /** @var Utopia\Swoole\Request $request */ + /** @var Appwrite\Utopia\Request $request */ /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Utopia\View $layout */ /** @var Utopia\Database\Document $project */ diff --git a/app/controllers/mock.php b/app/controllers/mock.php index 5020614ba..ab9cbfc8e 100644 --- a/app/controllers/mock.php +++ b/app/controllers/mock.php @@ -205,7 +205,7 @@ App::get('/v1/mock/tests/general/download') ->label('sdk.mock', true) ->inject('response') ->action(function ($response) { - /** @var Utopia\Swoole\Request $request */ + /** @var Appwrite\Utopia\Request $request */ $response ->setContentType('text/plain') @@ -236,7 +236,7 @@ App::post('/v1/mock/tests/general/upload') ->inject('request') ->inject('response') ->action(function ($x, $y, $z, $file, $request, $response) { - /** @var Utopia\Swoole\Request $request */ + /** @var Appwrite\Utopia\Request $request */ /** @var Utopia\Swoole\Response $response */ $file = $request->getFiles('file'); @@ -373,7 +373,7 @@ App::get('/v1/mock/tests/general/get-cookie') ->label('sdk.mock', true) ->inject('request') ->action(function ($request) { - /** @var Utopia\Swoole\Request $request */ + /** @var Appwrite\Utopia\Request $request */ if ($request->getCookie('cookieName', '') !== 'cookieValue') { throw new Exception('Missing cookie value', 400); @@ -551,7 +551,7 @@ App::get('/v1/mock/tests/general/oauth2/failure') App::shutdown(function($utopia, $response, $request) { /** @var Utopia\App $utopia */ - /** @var Utopia\Swoole\Request $request */ + /** @var Appwrite\Utopia\Request $request */ /** @var Appwrite\Utopia\Response $response */ $result = []; diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index bdd5d618e..fc701e3a6 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -13,7 +13,7 @@ use Utopia\Storage\Storage; App::init(function ($utopia, $request, $response, $project, $user, $events, $audits, $usage, $deletes, $database, $dbForProject, $mode) { /** @var Utopia\App $utopia */ - /** @var Utopia\Swoole\Request $request */ + /** @var Appwrite\Utopia\Request $request */ /** @var Appwrite\Utopia\Response $response */ /** @var Utopia\Database\Document $project */ /** @var Utopia\Database\Document $user */ @@ -124,7 +124,7 @@ App::init(function ($utopia, $request, $response, $project, $user, $events, $aud App::init(function ($utopia, $request, $project) { /** @var Utopia\App $utopia */ - /** @var Utopia\Swoole\Request $request */ + /** @var Appwrite\Utopia\Request $request */ /** @var Utopia\Database\Document $project */ $route = $utopia->match($request); @@ -177,7 +177,7 @@ App::init(function ($utopia, $request, $project) { App::shutdown(function ($utopia, $request, $response, $project, $events, $audits, $usage, $deletes, $database, $mode) { /** @var Utopia\App $utopia */ - /** @var Utopia\Swoole\Request $request */ + /** @var Appwrite\Utopia\Request $request */ /** @var Appwrite\Utopia\Response $response */ /** @var Utopia\Database\Document $project */ /** @var Appwrite\Event\Event $events */ diff --git a/app/controllers/shared/web.php b/app/controllers/shared/web.php index 37bfb0130..e45333808 100644 --- a/app/controllers/shared/web.php +++ b/app/controllers/shared/web.php @@ -5,7 +5,7 @@ use Utopia\Config\Config; App::init(function ($utopia, $request, $response, $layout) { /** @var Utopia\App $utopia */ - /** @var Utopia\Swoole\Request $request */ + /** @var Appwrite\Utopia\Request $request */ /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Utopia\View $layout */ diff --git a/app/controllers/web/home.php b/app/controllers/web/home.php index 97389b894..8c35f5ce4 100644 --- a/app/controllers/web/home.php +++ b/app/controllers/web/home.php @@ -258,7 +258,7 @@ App::get('/specs/:format') ->inject('response') ->action(function ($format, $platform, $tests, $utopia, $request, $response) { /** @var Utopia\App $utopia */ - /** @var Utopia\Swoole\Request $request */ + /** @var Appwrite\Utopia\Request $request */ /** @var Appwrite\Utopia\Response $response */ $platforms = [ diff --git a/app/init.php b/app/init.php index 89f2361d2..632a733c8 100644 --- a/app/init.php +++ b/app/init.php @@ -664,7 +664,7 @@ App::setResource('clients', function ($request, $console, $project) { }, ['request', 'console', 'project']); App::setResource('user', function($mode, $project, $console, $request, $response, $dbForProject, $dbForConsole) { - /** @var Utopia\Swoole\Request $request */ + /** @var Appwrite\Utopia\Request $request */ /** @var Appwrite\Utopia\Response $response */ /** @var Utopia\Database\Document $project */ /** @var Utopia\Database\Database $dbForProject */ @@ -748,7 +748,7 @@ App::setResource('user', function($mode, $project, $console, $request, $response }, ['mode', 'project', 'console', 'request', 'response', 'dbForProject', 'dbForConsole']); App::setResource('project', function($dbForConsole, $request, $console) { - /** @var Utopia\Swoole\Request $request */ + /** @var Appwrite\Utopia\Request $request */ /** @var Utopia\Database\Database $dbForConsole */ /** @var Utopia\Database\Document $console */ @@ -828,7 +828,7 @@ App::setResource('dbForConsole', function($db, $cache) { }, ['db', 'cache']); App::setResource('mode', function($request) { - /** @var Utopia\Swoole\Request $request */ + /** @var Appwrite\Utopia\Request $request */ /** * Defines the mode for the request: diff --git a/src/Appwrite/Utopia/Request.php b/src/Appwrite/Utopia/Request.php index cd4ad0f99..491f4259b 100644 --- a/src/Appwrite/Utopia/Request.php +++ b/src/Appwrite/Utopia/Request.php @@ -5,7 +5,7 @@ namespace Appwrite\Utopia; use Appwrite\Utopia\Request\Filter; use Utopia\Route; -use Utopia\Swoole\Request as UtopiaRequest; +use Appwrite\Utopia\Request as UtopiaRequest; class Request extends UtopiaRequest { From 266e967daebf76e1833fdb9b9733d9070acf76db Mon Sep 17 00:00:00 2001 From: Matej Baco Date: Sun, 2 Jan 2022 10:15:41 +0100 Subject: [PATCH 19/37] Recursive import bug fix --- src/Appwrite/Utopia/Request.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Utopia/Request.php b/src/Appwrite/Utopia/Request.php index 491f4259b..3703f8ced 100644 --- a/src/Appwrite/Utopia/Request.php +++ b/src/Appwrite/Utopia/Request.php @@ -5,7 +5,7 @@ namespace Appwrite\Utopia; use Appwrite\Utopia\Request\Filter; use Utopia\Route; -use Appwrite\Utopia\Request as UtopiaRequest; +use Utopia\Request as UtopiaRequest; class Request extends UtopiaRequest { From 924ea3a45a1e1f35b3becdc15bc1414215fd0e9e Mon Sep 17 00:00:00 2001 From: Matej Baco Date: Sun, 2 Jan 2022 12:43:48 +0100 Subject: [PATCH 20/37] Added response models --- app/controllers/general.php | 3 + src/Appwrite/Utopia/Response/Filters/V11.php | 198 +++++++++++++++++++ 2 files changed, 201 insertions(+) create mode 100644 src/Appwrite/Utopia/Response/Filters/V11.php diff --git a/app/controllers/general.php b/app/controllers/general.php index 26d389bad..5a9a2febe 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -16,6 +16,7 @@ use Appwrite\Network\Validator\Origin; use Appwrite\Utopia\Response\Filters\V06; use Appwrite\Utopia\Response\Filters\V07; use Appwrite\Utopia\Response\Filters\V08; +use Appwrite\Utopia\Response\Filters\V11; use Utopia\CLI\Console; use Utopia\Database\Document; use Utopia\Database\Query; @@ -148,6 +149,8 @@ App::init(function ($utopia, $request, $response, $console, $project, $dbForCons break; case version_compare ($responseFormat , '0.8.0', '<=') : Response::setFilter(new V08()); + case version_compare ($responseFormat , '0.11.0', '<=') : + Response::setFilter(new V11()); break; default: Response::setFilter(null); diff --git a/src/Appwrite/Utopia/Response/Filters/V11.php b/src/Appwrite/Utopia/Response/Filters/V11.php new file mode 100644 index 000000000..240dec37a --- /dev/null +++ b/src/Appwrite/Utopia/Response/Filters/V11.php @@ -0,0 +1,198 @@ +parsePermissions($content); + break; + case Response::MODEL_EXECUTION: + $parsedResponse = $this->parseExecutionPermissions($content); + break; + case Response::MODEL_FUNCTION: + $parsedResponse = $this->parseFunctionPermissions($content); + break; + // Convert status from boolean to int + case Response::MODEL_USER: + $parsedResponse = $this->parseStatus($content); + break; + + // Complex filters + case Response::MODEL_COLLECTION: + $parsedResponse = $this->parsePermissions($content); + $parsedResponse = $this->removeRule($content, 'enabled'); + $parsedResponse = $this->removeRule($content, 'permission'); + $parsedResponse = $this->removeRule($content, 'indexes'); + $parsedResponse = $this->removeRule($content, 'enabled'); + $parsedResponse = $this->addDate($content, 'dateCreated'); + $parsedResponse = $this->addDate($content, 'dateUpdated'); + $parsedResponse = $this->parseAttributes($content); + case Response::MODEL_LOG: + $parsedResponse = $this->removeRule($content, 'userId'); + $parsedResponse = $this->removeRule($content, 'userEmail'); + $parsedResponse = $this->removeRule($content, 'userName'); + $parsedResponse = $this->removeRule($content, 'mode'); + $parsedResponse = $this->removeRule($content, 'sum'); + case Response::MODEL_PROJECT: + $parsedResponse = $this->addTasks($content); + $parsedResponse = $this->parseAuthLimit($content); + $parsedResponse = $this->parseOAuths($content); + $parsedResponse = $this->parseAuthsStatus($content); + $parsedResponse = $this->removeServicesStatus($content); + break; + } + + return $parsedResponse; + } + + protected function parseStatus(array $content) + { + $content['status'] = $content['status'] === true ? + $content['emailVerification'] === true ? 1 : 0 + : 2; + + return $content; + } + + protected function parseAttributes(array $content) + { + $content['rules'] = \array_map(function($attribute) use($content) { + return [ + '$id' => $attribute['key'], + '$collection' => $content['$id'], + 'type' => $attribute['type'], + 'key' => $attribute['key'], + 'label' => $attribute['key'], + 'default' => $attribute['default'], + 'array' => $attribute['array'], + 'required' => $attribute['required'], + 'list' => $attribute['elements'], + ]; + }, $content['attributes']); + unset($content['attributes']); + + return $content; + } + + protected function parseAuthLimit(array $content) + { + $content['usersAuthLimit'] = $content['authLimit']; + unset($content['authLimit']); + + return $content; + } + + protected function parseOAuths(array $content) + { + $regexPattern = "/provider([a-zA-Z0-9]+)(Appid|Secret)/"; + + foreach ($content as $key => $value) { + \preg_match_all($regexPattern, $key, $regexGroups); + if(\count($regexGroups[1]) > 0 && \count($regexGroups[2]) > 0) { + $providerName = $regexGroups[1][0]; + $valueKey = $regexGroups[2][0]; + $content['usersOauth2' . $providerName . $valueKey] = $value; + unset($content['provider' . $providerName . $valueKey]); + } + } + + return $content; + } + + protected function parseAuthsStatus(array $content) + { + $regexPattern = "/auth([a-zA-Z0-9]+)/"; + + foreach ($content as $key => $value) { + \preg_match_all($regexPattern, $key, $regexGroups); + if(\count($regexGroups[1]) > 0) { + $providerName = $regexGroups[1][0]; + + $content[$providerName] = $value; + unset($content['auth' . $providerName]); + } + } + + return $content; + } + + protected function removeServicesStatus(array $content) + { + // Such a key is part of new response, but is not part of old one. We simply remove it, older version never + // expected it anyway. + foreach ($content as $key => $value) { + if(\str_starts_with($key, 'serviceStatusFor')) { + unset($content[$key]); + } + } + + return $content; + } + + protected function removeRule(array $content, $key) + { + // Such a key is part of new response, but is not part of old one. We simply remove it, older version never + // expected it anyway. + unset($content[$key]); + + return $content; + } + + protected function addDate(array $content, $key) + { + // We simply don't have the date available in the content anymore. + // We set it to valid integer that indicates the value is not right + $content[$key] = 0; + + return $content; + } + + protected function addTasks(array $content) + { + // We simply don't have the date available in the content anymore. + // We set it to valid array + $content['tasks'] = []; + + return $content; + } + + protected function parsePermissions(array $content) + { + $content['$permissions'] = [ 'read' => $content['$read'], 'write' => $content['$write'] ]; + unset($content['$read']); + unset($content['$write']); + + return $content; + } + + protected function parseFunctionPermissions(array $content) + { + $content['$permissions'] = [ 'execute' => $content['execute'] ]; + unset($content['execute']); + + return $content; + } + + protected function parseExecutionPermissions(array $content) + { + $content['$permissions'] = [ 'read' => $content['$read'] ]; + unset($content['$read']); + + return $content; + } +} From c6feea3c9f1198306decd8d6ac7b11edb6a376ab Mon Sep 17 00:00:00 2001 From: Matej Baco Date: Sun, 2 Jan 2022 14:25:13 +0100 Subject: [PATCH 21/37] Tests fix --- src/Appwrite/Utopia/Request.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Appwrite/Utopia/Request.php b/src/Appwrite/Utopia/Request.php index 3703f8ced..98dfffc0e 100644 --- a/src/Appwrite/Utopia/Request.php +++ b/src/Appwrite/Utopia/Request.php @@ -4,8 +4,9 @@ namespace Appwrite\Utopia; use Appwrite\Utopia\Request\Filter; +use Swoole\Http\Request as SwooleRequest; use Utopia\Route; -use Utopia\Request as UtopiaRequest; +use Utopia\Swoole\Request as UtopiaRequest; class Request extends UtopiaRequest { @@ -19,6 +20,14 @@ class Request extends UtopiaRequest */ private static $route = null; + /** + * Request constructor. + */ + public function __construct(SwooleRequest $request) + { + parent::__construct($request); + } + /** * Get Param * From a762fe7b3eb6f6b5c666e5a1925803b5a5ad8baf Mon Sep 17 00:00:00 2001 From: Matej Baco Date: Sun, 2 Jan 2022 16:19:27 +0100 Subject: [PATCH 22/37] Moved request format to app init --- app/controllers/general.php | 23 +++++++++++++++++-- app/http.php | 21 ----------------- composer.json | 9 ++++++-- .../Health/HealthCustomServerTest.php | 2 +- 4 files changed, 29 insertions(+), 26 deletions(-) diff --git a/app/controllers/general.php b/app/controllers/general.php index 5a9a2febe..15e58cec9 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -21,6 +21,7 @@ use Utopia\CLI\Console; use Utopia\Database\Document; use Utopia\Database\Query; use Utopia\Database\Validator\Authorization; +use Appwrite\Utopia\Request\Filters\V12; Config::setParam('domainVerification', false); Config::setParam('cookieDomain', 'localhost'); @@ -37,6 +38,26 @@ App::init(function ($utopia, $request, $response, $console, $project, $dbForCons /** @var Utopia\Locale\Locale $locale */ /** @var array $clients */ + /* + * Request format + */ + $route = $utopia->match($request); + Request::setRoute($route); + + $requestFormat = $request->getHeader('x-appwrite-response-format', App::getEnv('_APP_SYSTEM_RESPONSE_FORMAT', '')); + if ($requestFormat) { + switch($requestFormat) { + // TODO: For some reason console is still on 0.11. We dont want this filter logic in console, console uses 0.12 SDK + case version_compare ($requestFormat , '0.11.0', '<=') : + Request::setFilter(new V12()); + break; + default: + Request::setFilter(null); + } + } else { + Request::setFilter(null); + } + $domain = $request->getHostname(); $domains = Config::getParam('domains', []); if (!array_key_exists($domain, $domains)) { @@ -87,8 +108,6 @@ App::init(function ($utopia, $request, $response, $console, $project, $dbForCons $locale->setDefault($localeParam); } - $route = $utopia->match($request); - if ($project->isEmpty()) { throw new Exception('Project not found', 404); } diff --git a/app/http.php b/app/http.php index 7df9b963e..a73daa256 100644 --- a/app/http.php +++ b/app/http.php @@ -2,7 +2,6 @@ require_once __DIR__.'/../vendor/autoload.php'; -use Appwrite\Utopia\Request\Filters\V12; use Appwrite\Utopia\Response; use Swoole\Process; use Swoole\Http\Server; @@ -187,26 +186,6 @@ $http->on('request', function (SwooleRequest $swooleRequest, SwooleResponse $swo Authorization::cleanRoles(); Authorization::setRole('role:all'); - /* - * Request format - */ - $route = $app->match($request); - Request::setRoute($route); - - $requestFormat = $request->getHeader('x-appwrite-response-format', App::getEnv('_APP_SYSTEM_RESPONSE_FORMAT', '')); - if ($requestFormat) { - switch($requestFormat) { - // TODO: For some reason console is still on 0.11. We dont want this filter logic in console, console uses 0.12 SDK - case version_compare ($requestFormat , '0.11.0', '<=') : - Request::setFilter(new V12()); - break; - default: - Request::setFilter(null); - } - } else { - Request::setFilter(null); - } - $app->run($request, $response); } catch (\Throwable $th) { $version = App::getEnv('_APP_VERSION', 'UNKNOWN'); diff --git a/composer.json b/composer.json index 83d7d4fdb..fd744ed37 100644 --- a/composer.json +++ b/composer.json @@ -38,7 +38,7 @@ "appwrite/php-clamav": "1.1.*", "appwrite/php-runtimes": "0.6.*", - "utopia-php/framework": "0.19.*", + "utopia-php/framework": "dev-fix-get-args-after-init", "utopia-php/logger": "0.1.*", "utopia-php/abuse": "0.7.*", "utopia-php/analytics": "0.2.*", @@ -66,7 +66,12 @@ "adhocore/jwt": "1.1.2", "slickdeals/statsd": "3.1.0" }, - "repositories": [], + "repositories": [ + { + "type": "git", + "url": "https://github.com/utopia-php/framework" + } + ], "require-dev": { "appwrite/sdk-generator": "0.16.3", "phpunit/phpunit": "9.5.10", diff --git a/tests/e2e/Services/Health/HealthCustomServerTest.php b/tests/e2e/Services/Health/HealthCustomServerTest.php index f7483d797..a15e456e5 100644 --- a/tests/e2e/Services/Health/HealthCustomServerTest.php +++ b/tests/e2e/Services/Health/HealthCustomServerTest.php @@ -158,7 +158,7 @@ class HealthCustomServerTest extends Scope $this->assertEquals(200, $response['headers']['status-code']); $this->assertIsInt($response['body']['size']); - $this->assertLessThan(160, $response['body']['size']); + $this->assertLessThan(200, $response['body']['size']); /** * Test for FAILURE From f9994d8021d19e21538b8be867563e743b9c048e Mon Sep 17 00:00:00 2001 From: Matej Baco Date: Sun, 2 Jan 2022 16:23:37 +0100 Subject: [PATCH 23/37] Added request filter tests --- tests/e2e/General/HTTPTest.php | 48 ++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/tests/e2e/General/HTTPTest.php b/tests/e2e/General/HTTPTest.php index 4f9a8dc95..71d17e340 100644 --- a/tests/e2e/General/HTTPTest.php +++ b/tests/e2e/General/HTTPTest.php @@ -187,6 +187,54 @@ class HTTPTest extends Scope $this->assertEquals($body['continents']['AS'], 'Asia'); } + public function testRequestHeader() { + /** + * Test without header + */ + $response = $this->client->call(Client::METHOD_POST, '/teams', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => 'console' + ], $this->getHeaders()), [ + 'name' => 'Latest version Team', + 'teamId' => 'unique()' + ]); + + $this->assertEquals(201, $response['headers']['status-code']); + $team1Id = $response['body']['$id']; + + /** + * Test with header + */ + $response = $this->client->call(Client::METHOD_POST, '/teams', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => 'console', + 'x-appwrite-response-format' => '0.11.0' + ], $this->getHeaders()), [ + 'name' => 'Latest version Team' + // Notice "teamId' is not defined + ]); + + $this->assertEquals(201, $response['headers']['status-code']); + $team2Id = $response['body']['$id']; + + /** + * Cleanup, so I don't invalidate some listTeams requests by mistake + */ + $response = $this->client->call(Client::METHOD_DELETE, '/teams/' . $team1Id, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => 'console', + ], $this->getHeaders())); + + $this->assertEquals(204, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_DELETE, '/teams/' . $team2Id, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => 'console', + ], $this->getHeaders())); + + $this->assertEquals(204, $response['headers']['status-code']); + } + public function testVersions() { /** From 30f7293e815125c346c1ebee5e5e767d7ad94d4c Mon Sep 17 00:00:00 2001 From: Matej Baco Date: Sun, 2 Jan 2022 17:08:27 +0100 Subject: [PATCH 24/37] Moved test to proper space --- tests/e2e/General/HTTPTest.php | 64 +++---------------- .../Services/Teams/TeamsConsoleClientTest.php | 56 ++++++++++++++++ 2 files changed, 64 insertions(+), 56 deletions(-) diff --git a/tests/e2e/General/HTTPTest.php b/tests/e2e/General/HTTPTest.php index 71d17e340..f9f017fa6 100644 --- a/tests/e2e/General/HTTPTest.php +++ b/tests/e2e/General/HTTPTest.php @@ -18,7 +18,7 @@ class HTTPTest extends Scope /** * Test for SUCCESS */ - $response = $this->client->call(Client::METHOD_OPTIONS, '/', array_merge([ + $response = $this->client->call(Client::METHOD_OPTIONS, '/', \array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', ]), []); @@ -38,7 +38,7 @@ class HTTPTest extends Scope /** * Test for SUCCESS */ - $response = $this->client->call(Client::METHOD_GET, '/error', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/error', \array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', ]), []); @@ -54,7 +54,7 @@ class HTTPTest extends Scope /** * Test for SUCCESS */ - $response = $this->client->call(Client::METHOD_GET, '/manifest.json', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/manifest.json', \array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', ]), []); @@ -73,7 +73,7 @@ class HTTPTest extends Scope /** * Test for SUCCESS */ - $response = $this->client->call(Client::METHOD_GET, '/humans.txt', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/humans.txt', \array_merge([ 'origin' => 'http://localhost', ]), []); @@ -86,7 +86,7 @@ class HTTPTest extends Scope /** * Test for SUCCESS */ - $response = $this->client->call(Client::METHOD_GET, '/robots.txt', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/robots.txt', \array_merge([ 'origin' => 'http://localhost', ]), []); @@ -155,7 +155,7 @@ class HTTPTest extends Scope /** * Test without header */ - $response = $this->client->call(Client::METHOD_GET, '/locale/continents', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/locale/continents', \array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => 'console', ], $this->getHeaders())); @@ -173,7 +173,7 @@ class HTTPTest extends Scope /** * Test with header */ - $response = $this->client->call(Client::METHOD_GET, '/locale/continents', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/locale/continents', \array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => 'console', 'x-appwrite-response-format' => '0.6.2' @@ -187,60 +187,12 @@ class HTTPTest extends Scope $this->assertEquals($body['continents']['AS'], 'Asia'); } - public function testRequestHeader() { - /** - * Test without header - */ - $response = $this->client->call(Client::METHOD_POST, '/teams', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => 'console' - ], $this->getHeaders()), [ - 'name' => 'Latest version Team', - 'teamId' => 'unique()' - ]); - - $this->assertEquals(201, $response['headers']['status-code']); - $team1Id = $response['body']['$id']; - - /** - * Test with header - */ - $response = $this->client->call(Client::METHOD_POST, '/teams', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => 'console', - 'x-appwrite-response-format' => '0.11.0' - ], $this->getHeaders()), [ - 'name' => 'Latest version Team' - // Notice "teamId' is not defined - ]); - - $this->assertEquals(201, $response['headers']['status-code']); - $team2Id = $response['body']['$id']; - - /** - * Cleanup, so I don't invalidate some listTeams requests by mistake - */ - $response = $this->client->call(Client::METHOD_DELETE, '/teams/' . $team1Id, array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => 'console', - ], $this->getHeaders())); - - $this->assertEquals(204, $response['headers']['status-code']); - - $response = $this->client->call(Client::METHOD_DELETE, '/teams/' . $team2Id, array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => 'console', - ], $this->getHeaders())); - - $this->assertEquals(204, $response['headers']['status-code']); - } - public function testVersions() { /** * Test without header */ - $response = $this->client->call(Client::METHOD_GET, '/versions', array_merge([ + $response = $this->client->call(Client::METHOD_GET, '/versions', \array_merge([ 'content-type' => 'application/json', ], $this->getHeaders())); diff --git a/tests/e2e/Services/Teams/TeamsConsoleClientTest.php b/tests/e2e/Services/Teams/TeamsConsoleClientTest.php index 7ced83c4e..1d01ecc22 100644 --- a/tests/e2e/Services/Teams/TeamsConsoleClientTest.php +++ b/tests/e2e/Services/Teams/TeamsConsoleClientTest.php @@ -2,6 +2,7 @@ namespace Tests\E2E\Services\Teams; +use Tests\E2E\Client; use Tests\E2E\Scopes\Scope; use Tests\E2E\Scopes\ProjectConsole; use Tests\E2E\Scopes\SideClient; @@ -12,4 +13,59 @@ class TeamsConsoleClientTest extends Scope use TeamsBaseClient; use ProjectConsole; use SideClient; + + public function testRequestHeader() { + $headers = \array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => 'console' + ], $this->getHeaders()); + + \var_dump($headers); + + /** + * Test without header + */ + $response = $this->client->call(Client::METHOD_POST, '/teams', \array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => 'console' + ], $this->getHeaders()), [ + 'name' => 'Latest version Team', + 'teamId' => 'unique()' + ]); + + $this->assertEquals(201, $response['headers']['status-code']); + $team1Id = $response['body']['$id']; + + /** + * Test with header + */ + $response = $this->client->call(Client::METHOD_POST, '/teams', \array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => 'console', + 'x-appwrite-response-format' => '0.11.0' + ], $this->getHeaders()), [ + 'name' => 'Latest version Team' + // Notice "teamId' is not defined + ]); + + $this->assertEquals(201, $response['headers']['status-code']); + $team2Id = $response['body']['$id']; + + /** + * Cleanup, so I don't invalidate some listTeams requests by mistake + */ + $response = $this->client->call(Client::METHOD_DELETE, '/teams/' . $team1Id, \array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => 'console', + ], $this->getHeaders())); + + $this->assertEquals(204, $response['headers']['status-code']); + + $response = $this->client->call(Client::METHOD_DELETE, '/teams/' . $team2Id, \array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => 'console', + ], $this->getHeaders())); + + $this->assertEquals(204, $response['headers']['status-code']); + } } \ No newline at end of file From f80dc3a7ff58c1b299a1943652653795295b624e Mon Sep 17 00:00:00 2001 From: Matej Baco Date: Sun, 2 Jan 2022 17:25:02 +0100 Subject: [PATCH 25/37] Removed var dumps --- tests/e2e/Services/Teams/TeamsConsoleClientTest.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/tests/e2e/Services/Teams/TeamsConsoleClientTest.php b/tests/e2e/Services/Teams/TeamsConsoleClientTest.php index 1d01ecc22..7b7e24aee 100644 --- a/tests/e2e/Services/Teams/TeamsConsoleClientTest.php +++ b/tests/e2e/Services/Teams/TeamsConsoleClientTest.php @@ -15,13 +15,6 @@ class TeamsConsoleClientTest extends Scope use SideClient; public function testRequestHeader() { - $headers = \array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => 'console' - ], $this->getHeaders()); - - \var_dump($headers); - /** * Test without header */ From 35a665b2d7f196b0f2b71f8ce99fd2c8e1f7c54d Mon Sep 17 00:00:00 2001 From: Matej Baco Date: Mon, 3 Jan 2022 10:40:03 +0100 Subject: [PATCH 26/37] Added Health request filters --- src/Appwrite/Utopia/Response/Filters/V11.php | 65 +++++++++++++++++++- 1 file changed, 63 insertions(+), 2 deletions(-) diff --git a/src/Appwrite/Utopia/Response/Filters/V11.php b/src/Appwrite/Utopia/Response/Filters/V11.php index 240dec37a..d0e689012 100644 --- a/src/Appwrite/Utopia/Response/Filters/V11.php +++ b/src/Appwrite/Utopia/Response/Filters/V11.php @@ -8,8 +8,6 @@ use Exception; class V11 extends Filter { - // TODO: Health - // Convert 0.12 Data format to 0.11 format public function parse(array $content, string $model): array { @@ -31,6 +29,22 @@ class V11 extends Filter case Response::MODEL_USER: $parsedResponse = $this->parseStatus($content); break; + // Convert all Health responses back to original + case Response::MODEL_HEALTH_STATUS: + $parsedResponse = $this->parseHealthStatus($content); + break; + case Response::MODEL_HEALTH_VERSION: + $parsedResponse = $this->parseHealthVersion($content); + break; + case Response::MODEL_HEALTH_TIME: + $parsedResponse = $this->parseHealthTime($content); + break; + case Response::MODEL_HEALTH_QUEUE: + $parsedResponse = $this->parseHealthQueue($content); + break; + case Response::MODEL_HEALTH_ANTIVIRUS: + $parsedResponse = $this->parseHealthAntivirus($content); + break; // Complex filters case Response::MODEL_COLLECTION: @@ -60,6 +74,53 @@ class V11 extends Filter return $parsedResponse; } + protected function parseHealthAntivirus(array $content) + { + if($content['status'] === 'pass') { + $content['status'] = 'online'; + } + + if($content['status'] === 'fail') { + $content['status'] = 'offline'; + } + + return $content; + } + + protected function parseHealthTime(array $content) + { + $content['remote'] = $content['remoteTime']; + unset($content['remoteTime']); + + $content['local'] = $content['localTime']; + unset($content['localTime']); + + return $content; + } + + protected function parseHealthVersion(array $content) + { + // Did not change + + return $content; + } + + + protected function parseHealthQueue(array $content) + { + // Did not change + + return $content; + } + + protected function parseHealthStatus(array $content) + { + $content['status'] = 'OK'; // Is always returning pass, was always returning OK + unset($content['ping']); + + return $content; + } + protected function parseStatus(array $content) { $content['status'] = $content['status'] === true ? From df9e06404765bf3359c68b3525fd1b285925410a Mon Sep 17 00:00:00 2001 From: Matej Baco Date: Tue, 4 Jan 2022 10:05:21 +0100 Subject: [PATCH 27/37] Fixed TODOs --- app/controllers/general.php | 1 - src/Appwrite/Utopia/Request/Filters/V12.php | 12 +++++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/app/controllers/general.php b/app/controllers/general.php index 15e58cec9..e972dccc3 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -47,7 +47,6 @@ App::init(function ($utopia, $request, $response, $console, $project, $dbForCons $requestFormat = $request->getHeader('x-appwrite-response-format', App::getEnv('_APP_SYSTEM_RESPONSE_FORMAT', '')); if ($requestFormat) { switch($requestFormat) { - // TODO: For some reason console is still on 0.11. We dont want this filter logic in console, console uses 0.12 SDK case version_compare ($requestFormat , '0.11.0', '<=') : Request::setFilter(new V12()); break; diff --git a/src/Appwrite/Utopia/Request/Filters/V12.php b/src/Appwrite/Utopia/Request/Filters/V12.php index 392d62aee..4f8c4bc9d 100644 --- a/src/Appwrite/Utopia/Request/Filters/V12.php +++ b/src/Appwrite/Utopia/Request/Filters/V12.php @@ -134,18 +134,16 @@ class V12 extends Filter if(isset($usedOperator)) { [ $attributeKey, $filterValue ] = \explode($usedOperator, $filter); - // TODO: String or not? Any way to figure out? - $query = $attributeKey . '.' . $operators[$usedOperator] . '("' . $filterValue . '")'; + + $filterValue = \is_numeric($filterValue) ? $filterValue : '"' . $filterValue . '"'; + $query = $attributeKey . '.' . $operators[$usedOperator] . '(' . $filterValue . ')'; \array_push($queries, $query); } } } - // TODO: Can we even migrate search? Which key? Is $id key OK? - // TODO: What's difference between !empty and isset? - if(!empty($content['search'])) { - \array_push($queries, '$id.search("' . $content['search'] . '")'); - } + // We cannot migrate search properly + unset($content['search']); unset($content['filters']); unset($content['search']); From 2413a7fb428dc0eb02f1c19bd60c7ebc0e37d540 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Tue, 4 Jan 2022 16:30:50 +0400 Subject: [PATCH 28/37] fix: request and response filters --- app/controllers/general.php | 2 +- composer.json | 2 +- composer.lock | 151 ++++++++++++---- src/Appwrite/Utopia/Request.php | 39 +--- src/Appwrite/Utopia/Request/Filters/V12.php | 22 ++- src/Appwrite/Utopia/Response/Filters/V11.php | 181 +++++++++++++++++-- 6 files changed, 294 insertions(+), 103 deletions(-) diff --git a/app/controllers/general.php b/app/controllers/general.php index e972dccc3..8b0fbf8e0 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -47,7 +47,7 @@ App::init(function ($utopia, $request, $response, $console, $project, $dbForCons $requestFormat = $request->getHeader('x-appwrite-response-format', App::getEnv('_APP_SYSTEM_RESPONSE_FORMAT', '')); if ($requestFormat) { switch($requestFormat) { - case version_compare ($requestFormat , '0.11.0', '<=') : + case version_compare ($requestFormat , '0.12.0', '<') : Request::setFilter(new V12()); break; default: diff --git a/composer.json b/composer.json index fd744ed37..c60f897ce 100644 --- a/composer.json +++ b/composer.json @@ -38,7 +38,7 @@ "appwrite/php-clamav": "1.1.*", "appwrite/php-runtimes": "0.6.*", - "utopia-php/framework": "dev-fix-get-args-after-init", + "utopia-php/framework": "dev-fix-get-args-after-init as 0.19", "utopia-php/logger": "0.1.*", "utopia-php/abuse": "0.7.*", "utopia-php/analytics": "0.2.*", diff --git a/composer.lock b/composer.lock index 7fb2cd49a..55c39bc51 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "e0243d2a276d074c4af4ac21f521c953", + "content-hash": "d32b727a743b3a8811ec64c56f308694", "packages": [ { "name": "adhocore/jwt", @@ -2138,16 +2138,16 @@ }, { "name": "utopia-php/database", - "version": "0.13.1", + "version": "0.13.2", "source": { "type": "git", "url": "https://github.com/utopia-php/database.git", - "reference": "a1b2849c991b6384fe70e3c2d0633256a4fb795b" + "reference": "bf92279b707b3a10ee5ec5df5c065023b2221357" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/database/zipball/a1b2849c991b6384fe70e3c2d0633256a4fb795b", - "reference": "a1b2849c991b6384fe70e3c2d0633256a4fb795b", + "url": "https://api.github.com/repos/utopia-php/database/zipball/bf92279b707b3a10ee5ec5df5c065023b2221357", + "reference": "bf92279b707b3a10ee5ec5df5c065023b2221357", "shasum": "" }, "require": { @@ -2195,9 +2195,9 @@ ], "support": { "issues": "https://github.com/utopia-php/database/issues", - "source": "https://github.com/utopia-php/database/tree/0.13.1" + "source": "https://github.com/utopia-php/database/tree/0.13.2" }, - "time": "2021-12-29T14:04:55+00:00" + "time": "2022-01-04T10:51:22+00:00" }, { "name": "utopia-php/domains", @@ -2255,17 +2255,11 @@ }, { "name": "utopia-php/framework", - "version": "0.19.4", + "version": "dev-fix-get-args-after-init", "source": { "type": "git", - "url": "https://github.com/utopia-php/framework.git", - "reference": "b1c79f199a6adbf8526cea272d931213a8eb511d" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/utopia-php/framework/zipball/b1c79f199a6adbf8526cea272d931213a8eb511d", - "reference": "b1c79f199a6adbf8526cea272d931213a8eb511d", - "shasum": "" + "url": "https://github.com/utopia-php/framework", + "reference": "36a42dce039f043288673f0ff46284353543624d" }, "require": { "php": ">=8.0.0" @@ -2280,7 +2274,6 @@ "Utopia\\": "src/" } }, - "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], @@ -2296,11 +2289,7 @@ "php", "upf" ], - "support": { - "issues": "https://github.com/utopia-php/framework/issues", - "source": "https://github.com/utopia-php/framework/tree/0.19.4" - }, - "time": "2021-12-29T15:05:19+00:00" + "time": "2022-01-03T08:38:34+00:00" }, { "name": "utopia-php/image", @@ -3200,16 +3189,16 @@ }, { "name": "composer/semver", - "version": "3.2.6", + "version": "3.2.7", "source": { "type": "git", "url": "https://github.com/composer/semver.git", - "reference": "83e511e247de329283478496f7a1e114c9517506" + "reference": "deac27056b57e46faf136fae7b449eeaa71661ee" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/semver/zipball/83e511e247de329283478496f7a1e114c9517506", - "reference": "83e511e247de329283478496f7a1e114c9517506", + "url": "https://api.github.com/repos/composer/semver/zipball/deac27056b57e46faf136fae7b449eeaa71661ee", + "reference": "deac27056b57e46faf136fae7b449eeaa71661ee", "shasum": "" }, "require": { @@ -3261,7 +3250,7 @@ "support": { "irc": "irc://irc.freenode.org/composer", "issues": "https://github.com/composer/semver/issues", - "source": "https://github.com/composer/semver/tree/3.2.6" + "source": "https://github.com/composer/semver/tree/3.2.7" }, "funding": [ { @@ -3277,7 +3266,7 @@ "type": "tidelift" } ], - "time": "2021-10-25T11:34:17+00:00" + "time": "2022-01-04T09:57:54+00:00" }, { "name": "composer/xdebug-handler", @@ -6059,6 +6048,82 @@ ], "time": "2021-05-27T12:26:48+00:00" }, + { + "name": "symfony/polyfill-php72", + "version": "v1.23.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-php72.git", + "reference": "9a142215a36a3888e30d0a9eeea9766764e96976" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-php72/zipball/9a142215a36a3888e30d0a9eeea9766764e96976", + "reference": "9a142215a36a3888e30d0a9eeea9766764e96976", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.23-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Php72\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "polyfill", + "portable", + "shim" + ], + "support": { + "source": "https://github.com/symfony/polyfill-php72/tree/v1.23.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2021-05-27T09:17:38+00:00" + }, { "name": "symfony/service-contracts", "version": "v3.0.0", @@ -6327,22 +6392,23 @@ }, { "name": "twig/twig", - "version": "v2.14.8", + "version": "v2.14.10", "source": { "type": "git", "url": "https://github.com/twigphp/Twig.git", - "reference": "06b450a2326aa879faa2061ff72fe1588b3ab043" + "reference": "95fb194cd4dd6ac373a27af2bde2bad5d3f27aba" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/twigphp/Twig/zipball/06b450a2326aa879faa2061ff72fe1588b3ab043", - "reference": "06b450a2326aa879faa2061ff72fe1588b3ab043", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/95fb194cd4dd6ac373a27af2bde2bad5d3f27aba", + "reference": "95fb194cd4dd6ac373a27af2bde2bad5d3f27aba", "shasum": "" }, "require": { - "php": ">=7.2.5", + "php": ">=7.1.3", "symfony/polyfill-ctype": "^1.8", - "symfony/polyfill-mbstring": "^1.3" + "symfony/polyfill-mbstring": "^1.3", + "symfony/polyfill-php72": "^1.8" }, "require-dev": { "psr/container": "^1.0", @@ -6390,7 +6456,7 @@ ], "support": { "issues": "https://github.com/twigphp/Twig/issues", - "source": "https://github.com/twigphp/Twig/tree/v2.14.8" + "source": "https://github.com/twigphp/Twig/tree/v2.14.10" }, "funding": [ { @@ -6402,7 +6468,7 @@ "type": "tidelift" } ], - "time": "2021-11-25T13:38:06+00:00" + "time": "2022-01-03T21:13:26+00:00" }, { "name": "vimeo/psalm", @@ -6562,9 +6628,18 @@ "time": "2015-12-17T08:42:14+00:00" } ], - "aliases": [], + "aliases": [ + { + "package": "utopia-php/framework", + "version": "dev-fix-get-args-after-init", + "alias": "0.19", + "alias_normalized": "0.19.0.0" + } + ], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": { + "utopia-php/framework": 20 + }, "prefer-stable": false, "prefer-lowest": false, "platform": { diff --git a/src/Appwrite/Utopia/Request.php b/src/Appwrite/Utopia/Request.php index 98dfffc0e..d6ad3d8a8 100644 --- a/src/Appwrite/Utopia/Request.php +++ b/src/Appwrite/Utopia/Request.php @@ -28,39 +28,6 @@ class Request extends UtopiaRequest parent::__construct($request); } - /** - * Get Param - * - * Get param by current method name - * - * @param string $key - * @param mixed $default - * @return mixed - */ - public function getParam(string $key, $default = null): mixed - { - switch($this->getMethod()) { - case self::METHOD_GET: - return $this->getQuery($key, $default); - break; - case self::METHOD_POST: - case self::METHOD_PUT: - case self::METHOD_PATCH: - case self::METHOD_DELETE: - return $this->getPayload($key, $default); - break; - default: - return $this->getQuery($key, $default); - } - - if (self::hasFilter() && self::hasRoute()) { - $endpointIdentifier = self::getRoute()->getLabel('sdk.namespace', 'unknown') . '.' . self::getRoute()->getLabel('sdk.method', 'unknown'); - return self::getFilter()->parse($requestParameters, $endpointIdentifier); - } else { - return $requestParameters; - } - } - /** * Get Params * @@ -88,10 +55,10 @@ class Request extends UtopiaRequest if (self::hasFilter() && self::hasRoute()) { $endpointIdentifier = self::getRoute()->getLabel('sdk.namespace', 'unknown') . '.' . self::getRoute()->getLabel('sdk.method', 'unknown'); - return self::getFilter()->parse($requestParameters, $endpointIdentifier); - } else { - return $requestParameters; + $requestParameters = self::getFilter()->parse($requestParameters, $endpointIdentifier); } + + return $requestParameters; } diff --git a/src/Appwrite/Utopia/Request/Filters/V12.php b/src/Appwrite/Utopia/Request/Filters/V12.php index 4f8c4bc9d..b06a56159 100644 --- a/src/Appwrite/Utopia/Request/Filters/V12.php +++ b/src/Appwrite/Utopia/Request/Filters/V12.php @@ -93,9 +93,9 @@ class V12 extends Filter protected function removeParentProperties(array $content): array { - unset($content['parentDocument']); - unset($content['parentProperty']); - unset($content['parentPropertyType']); + if (isset($content['parentDocument'])) unset($content['parentDocument']); + if (isset($content['parentProperty'])) unset($content['parentProperty']); + if (isset($content['parentPropertyType'])) unset($content['parentPropertyType']); return $content; } @@ -103,17 +103,23 @@ class V12 extends Filter protected function convertStatus(array $content): array { - $content['status'] = $content['status'] === 2 ? false : true; + if (isset($content['status'])) { + $content['status'] = $content['status'] === 2 ? false : true; + } return $content; } protected function convertOrder(array $content): array { - $content['orderAttributes'] = [ $content['orderField'] ]; - $content['orderTypes'] = [ $content['orderType'] ]; + if (isset($content['orderField'])) { + $content['orderAttributes'] = [ $content['orderField'] ]; + unset($content['orderField']); + } - unset($content['orderField']); - unset($content['orderType']); + if (isset($content['orderType'])) { + $content['orderTypes'] = [ $content['orderType'] ]; + unset($content['orderType']); + } return $content; } diff --git a/src/Appwrite/Utopia/Response/Filters/V11.php b/src/Appwrite/Utopia/Response/Filters/V11.php index d0e689012..805e2a09c 100644 --- a/src/Appwrite/Utopia/Response/Filters/V11.php +++ b/src/Appwrite/Utopia/Response/Filters/V11.php @@ -16,19 +16,41 @@ class V11 extends Filter switch ($model) { // Update permissions case Response::MODEL_DOCUMENT: + $parsedResponse = $this->parsePermissions($content); + break; + case Response::MODEL_DOCUMENT_LIST: + $parsedResponse = $this->parseDocumentList($content); + break; + case Response::MODEL_FILE: $parsedResponse = $this->parsePermissions($content); break; + case Response::MODEL_FILE_LIST: + $parsedResponse = $this->parseFileList($content); + break; + case Response::MODEL_EXECUTION: $parsedResponse = $this->parseExecutionPermissions($content); break; + case Response::MODEL_EXECUTION_LIST: + $parsedResponse = $this->parseExecutionsList($content); + break; + case Response::MODEL_FUNCTION: $parsedResponse = $this->parseFunctionPermissions($content); break; + case Response::MODEL_FUNCTION_LIST: + $parsedResponse = $this->parseFunctionsList($content); + break; + // Convert status from boolean to int case Response::MODEL_USER: $parsedResponse = $this->parseStatus($content); break; + case Response::MODEL_USER_LIST: + $parsedResponse = $this->parseUserList($content); + break; + // Convert all Health responses back to original case Response::MODEL_HEALTH_STATUS: $parsedResponse = $this->parseHealthStatus($content); @@ -48,32 +70,154 @@ class V11 extends Filter // Complex filters case Response::MODEL_COLLECTION: - $parsedResponse = $this->parsePermissions($content); - $parsedResponse = $this->removeRule($content, 'enabled'); - $parsedResponse = $this->removeRule($content, 'permission'); - $parsedResponse = $this->removeRule($content, 'indexes'); - $parsedResponse = $this->removeRule($content, 'enabled'); - $parsedResponse = $this->addDate($content, 'dateCreated'); - $parsedResponse = $this->addDate($content, 'dateUpdated'); - $parsedResponse = $this->parseAttributes($content); + $parsedResponse = $this->parseCollection($content); + break; + case Response::MODEL_COLLECTION_LIST: + $parsedResponse = $this->parseCollectionList($content); + break; + case Response::MODEL_LOG: - $parsedResponse = $this->removeRule($content, 'userId'); - $parsedResponse = $this->removeRule($content, 'userEmail'); - $parsedResponse = $this->removeRule($content, 'userName'); - $parsedResponse = $this->removeRule($content, 'mode'); - $parsedResponse = $this->removeRule($content, 'sum'); + $parsedResponse = $this->parseLog($content); + break; + case Response::MODEL_LOG_LIST: + $parsedResponse = $this->parseLogList($content); + break; + case Response::MODEL_PROJECT: - $parsedResponse = $this->addTasks($content); - $parsedResponse = $this->parseAuthLimit($content); - $parsedResponse = $this->parseOAuths($content); - $parsedResponse = $this->parseAuthsStatus($content); - $parsedResponse = $this->removeServicesStatus($content); + $parsedResponse = $this->parseProject($content); + break; + case Response::MODEL_PROJECT_LIST: + $parsedResponse = $this->parseProjectList($content); break; } return $parsedResponse; } + protected function parseDocumentList(array $content) + { + $documents = $content['documents']; + $parsedResponse = []; + foreach ($documents as $document) { + $parsedResponse[] = $this->parsePermissions($document); + } + $content['documents'] = $parsedResponse; + return $content; + } + + protected function parseFileList(array $content) + { + $files = $content['files']; + $parsedResponse = []; + foreach ($files as $file) { + $parsedResponse[] = $this->parsePermissions($file); + } + $content['files'] = $parsedResponse; + return $content; + } + + protected function parseExecutionsList(array $content) + { + $executions = $content['executions']; + $parsedResponse = []; + foreach ($executions as $execution) { + $parsedResponse[] = $this->parseExecutionPermissions($execution); + } + $content['executions'] = $parsedResponse; + return $content; + } + + protected function parseFunctionsList(array $content) + { + $functions = $content['functions']; + $parsedResponse = []; + foreach ($functions as $function) { + $parsedResponse[] = $this->parseFunctionPermissions($function); + } + $content['functions'] = $parsedResponse; + return $content; + } + + protected function parseUserList(array $content) + { + $users = $content['users']; + $parsedResponse = []; + foreach ($users as $user) { + $parsedResponse[] = $this->parseStatus($user); + } + $content['users'] = $parsedResponse; + return $content; + } + + protected function parseCollection(array $content) + { + $parsedResponse = []; + $parsedResponse = $this->parsePermissions($content); + $parsedResponse = $this->removeRule($content, 'enabled'); + $parsedResponse = $this->removeRule($content, 'permission'); + $parsedResponse = $this->removeRule($content, 'indexes'); + $parsedResponse = $this->removeRule($content, 'enabled'); + $parsedResponse = $this->addDate($content, 'dateCreated'); + $parsedResponse = $this->addDate($content, 'dateUpdated'); + $parsedResponse = $this->parseAttributes($content); + return $parsedResponse; + } + + protected function parseCollectionList(array $content) + { + $collections = $content['collections']; + $parsedResponse = []; + foreach ($collections as $collection) { + $parsedResponse[] = $this->parseCollection($collection); + } + $content['collections'] = $parsedResponse; + return $content; + } + + protected function parseLog(array $content) + { + $parsedResponse = []; + $parsedResponse = $this->removeRule($content, 'userId'); + $parsedResponse = $this->removeRule($content, 'userEmail'); + $parsedResponse = $this->removeRule($content, 'userName'); + $parsedResponse = $this->removeRule($content, 'mode'); + $parsedResponse = $this->removeRule($content, 'sum'); + return $parsedResponse; + } + + protected function parseLogList(array $content) + { + $logs = $content['logs']; + $parsedResponse = []; + foreach ($logs as $log) { + $parsedResponse[] = $this->parseLog($log); + } + $content['logs'] = $parsedResponse; + return $content; + } + + protected function parseProject(array $content) + { + $parsedResponse = []; + $parsedResponse = $this->addTasks($content); + $parsedResponse = $this->parseAuthLimit($content); + $parsedResponse = $this->parseOAuths($content); + $parsedResponse = $this->parseAuthsStatus($content); + $parsedResponse = $this->removeServicesStatus($content); + return $parsedResponse; + } + + protected function parseProjectList(array $content) + { + $projects = $content['projects']; + $parsedResponse = []; + foreach ($projects as $project) { + $parsedResponse[] = $this->parseProject($project); + } + $content['projects'] = $parsedResponse; + return $content; + } + protected function parseHealthAntivirus(array $content) { if($content['status'] === 'pass') { @@ -237,7 +381,6 @@ class V11 extends Filter $content['$permissions'] = [ 'read' => $content['$read'], 'write' => $content['$write'] ]; unset($content['$read']); unset($content['$write']); - return $content; } From 0a508cecc1cf9b6a404d6fbf38b33afa02e0735c Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Tue, 4 Jan 2022 14:02:51 +0100 Subject: [PATCH 29/37] ci: add travis again --- .travis.yml_tmp => .travis.yml | 1 - 1 file changed, 1 deletion(-) rename .travis.yml_tmp => .travis.yml (99%) diff --git a/.travis.yml_tmp b/.travis.yml similarity index 99% rename from .travis.yml_tmp rename to .travis.yml index 197f30923..069e8b482 100644 --- a/.travis.yml_tmp +++ b/.travis.yml @@ -2,7 +2,6 @@ dist: focal arch: - amd64 - - arm64-graviton2 os: linux From fc41b5f369cf85a1fcb068aa0eef0e5d49201fb5 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Tue, 4 Jan 2022 14:12:40 +0100 Subject: [PATCH 30/37] fix: increase sleep --- .travis.yml | 2 +- tests/e2e/Scopes/Scope.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 069e8b482..9b39b3f33 100644 --- a/.travis.yml +++ b/.travis.yml @@ -53,7 +53,7 @@ install: - docker pull php:8.0-cli-alpine - docker-compose build - docker-compose up -d -- sleep 10 +- sleep 60 script: - docker ps -a diff --git a/tests/e2e/Scopes/Scope.php b/tests/e2e/Scopes/Scope.php index 267d155c6..b5b5e0e77 100644 --- a/tests/e2e/Scopes/Scope.php +++ b/tests/e2e/Scopes/Scope.php @@ -46,7 +46,7 @@ abstract class Scope extends TestCase protected function getLastRequest():array { - sleep(1); + sleep(5); $resquest = json_decode(file_get_contents('http://request-catcher:5000/__last_request__'), true); $resquest['data'] = json_decode($resquest['data'], true); From 4dede67a68ad26f250ae20530ad8370bf4af3ef9 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Tue, 4 Jan 2022 14:25:00 +0100 Subject: [PATCH 31/37] fix travis --- .travis.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9b39b3f33..13d5387b0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -58,11 +58,11 @@ install: script: - docker ps -a # Tests should fail if any container is in exited status -- ALL_UP=`docker ps -aq --filter "status=exited"` -- > - if [[ "$ALL_UP" != "" ]]; then - exit 1 - fi +# - ALL_UP=`docker ps -aq --filter "status=exited"` +# - > +# if [[ "$ALL_UP" != "" ]]; then +# exit 1 +# fi - docker-compose logs appwrite - docker-compose logs appwrite-realtime - docker-compose logs mariadb From 566f6251942b33212c068cf12d3fd216f21300fd Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Tue, 4 Jan 2022 20:27:31 +0545 Subject: [PATCH 32/37] sdk generating check list --- CONTRIBUTING.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1a453a3b5..341ffcd0f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -295,6 +295,16 @@ For generating a new console SDK follow the next steps: 5. Copy `iife/sdk.js` to `appwrite.js` 6. Go back to the root of the project `run npm run build` +## Checklist for Releasing SDKs + +Things to remember when releasing SDKs + +* Update the Changelogs in **docs/sdks** (right now only Dart and Flutter are using these) +* Update **GETTING_STARTED.md** in **docs/sdks** for each SDKs if any changes in the related APIs in there +* Update SDK versions as required on **app/config/platforms.php** +* Generate SDKs using the command `php app/cli.php sdks` and follow the instructions +* Release new tags on GitHub repository for each SDKs + ## Debug Appwrite uses [yasd](https://github.com/swoole/yasd) debugger, which can be made available during build of Appwrite. You can connect to the debugger using VS Code [PHP Debug](https://marketplace.visualstudio.com/items?itemName=felixfbecker.php-debug) extension or if you are in PHP Storm you don't need any plugin. Below are the settings required for remote debugger connection. From eed3d3d51035ccf17705a5d4a10120e30e8b78cb Mon Sep 17 00:00:00 2001 From: Matej Baco Date: Tue, 4 Jan 2022 15:43:01 +0100 Subject: [PATCH 33/37] Removed temp branch change --- composer.json | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/composer.json b/composer.json index e965f9e98..28b1c0f3e 100644 --- a/composer.json +++ b/composer.json @@ -38,7 +38,7 @@ "appwrite/php-clamav": "1.1.*", "appwrite/php-runtimes": "0.6.*", - "utopia-php/framework": "dev-fix-get-args-after-init as 0.19", + "utopia-php/framework": "0.19.5", "utopia-php/logger": "0.1.*", "utopia-php/abuse": "0.7.*", "utopia-php/analytics": "0.2.*", @@ -66,12 +66,6 @@ "adhocore/jwt": "1.1.2", "slickdeals/statsd": "3.1.0" }, - "repositories": [ - { - "type": "git", - "url": "https://github.com/utopia-php/framework" - } - ], "require-dev": { "appwrite/sdk-generator": "0.17.0", "phpunit/phpunit": "9.5.10", From 06e1f6afd110ca87180e987a42f44725d4b5d673 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Tue, 4 Jan 2022 16:19:03 +0100 Subject: [PATCH 34/37] chore: composer update --- composer.lock | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/composer.lock b/composer.lock index 55c39bc51..ed081bd8c 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "d32b727a743b3a8811ec64c56f308694", + "content-hash": "d0df4734e38f660ce979011d70155357", "packages": [ { "name": "adhocore/jwt", @@ -2255,11 +2255,17 @@ }, { "name": "utopia-php/framework", - "version": "dev-fix-get-args-after-init", + "version": "0.19.5", "source": { "type": "git", - "url": "https://github.com/utopia-php/framework", - "reference": "36a42dce039f043288673f0ff46284353543624d" + "url": "https://github.com/utopia-php/framework.git", + "reference": "1c28ba9a5b491cf7c90c535fefee5832c7133623" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/utopia-php/framework/zipball/1c28ba9a5b491cf7c90c535fefee5832c7133623", + "reference": "1c28ba9a5b491cf7c90c535fefee5832c7133623", + "shasum": "" }, "require": { "php": ">=8.0.0" @@ -2274,6 +2280,7 @@ "Utopia\\": "src/" } }, + "notification-url": "https://packagist.org/downloads/", "license": [ "MIT" ], @@ -2289,7 +2296,11 @@ "php", "upf" ], - "time": "2022-01-03T08:38:34+00:00" + "support": { + "issues": "https://github.com/utopia-php/framework/issues", + "source": "https://github.com/utopia-php/framework/tree/0.19.5" + }, + "time": "2022-01-04T14:40:23+00:00" }, { "name": "utopia-php/image", @@ -3069,16 +3080,16 @@ }, { "name": "appwrite/sdk-generator", - "version": "0.16.3", + "version": "0.17.0", "source": { "type": "git", "url": "https://github.com/appwrite/sdk-generator.git", - "reference": "6185cdfe4c4261287240639f3a7fdc05e7ae2337" + "reference": "a68e072170a81532cfb0ff914864d8f074a73a37" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/6185cdfe4c4261287240639f3a7fdc05e7ae2337", - "reference": "6185cdfe4c4261287240639f3a7fdc05e7ae2337", + "url": "https://api.github.com/repos/appwrite/sdk-generator/zipball/a68e072170a81532cfb0ff914864d8f074a73a37", + "reference": "a68e072170a81532cfb0ff914864d8f074a73a37", "shasum": "" }, "require": { @@ -3112,9 +3123,9 @@ "description": "Appwrite PHP library for generating API SDKs for multiple programming languages and platforms", "support": { "issues": "https://github.com/appwrite/sdk-generator/issues", - "source": "https://github.com/appwrite/sdk-generator/tree/0.16.3" + "source": "https://github.com/appwrite/sdk-generator/tree/0.17.0" }, - "time": "2021-12-16T23:56:47+00:00" + "time": "2022-01-04T09:24:44+00:00" }, { "name": "composer/pcre", @@ -6628,18 +6639,9 @@ "time": "2015-12-17T08:42:14+00:00" } ], - "aliases": [ - { - "package": "utopia-php/framework", - "version": "dev-fix-get-args-after-init", - "alias": "0.19", - "alias_normalized": "0.19.0.0" - } - ], + "aliases": [], "minimum-stability": "stable", - "stability-flags": { - "utopia-php/framework": 20 - }, + "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, "platform": { From 972ce959b6278f65db69a2e91a551623d1148f2e Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Tue, 4 Jan 2022 16:48:15 +0100 Subject: [PATCH 35/37] fix: tests --- phpunit.xml | 2 +- tests/e2e/Services/Account/AccountBase.php | 23 +++------------------- 2 files changed, 4 insertions(+), 21 deletions(-) diff --git a/phpunit.xml b/phpunit.xml index 2fbb75e22..ceba1dcbf 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -6,7 +6,7 @@ convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" - stopOnFailure="false" + stopOnFailure="true" > diff --git a/tests/e2e/Services/Account/AccountBase.php b/tests/e2e/Services/Account/AccountBase.php index 8fe3610cf..fcb9e8c8f 100644 --- a/tests/e2e/Services/Account/AccountBase.php +++ b/tests/e2e/Services/Account/AccountBase.php @@ -756,18 +756,7 @@ trait AccountBase * Prefs size exceeded */ - $prefsObject = []; - - $text1Kb = ""; - for($i = 0; $i < 1024; $i++) { - $text1Kb .= "🍰"; - } - - // Add 100 keys, each is 1kB - for($i = 0; $i < 100; $i++) { - $prefsObject["k" . $i] = $text1Kb; - } - // That makes total size minimum of 100kB, plus key size, plus any JSON syntax stuff. Max supported is 64kB, so this should exceed. + $prefsObject = ["longValue" => str_repeat("🍰", 100000)]; $response = $this->client->call(Client::METHOD_PATCH, '/account/prefs', array_merge([ 'origin' => 'http://localhost', @@ -781,14 +770,8 @@ trait AccountBase $this->assertEquals(400, $response['headers']['status-code']); // Now let's test the same thing, but with normal symbol instead of multi-byte cake emoji - $prefsObject = []; - $text1Kb = ""; - for($i = 0; $i < 1024; $i++) { - $text1Kb .= "A"; - } - for($i = 0; $i < 100; $i++) { - $prefsObject["key" . $i] = $text1Kb; - } + $prefsObject = ["longValue" => str_repeat("-", 100000)]; + $response = $this->client->call(Client::METHOD_PATCH, '/account/prefs', array_merge([ 'origin' => 'http://localhost', From 49e9e1b9cd2840798518aed67073f01ac3eb7690 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Tue, 4 Jan 2022 16:50:48 +0100 Subject: [PATCH 36/37] fix: tests --- phpunit.xml | 2 +- tests/e2e/Services/Account/AccountBase.php | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/phpunit.xml b/phpunit.xml index ceba1dcbf..2fbb75e22 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -6,7 +6,7 @@ convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" - stopOnFailure="true" + stopOnFailure="false" > diff --git a/tests/e2e/Services/Account/AccountBase.php b/tests/e2e/Services/Account/AccountBase.php index fcb9e8c8f..2b0da9965 100644 --- a/tests/e2e/Services/Account/AccountBase.php +++ b/tests/e2e/Services/Account/AccountBase.php @@ -755,7 +755,6 @@ trait AccountBase /** * Prefs size exceeded */ - $prefsObject = ["longValue" => str_repeat("🍰", 100000)]; $response = $this->client->call(Client::METHOD_PATCH, '/account/prefs', array_merge([ @@ -772,7 +771,6 @@ trait AccountBase // Now let's test the same thing, but with normal symbol instead of multi-byte cake emoji $prefsObject = ["longValue" => str_repeat("-", 100000)]; - $response = $this->client->call(Client::METHOD_PATCH, '/account/prefs', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', From f23b6cc55e57a4f62a98f01c4792f96c3854c73a Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Tue, 4 Jan 2022 17:02:23 +0100 Subject: [PATCH 37/37] fix: disable github action --- .github/workflows/{tests.yml => tests.yml.tmp} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{tests.yml => tests.yml.tmp} (100%) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml.tmp similarity index 100% rename from .github/workflows/tests.yml rename to .github/workflows/tests.yml.tmp