From 61d7e8634c0e8800f2ef6c566a72863e792aba7b Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Thu, 24 Feb 2022 09:57:56 +0000 Subject: [PATCH 1/6] Update Request Filters --- app/controllers/general.php | 4 +++ src/Appwrite/Utopia/Request/Filters/V13.php | 33 +++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 src/Appwrite/Utopia/Request/Filters/V13.php diff --git a/app/controllers/general.php b/app/controllers/general.php index afe9a5f5e2..7b70804245 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -19,6 +19,7 @@ use Utopia\Database\Document; use Utopia\Database\Query; use Utopia\Database\Validator\Authorization; use Appwrite\Utopia\Request\Filters\V12; +use Appwrite\Utopia\Request\Filters\V13; use Utopia\Validator\Text; Config::setParam('domainVerification', false); @@ -45,6 +46,9 @@ 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.13.0', '<') : + Request::setFilter(new V13()); + break; case version_compare ($requestFormat , '0.12.0', '<') : Request::setFilter(new V12()); break; diff --git a/src/Appwrite/Utopia/Request/Filters/V13.php b/src/Appwrite/Utopia/Request/Filters/V13.php new file mode 100644 index 0000000000..25fd29e764 --- /dev/null +++ b/src/Appwrite/Utopia/Request/Filters/V13.php @@ -0,0 +1,33 @@ +convertStringToNum($content, "min"); + $content = $this->convertStringToNum($content, "max"); + $content = $this->convertStringToNum($content, "default"); + break; + case "database.createIntegerAttribute": + $content = $this->convertStringToNum($content, "min"); + $content = $this->convertStringToNum($content, "max"); + $content = $this->convertStringToNum($content, "default"); + break; + } + + return $content; + } + + private function convertStringToNum($content, $value) { + $content[$value] = (float) $content[$value]; + return $content; + } +} From 8ff280a7514bada0ce01ea5f64c549e4cac9e957 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Fri, 25 Feb 2022 09:46:03 +0000 Subject: [PATCH 2/6] Convert num to string instead of visa versa --- src/Appwrite/Utopia/Request/Filters/V13.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Appwrite/Utopia/Request/Filters/V13.php b/src/Appwrite/Utopia/Request/Filters/V13.php index 25fd29e764..6c44b75918 100644 --- a/src/Appwrite/Utopia/Request/Filters/V13.php +++ b/src/Appwrite/Utopia/Request/Filters/V13.php @@ -12,22 +12,22 @@ class V13 extends Filter switch ($model) { // Replaced Types case "database.createFloatAttribute": - $content = $this->convertStringToNum($content, "min"); - $content = $this->convertStringToNum($content, "max"); - $content = $this->convertStringToNum($content, "default"); + $content = $this->convertNumToString($content, "min"); + $content = $this->convertNumToString($content, "max"); + $content = $this->convertNumToString($content, "default"); break; case "database.createIntegerAttribute": - $content = $this->convertStringToNum($content, "min"); - $content = $this->convertStringToNum($content, "max"); - $content = $this->convertStringToNum($content, "default"); + $content = $this->convertNumToString($content, "min"); + $content = $this->convertNumToString($content, "max"); + $content = $this->convertNumToString($content, "default"); break; } return $content; } - private function convertStringToNum($content, $value) { - $content[$value] = (float) $content[$value]; + private function convertNumToString($content, $value) { + $content[$value] = (string) $content[$value]; return $content; } } From a88be70e5e076b486ad094b3d37a07b43151b697 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Fri, 25 Feb 2022 10:37:13 +0000 Subject: [PATCH 3/6] Update V13.php --- src/Appwrite/Utopia/Request/Filters/V13.php | 23 ++++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/Appwrite/Utopia/Request/Filters/V13.php b/src/Appwrite/Utopia/Request/Filters/V13.php index 6c44b75918..a70f0eda54 100644 --- a/src/Appwrite/Utopia/Request/Filters/V13.php +++ b/src/Appwrite/Utopia/Request/Filters/V13.php @@ -12,22 +12,29 @@ class V13 extends Filter switch ($model) { // Replaced Types case "database.createFloatAttribute": - $content = $this->convertNumToString($content, "min"); - $content = $this->convertNumToString($content, "max"); - $content = $this->convertNumToString($content, "default"); + $content = $this->converStringToNum($content, "min"); + $content = $this->converStringToNum($content, "max"); + $content = $this->converStringToNum($content, "default"); break; case "database.createIntegerAttribute": - $content = $this->convertNumToString($content, "min"); - $content = $this->convertNumToString($content, "max"); - $content = $this->convertNumToString($content, "default"); + $content = $this->converStringToNum($content, "min"); + $content = $this->converStringToNum($content, "max"); + $content = $this->converStringToNum($content, "default"); break; + case "functions.createExecution": + $content = $this->convertExecution($content); } return $content; } - private function convertNumToString($content, $value) { - $content[$value] = (string) $content[$value]; + private function converStringToNum($content, $value) { + $content[$value] = (int) $content[$value]; + return $content; + } + + private function convertExecution($content) { + $content['async'] = true; return $content; } } From 9cc67066ce6c2bf4aa192aaaed85af4420e4805b Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Mon, 28 Feb 2022 20:55:18 +0000 Subject: [PATCH 4/6] address Comments --- app/controllers/general.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/controllers/general.php b/app/controllers/general.php index efab455eb3..45c45e80ee 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -13,13 +13,13 @@ use Utopia\Config\Config; use Utopia\Domains\Domain; use Appwrite\Auth\Auth; use Appwrite\Network\Validator\Origin; -use Appwrite\Utopia\Response\Filters\V11; +use Appwrite\Utopia\Response\Filters\V11 as ResponseV11; use Utopia\CLI\Console; use Utopia\Database\Document; use Utopia\Database\Query; use Utopia\Database\Validator\Authorization; -use Appwrite\Utopia\Request\Filters\V12; -use Appwrite\Utopia\Request\Filters\V13; +use Appwrite\Utopia\Request\Filters\V12 as RequestV12; +use Appwrite\Utopia\Request\Filters\V13 as RequestV13; use Utopia\Validator\Text; Config::setParam('domainVerification', false); @@ -47,10 +47,10 @@ App::init(function ($utopia, $request, $response, $console, $project, $dbForCons if ($requestFormat) { switch($requestFormat) { case version_compare ($requestFormat , '0.13.0', '<') : - Request::setFilter(new V13()); + Request::setFilter(new RequestV13()); break; case version_compare ($requestFormat , '0.12.0', '<') : - Request::setFilter(new V12()); + Request::setFilter(new RequestV12()); break; default: Request::setFilter(null); @@ -162,7 +162,7 @@ App::init(function ($utopia, $request, $response, $console, $project, $dbForCons if ($responseFormat) { switch($responseFormat) { case version_compare ($responseFormat , '0.11.0', '<=') : - Response::setFilter(new V11()); + Response::setFilter(new ResponseV11()); break; default: Response::setFilter(null); From 8406b973f5bc3bc6115c0d4e28d1ddae9536a2c3 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Tue, 1 Mar 2022 16:52:38 +0400 Subject: [PATCH 5/6] feat: update order of request filters --- app/controllers/general.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/general.php b/app/controllers/general.php index 45c45e80ee..b77857c04b 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -46,12 +46,12 @@ 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.13.0', '<') : - Request::setFilter(new RequestV13()); - break; case version_compare ($requestFormat , '0.12.0', '<') : Request::setFilter(new RequestV12()); break; + case version_compare ($requestFormat , '0.13.0', '<') : + Request::setFilter(new RequestV13()); + break; default: Request::setFilter(null); } From 2cf9364498d6c029631df8f71b339bdccd10dbd3 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Tue, 1 Mar 2022 21:53:28 +0400 Subject: [PATCH 6/6] feat: fix throw --- app/controllers/api/functions.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index d2b273aa41..a8bf793532 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -999,7 +999,6 @@ App::get('/v1/functions/:functionId/executions') $function = Authorization::skip(fn() => $dbForProject->getDocument('functions', $functionId)); - throw new Exception('Function not found', 404, Exception::FUNCTION_NOT_FOUND); if ($function->isEmpty()) { throw new Exception('Function not found', 404, Exception::FUNCTION_NOT_FOUND); }