From dbab79fa5420c4493f3d9a4f2a922e4d770fc130 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Sat, 16 May 2020 14:28:26 +0300 Subject: [PATCH 01/16] Added yaml support --- Dockerfile | 2 +- app/controllers/api/projects.php | 2 +- app/init.php | 2 +- composer.json | 1 + src/Appwrite/Response/Response.php | 42 ++++++++++++++++++++++++++++++ 5 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 src/Appwrite/Response/Response.php diff --git a/Dockerfile b/Dockerfile index 25269eae08..3f662f8945 100644 --- a/Dockerfile +++ b/Dockerfile @@ -84,7 +84,7 @@ RUN \ add-apt-repository ppa:certbot/certbot && \ apt-get update && \ apt-get install -y --no-install-recommends --no-install-suggests htop supervisor php$PHP_VERSION php$PHP_VERSION-fpm \ - php$PHP_VERSION-mysqlnd php$PHP_VERSION-curl php$PHP_VERSION-imagick php$PHP_VERSION-mbstring php$PHP_VERSION-dom webp certbot && \ + php$PHP_VERSION-mysqlnd php$PHP_VERSION-curl php$PHP_VERSION-imagick php$PHP_VERSION-mbstring php$PHP_VERSION-dom php$PHP_VERSION-yaml webp certbot && \ # Nginx echo "deb http://nginx.org/packages/mainline/ubuntu/ bionic nginx" >> /etc/apt/sources.list.d/nginx.list && \ wget -q http://nginx.org/keys/nginx_signing.key && \ diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 64689904e6..dc1b8a27c0 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -175,7 +175,7 @@ $utopia->get('/v1/projects/:projectId/usage') ], 'last30' => [ 'start' => DateTime::createFromFormat('U', strtotime('-30 days')), - 'end' => DateTime::createFromFormat('U', strtotime('today')), + 'end' => DateTime::createFromFormat('U', strtotime('tomorrow')), 'group' => '1d', ], 'last90' => [ diff --git a/app/init.php b/app/init.php index 68f45400c8..1d8fd20809 100644 --- a/app/init.php +++ b/app/init.php @@ -13,7 +13,6 @@ if (file_exists(__DIR__.'/../vendor/autoload.php')) { use Utopia\App; use Utopia\Request; -use Utopia\Response; use Utopia\Config\Config; use Utopia\Locale\Locale; use Utopia\Registry\Registry; @@ -23,6 +22,7 @@ use Appwrite\Database\Document; use Appwrite\Database\Validator\Authorization; use Appwrite\Database\Adapter\MySQL as MySQLAdapter; use Appwrite\Database\Adapter\Redis as RedisAdapter; +use Appwrite\Response\Response; use PHPMailer\PHPMailer\PHPMailer; const APP_NAME = 'Appwrite'; diff --git a/composer.json b/composer.json index b82772a6e2..bed5cc94fd 100644 --- a/composer.json +++ b/composer.json @@ -23,6 +23,7 @@ "ext-imagick": "*", "ext-mbstring": "*", "ext-json": "*", + "ext-yaml": "*", "ext-dom": "*", "ext-redis": "*", "ext-pdo": "*", diff --git a/src/Appwrite/Response/Response.php b/src/Appwrite/Response/Response.php new file mode 100644 index 0000000000..06a378ac5e --- /dev/null +++ b/src/Appwrite/Response/Response.php @@ -0,0 +1,42 @@ +setContentType(Response::CONTENT_TYPE_YAML) + ->send(yaml_emit($data, YAML_UTF8_ENCODING)) + ; + } +} From 81ef66a29ade6c47953e6908e57d335a171ba3e9 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Fri, 5 Jun 2020 12:53:06 +0300 Subject: [PATCH 02/16] Work in progress --- CHANGES.md | 5 ++ app/controllers/api/account.php | 27 ++------ src/Appwrite/Response/Response.php | 75 +++++++++++++++++++++- src/Appwrite/Response/Result.php | 46 +++++++++++++ src/Appwrite/Response/Results/File.php | 40 ++++++++++++ src/Appwrite/Response/Results/Files.php | 40 ++++++++++++ src/Appwrite/Response/Results/Health.php | 40 ++++++++++++ src/Appwrite/Response/Results/Logs.php | 37 +++++++++++ src/Appwrite/Response/Results/Prefs.php | 40 ++++++++++++ src/Appwrite/Response/Results/Session.php | 37 +++++++++++ src/Appwrite/Response/Results/Sessions.php | 37 +++++++++++ src/Appwrite/Response/Results/Token.php | 37 +++++++++++ src/Appwrite/Response/Results/User.php | 40 ++++++++++++ 13 files changed, 475 insertions(+), 26 deletions(-) create mode 100644 src/Appwrite/Response/Result.php create mode 100644 src/Appwrite/Response/Results/File.php create mode 100644 src/Appwrite/Response/Results/Files.php create mode 100644 src/Appwrite/Response/Results/Health.php create mode 100644 src/Appwrite/Response/Results/Logs.php create mode 100644 src/Appwrite/Response/Results/Prefs.php create mode 100644 src/Appwrite/Response/Results/Session.php create mode 100644 src/Appwrite/Response/Results/Sessions.php create mode 100644 src/Appwrite/Response/Results/Token.php create mode 100644 src/Appwrite/Response/Results/User.php diff --git a/CHANGES.md b/CHANGES.md index b1a7cc02a1..9fea296376 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -3,6 +3,11 @@ ## Features - New route in Locale API to fetch a list of languages +- New and consistent response format for all API object + new response examples in the docs + - Removed user roles attribute from user object (can be fetched from /v1/teams/memberships) ** + - Removed type attribute from session object response (used only internally) + - ** - might be changed before merging to master + ## Bug Fixes diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 282a5d9a22..dd78f84dab 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -44,7 +44,6 @@ $utopia->init(function() use (&$oauth2Keys) { $oauth2Keys[] = 'oauth2'.ucfirst($key); $oauth2Keys[] = 'oauth2'.ucfirst($key).'AccessToken'; } - }); $utopia->post('/v1/account') @@ -133,17 +132,7 @@ $utopia->post('/v1/account') ->setParam('resource', 'users/'.$user->getId()) ; - $response - ->setStatusCode(Response::STATUS_CODE_CREATED) - ->json(array_merge($user->getArrayCopy(array_merge( - [ - '$id', - 'email', - 'registration', - 'name', - ], - $oauth2Keys - )), ['roles' => Authorization::getRoles()])); + $response->dynamic($user); } ); @@ -232,8 +221,9 @@ $utopia->post('/v1/account/sessions') ->addCookie(Auth::$cookieName.'_legacy', Auth::encodeSession($profile->getId(), $secret), $expiry, '/', COOKIE_DOMAIN, ('https' == $protocol), true, null) ->addCookie(Auth::$cookieName, Auth::encodeSession($profile->getId(), $secret), $expiry, '/', COOKIE_DOMAIN, ('https' == $protocol), true, COOKIE_SAMESITE) ->setStatusCode(Response::STATUS_CODE_CREATED) - ->json($session->getArrayCopy(['$id', 'type', 'expire'])) ; + + $response->dynamic($session); } ); @@ -535,16 +525,7 @@ $utopia->get('/v1/account') ->label('sdk.response', ['200' => 'user']) ->action( function () use ($response, &$user, $oauth2Keys) { - $response->json(array_merge($user->getArrayCopy(array_merge( - [ - '$id', - 'email', - 'emailVerification', - 'registration', - 'name', - ], - $oauth2Keys - )), ['roles' => Authorization::getRoles()])); + $response->dynamic($user); } ); diff --git a/src/Appwrite/Response/Response.php b/src/Appwrite/Response/Response.php index 06a378ac5e..5dbdc537be 100644 --- a/src/Appwrite/Response/Response.php +++ b/src/Appwrite/Response/Response.php @@ -2,20 +2,89 @@ namespace Appwrite\Response; -use Appwrite\Database\Document; use Exception; +use Appwrite\Database\Document; +use Appwrite\Response\Results\User; use Utopia\Response as UtopiaResponse; class Response extends UtopiaResponse { + + public function __construct() + { + $this + ->setResult(new User) + ; + } + /** * HTTP content types */ const CONTENT_TYPE_YAML = 'application/x-yaml'; - public function dynamic(Document $document) + /** + * List of defined output objects + */ + protected $results = []; + + /** + * Set Result Object + * + * @return self + */ + public function setResult(Result $result): self { - # code... + $this->results[$result->getCollection()] = $result; + + return $this; + } + + /** + * Get Result Object + * + * @return Result + */ + public function getResult(string $key): Result + { + if(!isset($this->results[$key])) { + throw new Exception('Undefined result'); + } + + return $this->results[$key]; + } + + /** + * Validate response objects and outputs + * the response according to given format type + */ + public function dynamic(Document $document, $type = self::CONTENT_TYPE_JSON) + { + $collection = $document->getCollection(); + $data = $document->getArrayCopy(); + $result = $this->getResult($collection); + $output = []; + + foreach($result->getRules() as $key => $rule) { + if(!isset($data[$key])) { + throw new Exception('Missing result key'); + } + + $output[$key] = $data[$key]; + } + + switch ($type) { + case self::CONTENT_TYPE_JSON: + return $this->json($output); + break; + + case self::CONTENT_TYPE_YAML: + return $this->yaml($output); + break; + + default: + throw new Exception('Unknown content type'); + break; + } } /** diff --git a/src/Appwrite/Response/Result.php b/src/Appwrite/Response/Result.php new file mode 100644 index 0000000000..adc1c9f7d8 --- /dev/null +++ b/src/Appwrite/Response/Result.php @@ -0,0 +1,46 @@ +rules; + } + + /** + * Add a New Rule + */ + protected function addRule(string $key, string $type, string $description, string $example): self + { + $this->rules[$key] = [ + 'type' => $type, + 'description' => $description, + 'example' => $example, + ]; + + return $this; + } +} \ No newline at end of file diff --git a/src/Appwrite/Response/Results/File.php b/src/Appwrite/Response/Results/File.php new file mode 100644 index 0000000000..246fcdb9c1 --- /dev/null +++ b/src/Appwrite/Response/Results/File.php @@ -0,0 +1,40 @@ +addRule('$id', 'string', 'User ID.', '5e5ea5c16897e') + ->addRule('name', 'string', 'User name.', 'John Doe') + ->addRule('email', 'string', 'User email address.', 'john@appwrite.io') + ->addRule('emailVerification', 'string', 'Email verification status.', true) + ->addRule('registration', 'integer', 'User registration date in UNIX format.', 1583261121) + ; + } + + /** + * Get Name + * + * @return string + */ + public function getName():string + { + return 'User'; + } + + /** + * Get Collection + * + * @return string + */ + public function getCollection():string + { + return Database::SYSTEM_COLLECTION_TOKENS; + } +} \ No newline at end of file diff --git a/src/Appwrite/Response/Results/Files.php b/src/Appwrite/Response/Results/Files.php new file mode 100644 index 0000000000..11454c070a --- /dev/null +++ b/src/Appwrite/Response/Results/Files.php @@ -0,0 +1,40 @@ +addRule('$id', 'string', 'User ID.', '5e5ea5c16897e') + ->addRule('name', 'string', 'User name.', 'John Doe') + ->addRule('email', 'string', 'User email address.', 'john@appwrite.io') + ->addRule('emailVerification', 'string', 'Email verification status.', true) + ->addRule('registration', 'integer', 'User registration date in UNIX format.', 1583261121) + ; + } + + /** + * Get Name + * + * @return string + */ + public function getName():string + { + return 'User'; + } + + /** + * Get Collection + * + * @return string + */ + public function getCollection():string + { + return Database::SYSTEM_COLLECTION_TOKENS; + } +} \ No newline at end of file diff --git a/src/Appwrite/Response/Results/Health.php b/src/Appwrite/Response/Results/Health.php new file mode 100644 index 0000000000..0b5b1c981c --- /dev/null +++ b/src/Appwrite/Response/Results/Health.php @@ -0,0 +1,40 @@ +addRule('$id', 'string', 'User ID.', '5e5ea5c16897e') + ->addRule('name', 'string', 'User name.', 'John Doe') + ->addRule('email', 'string', 'User email address.', 'john@appwrite.io') + ->addRule('emailVerification', 'string', 'Email verification status.', true) + ->addRule('registration', 'integer', 'User registration date in UNIX format.', 1583261121) + ; + } + + /** + * Get Name + * + * @return string + */ + public function getName():string + { + return 'User'; + } + + /** + * Get Collection + * + * @return string + */ + public function getCollection():string + { + return Database::SYSTEM_COLLECTION_TOKENS; + } +} \ No newline at end of file diff --git a/src/Appwrite/Response/Results/Logs.php b/src/Appwrite/Response/Results/Logs.php new file mode 100644 index 0000000000..45599a787f --- /dev/null +++ b/src/Appwrite/Response/Results/Logs.php @@ -0,0 +1,37 @@ +addRule('$id', 'string', 'Session ID.', '5e5ea5c16897e') + ->addRule('expire', 'integer', 'Session expiration date in UNIX format.', 1583261121) + ; + } + + /** + * Get Name + * + * @return string + */ + public function getName():string + { + return 'Session'; + } + + /** + * Get Collection + * + * @return string + */ + public function getCollection():string + { + return Database::SYSTEM_COLLECTION_TOKENS; + } +} \ No newline at end of file diff --git a/src/Appwrite/Response/Results/Prefs.php b/src/Appwrite/Response/Results/Prefs.php new file mode 100644 index 0000000000..2cf28bdd7c --- /dev/null +++ b/src/Appwrite/Response/Results/Prefs.php @@ -0,0 +1,40 @@ +addRule('$id', 'string', 'User ID.', '5e5ea5c16897e') + ->addRule('name', 'string', 'User name.', 'John Doe') + ->addRule('email', 'string', 'User email address.', 'john@appwrite.io') + ->addRule('emailVerification', 'string', 'Email verification status.', true) + ->addRule('registration', 'integer', 'User registration date in UNIX format.', 1583261121) + ; + } + + /** + * Get Name + * + * @return string + */ + public function getName():string + { + return 'User'; + } + + /** + * Get Collection + * + * @return string + */ + public function getCollection():string + { + return Database::SYSTEM_COLLECTION_TOKENS; + } +} \ No newline at end of file diff --git a/src/Appwrite/Response/Results/Session.php b/src/Appwrite/Response/Results/Session.php new file mode 100644 index 0000000000..8cd2577d87 --- /dev/null +++ b/src/Appwrite/Response/Results/Session.php @@ -0,0 +1,37 @@ +addRule('$id', 'string', 'Session ID.', '5e5ea5c16897e') + ->addRule('expire', 'integer', 'Session expiration date in UNIX format.', 1583261121) + ; + } + + /** + * Get Name + * + * @return string + */ + public function getName():string + { + return 'Session'; + } + + /** + * Get Collection + * + * @return string + */ + public function getCollection():string + { + return Database::SYSTEM_COLLECTION_TOKENS; + } +} \ No newline at end of file diff --git a/src/Appwrite/Response/Results/Sessions.php b/src/Appwrite/Response/Results/Sessions.php new file mode 100644 index 0000000000..944aee2f8b --- /dev/null +++ b/src/Appwrite/Response/Results/Sessions.php @@ -0,0 +1,37 @@ +addRule('$id', 'string', 'Session ID.', '5e5ea5c16897e') + ->addRule('expire', 'integer', 'Session expiration date in UNIX format.', 1583261121) + ; + } + + /** + * Get Name + * + * @return string + */ + public function getName():string + { + return 'Session'; + } + + /** + * Get Collection + * + * @return string + */ + public function getCollection():string + { + return Database::SYSTEM_COLLECTION_TOKENS; + } +} \ No newline at end of file diff --git a/src/Appwrite/Response/Results/Token.php b/src/Appwrite/Response/Results/Token.php new file mode 100644 index 0000000000..2b2dd9fc07 --- /dev/null +++ b/src/Appwrite/Response/Results/Token.php @@ -0,0 +1,37 @@ +addRule('$id', 'string', 'Token ID.', '5e5ea5c16897e') + ->addRule('expire', 'integer', 'Token expiration date in UNIX format.', 1583261121) + ; + } + + /** + * Get Name + * + * @return string + */ + public function getName():string + { + return 'User'; + } + + /** + * Get Collection + * + * @return string + */ + public function getCollection():string + { + return Database::SYSTEM_COLLECTION_TOKENS; + } +} \ No newline at end of file diff --git a/src/Appwrite/Response/Results/User.php b/src/Appwrite/Response/Results/User.php new file mode 100644 index 0000000000..8620a18f63 --- /dev/null +++ b/src/Appwrite/Response/Results/User.php @@ -0,0 +1,40 @@ +addRule('$id', 'string', 'User ID.', '5e5ea5c16897e') + ->addRule('name', 'string', 'User name.', 'John Doe') + ->addRule('email', 'string', 'User email address.', 'john@appwrite.io') + ->addRule('emailVerification', 'string', 'Email verification status.', true) + ->addRule('registration', 'integer', 'User registration date in UNIX format.', 1583261121) + ; + } + + /** + * Get Name + * + * @return string + */ + public function getName():string + { + return 'User'; + } + + /** + * Get Collection + * + * @return string + */ + public function getCollection():string + { + return Database::SYSTEM_COLLECTION_TOKENS; + } +} \ No newline at end of file From 9462e1c75bd47640cf88f158a838364ee694a179 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Sun, 21 Jun 2020 16:31:51 +0300 Subject: [PATCH 03/16] Updated structures --- CHANGES.md | 13 ++++--------- Dockerfile | 2 +- src/Appwrite/Response/Response.php | 2 +- src/Appwrite/Response/{Results => Result}/File.php | 2 +- src/Appwrite/Response/{Results => Result}/Files.php | 2 +- .../Response/{Results => Result}/Health.php | 2 +- src/Appwrite/Response/{Results => Result}/Logs.php | 2 +- src/Appwrite/Response/{Results => Result}/Prefs.php | 2 +- .../Response/{Results => Result}/Session.php | 2 +- .../Response/{Results => Result}/Sessions.php | 2 +- src/Appwrite/Response/{Results => Result}/Token.php | 2 +- src/Appwrite/Response/{Results => Result}/User.php | 2 +- 12 files changed, 15 insertions(+), 20 deletions(-) rename src/Appwrite/Response/{Results => Result}/File.php (96%) rename src/Appwrite/Response/{Results => Result}/Files.php (96%) rename src/Appwrite/Response/{Results => Result}/Health.php (96%) rename src/Appwrite/Response/{Results => Result}/Logs.php (94%) rename src/Appwrite/Response/{Results => Result}/Prefs.php (96%) rename src/Appwrite/Response/{Results => Result}/Session.php (94%) rename src/Appwrite/Response/{Results => Result}/Sessions.php (94%) rename src/Appwrite/Response/{Results => Result}/Token.php (94%) rename src/Appwrite/Response/{Results => Result}/User.php (96%) diff --git a/CHANGES.md b/CHANGES.md index 4d255f717e..fb1355bf69 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,14 +2,6 @@ ## Features -<<<<<<< HEAD -- New route in Locale API to fetch a list of languages -- New and consistent response format for all API object + new response examples in the docs - - Removed user roles attribute from user object (can be fetched from /v1/teams/memberships) ** - - Removed type attribute from session object response (used only internally) - - ** - might be changed before merging to master - -======= - New route in Locale API to fetch a list of languages (@TorstenDittmann) - Added Google Fonts to Appwrite for offline availability - Added a new route in the Avatars API to get user initials avatar @@ -26,7 +18,10 @@ - Upgraded Redis Resque queue library to version 1.3.6 - Added container names to docker-compose.yml (@drandell) - Upgraded ClamAV container image to version 1.0.9 ->>>>>>> 0abfa5e5fc2ff2d43a43426fbdaf90b62315c8e9 +- - New and consistent response format for all API object + new response examples in the docs + - Removed user roles attribute from user object (can be fetched from /v1/teams/memberships) ** + - Removed type attribute from session object response (used only internally) + - ** - might be changed before merging to master ## Bug Fixes diff --git a/Dockerfile b/Dockerfile index c4e7e72c82..03b1d5eea4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -94,7 +94,7 @@ RUN \ add-apt-repository ppa:certbot/certbot && \ apt-get update && \ apt-get install -y --no-install-recommends --no-install-suggests php$PHP_VERSION php$PHP_VERSION-fpm \ - php$PHP_VERSION-mysqlnd php$PHP_VERSION-curl php$PHP_VERSION-imagick php$PHP_VERSION-mbstring php$PHP_VERSION-dom webp certbot && \ + php$PHP_VERSION-mysqlnd php$PHP_VERSION-curl php$PHP_VERSION-imagick php$PHP_VERSION-mbstring php$PHP_VERSION-dom php$PHP_VERSION-yaml webp certbot && \ # Nginx wget http://nginx.org/download/nginx-1.19.0.tar.gz && \ tar -xzvf nginx-1.19.0.tar.gz && rm nginx-1.19.0.tar.gz && \ diff --git a/src/Appwrite/Response/Response.php b/src/Appwrite/Response/Response.php index 5dbdc537be..4abb0c36c0 100644 --- a/src/Appwrite/Response/Response.php +++ b/src/Appwrite/Response/Response.php @@ -4,7 +4,7 @@ namespace Appwrite\Response; use Exception; use Appwrite\Database\Document; -use Appwrite\Response\Results\User; +use Appwrite\Response\Result\User; use Utopia\Response as UtopiaResponse; class Response extends UtopiaResponse diff --git a/src/Appwrite/Response/Results/File.php b/src/Appwrite/Response/Result/File.php similarity index 96% rename from src/Appwrite/Response/Results/File.php rename to src/Appwrite/Response/Result/File.php index 246fcdb9c1..229b824799 100644 --- a/src/Appwrite/Response/Results/File.php +++ b/src/Appwrite/Response/Result/File.php @@ -1,6 +1,6 @@ Date: Sun, 21 Jun 2020 17:44:52 +0300 Subject: [PATCH 04/16] Updated definitions --- app/controllers/api/database.php | 2 +- src/Appwrite/Response/Result/{Logs.php => Log.php} | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename src/Appwrite/Response/Result/{Logs.php => Log.php} (96%) diff --git a/app/controllers/api/database.php b/app/controllers/api/database.php index d8ecedab84..9480048e1c 100644 --- a/app/controllers/api/database.php +++ b/app/controllers/api/database.php @@ -357,7 +357,7 @@ $utopia->post('/v1/database/collections/:collectionId/documents') ->param('write', [], function () { return new ArrayList(new Text(64)); }, 'An array of strings with write permissions. By default no user is granted with any write permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions.') ->param('parentDocument', '', function () { return new UID(); }, 'Parent document unique ID. Use when you want your new document to be a child of a parent document.', true) ->param('parentProperty', '', function () { return new Key(); }, 'Parent document property name. Use when you want your new document to be a child of a parent document.', true) - ->param('parentPropertyType', Document::SET_TYPE_ASSIGN, function () { return new WhiteList([Document::SET_TYPE_ASSIGN, Document::SET_TYPE_APPEND, Document::SET_TYPE_PREPEND]); }, 'Parent document property connection type. You can set this value to **assign**, **append** or **prepend**, default value is assign. Use when you want your new document to be a child of a parent document.', true) + ->param('parentPropertyType', Document::SET_TYPE_ASSIGN, function () { return new WhiteList([Document::SET_TYPE_ASSIGN, Document::SET_TYPE_APPEND, Document::SET_TYPE_PREPEND]); }, 'Parent document property connection type. You can set this value to **assign**, **append** or **prepend**, default value is assign. **append** or **prepend** should be set when the parent property is array. Use when you want your new document to be a child of a parent document.', true) ->action( function ($collectionId, $data, $read, $write, $parentDocument, $parentProperty, $parentPropertyType) use ($response, $projectDB, $webhook, $audit) { $data = (\is_string($data)) ? \json_decode($data, true) : $data; // Cast to JSON array diff --git a/src/Appwrite/Response/Result/Logs.php b/src/Appwrite/Response/Result/Log.php similarity index 96% rename from src/Appwrite/Response/Result/Logs.php rename to src/Appwrite/Response/Result/Log.php index 980534c193..c1a22a1d53 100644 --- a/src/Appwrite/Response/Result/Logs.php +++ b/src/Appwrite/Response/Result/Log.php @@ -5,7 +5,7 @@ namespace Appwrite\Response\Result; use Appwrite\Database\Database; use Appwrite\Response\Result; -class Logs extends Result +class Log extends Result { public function __construct() { From 32f917c78ac22544d113d21aac571da90d1c0a2c Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Mon, 22 Jun 2020 15:17:14 +0300 Subject: [PATCH 05/16] Updated namespace structure --- app/controllers/api/account.php | 3 +- app/init.php | 2 +- src/Appwrite/Response/Result/Sessions.php | 37 ------------------- .../{Response => Utopia}/Response.php | 11 +++--- src/Appwrite/{ => Utopia}/Response/Result.php | 2 +- .../{ => Utopia}/Response/Result/File.php | 4 +- .../{ => Utopia}/Response/Result/Files.php | 4 +- .../{ => Utopia}/Response/Result/Health.php | 4 +- .../{ => Utopia}/Response/Result/Log.php | 4 +- .../{ => Utopia}/Response/Result/Prefs.php | 4 +- .../{ => Utopia}/Response/Result/Session.php | 4 +- .../{ => Utopia}/Response/Result/Token.php | 4 +- .../{ => Utopia}/Response/Result/User.php | 6 +-- 13 files changed, 27 insertions(+), 62 deletions(-) delete mode 100644 src/Appwrite/Response/Result/Sessions.php rename src/Appwrite/{Response => Utopia}/Response.php (89%) rename src/Appwrite/{ => Utopia}/Response/Result.php (95%) rename src/Appwrite/{ => Utopia}/Response/Result/File.php (91%) rename src/Appwrite/{ => Utopia}/Response/Result/Files.php (91%) rename src/Appwrite/{ => Utopia}/Response/Result/Health.php (91%) rename src/Appwrite/{ => Utopia}/Response/Result/Log.php (88%) rename src/Appwrite/{ => Utopia}/Response/Result/Prefs.php (91%) rename src/Appwrite/{ => Utopia}/Response/Result/Session.php (88%) rename src/Appwrite/{ => Utopia}/Response/Result/Token.php (88%) rename src/Appwrite/{ => Utopia}/Response/Result/User.php (86%) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index c2c2c642ac..b4d9beb211 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -133,7 +133,8 @@ $utopia->post('/v1/account') ->setParam('resource', 'users/'.$user->getId()) ; - $response->dynamic($user); + $response->json($user->getArrayCopy()); + //$response->dynamic($user); } ); diff --git a/app/init.php b/app/init.php index 69795f56cf..c6f531e083 100644 --- a/app/init.php +++ b/app/init.php @@ -22,7 +22,7 @@ use Appwrite\Database\Document; use Appwrite\Database\Validator\Authorization; use Appwrite\Database\Adapter\MySQL as MySQLAdapter; use Appwrite\Database\Adapter\Redis as RedisAdapter; -use Appwrite\Response\Response; +use Appwrite\Utopia\Response; use PHPMailer\PHPMailer\PHPMailer; const APP_NAME = 'Appwrite'; diff --git a/src/Appwrite/Response/Result/Sessions.php b/src/Appwrite/Response/Result/Sessions.php deleted file mode 100644 index b778655a2d..0000000000 --- a/src/Appwrite/Response/Result/Sessions.php +++ /dev/null @@ -1,37 +0,0 @@ -addRule('$id', 'string', 'Session ID.', '5e5ea5c16897e') - ->addRule('expire', 'integer', 'Session expiration date in UNIX format.', 1583261121) - ; - } - - /** - * Get Name - * - * @return string - */ - public function getName():string - { - return 'Session'; - } - - /** - * Get Collection - * - * @return string - */ - public function getCollection():string - { - return Database::SYSTEM_COLLECTION_TOKENS; - } -} \ No newline at end of file diff --git a/src/Appwrite/Response/Response.php b/src/Appwrite/Utopia/Response.php similarity index 89% rename from src/Appwrite/Response/Response.php rename to src/Appwrite/Utopia/Response.php index 4abb0c36c0..cd25802cc6 100644 --- a/src/Appwrite/Response/Response.php +++ b/src/Appwrite/Utopia/Response.php @@ -1,10 +1,11 @@ setResult(new User) + ->setResult(new User()) ; } @@ -47,7 +48,7 @@ class Response extends UtopiaResponse public function getResult(string $key): Result { if(!isset($this->results[$key])) { - throw new Exception('Undefined result'); + throw new Exception('Undefined result: '.$key); } return $this->results[$key]; @@ -66,7 +67,7 @@ class Response extends UtopiaResponse foreach($result->getRules() as $key => $rule) { if(!isset($data[$key])) { - throw new Exception('Missing result key'); + throw new Exception('Missing response key: ' . $key); } $output[$key] = $data[$key]; diff --git a/src/Appwrite/Response/Result.php b/src/Appwrite/Utopia/Response/Result.php similarity index 95% rename from src/Appwrite/Response/Result.php rename to src/Appwrite/Utopia/Response/Result.php index adc1c9f7d8..a65f7ae101 100644 --- a/src/Appwrite/Response/Result.php +++ b/src/Appwrite/Utopia/Response/Result.php @@ -1,6 +1,6 @@ Date: Mon, 22 Jun 2020 17:33:37 +0300 Subject: [PATCH 06/16] Added support for default values --- src/Appwrite/Utopia/Response.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Appwrite/Utopia/Response.php b/src/Appwrite/Utopia/Response.php index cd25802cc6..34556543b3 100644 --- a/src/Appwrite/Utopia/Response.php +++ b/src/Appwrite/Utopia/Response.php @@ -67,7 +67,12 @@ class Response extends UtopiaResponse foreach($result->getRules() as $key => $rule) { if(!isset($data[$key])) { - throw new Exception('Missing response key: ' . $key); + if(!is_null($rule['default'])) { + $data[$key] = $rule['default']; + } + else { + throw new Exception('Missing response key: ' . $key); + } } $output[$key] = $data[$key]; From 416d767ff050ac4e4115c9e69363aa6b591dc7dd Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Mon, 22 Jun 2020 19:25:01 +0300 Subject: [PATCH 07/16] Changed rule structure --- src/Appwrite/Utopia/Response/Result.php | 14 ++++--- src/Appwrite/Utopia/Response/Result/User.php | 41 +++++++++++++++++--- 2 files changed, 44 insertions(+), 11 deletions(-) diff --git a/src/Appwrite/Utopia/Response/Result.php b/src/Appwrite/Utopia/Response/Result.php index a65f7ae101..facad4dc99 100644 --- a/src/Appwrite/Utopia/Response/Result.php +++ b/src/Appwrite/Utopia/Response/Result.php @@ -33,13 +33,15 @@ abstract class Result /** * Add a New Rule */ - protected function addRule(string $key, string $type, string $description, string $example): self + protected function addRule(string $key, array $options): self { - $this->rules[$key] = [ - 'type' => $type, - 'description' => $description, - 'example' => $example, - ]; + $this->rules[$key] = array_merge([ + 'type' => '', + 'description' => '', + 'default' => null, + 'example' => '', + 'array' => false, + ], $options); return $this; } diff --git a/src/Appwrite/Utopia/Response/Result/User.php b/src/Appwrite/Utopia/Response/Result/User.php index 2baae62ccb..e9afa14d2f 100644 --- a/src/Appwrite/Utopia/Response/Result/User.php +++ b/src/Appwrite/Utopia/Response/Result/User.php @@ -10,11 +10,42 @@ class User extends Result public function __construct() { $this - ->addRule('$id', 'string', 'User ID.', '5e5ea5c16897e') - ->addRule('name', 'string', 'User name.', 'John Doe') - ->addRule('email', 'string', 'User email address.', 'john@appwrite.io') - ->addRule('emailVerification', 'string', 'Email verification status.', true) - ->addRule('registration', 'integer', 'User registration date in UNIX format.', 1583261121) + ->addRule('$id', [ + 'type' => 'string', + 'description' => 'User ID.', + 'example' => '5e5ea5c16897e', + ]) + ->addRule('name', [ + 'type' => 'string', + 'description' => 'User name.', + 'default' => '', + 'example' => 'John Doe', + ]) + ->addRule('email', [ + 'type' => 'string', + 'description' => 'User email address.', + 'default' => '', + 'example' => 'john@appwrite.io', + ]) + ->addRule('emailVerification', [ + 'type' => 'boolean', + 'description' => 'Email verification status.', + 'default' => false, + 'example' => true, + ]) + ->addRule('prefs', [ + 'type' => 'json', + 'description' => 'User preferences as a key-value object', + 'default' => new \stdClass, + 'example' => ['theme' => 'dark', 'timezone' => 'UTC'], + ]) + ->addRule('roles', [ + 'type' => 'string', + 'description' => 'User list of roles', + 'default' => [], + 'example' => [], + 'array' => true, + ]) ; } From e6a4020fd1e78bb93d0a971ee57c9655f7219c67 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Mon, 22 Jun 2020 19:31:59 +0300 Subject: [PATCH 08/16] Set user roles at app init --- app/app.php | 2 ++ app/controllers/api/account.php | 30 +++--------------------------- 2 files changed, 5 insertions(+), 27 deletions(-) diff --git a/app/app.php b/app/app.php index 64a4967568..8aa9905a35 100644 --- a/app/app.php +++ b/app/app.php @@ -180,6 +180,8 @@ $utopia->init(function () use ($utopia, $request, $response, &$user, $project, $ } }, $user->getAttribute('memberships', [])); + $user->setAttribute('roles', Authorization::getRoles()); + // TDOO Check if user is god if (!\in_array($scope, $scopes)) { diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index b4d9beb211..ccb3f50b3e 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -709,15 +709,7 @@ $utopia->patch('/v1/account/name') ->setParam('resource', 'users/'.$user->getId()) ; - $response->json(\array_merge($user->getArrayCopy(\array_merge( - [ - '$id', - 'email', - 'registration', - 'name', - ], - $oauth2Keys - )), ['roles' => Authorization::getRoles()])); + $response->dynamic($user); } ); @@ -751,15 +743,7 @@ $utopia->patch('/v1/account/password') ->setParam('resource', 'users/'.$user->getId()) ; - $response->json(\array_merge($user->getArrayCopy(\array_merge( - [ - '$id', - 'email', - 'registration', - 'name', - ], - $oauth2Keys - )), ['roles' => Authorization::getRoles()])); + $response->dynamic($user); } ); @@ -809,15 +793,7 @@ $utopia->patch('/v1/account/email') ->setParam('resource', 'users/'.$user->getId()) ; - $response->json(\array_merge($user->getArrayCopy(\array_merge( - [ - '$id', - 'email', - 'registration', - 'name', - ], - $oauth2Keys - )), ['roles' => Authorization::getRoles()])); + $response->dynamic($user); } ); From fff951c8fb1fc05c1b0ed165efa9937dcf8b1fc7 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Mon, 22 Jun 2020 21:38:14 +0300 Subject: [PATCH 09/16] Fixed tests --- app/app.php | 2 -- app/controllers/api/account.php | 13 +++++++------ app/controllers/api/users.php | 14 +++----------- 3 files changed, 10 insertions(+), 19 deletions(-) diff --git a/app/app.php b/app/app.php index 8aa9905a35..64a4967568 100644 --- a/app/app.php +++ b/app/app.php @@ -180,8 +180,6 @@ $utopia->init(function () use ($utopia, $request, $response, &$user, $project, $ } }, $user->getAttribute('memberships', [])); - $user->setAttribute('roles', Authorization::getRoles()); - // TDOO Check if user is god if (!\in_array($scope, $scopes)) { diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index ccb3f50b3e..56e1ffe8a0 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -25,6 +25,7 @@ use Appwrite\Database\Validator\Authorization; use Appwrite\Template\Template; use Appwrite\OpenSSL\OpenSSL; use Appwrite\URL\URL as URLParser; +use Appwrite\Utopia\Response as UtopiaResponse; use DeviceDetector\DeviceDetector; use GeoIp2\Database\Reader; use Utopia\Validator\ArrayList; @@ -133,8 +134,8 @@ $utopia->post('/v1/account') ->setParam('resource', 'users/'.$user->getId()) ; - $response->json($user->getArrayCopy()); - //$response->dynamic($user); + $response->setStatusCode(UtopiaResponse::STATUS_CODE_CREATED); + $response->dynamic($user->setAttribute('roles', Authorization::getRoles())); } ); @@ -528,7 +529,7 @@ $utopia->get('/v1/account') ->label('sdk.response', ['200' => 'user']) ->action( function () use ($response, &$user, $oauth2Keys) { - $response->dynamic($user); + $response->dynamic($user->setAttribute('roles', Authorization::getRoles())); } ); @@ -709,7 +710,7 @@ $utopia->patch('/v1/account/name') ->setParam('resource', 'users/'.$user->getId()) ; - $response->dynamic($user); + $response->dynamic($user->setAttribute('roles', Authorization::getRoles())); } ); @@ -743,7 +744,7 @@ $utopia->patch('/v1/account/password') ->setParam('resource', 'users/'.$user->getId()) ; - $response->dynamic($user); + $response->dynamic($user->setAttribute('roles', Authorization::getRoles())); } ); @@ -793,7 +794,7 @@ $utopia->patch('/v1/account/email') ->setParam('resource', 'users/'.$user->getId()) ; - $response->dynamic($user); + $response->dynamic($user->setAttribute('roles', Authorization::getRoles()));$response->dynamic($user); } ); diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index d032cef947..03409bd3c7 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -3,7 +3,6 @@ global $utopia, $response, $projectDB; use Utopia\Exception; -use Utopia\Response; use Utopia\Validator\Assoc; use Utopia\Validator\WhiteList; use Utopia\Validator\Email; @@ -18,6 +17,7 @@ use Appwrite\Auth\Validator\Password; use Appwrite\Database\Database; use Appwrite\Database\Exception\Duplicate; use Appwrite\Database\Validator\UID; +use Appwrite\Utopia\Response; use DeviceDetector\DeviceDetector; use GeoIp2\Database\Reader; @@ -79,16 +79,8 @@ $utopia->post('/v1/users') $oauth2Keys[] = 'oauth2'.\ucfirst($key).'AccessToken'; } - $response - ->setStatusCode(Response::STATUS_CODE_CREATED) - ->json(\array_merge($user->getArrayCopy(\array_merge([ - '$id', - 'status', - 'email', - 'registration', - 'emailVerification', - 'name', - ], $oauth2Keys)), ['roles' => []])); + $response->setStatusCode(Response::STATUS_CODE_CREATED); + $response->dynamic($user); } ); From 29c8954b21ecaabb109a47fb39981e70ad5707b7 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Mon, 22 Jun 2020 22:06:57 +0300 Subject: [PATCH 10/16] Fixed tests --- app/controllers/api/account.php | 2 +- src/Appwrite/Utopia/Response/Result/User.php | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 56e1ffe8a0..1c9279936d 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -226,7 +226,7 @@ $utopia->post('/v1/account/sessions') ->setStatusCode(Response::STATUS_CODE_CREATED) ; - $response->dynamic($session); + $response->json($session->getArrayCopy()); } ); diff --git a/src/Appwrite/Utopia/Response/Result/User.php b/src/Appwrite/Utopia/Response/Result/User.php index e9afa14d2f..4ffa502198 100644 --- a/src/Appwrite/Utopia/Response/Result/User.php +++ b/src/Appwrite/Utopia/Response/Result/User.php @@ -21,6 +21,18 @@ class User extends Result 'default' => '', 'example' => 'John Doe', ]) + ->addRule('registration', [ + 'type' => 'integer', + 'description' => 'User registration date in unix timestamp.', + 'default' => false, + 'example' => true, + ]) + ->addRule('status', [ + 'type' => 'integer', + 'description' => 'User status. 0 for Unavtivated, 1 for active and 2 is blocked.', + 'default' => false, + 'example' => true, + ]) ->addRule('email', [ 'type' => 'string', 'description' => 'User email address.', From 72edaf7ff568034ffdcb232f92d0567d3c431b58 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Tue, 23 Jun 2020 00:55:45 +0300 Subject: [PATCH 11/16] Added locale object --- app/controllers/api/locale.php | 8 ++- src/Appwrite/Utopia/Response.php | 2 + src/Appwrite/Utopia/Response/Result/Files.php | 40 ----------- .../Utopia/Response/Result/Locale.php | 71 +++++++++++++++++++ src/Appwrite/Utopia/Response/Result/Prefs.php | 40 ----------- 5 files changed, 79 insertions(+), 82 deletions(-) delete mode 100644 src/Appwrite/Utopia/Response/Result/Files.php create mode 100644 src/Appwrite/Utopia/Response/Result/Locale.php delete mode 100644 src/Appwrite/Utopia/Response/Result/Prefs.php diff --git a/app/controllers/api/locale.php b/app/controllers/api/locale.php index 30a1211e91..4064eb8bc1 100644 --- a/app/controllers/api/locale.php +++ b/app/controllers/api/locale.php @@ -2,6 +2,7 @@ global $utopia, $register, $request, $response, $projectDB, $project, $user, $audit; +use Appwrite\Database\Document; use Utopia\App; use Utopia\Locale\Locale; use GeoIp2\Database\Reader; @@ -30,6 +31,7 @@ $utopia->get('/v1/locale') $ip = '79.177.241.94'; } + $output['$collection'] = 'locale'; $output['ip'] = $ip; $currency = null; @@ -43,7 +45,7 @@ $utopia->get('/v1/locale') $output['continentCode'] = $record->continent->code; $output['eu'] = (\in_array($record->country->isoCode, $eu)) ? true : false; - foreach ($currencies as $code => $element) { + foreach ($currencies as $element) { if (isset($element['locations']) && isset($element['code']) && \in_array($record->country->isoCode, $element['locations'])) { $currency = $element['code']; } @@ -62,7 +64,9 @@ $utopia->get('/v1/locale') $response ->addHeader('Cache-Control', 'public, max-age='.$time) ->addHeader('Expires', \date('D, d M Y H:i:s', \time() + $time).' GMT') // 45 days cache - ->json($output); + ; + + $response->dynamic(new Document($output)); } ); diff --git a/src/Appwrite/Utopia/Response.php b/src/Appwrite/Utopia/Response.php index 34556543b3..6d52e8f52d 100644 --- a/src/Appwrite/Utopia/Response.php +++ b/src/Appwrite/Utopia/Response.php @@ -6,6 +6,7 @@ use Exception; use Appwrite\Database\Document; use Appwrite\Utopia\Response\Result; use Appwrite\Utopia\Response\Result\User; +use Appwrite\Utopia\Response\Result\Locale; use Utopia\Response as UtopiaResponse; class Response extends UtopiaResponse @@ -15,6 +16,7 @@ class Response extends UtopiaResponse { $this ->setResult(new User()) + ->setResult(new Locale()) ; } diff --git a/src/Appwrite/Utopia/Response/Result/Files.php b/src/Appwrite/Utopia/Response/Result/Files.php deleted file mode 100644 index 516b337a71..0000000000 --- a/src/Appwrite/Utopia/Response/Result/Files.php +++ /dev/null @@ -1,40 +0,0 @@ -addRule('$id', 'string', 'User ID.', '5e5ea5c16897e') - ->addRule('name', 'string', 'User name.', 'John Doe') - ->addRule('email', 'string', 'User email address.', 'john@appwrite.io') - ->addRule('emailVerification', 'string', 'Email verification status.', true) - ->addRule('registration', 'integer', 'User registration date in UNIX format.', 1583261121) - ; - } - - /** - * Get Name - * - * @return string - */ - public function getName():string - { - return 'User'; - } - - /** - * Get Collection - * - * @return string - */ - public function getCollection():string - { - return Database::SYSTEM_COLLECTION_TOKENS; - } -} \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Result/Locale.php b/src/Appwrite/Utopia/Response/Result/Locale.php new file mode 100644 index 0000000000..cfbe2a2a08 --- /dev/null +++ b/src/Appwrite/Utopia/Response/Result/Locale.php @@ -0,0 +1,71 @@ +addRule('ip', [ + 'type' => 'string', + 'description' => 'User IP address.', + 'example' => '127.0.0.1', + ]) + ->addRule('countryCode', [ + 'type' => 'string', + 'description' => 'Country code in [ISO 3166-1](http://en.wikipedia.org/wiki/ISO_3166-1) two-character format', + 'example' => 'US', + ]) + ->addRule('country', [ + 'type' => 'string', + 'description' => 'Country name. This field support localization.', + 'example' => 'United States', + ]) + ->addRule('continentCode', [ + 'type' => 'string', + 'description' => 'Continent code. A two character continent code "AF" for Africa, "AN" for Antarctica, "AS" for Asia, "EU" for Europe, "NA" for North America, "OC" for Oceania, and "SA" for South America.', + 'example' => 'NA', + ]) + ->addRule('continent', [ + 'type' => 'string', + 'description' => 'Continent name. This field support localization.', + 'example' => 'North America', + ]) + ->addRule('eu', [ + 'type' => 'Boolean', + 'description' => 'True if country is part of the Europian Union.', + 'default' => false, + 'example' => false, + ]) + ->addRule('currency', [ + 'type' => 'string', + 'description' => 'ISO 4217 Email verification status.', + 'description' => 'Currency code in [ISO 4217-1](http://en.wikipedia.org/wiki/ISO_4217) three-character format', + 'example' => 'USD', + ]) + ; + } + + /** + * Get Name + * + * @return string + */ + public function getName():string + { + return 'User'; + } + + /** + * Get Collection + * + * @return string + */ + public function getCollection():string + { + return 'locale'; + } +} \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Result/Prefs.php b/src/Appwrite/Utopia/Response/Result/Prefs.php deleted file mode 100644 index 8cfc741fd2..0000000000 --- a/src/Appwrite/Utopia/Response/Result/Prefs.php +++ /dev/null @@ -1,40 +0,0 @@ -addRule('$id', 'string', 'User ID.', '5e5ea5c16897e') - ->addRule('name', 'string', 'User name.', 'John Doe') - ->addRule('email', 'string', 'User email address.', 'john@appwrite.io') - ->addRule('emailVerification', 'string', 'Email verification status.', true) - ->addRule('registration', 'integer', 'User registration date in UNIX format.', 1583261121) - ; - } - - /** - * Get Name - * - * @return string - */ - public function getName():string - { - return 'User'; - } - - /** - * Get Collection - * - * @return string - */ - public function getCollection():string - { - return Database::SYSTEM_COLLECTION_TOKENS; - } -} \ No newline at end of file From b42c99ea94de043fc997da2e08a0e6c4bba9e1c1 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Tue, 23 Jun 2020 13:06:07 +0300 Subject: [PATCH 12/16] Dynamic nginx max request size --- Dockerfile | 3 +-- bin/start | 2 ++ docker-compose.yml | 1 - docker/{nginx.conf => nginx.conf.template} | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) rename docker/{nginx.conf => nginx.conf.template} (98%) diff --git a/Dockerfile b/Dockerfile index c4e7e72c82..8a86a910fc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -130,13 +130,12 @@ RUN \ # Set Upload Limit (default to 100MB) RUN echo "upload_max_filesize = ${_APP_STORAGE_LIMIT}" >> /etc/php/$PHP_VERSION/fpm/conf.d/appwrite.ini RUN echo "post_max_size = ${_APP_STORAGE_LIMIT}" >> /etc/php/$PHP_VERSION/fpm/conf.d/appwrite.ini -RUN echo "env[TESTME] = your-secret-key" >> /etc/php/$PHP_VERSION/fpm/conf.d/appwrite.ini # Add logs file RUN echo "" >> /var/log/appwrite.log # Nginx Configuration (with self-signed ssl certificates) -COPY ./docker/nginx.conf /etc/nginx/nginx.conf +COPY ./docker/nginx.conf.template /etc/nginx/nginx.conf.template COPY ./docker/ssl/cert.pem /etc/nginx/ssl/cert.pem COPY ./docker/ssl/key.pem /etc/nginx/ssl/key.pem diff --git a/bin/start b/bin/start index 931aa101f6..4b0616978e 100755 --- a/bin/start +++ b/bin/start @@ -4,6 +4,8 @@ export PHP_VERSION=$PHP_VERSION chown -Rf www-data.www-data /usr/share/nginx/html/ +sed 's/%_APP_STORAGE_LIMIT%/'$_APP_STORAGE_LIMIT'/g' /etc/nginx/nginx.conf.template > /etc/nginx/nginx.conf + # Function to update the fpm configuration to make the service environment variables available function setEnvironmentVariable() { if [ -z "$2" ]; then diff --git a/docker-compose.yml b/docker-compose.yml index ae7c46ed85..26a2ed016f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -54,7 +54,6 @@ services: - ./docs:/usr/share/nginx/html/docs - ./public:/usr/share/nginx/html/public - ./src:/usr/share/nginx/html/src - - ./docker/nginx.conf:/etc/nginx/nginx.conf depends_on: - mariadb - redis diff --git a/docker/nginx.conf b/docker/nginx.conf.template similarity index 98% rename from docker/nginx.conf rename to docker/nginx.conf.template index 7b62ec9a5b..f0f748d943 100644 --- a/docker/nginx.conf +++ b/docker/nginx.conf.template @@ -16,7 +16,7 @@ http { tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; - client_max_body_size 10M; + client_max_body_size %_APP_STORAGE_LIMIT%; # server_names_hash_bucket_size 64; # server_name_in_redirect off; From 27febf9d555c92fa48c9d8e6ed9c3481e38f7787 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Tue, 23 Jun 2020 13:33:52 +0300 Subject: [PATCH 13/16] Updated change log --- CHANGES.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 233301df9e..0fd4bc1bca 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -18,6 +18,7 @@ - Upgraded Redis Resque queue library to version 1.3.6 - Added container names to docker-compose.yml (@drandell) - Upgraded ClamAV container image to version 1.0.9 +- Optimised function execution by using fully-qualified function calls ## Bug Fixes @@ -31,6 +32,8 @@ - Fixed update form labels and tooltips for Flutter Android apps - Fixed missing custom scopes param for OAuth2 session create API route - Fixed wrong JSON validation when creating and updating database documnets +- Fixed bug where max file size was limited to max of 10MB +- Fixed bug preventing the deletion of the project logo ## Security From 2f1e25fc098a6f34e5a333e986f44e97c0501620 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Tue, 23 Jun 2020 18:01:20 +0300 Subject: [PATCH 14/16] Updated naming conventions --- app/app.php | 9 ++- app/controllers/api/account.php | 15 ++--- app/controllers/api/locale.php | 4 +- app/controllers/api/users.php | 2 +- src/Appwrite/Utopia/Response.php | 66 +++++++++---------- .../Utopia/Response/{Result.php => Model.php} | 4 +- src/Appwrite/Utopia/Response/Model/Error.php | 50 ++++++++++++++ .../Utopia/Response/Model/ErrorDev.php | 43 ++++++++++++ src/Appwrite/Utopia/Response/Model/File.php | 34 ++++++++++ src/Appwrite/Utopia/Response/Model/Health.php | 33 ++++++++++ .../Response/{Result => Model}/Locale.php | 13 ++-- src/Appwrite/Utopia/Response/Model/Log.php | 33 ++++++++++ .../Utopia/Response/Model/Session.php | 33 ++++++++++ src/Appwrite/Utopia/Response/Model/Token.php | 33 ++++++++++ .../Response/{Result => Model}/User.php | 12 ++-- src/Appwrite/Utopia/Response/Result/File.php | 40 ----------- .../Utopia/Response/Result/Health.php | 40 ----------- src/Appwrite/Utopia/Response/Result/Log.php | 37 ----------- .../Utopia/Response/Result/Session.php | 37 ----------- src/Appwrite/Utopia/Response/Result/Token.php | 37 ----------- 20 files changed, 321 insertions(+), 254 deletions(-) rename src/Appwrite/Utopia/Response/{Result.php => Model.php} (90%) create mode 100644 src/Appwrite/Utopia/Response/Model/Error.php create mode 100644 src/Appwrite/Utopia/Response/Model/ErrorDev.php create mode 100644 src/Appwrite/Utopia/Response/Model/File.php create mode 100644 src/Appwrite/Utopia/Response/Model/Health.php rename src/Appwrite/Utopia/Response/{Result => Model}/Locale.php (89%) create mode 100644 src/Appwrite/Utopia/Response/Model/Log.php create mode 100644 src/Appwrite/Utopia/Response/Model/Session.php create mode 100644 src/Appwrite/Utopia/Response/Model/Token.php rename src/Appwrite/Utopia/Response/{Result => Model}/User.php (90%) delete mode 100644 src/Appwrite/Utopia/Response/Result/File.php delete mode 100644 src/Appwrite/Utopia/Response/Result/Health.php delete mode 100644 src/Appwrite/Utopia/Response/Result/Log.php delete mode 100644 src/Appwrite/Utopia/Response/Result/Session.php delete mode 100644 src/Appwrite/Utopia/Response/Result/Token.php diff --git a/app/app.php b/app/app.php index 64a4967568..f6d81fcb6f 100644 --- a/app/app.php +++ b/app/app.php @@ -17,6 +17,7 @@ use Appwrite\Database\Document; use Appwrite\Database\Validator\Authorization; use Appwrite\Event\Event; use Appwrite\Network\Validator\Origin; +use Appwrite\Utopia\Response; /* * Configuration files @@ -270,7 +271,6 @@ $utopia->options(function () use ($request, $response) { }); $utopia->error(function ($error /* @var $error Exception */) use ($request, $response, $utopia, $project) { - $env = Config::getParam('env'); $version = Config::getParam('version'); switch ($error->getCode()) { @@ -292,7 +292,7 @@ $utopia->error(function ($error /* @var $error Exception */) use ($request, $res $_SERVER = []; // Reset before reporting to error log to avoid keys being compromised - $output = ((App::MODE_TYPE_DEVELOPMENT == $env)) ? [ + $output = ($utopia->isDevelopment()) ? [ 'message' => $error->getMessage(), 'code' => $error->getCode(), 'file' => $error->getFile(), @@ -337,9 +337,8 @@ $utopia->error(function ($error /* @var $error Exception */) use ($request, $res $response->send($layout->render()); } - $response - ->json($output) - ; + $response->dynamic(new Document($output), + $utopia->isDevelopment() ? Response::MODEL_ERROR_DEV : Response::MODEL_LOCALE); }); $utopia->get('/manifest.json') diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 1c9279936d..5c84b6a0fc 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -4,7 +4,6 @@ global $utopia, $register, $request, $response, $user, $audit, $webhook, $mail, $project, $projectDB, $clients; use Utopia\Exception; -use Utopia\Response; use Utopia\Config\Config; use Utopia\Validator\Assoc; use Utopia\Validator\Text; @@ -25,7 +24,7 @@ use Appwrite\Database\Validator\Authorization; use Appwrite\Template\Template; use Appwrite\OpenSSL\OpenSSL; use Appwrite\URL\URL as URLParser; -use Appwrite\Utopia\Response as UtopiaResponse; +use Appwrite\Utopia\Response; use DeviceDetector\DeviceDetector; use GeoIp2\Database\Reader; use Utopia\Validator\ArrayList; @@ -134,8 +133,8 @@ $utopia->post('/v1/account') ->setParam('resource', 'users/'.$user->getId()) ; - $response->setStatusCode(UtopiaResponse::STATUS_CODE_CREATED); - $response->dynamic($user->setAttribute('roles', Authorization::getRoles())); + $response->setStatusCode(Response::STATUS_CODE_CREATED); + $response->dynamic($user->setAttribute('roles', Authorization::getRoles()), Response::MODEL_USER); } ); @@ -529,7 +528,7 @@ $utopia->get('/v1/account') ->label('sdk.response', ['200' => 'user']) ->action( function () use ($response, &$user, $oauth2Keys) { - $response->dynamic($user->setAttribute('roles', Authorization::getRoles())); + $response->dynamic($user->setAttribute('roles', Authorization::getRoles()), Response::MODEL_USER); } ); @@ -710,7 +709,7 @@ $utopia->patch('/v1/account/name') ->setParam('resource', 'users/'.$user->getId()) ; - $response->dynamic($user->setAttribute('roles', Authorization::getRoles())); + $response->dynamic($user->setAttribute('roles', Authorization::getRoles()), Response::MODEL_USER); } ); @@ -744,7 +743,7 @@ $utopia->patch('/v1/account/password') ->setParam('resource', 'users/'.$user->getId()) ; - $response->dynamic($user->setAttribute('roles', Authorization::getRoles())); + $response->dynamic($user->setAttribute('roles', Authorization::getRoles()), Response::MODEL_USER); } ); @@ -794,7 +793,7 @@ $utopia->patch('/v1/account/email') ->setParam('resource', 'users/'.$user->getId()) ; - $response->dynamic($user->setAttribute('roles', Authorization::getRoles()));$response->dynamic($user); + $response->dynamic($user->setAttribute('roles', Authorization::getRoles()), Response::MODEL_USER); } ); diff --git a/app/controllers/api/locale.php b/app/controllers/api/locale.php index 4064eb8bc1..c778d9fd4c 100644 --- a/app/controllers/api/locale.php +++ b/app/controllers/api/locale.php @@ -3,6 +3,7 @@ global $utopia, $register, $request, $response, $projectDB, $project, $user, $audit; use Appwrite\Database\Document; +use Appwrite\Utopia\Response; use Utopia\App; use Utopia\Locale\Locale; use GeoIp2\Database\Reader; @@ -31,7 +32,6 @@ $utopia->get('/v1/locale') $ip = '79.177.241.94'; } - $output['$collection'] = 'locale'; $output['ip'] = $ip; $currency = null; @@ -66,7 +66,7 @@ $utopia->get('/v1/locale') ->addHeader('Expires', \date('D, d M Y H:i:s', \time() + $time).' GMT') // 45 days cache ; - $response->dynamic(new Document($output)); + $response->dynamic(new Document($output), Response::MODEL_LOCALE); } ); diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index 03409bd3c7..c607f6b68c 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -80,7 +80,7 @@ $utopia->post('/v1/users') } $response->setStatusCode(Response::STATUS_CODE_CREATED); - $response->dynamic($user); + $response->dynamic($user, Response::MODEL_USER); } ); diff --git a/src/Appwrite/Utopia/Response.php b/src/Appwrite/Utopia/Response.php index 6d52e8f52d..e49fafcda3 100644 --- a/src/Appwrite/Utopia/Response.php +++ b/src/Appwrite/Utopia/Response.php @@ -4,19 +4,27 @@ namespace Appwrite\Utopia; use Exception; use Appwrite\Database\Document; -use Appwrite\Utopia\Response\Result; -use Appwrite\Utopia\Response\Result\User; -use Appwrite\Utopia\Response\Result\Locale; +use Appwrite\Utopia\Response\Model; +use Appwrite\Utopia\Response\Model\Error; +use Appwrite\Utopia\Response\Model\ErrorDev; +use Appwrite\Utopia\Response\Model\User; +use Appwrite\Utopia\Response\Model\Locale; use Utopia\Response as UtopiaResponse; class Response extends UtopiaResponse { + const MODEL_ERROR = 'error'; + const MODEL_ERROR_DEV = 'errorDev'; + const MODEL_USER = 'user'; + const MODEL_LOCALE = 'locale'; public function __construct() { $this - ->setResult(new User()) - ->setResult(new Locale()) + ->setModel(new Error()) + ->setModel(new ErrorDev()) + ->setModel(new User()) + ->setModel(new Locale()) ; } @@ -28,71 +36,63 @@ class Response extends UtopiaResponse /** * List of defined output objects */ - protected $results = []; + protected $models = []; /** - * Set Result Object + * Set Model Object * * @return self */ - public function setResult(Result $result): self + public function setModel(Model $instance): self { - $this->results[$result->getCollection()] = $result; + $this->models[$instance->getType()] = $instance; return $this; } /** - * Get Result Object + * Get Model Object * - * @return Result + * @return Model */ - public function getResult(string $key): Result + public function getModel(string $key): Model { - if(!isset($this->results[$key])) { - throw new Exception('Undefined result: '.$key); + if(!isset($this->models[$key])) { + throw new Exception('Undefined model: '.$key); } - return $this->results[$key]; + return $this->models[$key]; } /** * Validate response objects and outputs * the response according to given format type */ - public function dynamic(Document $document, $type = self::CONTENT_TYPE_JSON) + public function dynamic(Document $document, string $model) { - $collection = $document->getCollection(); $data = $document->getArrayCopy(); - $result = $this->getResult($collection); + $model = $this->getModel($model); $output = []; - foreach($result->getRules() as $key => $rule) { + foreach($model->getRules() as $key => $rule) { if(!isset($data[$key])) { if(!is_null($rule['default'])) { $data[$key] = $rule['default']; } else { - throw new Exception('Missing response key: ' . $key); + throw new Exception('Missing response key: '.$key); } } + if($rule['array'] && !is_array($data[$key])) { + throw new Exception($key.' must be an array of '.$rule['type'].' types'); + } + $output[$key] = $data[$key]; } - switch ($type) { - case self::CONTENT_TYPE_JSON: - return $this->json($output); - break; - - case self::CONTENT_TYPE_YAML: - return $this->yaml($output); - break; - - default: - throw new Exception('Unknown content type'); - break; - } + return $this->json($output); + //return $this->yaml($output); } /** diff --git a/src/Appwrite/Utopia/Response/Result.php b/src/Appwrite/Utopia/Response/Model.php similarity index 90% rename from src/Appwrite/Utopia/Response/Result.php rename to src/Appwrite/Utopia/Response/Model.php index facad4dc99..b50224935b 100644 --- a/src/Appwrite/Utopia/Response/Result.php +++ b/src/Appwrite/Utopia/Response/Model.php @@ -2,7 +2,7 @@ namespace Appwrite\Utopia\Response; -abstract class Result +abstract class Model { protected $rules = []; @@ -18,7 +18,7 @@ abstract class Result * * @return string */ - abstract public function getCollection():string; + abstract public function getType():string; /** * Get Rules diff --git a/src/Appwrite/Utopia/Response/Model/Error.php b/src/Appwrite/Utopia/Response/Model/Error.php new file mode 100644 index 0000000000..95a4764d4a --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/Error.php @@ -0,0 +1,50 @@ +addRule('message', [ + 'type' => 'string', + 'description' => 'Error message.', + 'example' => 'Not found', + ]) + ->addRule('code', [ + 'type' => 'string', + 'description' => 'Error code.', + 'example' => '404', + ]) + ->addRule('version', [ + 'type' => 'string', + 'description' => 'Server version number.', + 'example' => APP_VERSION_STABLE, + ]) + ; + } + + /** + * Get Name + * + * @return string + */ + public function getName():string + { + return 'Error'; + } + + /** + * Get Collection + * + * @return string + */ + public function getType():string + { + return Response::MODEL_ERROR; + } +} \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Model/ErrorDev.php b/src/Appwrite/Utopia/Response/Model/ErrorDev.php new file mode 100644 index 0000000000..7069f2b11b --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/ErrorDev.php @@ -0,0 +1,43 @@ +addRule('file', [ + 'type' => 'string', + 'description' => 'File path.', + 'example' => '/usr/share/nginx/html/vendor/utopia-php/framework/src/App.php', + ]) + ->addRule('line', [ + 'type' => 'integer', + 'description' => 'Line number.', + 'example' => 209, + ]) + // ->addRule('trace', [ + // 'type' => 'string', + // 'description' => 'Error trace.', + // 'example' => [ + // '' + // ], + // ]) + ; + } + + /** + * Get Collection + * + * @return string + */ + public function getType():string + { + return Response::MODEL_ERROR_DEV; + } +} \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Model/File.php b/src/Appwrite/Utopia/Response/Model/File.php new file mode 100644 index 0000000000..875c6f4bd7 --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/File.php @@ -0,0 +1,34 @@ +addRule('$id', 'string', 'User ID.', '5e5ea5c16897e') - ->addRule('name', 'string', 'User name.', 'John Doe') - ->addRule('email', 'string', 'User email address.', 'john@appwrite.io') - ->addRule('emailVerification', 'string', 'Email verification status.', true) - ->addRule('registration', 'integer', 'User registration date in UNIX format.', 1583261121) - ; - } - - /** - * Get Name - * - * @return string - */ - public function getName():string - { - return 'User'; - } - - /** - * Get Collection - * - * @return string - */ - public function getCollection():string - { - return Database::SYSTEM_COLLECTION_TOKENS; - } -} \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Result/Health.php b/src/Appwrite/Utopia/Response/Result/Health.php deleted file mode 100644 index 9d3c7cd64d..0000000000 --- a/src/Appwrite/Utopia/Response/Result/Health.php +++ /dev/null @@ -1,40 +0,0 @@ -addRule('$id', 'string', 'User ID.', '5e5ea5c16897e') - ->addRule('name', 'string', 'User name.', 'John Doe') - ->addRule('email', 'string', 'User email address.', 'john@appwrite.io') - ->addRule('emailVerification', 'string', 'Email verification status.', true) - ->addRule('registration', 'integer', 'User registration date in UNIX format.', 1583261121) - ; - } - - /** - * Get Name - * - * @return string - */ - public function getName():string - { - return 'User'; - } - - /** - * Get Collection - * - * @return string - */ - public function getCollection():string - { - return Database::SYSTEM_COLLECTION_TOKENS; - } -} \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Result/Log.php b/src/Appwrite/Utopia/Response/Result/Log.php deleted file mode 100644 index 784eefa662..0000000000 --- a/src/Appwrite/Utopia/Response/Result/Log.php +++ /dev/null @@ -1,37 +0,0 @@ -addRule('$id', 'string', 'Session ID.', '5e5ea5c16897e') - ->addRule('expire', 'integer', 'Session expiration date in UNIX format.', 1583261121) - ; - } - - /** - * Get Name - * - * @return string - */ - public function getName():string - { - return 'Session'; - } - - /** - * Get Collection - * - * @return string - */ - public function getCollection():string - { - return Database::SYSTEM_COLLECTION_TOKENS; - } -} \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Result/Session.php b/src/Appwrite/Utopia/Response/Result/Session.php deleted file mode 100644 index 93270bb05a..0000000000 --- a/src/Appwrite/Utopia/Response/Result/Session.php +++ /dev/null @@ -1,37 +0,0 @@ -addRule('$id', 'string', 'Session ID.', '5e5ea5c16897e') - ->addRule('expire', 'integer', 'Session expiration date in UNIX format.', 1583261121) - ; - } - - /** - * Get Name - * - * @return string - */ - public function getName():string - { - return 'Session'; - } - - /** - * Get Collection - * - * @return string - */ - public function getCollection():string - { - return Database::SYSTEM_COLLECTION_TOKENS; - } -} \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Result/Token.php b/src/Appwrite/Utopia/Response/Result/Token.php deleted file mode 100644 index 29eb15473a..0000000000 --- a/src/Appwrite/Utopia/Response/Result/Token.php +++ /dev/null @@ -1,37 +0,0 @@ -addRule('$id', 'string', 'Token ID.', '5e5ea5c16897e') - ->addRule('expire', 'integer', 'Token expiration date in UNIX format.', 1583261121) - ; - } - - /** - * Get Name - * - * @return string - */ - public function getName():string - { - return 'User'; - } - - /** - * Get Collection - * - * @return string - */ - public function getCollection():string - { - return Database::SYSTEM_COLLECTION_TOKENS; - } -} \ No newline at end of file From e469cccb61077792ff664d5878867f61dd116438 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Tue, 23 Jun 2020 21:53:24 +0300 Subject: [PATCH 15/16] Added models constants --- src/Appwrite/Utopia/Response.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/Appwrite/Utopia/Response.php b/src/Appwrite/Utopia/Response.php index e49fafcda3..a0dff6e767 100644 --- a/src/Appwrite/Utopia/Response.php +++ b/src/Appwrite/Utopia/Response.php @@ -13,10 +13,34 @@ use Utopia\Response as UtopiaResponse; class Response extends UtopiaResponse { + // General + const MODEL_LOG = 'log'; const MODEL_ERROR = 'error'; const MODEL_ERROR_DEV = 'errorDev'; + + // Users const MODEL_USER = 'user'; + const MODEL_SESSION = 'session'; + const MODEL_TOKEN = 'token'; + + // Database + const MODEL_COLLECTION = 'collection'; + + // Locale const MODEL_LOCALE = 'locale'; + const MODEL_COUNTRY = 'country'; + const MODEL_CONTINENT = 'continent'; + const MODEL_CURRENCY = 'currency'; + const MODEL_LANGUAGE = 'langauge'; + const MODEL_PHONE = 'phone'; + + // Storage + const MODEL_FILE = 'file'; + const MODEL_BUCKET = 'bucket'; + + // Teams + const MODEL_TEAM = 'team'; + const MODEL_MEMBERSHIP = 'membership'; public function __construct() { From 33e9c486c8afd6c66814e9c19aab2962c0295b12 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Tue, 23 Jun 2020 21:53:48 +0300 Subject: [PATCH 16/16] JSON output -> dynamic output --- app/controllers/api/account.php | 2 +- app/controllers/api/database.php | 19 ----------- src/Appwrite/Utopia/Response/Model/Health.php | 33 ------------------- 3 files changed, 1 insertion(+), 53 deletions(-) delete mode 100644 src/Appwrite/Utopia/Response/Model/Health.php diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 5c84b6a0fc..a830827796 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -225,7 +225,7 @@ $utopia->post('/v1/account/sessions') ->setStatusCode(Response::STATUS_CODE_CREATED) ; - $response->json($session->getArrayCopy()); + $response->dynamic($session, Response::MODEL_SESSION); } ); diff --git a/app/controllers/api/database.php b/app/controllers/api/database.php index 9480048e1c..c7f2c63241 100644 --- a/app/controllers/api/database.php +++ b/app/controllers/api/database.php @@ -115,25 +115,6 @@ $utopia->get('/v1/database/collections') ->param('orderType', 'ASC', function () { return new WhiteList(['ASC', 'DESC']); }, 'Order result by ASC or DESC order.', true) ->action( function ($search, $limit, $offset, $orderType) use ($response, $projectDB) { - /*$vl = new Structure($projectDB); - - var_dump($vl->isValid(new Document([ - '$collection' => Database::SYSTEM_COLLECTION_RULES, - '$permissions' => [ - 'read' => ['*'], - 'write' => ['*'], - ], - 'label' => 'Platforms', - 'key' => 'platforms', - 'type' => 'document', - 'default' => [], - 'required' => false, - 'array' => true, - 'options' => [Database::SYSTEM_COLLECTION_PLATFORMS], - ]))); - - var_dump($vl->getDescription());*/ - $results = $projectDB->getCollection([ 'limit' => $limit, 'offset' => $offset, diff --git a/src/Appwrite/Utopia/Response/Model/Health.php b/src/Appwrite/Utopia/Response/Model/Health.php deleted file mode 100644 index 72a9acfdfd..0000000000 --- a/src/Appwrite/Utopia/Response/Model/Health.php +++ /dev/null @@ -1,33 +0,0 @@ -