From 743c214a668b797e212cf2a4f2e54299bc239e27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 24 Jul 2023 15:12:36 +0200 Subject: [PATCH] PR review changes --- app/config/variables.php | 4 +-- app/controllers/api/functions.php | 31 +++++++++---------- app/controllers/api/project.php | 27 +++++----------- app/controllers/api/proxy.php | 4 +-- docker-compose.yml | 18 ----------- docs/references/functions/create-variable.md | 2 +- docs/references/project/create-variable.md | 2 +- src/Appwrite/Utopia/Response/Model/Branch.php | 4 +-- 8 files changed, 30 insertions(+), 62 deletions(-) diff --git a/app/config/variables.php b/app/config/variables.php index 46abf671cb..024f6c332e 100644 --- a/app/config/variables.php +++ b/app/config/variables.php @@ -63,9 +63,9 @@ return [ ], [ 'name' => '_APP_DOMAIN_FUNCTIONS', - 'description' => 'A domain to use for function preview URLs. Setting to "disabled" turns off function preview URLs.', + 'description' => 'A domain to use for function preview URLs. Setting to empty turns off function preview URLs.', 'introduction' => '', - 'default' => 'disabled', + 'default' => '', 'required' => false, 'question' => '', 'filter' => '' diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 9611be1b99..52e0c363d9 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -225,8 +225,8 @@ App::post('/v1/functions') $redeployVcsLogic($request, $function, $project, $installation, $dbForProject, $template); } - $functionsDomain = App::getEnv('_APP_DOMAIN_FUNCTIONS', 'disabled'); - if ($functionsDomain !== 'disabled') { + $functionsDomain = App::getEnv('_APP_DOMAIN_FUNCTIONS', ''); + if (!empty($functionsDomain)) { $ruleId = ID::unique(); $routeSubdomain = ID::unique(); $domain = "{$routeSubdomain}.{$functionsDomain}"; @@ -1814,11 +1814,10 @@ App::get('/v1/functions/:functionId/variables/:variableId') throw new Exception(Exception::FUNCTION_NOT_FOUND); } - $variable = $dbForProject->findOne('variables', [ - Query::equal('$id', [$variableId]), - Query::equal('resourceInternalId', [$function->getInternalId()]), - Query::equal('resourceType', ['function']), - ]); + $variable = $dbForProject->getDocument('variables', $variableId); + if ($variable === false || $variable->isEmpty() || $variable->getAttribute('resourceInternalId') !== $function->getInternalId() || $variable->getAttribute('resourceType') !== 'function') { + throw new Exception(Exception::VARIABLE_NOT_FOUND); + } if ($variable === false || $variable->isEmpty()) { throw new Exception(Exception::VARIABLE_NOT_FOUND); @@ -1856,11 +1855,10 @@ App::put('/v1/functions/:functionId/variables/:variableId') throw new Exception(Exception::FUNCTION_NOT_FOUND); } - $variable = $dbForProject->findOne('variables', [ - Query::equal('$id', [$variableId]), - Query::equal('resourceInternalId', [$function->getInternalId()]), - Query::equal('resourceType', ['function']), - ]); + $variable = $dbForProject->getDocument('variables', $variableId); + if ($variable === false || $variable->isEmpty() || $variable->getAttribute('resourceInternalId') !== $function->getInternalId() || $variable->getAttribute('resourceType') !== 'function') { + throw new Exception(Exception::VARIABLE_NOT_FOUND); + } if ($variable === false || $variable->isEmpty()) { throw new Exception(Exception::VARIABLE_NOT_FOUND); @@ -1916,11 +1914,10 @@ App::delete('/v1/functions/:functionId/variables/:variableId') throw new Exception(Exception::FUNCTION_NOT_FOUND); } - $variable = $dbForProject->findOne('variables', [ - Query::equal('$id', [$variableId]), - Query::equal('resourceInternalId', [$function->getInternalId()]), - Query::equal('resourceType', ['function']), - ]); + $variable = $dbForProject->getDocument('variables', $variableId); + if ($variable === false || $variable->isEmpty() || $variable->getAttribute('resourceInternalId') !== $function->getInternalId() || $variable->getAttribute('resourceType') !== 'function') { + throw new Exception(Exception::VARIABLE_NOT_FOUND); + } if ($variable === false || $variable->isEmpty()) { throw new Exception(Exception::VARIABLE_NOT_FOUND); diff --git a/app/controllers/api/project.php b/app/controllers/api/project.php index 768957859e..bc6a2de01f 100644 --- a/app/controllers/api/project.php +++ b/app/controllers/api/project.php @@ -216,14 +216,11 @@ App::get('/v1/project/variables/:variableId') ->label('sdk.response.model', Response::MODEL_VARIABLE) ->param('variableId', '', new UID(), 'Variable unique ID.', false) ->inject('response') + ->inject('project') ->inject('dbForProject') - ->action(function (string $variableId, Response $response, Database $dbForProject) { - $variable = $dbForProject->findOne('variables', [ - Query::equal('$id', [$variableId]), - Query::equal('resourceType', ['project']), - ]); - - if ($variable === false || $variable->isEmpty()) { + ->action(function (string $variableId, Response $response, Document $project, Database $dbForProject) { + $variable = $dbForProject->getDocument('variables', $variableId); + if ($variable === false || $variable->isEmpty() || $variable->getAttribute('resourceType') !== 'project') { throw new Exception(Exception::VARIABLE_NOT_FOUND); } @@ -248,12 +245,8 @@ App::put('/v1/project/variables/:variableId') ->inject('response') ->inject('dbForProject') ->action(function (string $variableId, string $key, ?string $value, Document $project, Response $response, Database $dbForProject) { - $variable = $dbForProject->findOne('variables', [ - Query::equal('$id', [$variableId]), - Query::equal('resourceType', ['project']), - ]); - - if ($variable === false || $variable->isEmpty()) { + $variable = $dbForProject->getDocument('variables', $variableId); + if ($variable === false || $variable->isEmpty() || $variable->getAttribute('resourceType') !== 'project') { throw new Exception(Exception::VARIABLE_NOT_FOUND); } @@ -296,12 +289,8 @@ App::delete('/v1/project/variables/:variableId') ->inject('response') ->inject('dbForProject') ->action(function (string $variableId, Document $project, Response $response, Database $dbForProject) { - $variable = $dbForProject->findOne('variables', [ - Query::equal('$id', [$variableId]), - Query::equal('resourceType', ['project']), - ]); - - if ($variable === false || $variable->isEmpty()) { + $variable = $dbForProject->getDocument('variables', $variableId); + if ($variable === false || $variable->isEmpty() || $variable->getAttribute('resourceType') !== 'project') { throw new Exception(Exception::VARIABLE_NOT_FOUND); } diff --git a/app/controllers/api/proxy.php b/app/controllers/api/proxy.php index 2d1426545c..be771e7f31 100644 --- a/app/controllers/api/proxy.php +++ b/app/controllers/api/proxy.php @@ -94,8 +94,8 @@ App::post('/v1/proxy/rules') ]); $status = 'created'; - $functionsDomain = App::getEnv('_APP_DOMAIN_FUNCTIONS', 'disabled'); - if ($functionsDomain !== 'disabled' && \str_ends_with($domain->get(), $functionsDomain)) { + $functionsDomain = App::getEnv('_APP_DOMAIN_FUNCTIONS'); + if (!empty($functionsDomain) && \str_ends_with($domain->get(), $functionsDomain)) { $status = 'verified'; } diff --git a/docker-compose.yml b/docker-compose.yml index 9d84623abc..3a87d6844e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -742,24 +742,6 @@ services: - OPR_EXECUTOR_LOGGING_PROVIDER=$_APP_LOGGING_PROVIDER - OPR_EXECUTOR_LOGGING_CONFIG=$_APP_LOGGING_CONFIG - # openruntimes-proxy: - # container_name: openruntimes-proxy - # hostname: proxy - # <<: *x-logging - # image: meldiron/proxy:0.3.0 - # networks: - # - appwrite - # environment: - # - OPR_PROXY_ALGORITHM=random - # - OPR_PROXY_EXECUTORS=exc1,exc2 - # - OPR_PROXY_HEALTHCHECK=enabled - # - OPR_PROXY_HEALTHCHECK_INTERVAL=10000 - # - OPR_PROXY_SECRET=$_APP_EXECUTOR_SECRET - # - OPR_PROXY_EXECUTOR_SECRET=$_APP_EXECUTOR_SECRET - # - OPR_PROXY_ENV=development - # - OPR_PROXY_LOGGING_PROVIDER=$_APP_LOGGING_PROVIDER - # - OPR_PROXY_LOGGING_CONFIG=$_APP_LOGGING_CONFIG - mariadb: image: mariadb:10.7 # fix issues when upgrading using: mysql_upgrade -u root -p container_name: appwrite-mariadb diff --git a/docs/references/functions/create-variable.md b/docs/references/functions/create-variable.md index 35747c42a6..d5c11ff2ab 100644 --- a/docs/references/functions/create-variable.md +++ b/docs/references/functions/create-variable.md @@ -1 +1 @@ -Create a new function variable. These variables can be accessed within function in the `env` object under the request variable. \ No newline at end of file +Create a new function variable. These variables can be accessed within function as environment variable. \ No newline at end of file diff --git a/docs/references/project/create-variable.md b/docs/references/project/create-variable.md index 3a32fc1916..d49135a006 100644 --- a/docs/references/project/create-variable.md +++ b/docs/references/project/create-variable.md @@ -1 +1 @@ -Create a new project variable. These variables can be accessed by every function. \ No newline at end of file +Create a new project variable. \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Model/Branch.php b/src/Appwrite/Utopia/Response/Model/Branch.php index 9ca567965e..9264006ecc 100644 --- a/src/Appwrite/Utopia/Response/Model/Branch.php +++ b/src/Appwrite/Utopia/Response/Model/Branch.php @@ -12,9 +12,9 @@ class Branch extends Model $this ->addRule('name', [ 'type' => self::TYPE_STRING, - 'description' => 'Repository Name.', + 'description' => 'Branch Name.', 'default' => '', - 'example' => 'appwrite', + 'example' => 'main', ]); }