From 6392ceef55ce6d7cd403755b96dce64cd35a6de0 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Tue, 27 Oct 2020 21:44:15 +0200 Subject: [PATCH 01/40] Updated src folder --- src/Appwrite/Auth/OAuth2/Box.php | 11 +++++++++-- src/Appwrite/Auth/OAuth2/Github.php | 2 +- src/Appwrite/Database/Adapter/MySQL.php | 2 +- src/Appwrite/Database/Database.php | 8 ++++---- src/Appwrite/Database/Validator/Structure.php | 2 +- src/Appwrite/Database/Validator/UID.php | 2 +- src/Appwrite/Docker/Compose.php | 2 +- src/Appwrite/Docker/Env.php | 5 ++--- src/Appwrite/Extend/PDOStatement.php | 6 +++--- src/Appwrite/Network/Validator/CNAME.php | 2 +- src/Appwrite/Network/Validator/Domain.php | 4 ++-- src/Appwrite/Network/Validator/Origin.php | 2 +- src/Appwrite/Storage/Validator/FileName.php | 2 +- src/Appwrite/Storage/Validator/FileSize.php | 2 +- src/Appwrite/Storage/Validator/Upload.php | 2 +- src/Appwrite/Swoole/Files.php | 14 +++++++------- src/Appwrite/Swoole/Request.php | 8 ++++---- src/Appwrite/Swoole/Response.php | 9 ++++----- src/Appwrite/Task/Validator/Cron.php | 2 +- src/Appwrite/Utopia/Response.php | 19 +++++++++---------- src/Appwrite/Utopia/Response/Model/File.php | 1 - 21 files changed, 55 insertions(+), 52 deletions(-) diff --git a/src/Appwrite/Auth/OAuth2/Box.php b/src/Appwrite/Auth/OAuth2/Box.php index 48e2a387a..7fbcf5954 100644 --- a/src/Appwrite/Auth/OAuth2/Box.php +++ b/src/Appwrite/Auth/OAuth2/Box.php @@ -9,9 +9,14 @@ use Appwrite\Auth\OAuth2; class Box extends OAuth2 { - + /** + * @var string + */ private $endpoint = 'https://account.box.com/api/oauth2/'; + /** + * @var string + */ private $resourceEndpoint = 'https://api.box.com/2.0/'; /** @@ -19,6 +24,9 @@ class Box extends OAuth2 */ protected $user = []; + /** + * @var array + */ protected $scopes = [ 'manage_app_users', ]; @@ -148,5 +156,4 @@ class Box extends OAuth2 return $this->user; } - } \ No newline at end of file diff --git a/src/Appwrite/Auth/OAuth2/Github.php b/src/Appwrite/Auth/OAuth2/Github.php index 3ab8e51a8..0f86b8910 100644 --- a/src/Appwrite/Auth/OAuth2/Github.php +++ b/src/Appwrite/Auth/OAuth2/Github.php @@ -125,7 +125,7 @@ class Github extends OAuth2 * @return array */ protected function getUser(string $accessToken) - { + { if (empty($this->user)) { $this->user = \json_decode($this->request('GET', 'https://api.github.com/user', ['Authorization: token '.\urlencode($accessToken)]), true); } diff --git a/src/Appwrite/Database/Adapter/MySQL.php b/src/Appwrite/Database/Adapter/MySQL.php index d361433df..b61e473c4 100644 --- a/src/Appwrite/Database/Adapter/MySQL.php +++ b/src/Appwrite/Database/Adapter/MySQL.php @@ -232,7 +232,7 @@ class MySQL extends Adapter // Handle array of relations if (self::DATA_TYPE_ARRAY === $type) { - if(!is_array($value)) { // Property should be of type array, if not = skip + if (!is_array($value)) { // Property should be of type array, if not = skip continue; } diff --git a/src/Appwrite/Database/Database.php b/src/Appwrite/Database/Database.php index 70725a89d..c0d8deb84 100644 --- a/src/Appwrite/Database/Database.php +++ b/src/Appwrite/Database/Database.php @@ -452,7 +452,7 @@ class Database $filters = $rule->getAttribute('filter', null); $value = $document->getAttribute($key, null); - if(($value !== null) && is_array($filters)) { + if (($value !== null) && is_array($filters)) { foreach ($filters as $filter) { $value = $this->encodeAttribute($filter, $value); $document->setAttribute($key, $value); @@ -473,7 +473,7 @@ class Database $filters = $rule->getAttribute('filter', null); $value = $document->getAttribute($key, null); - if(($value !== null) && is_array($filters)) { + if (($value !== null) && is_array($filters)) { foreach (array_reverse($filters) as $filter) { $value = $this->decodeAttribute($filter, $value); $document->setAttribute($key, $value); @@ -492,7 +492,7 @@ class Database */ static protected function encodeAttribute(string $name, $value) { - if(!isset(self::$filters[$name])) { + if (!isset(self::$filters[$name])) { throw new Exception('Filter not found'); } @@ -513,7 +513,7 @@ class Database */ static protected function decodeAttribute(string $name, $value) { - if(!isset(self::$filters[$name])) { + if (!isset(self::$filters[$name])) { throw new Exception('Filter not found'); } diff --git a/src/Appwrite/Database/Validator/Structure.php b/src/Appwrite/Database/Validator/Structure.php index 34d885039..5aea6c1b3 100644 --- a/src/Appwrite/Database/Validator/Structure.php +++ b/src/Appwrite/Database/Validator/Structure.php @@ -157,7 +157,7 @@ class Structure extends Validator foreach ($array as $key => $value) { $rule = $collection->search('key', $key, $rules); - if(!$rule) { + if (!$rule) { continue; } diff --git a/src/Appwrite/Database/Validator/UID.php b/src/Appwrite/Database/Validator/UID.php index a68c3da35..4cc3f1d5b 100644 --- a/src/Appwrite/Database/Validator/UID.php +++ b/src/Appwrite/Database/Validator/UID.php @@ -37,7 +37,7 @@ class UID extends Validator return false; } - if(mb_strlen($value) > 32) { + if (mb_strlen($value) > 32) { return false; } diff --git a/src/Appwrite/Docker/Compose.php b/src/Appwrite/Docker/Compose.php index e9fb90687..e5c6a8171 100644 --- a/src/Appwrite/Docker/Compose.php +++ b/src/Appwrite/Docker/Compose.php @@ -48,7 +48,7 @@ class Compose */ public function getService(string $name): Service { - if(!isset($this->compose['services'][$name])) { + if (!isset($this->compose['services'][$name])) { throw new Exception('Service not found'); } diff --git a/src/Appwrite/Docker/Env.php b/src/Appwrite/Docker/Env.php index f97f68b00..3076eb643 100644 --- a/src/Appwrite/Docker/Env.php +++ b/src/Appwrite/Docker/Env.php @@ -16,15 +16,14 @@ class Env */ public function __construct(string $data) { - $data = explode("\n", $data); - foreach($data as &$row) { + foreach ($data as &$row) { $row = explode('=', $row); $key = (isset($row[0])) ? trim($row[0]) : null; $value = (isset($row[1])) ? trim($row[1]) : null; - if($key) { + if ($key) { $this->vars[$key] = $value; } } diff --git a/src/Appwrite/Extend/PDOStatement.php b/src/Appwrite/Extend/PDOStatement.php index a752f9f27..412607d9e 100644 --- a/src/Appwrite/Extend/PDOStatement.php +++ b/src/Appwrite/Extend/PDOStatement.php @@ -73,15 +73,15 @@ class PDOStatement extends PDOStatementNative $this->pdo = $this->pdo->reconnect(); $this->PDOStatement = $this->pdo->prepare($this->PDOStatement->queryString, []); - foreach($this->values as $key => $set) { + foreach ($this->values as $key => $set) { $this->PDOStatement->bindValue($key, $set['value'], $set['data_type']); } - foreach($this->params as $key => $set) { + foreach ($this->params as $key => $set) { $this->PDOStatement->bindParam($key, $set['variable'], $set['data_type'], $set['length'], $set['driver_options']); } - foreach($this->columns as $key => $set) { + foreach ($this->columns as $key => $set) { $this->PDOStatement->bindColumn($key, $set['param'], $set['type'], $set['maxlen'], $set['driverdata']); } diff --git a/src/Appwrite/Network/Validator/CNAME.php b/src/Appwrite/Network/Validator/CNAME.php index 1d299e48c..c2adfdddd 100644 --- a/src/Appwrite/Network/Validator/CNAME.php +++ b/src/Appwrite/Network/Validator/CNAME.php @@ -36,7 +36,7 @@ class CNAME extends Validator */ public function isValid($domain) { - if(!is_string($domain)) { + if (!is_string($domain)) { return false; } diff --git a/src/Appwrite/Network/Validator/Domain.php b/src/Appwrite/Network/Validator/Domain.php index 848e338d6..0d5def06c 100644 --- a/src/Appwrite/Network/Validator/Domain.php +++ b/src/Appwrite/Network/Validator/Domain.php @@ -37,11 +37,11 @@ class Domain extends Validator */ public function isValid($value) { - if(empty($value)) { + if (empty($value)) { return false; } - if(!is_string($value)) { + if (!is_string($value)) { return false; } diff --git a/src/Appwrite/Network/Validator/Origin.php b/src/Appwrite/Network/Validator/Origin.php index 62f1608af..c0afb1f56 100644 --- a/src/Appwrite/Network/Validator/Origin.php +++ b/src/Appwrite/Network/Validator/Origin.php @@ -99,7 +99,7 @@ class Origin extends Validator */ public function isValid($origin) { - if(!is_string($origin)) { + if (!is_string($origin)) { return false; } diff --git a/src/Appwrite/Storage/Validator/FileName.php b/src/Appwrite/Storage/Validator/FileName.php index a7d2e43a7..acb76fdab 100644 --- a/src/Appwrite/Storage/Validator/FileName.php +++ b/src/Appwrite/Storage/Validator/FileName.php @@ -24,7 +24,7 @@ class FileName extends Validator return false; } - if(!is_string($name)) { + if (!is_string($name)) { return false; } diff --git a/src/Appwrite/Storage/Validator/FileSize.php b/src/Appwrite/Storage/Validator/FileSize.php index ab5d36144..1bbf74918 100644 --- a/src/Appwrite/Storage/Validator/FileSize.php +++ b/src/Appwrite/Storage/Validator/FileSize.php @@ -35,7 +35,7 @@ class FileSize extends Validator */ public function isValid($fileSize) { - if(!is_int($fileSize)) { + if (!is_int($fileSize)) { return false; } diff --git a/src/Appwrite/Storage/Validator/Upload.php b/src/Appwrite/Storage/Validator/Upload.php index 023946442..38296e8d0 100644 --- a/src/Appwrite/Storage/Validator/Upload.php +++ b/src/Appwrite/Storage/Validator/Upload.php @@ -20,7 +20,7 @@ class Upload extends Validator */ public function isValid($path) { - if(!is_string($path)) { + if (!is_string($path)) { return false; } diff --git a/src/Appwrite/Swoole/Files.php b/src/Appwrite/Swoole/Files.php index 7971beba2..8c8e52ea3 100644 --- a/src/Appwrite/Swoole/Files.php +++ b/src/Appwrite/Swoole/Files.php @@ -51,7 +51,7 @@ class Files */ public static function removeMimeType(string $mimeType): void { - if(isset(self::$mimeTypes[$mimeType])) { + if (isset(self::$mimeTypes[$mimeType])) { unset(self::$mimeTypes[$mimeType]); } } @@ -85,7 +85,7 @@ class Files */ public static function load(string $directory, string $root = null): void { - if(!is_readable($directory)) { + if (!is_readable($directory)) { throw new Exception('Failed to load directory: '.$directory); } @@ -106,7 +106,7 @@ class Files continue; } - if(substr($path, 0, 1) === '.') { + if (substr($path, 0, 1) === '.') { continue; } @@ -127,7 +127,7 @@ class Files closedir($handle); - if($directory === $root) { + if ($directory === $root) { echo '[Static Files] Loadded '.self::$count.' files'.PHP_EOL; } } @@ -139,7 +139,7 @@ class Files */ public static function isFileLoaded(string $uri): bool { - if(!array_key_exists($uri, self::$loaded)) { + if (!array_key_exists($uri, self::$loaded)) { return false; } @@ -153,7 +153,7 @@ class Files */ public static function getFileContents(string $uri): string { - if(!array_key_exists($uri, self::$loaded)) { + if (!array_key_exists($uri, self::$loaded)) { throw new Exception('File not found or not loaded: '.$uri); } @@ -167,7 +167,7 @@ class Files */ public static function getFileMimeType(string $uri): string { - if(!array_key_exists($uri, self::$loaded)) { + if (!array_key_exists($uri, self::$loaded)) { throw new Exception('File not found or not loaded: '.$uri); } diff --git a/src/Appwrite/Swoole/Request.php b/src/Appwrite/Swoole/Request.php index 453592468..d3b04809e 100644 --- a/src/Appwrite/Swoole/Request.php +++ b/src/Appwrite/Swoole/Request.php @@ -33,7 +33,7 @@ class Request extends UtopiaRequest */ public function getParam(string $key, $default = null) { - switch($this->getMethod()) { + switch ($this->getMethod()) { case self::METHOD_GET: return $this->getQuery($key, $default); break; @@ -57,7 +57,7 @@ class Request extends UtopiaRequest */ public function getParams(): array { - switch($this->getMethod()) { + switch ($this->getMethod()) { case self::METHOD_GET: return (!empty($this->swoole->get)) ? $this->swoole->get : []; break; @@ -143,7 +143,7 @@ class Request extends UtopiaRequest { $protocol = $this->getHeader('x-forwarded-proto', $this->getServer('server_protocol', 'https')); - if($protocol === 'HTTP/1.1') { + if ($protocol === 'HTTP/1.1') { return 'http'; } @@ -317,7 +317,7 @@ class Request extends UtopiaRequest break; } - if(empty($this->payload)) { // Make sure we return same data type even if json payload is empty or failed + if (empty($this->payload)) { // Make sure we return same data type even if json payload is empty or failed $this->payload = []; } } diff --git a/src/Appwrite/Swoole/Response.php b/src/Appwrite/Swoole/Response.php index 766101146..98f481ee8 100644 --- a/src/Appwrite/Swoole/Response.php +++ b/src/Appwrite/Swoole/Response.php @@ -37,7 +37,7 @@ class Response extends UtopiaResponse * Response constructor. */ public function __construct(SwooleResponse $response) - { + { $this->swoole = $response; parent::__construct(\microtime(true)); } @@ -54,7 +54,7 @@ class Response extends UtopiaResponse */ public function send(string $body = '', int $exit = null): void { - if(!$this->disablePayload) { + if (!$this->disablePayload) { $this->addHeader('X-Debug-Speed', (string)(microtime(true) - $this->startTime)); $this @@ -67,13 +67,12 @@ class Response extends UtopiaResponse $this->size = $this->size + strlen(implode("\n", $this->headers)) + $length; - if(array_key_exists( + if (array_key_exists( $this->contentType, $this->compressed ) && ($length <= $chunk)) { // Dont compress with GZIP / Brotli if header is not listed and size is bigger than 2mb $this->swoole->end($body); - } - else { + } else { for ($i=0; $i < ceil($length / $chunk); $i++) { $this->swoole->write(substr($body, ($i * $chunk), min((($i * $chunk) + $chunk), $length))); } diff --git a/src/Appwrite/Task/Validator/Cron.php b/src/Appwrite/Task/Validator/Cron.php index 68c7c4b0f..18f427ee7 100644 --- a/src/Appwrite/Task/Validator/Cron.php +++ b/src/Appwrite/Task/Validator/Cron.php @@ -30,7 +30,7 @@ class Cron extends Validator */ public function isValid($value) { - if(empty($value)) { + if (empty($value)) { return true; } diff --git a/src/Appwrite/Utopia/Response.php b/src/Appwrite/Utopia/Response.php index b2a9f5b5d..2bcf979c3 100644 --- a/src/Appwrite/Utopia/Response.php +++ b/src/Appwrite/Utopia/Response.php @@ -101,7 +101,7 @@ class Response extends UtopiaResponse */ public function getModel(string $key): Model { - if(!isset($this->models[$key])) { + if (!isset($this->models[$key])) { throw new Exception('Undefined model: '.$key); } @@ -126,23 +126,22 @@ class Response extends UtopiaResponse $model = $this->getModel($model); $output = []; - foreach($model->getRules() as $key => $rule) { - if(!$document->isSet($key)) { - if(!is_null($rule['default'])) { + foreach ($model->getRules() as $key => $rule) { + if (!$document->isSet($key)) { + if (!is_null($rule['default'])) { $document->setAttribute($key, $rule['default']); - } - else { + } else { throw new Exception('Missing response key: '.$key); } } - if($rule['array']) { - if(!is_array($data[$key])) { + if ($rule['array']) { + if (!is_array($data[$key])) { throw new Exception($key.' must be an array of '.$rule['type'].' types'); } foreach ($data[$key] as &$item) { - if(array_key_exists($rule['type'], $this->models) && $item instanceof Document) { + if (array_key_exists($rule['type'], $this->models) && $item instanceof Document) { $item = $this->output($item, $rule['type']); } } @@ -168,7 +167,7 @@ class Response extends UtopiaResponse */ public function yaml(array $data): void { - if(!extension_loaded('yaml')) { + if (!extension_loaded('yaml')) { throw new Exception('Missing yaml extension. Learn more at: https://www.php.net/manual/en/book.yaml.php'); } diff --git a/src/Appwrite/Utopia/Response/Model/File.php b/src/Appwrite/Utopia/Response/Model/File.php index 875c6f4bd..2b48e0411 100644 --- a/src/Appwrite/Utopia/Response/Model/File.php +++ b/src/Appwrite/Utopia/Response/Model/File.php @@ -9,7 +9,6 @@ class File extends Model { public function __construct() { - } /** From b8b77822c23505fd9122f4e275c92b2cb77b0205 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Tue, 27 Oct 2020 21:46:15 +0200 Subject: [PATCH 02/40] Updated controllers folder --- app/controllers/api/account.php | 2 -- app/controllers/api/functions.php | 10 +++++----- app/controllers/api/teams.php | 1 - app/controllers/api/users.php | 6 ++---- app/controllers/general.php | 27 +++++++++++++-------------- app/controllers/web/console.php | 5 ++--- 6 files changed, 22 insertions(+), 29 deletions(-) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 9d6785309..d3275eb70 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -648,7 +648,6 @@ App::get('/v1/account/sessions') $sessions[$index]['geo']['isoCode'] = '--'; $sessions[$index]['geo']['country'] = $locale->getText('locale.country.unknown'); } - } catch (\Exception $e) { $sessions[$index]['geo']['isoCode'] = '--'; $sessions[$index]['geo']['country'] = $locale->getText('locale.country.unknown'); @@ -732,7 +731,6 @@ App::get('/v1/account/logs') $output[$i]['geo']['isoCode'] = '--'; $output[$i]['geo']['country'] = $locale->getText('locale.country.unknown'); } - } catch (\Exception $e) { $output[$i]['geo']['isoCode'] = '--'; $output[$i]['geo']['country'] = $locale->getText('locale.country.unknown'); diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 039eeb3f5..79b9fc791 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -352,7 +352,7 @@ App::get('/v1/functions/:functionId/tags/:tagId') $tag = $projectDB->getDocument($tagId); - if($tag->getAttribute('functionId') !== $function->getId()) { + if ($tag->getAttribute('functionId') !== $function->getId()) { throw new Exception('Tag not found', 404); } @@ -382,7 +382,7 @@ App::delete('/v1/functions/:functionId/tags/:tagId') $tag = $projectDB->getDocument($tagId); - if($tag->getAttribute('functionId') !== $function->getId()) { + if ($tag->getAttribute('functionId') !== $function->getId()) { throw new Exception('Tag not found', 404); } @@ -428,7 +428,7 @@ App::post('/v1/functions/:functionId/executions') $tag = $projectDB->getDocument($function->getAttribute('tag')); - if($tag->getAttribute('functionId') !== $function->getId()) { + if ($tag->getAttribute('functionId') !== $function->getId()) { throw new Exception('Tag not found. Deploy tag before trying to execute a function', 404); } @@ -455,7 +455,7 @@ App::post('/v1/functions/:functionId/executions') throw new Exception('Failed saving execution to DB', 500); } - if((bool)$async) { + if ((bool)$async) { // Issue a TLS certificate when domain is verified Resque::enqueue('v1-functions', 'FunctionsV1', [ 'projectId' => $project->getId(), @@ -527,7 +527,7 @@ App::get('/v1/functions/:functionId/executions/:executionId') $execution = $projectDB->getDocument($executionId); - if($execution->getAttribute('functionId') !== $function->getId()) { + if ($execution->getAttribute('functionId') !== $function->getId()) { throw new Exception('Execution not found', 404); } diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index ae9e44015..e07ba8689 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -594,7 +594,6 @@ App::patch('/v1/teams/:teamId/memberships/:inviteId/status') 'email' => $user->getAttribute('email'), 'name' => $user->getAttribute('name'), ])), Response::MODEL_MEMBERSHIP); - }, ['request', 'response', 'user', 'projectDB', 'audits']); App::delete('/v1/teams/:teamId/memberships/:inviteId') diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index 741d0c661..01cc6b83a 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -279,7 +279,6 @@ App::get('/v1/users/:userId/sessions') $sessions[$index]['geo']['isoCode'] = '--'; $sessions[$index]['geo']['country'] = $locale->getText('locale.country.unknown'); } - } catch (\Exception $e) { $sessions[$index]['geo']['isoCode'] = '--'; $sessions[$index]['geo']['country'] = $locale->getText('locale.country.unknown'); @@ -365,14 +364,13 @@ App::get('/v1/users/:userId/logs') try { $record = $geodb->get($log['ip']); - if($record){ + if ($record) { $output[$i]['geo']['isoCode'] = \strtolower($record['country']['iso_code']); $output[$i]['geo']['country'] = (isset($countries[$record['country']['iso_code']])) ? $countries[$record['country']['iso_code']] : $locale->getText('locale.country.unknown'); - } else{ + } else { $output[$i]['geo']['isoCode'] = '--'; $output[$i]['geo']['country'] = $locale->getText('locale.country.unknown'); } - } catch (\Exception $e) { $output[$i]['geo']['isoCode'] = '--'; $output[$i]['geo']['country'] = $locale->getText('locale.country.unknown'); diff --git a/app/controllers/general.php b/app/controllers/general.php index 5aae62ac3..7b4470e84 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -44,7 +44,7 @@ App::init(function ($utopia, $request, $response, $console, $project, $user, $lo $route = $utopia->match($request); - if(!empty($route->getLabel('sdk.platform', [])) && empty($project->getId()) && ($route->getLabel('scope', '') !== 'public')) { + if (!empty($route->getLabel('sdk.platform', [])) && empty($project->getId()) && ($route->getLabel('scope', '') !== 'public')) { throw new Exception('Missing or unknown project ID', 400); } @@ -99,8 +99,8 @@ App::init(function ($utopia, $request, $response, $console, $project, $user, $lo * @see https://www.owasp.org/index.php/List_of_useful_HTTP_headers */ if (App::getEnv('_APP_OPTIONS_FORCE_HTTPS', 'disabled') === 'enabled') { // Force HTTPS - if($request->getProtocol() !== 'https') { - return $response->redirect('https://'.$request->getHostname().$request->getURI()); + if ($request->getProtocol() !== 'https') { + return $response->redirect('https://'.$request->getHostname().$request->getURI()); } $response->addHeader('Strict-Transport-Security', 'max-age='.(60 * 60 * 24 * 126)); // 126 days @@ -126,11 +126,11 @@ App::init(function ($utopia, $request, $response, $console, $project, $user, $lo $origin = $request->getOrigin($request->getReferer('')); $originValidator = new Origin(\array_merge($project->getAttribute('platforms', []), $console->getAttribute('platforms', []))); - if(!$originValidator->isValid($origin) + if (!$originValidator->isValid($origin) && \in_array($request->getMethod(), [Request::METHOD_POST, Request::METHOD_PUT, Request::METHOD_PATCH, Request::METHOD_DELETE]) && $route->getLabel('origin', false) !== '*' && empty($request->getHeader('x-appwrite-key', ''))) { - throw new Exception($originValidator->getDescription(), 403); + throw new Exception($originValidator->getDescription(), 403); } /* @@ -269,7 +269,7 @@ App::shutdown(function ($utopia, $request, $response, $project, $webhooks, $audi $route = $utopia->match($request); - if($project->getId() + if ($project->getId() && $mode !== APP_MODE_ADMIN && !empty($route->getLabel('sdk.namespace', null))) { // Don't calculate console usage and admin mode @@ -305,7 +305,7 @@ App::error(function ($error, $utopia, $request, $response, $layout, $project) { /** @var Utopia\View $layout */ /** @var Appwrite\Database\Document $project */ - if(php_sapi_name() === 'cli') { + if (php_sapi_name() === 'cli') { var_dump(get_class($error)); var_dump($error->getMessage()); var_dump($error->getFile()); @@ -379,7 +379,6 @@ App::error(function ($error, $utopia, $request, $response, $layout, $project) { $response->dynamic(new Document($output), $utopia->isDevelopment() ? Response::MODEL_ERROR_DEV : Response::MODEL_LOCALE); - }, ['error', 'utopia', 'request', 'response', 'layout', 'project']); App::get('/manifest.json') @@ -435,25 +434,25 @@ App::get('/.well-known/acme-challenge') $path = \str_replace('/.well-known/acme-challenge/', '', $request->getParam('q')); $absolute = \realpath($base.'/.well-known/acme-challenge/'.$path); - if(!$base) { + if (!$base) { throw new Exception('Storage error', 500); } - if(!$absolute) { + if (!$absolute) { throw new Exception('Unknown path', 404); } - if(!\substr($absolute, 0, \strlen($base)) === $base) { + if (!\substr($absolute, 0, \strlen($base)) === $base) { throw new Exception('Invalid path', 401); } - if(!\file_exists($absolute)) { + if (!\file_exists($absolute)) { throw new Exception('Unknown path', 404); } $content = @\file_get_contents($absolute); - if(!$content) { + if (!$content) { throw new Exception('Failed to get contents', 500); } @@ -463,6 +462,6 @@ App::get('/.well-known/acme-challenge') include_once __DIR__ . '/shared/api.php'; include_once __DIR__ . '/shared/web.php'; -foreach(Config::getParam('services', []) as $service) { +foreach (Config::getParam('services', []) as $service) { include_once $service['controller']; } \ No newline at end of file diff --git a/app/controllers/web/console.php b/app/controllers/web/console.php index 6c2f7ba44..0be4503b3 100644 --- a/app/controllers/web/console.php +++ b/app/controllers/web/console.php @@ -385,10 +385,9 @@ App::get('/console/version') try { $version = \json_decode(@\file_get_contents(App::getEnv('_APP_HOME', 'http://localhost').'/v1/health/version'), true); - if($version && isset($version['version'])) { + if ($version && isset($version['version'])) { return $response->json(['version' => $version['version']]); - } - else { + } else { throw new Exception('Failed to check for a newer version', 500); } } catch (\Throwable $th) { From e009f9c60b4c314b5759e6dd6aae798a672421fd Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Tue, 27 Oct 2020 21:48:38 +0200 Subject: [PATCH 03/40] Updated tests folder --- tests/e2e/Client.php | 4 ++-- tests/e2e/Scopes/ProjectCustom.php | 2 +- tests/e2e/Scopes/Scope.php | 6 +++--- tests/e2e/Services/Health/HealthBase.php | 1 - tests/e2e/Services/Projects/ProjectsBase.php | 1 - tests/e2e/Services/Projects/ProjectsConsoleClientTest.php | 8 ++++---- tests/e2e/Services/Teams/TeamsBase.php | 4 ++-- tests/e2e/Services/Teams/TeamsBaseClient.php | 2 +- tests/e2e/Services/Teams/TeamsBaseServer.php | 2 +- tests/unit/Docker/ComposeTest.php | 2 +- tests/unit/Docker/EnvTest.php | 2 +- tests/unit/Network/Validators/OriginTest.php | 1 - tests/unit/Storage/StorageTest.php | 2 +- tests/unit/Swoole/FilesTest.php | 1 - 14 files changed, 17 insertions(+), 21 deletions(-) diff --git a/tests/e2e/Client.php b/tests/e2e/Client.php index e2a805a2b..2d8eff951 100644 --- a/tests/e2e/Client.php +++ b/tests/e2e/Client.php @@ -218,7 +218,7 @@ class Client case 'application/json': $json = json_decode($responseBody, true); - if($json === null) { + if ($json === null) { throw new Exception('Failed to parse response: '.$responseBody); } @@ -235,7 +235,7 @@ class Client $responseHeaders['status-code'] = $responseStatus; - if($responseStatus === 500) { + if ($responseStatus === 500) { echo 'Server error('.$method.': '.$path.'. Params: '.json_encode($params).'): '.json_encode($responseBody)."\n"; } diff --git a/tests/e2e/Scopes/ProjectCustom.php b/tests/e2e/Scopes/ProjectCustom.php index d4d787784..831a0fbb7 100644 --- a/tests/e2e/Scopes/ProjectCustom.php +++ b/tests/e2e/Scopes/ProjectCustom.php @@ -16,7 +16,7 @@ trait ProjectCustom */ public function getProject(): array { - if(!empty(self::$project)) { + if (!empty(self::$project)) { return self::$project; } diff --git a/tests/e2e/Scopes/Scope.php b/tests/e2e/Scopes/Scope.php index 61920877b..09d8f5981 100644 --- a/tests/e2e/Scopes/Scope.php +++ b/tests/e2e/Scopes/Scope.php @@ -36,7 +36,7 @@ abstract class Scope extends TestCase sleep(10); $emails = json_decode(file_get_contents('http://maildev/email'), true); - if($emails && is_array($emails)) { + if ($emails && is_array($emails)) { return end($emails); } @@ -63,7 +63,7 @@ abstract class Scope extends TestCase */ public function getRoot(): array { - if((self::$root)) { + if ((self::$root)) { return self::$root; } @@ -114,7 +114,7 @@ abstract class Scope extends TestCase */ public function getUser(): array { - if(isset(self::$user[$this->getProject()['$id']])) { + if (isset(self::$user[$this->getProject()['$id']])) { return self::$user[$this->getProject()['$id']]; } diff --git a/tests/e2e/Services/Health/HealthBase.php b/tests/e2e/Services/Health/HealthBase.php index ff9aab9f8..b7d4ce477 100644 --- a/tests/e2e/Services/Health/HealthBase.php +++ b/tests/e2e/Services/Health/HealthBase.php @@ -6,5 +6,4 @@ use Tests\E2E\Client; trait HealthBase { - } \ No newline at end of file diff --git a/tests/e2e/Services/Projects/ProjectsBase.php b/tests/e2e/Services/Projects/ProjectsBase.php index dd802a540..ef67968b9 100644 --- a/tests/e2e/Services/Projects/ProjectsBase.php +++ b/tests/e2e/Services/Projects/ProjectsBase.php @@ -6,5 +6,4 @@ use Tests\E2E\Client; trait ProjectsBase { - } \ No newline at end of file diff --git a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php index ac3ff8724..17b8eb313 100644 --- a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php +++ b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php @@ -139,7 +139,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(400, $response['headers']['status-code']); - return $data; + return $data; } /** @@ -198,7 +198,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(400, $response['headers']['status-code']); - return $data; + return $data; } /** @@ -256,7 +256,7 @@ class ProjectsConsoleClientTest extends Scope * Test for SUCCESS */ - foreach($providers as $key => $provider) { + foreach ($providers as $key => $provider) { $response = $this->client->call(Client::METHOD_PATCH, '/projects/'.$id.'/oauth2', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], @@ -279,7 +279,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertNotEmpty($response['body']); $this->assertEquals($id, $response['body']['$id']); - foreach($providers as $key => $provider) { + foreach ($providers as $key => $provider) { $this->assertEquals('AppId-'.ucfirst($key), $response['body']['usersOauth2'.ucfirst($key).'Appid']); $this->assertEquals('Secret-'.ucfirst($key), $response['body']['usersOauth2'.ucfirst($key).'Secret']); } diff --git a/tests/e2e/Services/Teams/TeamsBase.php b/tests/e2e/Services/Teams/TeamsBase.php index a8ac2ac43..cdcb48b22 100644 --- a/tests/e2e/Services/Teams/TeamsBase.php +++ b/tests/e2e/Services/Teams/TeamsBase.php @@ -96,7 +96,7 @@ trait TeamsBase * Test for FAILURE */ - return []; + return []; } /** @@ -171,7 +171,7 @@ trait TeamsBase * Test for FAILURE */ - return []; + return []; } public function testUpdateTeam():array diff --git a/tests/e2e/Services/Teams/TeamsBaseClient.php b/tests/e2e/Services/Teams/TeamsBaseClient.php index 25bbcbdd5..72fc99d88 100644 --- a/tests/e2e/Services/Teams/TeamsBaseClient.php +++ b/tests/e2e/Services/Teams/TeamsBaseClient.php @@ -32,7 +32,7 @@ trait TeamsBaseClient * Test for FAILURE */ - return $data; + return $data; } /** diff --git a/tests/e2e/Services/Teams/TeamsBaseServer.php b/tests/e2e/Services/Teams/TeamsBaseServer.php index 9869ce590..846c321b1 100644 --- a/tests/e2e/Services/Teams/TeamsBaseServer.php +++ b/tests/e2e/Services/Teams/TeamsBaseServer.php @@ -28,7 +28,7 @@ trait TeamsBaseServer * Test for FAILURE */ - return []; + return []; } diff --git a/tests/unit/Docker/ComposeTest.php b/tests/unit/Docker/ComposeTest.php index 210fee96d..c484fc17e 100644 --- a/tests/unit/Docker/ComposeTest.php +++ b/tests/unit/Docker/ComposeTest.php @@ -18,7 +18,7 @@ class ComposeTest extends TestCase { $data = @file_get_contents(__DIR__.'/../../resources/docker/docker-compose.yml'); - if($data === false) { + if ($data === false) { throw new Exception('Failed to read compose file'); } diff --git a/tests/unit/Docker/EnvTest.php b/tests/unit/Docker/EnvTest.php index 6e706a43f..2fb3e6d55 100644 --- a/tests/unit/Docker/EnvTest.php +++ b/tests/unit/Docker/EnvTest.php @@ -18,7 +18,7 @@ class EnvTest extends TestCase { $data = @file_get_contents(__DIR__.'/../../resources/docker/.env'); - if($data === false) { + if ($data === false) { throw new Exception('Failed to read compose file'); } diff --git a/tests/unit/Network/Validators/OriginTest.php b/tests/unit/Network/Validators/OriginTest.php index 5b1cc2f44..4ba618f32 100644 --- a/tests/unit/Network/Validators/OriginTest.php +++ b/tests/unit/Network/Validators/OriginTest.php @@ -60,6 +60,5 @@ class OriginTest extends TestCase $this->assertEquals($validator->isValid('appwrite-windows://com.company.appname'), false); $this->assertEquals($validator->getDescription(), 'Invalid Origin. Register your new client (com.company.appname) as a new Windows platform on your project console dashboard'); - } } \ No newline at end of file diff --git a/tests/unit/Storage/StorageTest.php b/tests/unit/Storage/StorageTest.php index 7ffe9ce50..4d3196612 100644 --- a/tests/unit/Storage/StorageTest.php +++ b/tests/unit/Storage/StorageTest.php @@ -28,7 +28,7 @@ class StorageTest extends TestCase try { get_class(Storage::getDevice('disk-c')); $this->fail("Expected exception not thrown"); - } catch(Exception $e) { + } catch (Exception $e) { $this->assertEquals('The device "disk-c" is not listed', $e->getMessage()); } } diff --git a/tests/unit/Swoole/FilesTest.php b/tests/unit/Swoole/FilesTest.php index adcf4b4fc..6059076de 100644 --- a/tests/unit/Swoole/FilesTest.php +++ b/tests/unit/Swoole/FilesTest.php @@ -43,6 +43,5 @@ class FilesTest extends TestCase $this->assertNotEmpty(Files::getFileContents('/dist/scripts/app.js')); $this->assertNotEmpty(Files::getFileContents('/dist/styles/default-ltr.css')); $this->assertNotEmpty(Files::getFileContents('/dist/styles/default-rtl.css')); - } } \ No newline at end of file From a75026b290b6c7a48455769a878bf638437038f1 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Tue, 27 Oct 2020 21:50:18 +0200 Subject: [PATCH 04/40] Updated array syntax --- src/Appwrite/Database/Document.php | 2 +- src/Appwrite/Storage/Storage.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Appwrite/Database/Document.php b/src/Appwrite/Database/Document.php index 2a472b839..aa90fba10 100644 --- a/src/Appwrite/Database/Document.php +++ b/src/Appwrite/Database/Document.php @@ -219,7 +219,7 @@ class Document extends ArrayObject { $array = parent::getArrayCopy(); - $output = array(); + $output = []; foreach ($array as $key => &$value) { if (!empty($whitelist) && !\in_array($key, $whitelist)) { // Export only whitelisted fields diff --git a/src/Appwrite/Storage/Storage.php b/src/Appwrite/Storage/Storage.php index fc98f19fd..d10c6b38a 100644 --- a/src/Appwrite/Storage/Storage.php +++ b/src/Appwrite/Storage/Storage.php @@ -13,7 +13,7 @@ class Storage * * @var array */ - public static $devices = array(); + public static $devices = []; /** * Set Device. From 3aa78a1a0f81b199a39ee531549585136fe3d68b Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Tue, 27 Oct 2020 21:56:37 +0200 Subject: [PATCH 05/40] Updated default upload size --- .env | 2 +- Dockerfile | 4 ++-- Dockerfile.nginx | 2 +- app/config/variables.php | 2 +- app/http.php | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.env b/.env index 30b4a83f7..9764cfe89 100644 --- a/.env +++ b/.env @@ -24,6 +24,6 @@ _APP_SMTP_PORT=25 _APP_SMTP_SECURE= _APP_SMTP_USERNAME= _APP_SMTP_PASSWORD= -_APP_STORAGE_LIMIT=100000000 +_APP_STORAGE_LIMIT=10000000 _APP_FUNCTIONS_TIMEOUT=900 _APP_FUNCTIONS_CONTAINERS=10 diff --git a/Dockerfile b/Dockerfile index 60db67596..9a1003cba 100755 --- a/Dockerfile +++ b/Dockerfile @@ -75,7 +75,7 @@ ENV _APP_SERVER=swoole \ _APP_OPTIONS_ABUSE=enabled \ _APP_OPTIONS_FORCE_HTTPS=disabled \ _APP_OPENSSL_KEY_V1=your-secret-key \ - _APP_STORAGE_LIMIT=100000000 \ + _APP_STORAGE_LIMIT=10000000 \ _APP_STORAGE_ANTIVIRUS=enabled \ _APP_REDIS_HOST=redis \ _APP_REDIS_PORT=6379 \ @@ -180,7 +180,7 @@ RUN echo extension=maxminddb.so >> /usr/local/etc/php/conf.d/maxminddb.ini RUN echo "opcache.preload_user=www-data" >> /usr/local/etc/php/conf.d/appwrite.ini RUN echo "opcache.preload=/usr/src/code/app/preload.php" >> /usr/local/etc/php/conf.d/appwrite.ini -RUN echo "opcache.enable_cli = 1" >> /usr/local/etc/php/conf.d/appwrite.ini +RUN echo "opcache.enable_cli=1" >> /usr/local/etc/php/conf.d/appwrite.ini EXPOSE 80 diff --git a/Dockerfile.nginx b/Dockerfile.nginx index 3bd88a7d3..b7acd23a7 100644 --- a/Dockerfile.nginx +++ b/Dockerfile.nginx @@ -60,7 +60,7 @@ ENV TZ=Asia/Tel_Aviv \ _APP_OPTIONS_ABUSE=enabled \ _APP_OPTIONS_FORCE_HTTPS=disabled \ _APP_OPENSSL_KEY_V1=your-secret-key \ - _APP_STORAGE_LIMIT=100000000 \ + _APP_STORAGE_LIMIT=10000000 \ _APP_STORAGE_ANTIVIRUS=enabled \ _APP_REDIS_HOST=redis \ _APP_REDIS_PORT=6379 \ diff --git a/app/config/variables.php b/app/config/variables.php index 66308fcef..3da5a21e2 100644 --- a/app/config/variables.php +++ b/app/config/variables.php @@ -135,7 +135,7 @@ return [ ], [ 'name' => '_APP_STORAGE_LIMIT', - 'default' => '100000000', + 'default' => '10000000', 'required' => false, 'question' => '', ], diff --git a/app/http.php b/app/http.php index a5f0dbd43..89b3d1f9e 100644 --- a/app/http.php +++ b/app/http.php @@ -23,7 +23,7 @@ sleep(2); $http = new Server("0.0.0.0", 80); -$payloadSize = max(4000000 /* 4mb */, App::getEnv('_APP_STORAGE_LIMIT', 100000000)); +$payloadSize = max(4000000 /* 4mb */, App::getEnv('_APP_STORAGE_LIMIT', 10000000 /* 10mb */)); $http ->set([ @@ -49,7 +49,7 @@ $http->on('AfterReload', function($serv, $workerId) { }); $http->on('start', function (Server $http) use ($payloadSize) { - Console::success('Server started succefully (max payload is '.$payloadSize.' bytes)'); + Console::success('Server started succefully (max payload is '.number_format($payloadSize).' bytes)'); Console::info("Master pid {$http->master_pid}, manager pid {$http->manager_pid}"); From 7625aec6200824e6b00dd7df43a543fa605d5b4b Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Wed, 28 Oct 2020 06:52:20 +0200 Subject: [PATCH 06/40] Updated missing vars --- app/views/install/compose.phtml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/views/install/compose.phtml b/app/views/install/compose.phtml index 089bb438f..ca1905217 100644 --- a/app/views/install/compose.phtml +++ b/app/views/install/compose.phtml @@ -243,6 +243,9 @@ services: - _APP_REDIS_PORT - _APP_SMTP_HOST - _APP_SMTP_PORT + - _APP_SMTP_SECURE + - _APP_SMTP_USERNAME + - _APP_SMTP_PASSWORD appwrite-schedule: image: appwrite/appwrite: From 57455db88b7a9e27403a9d05c9bc2a2eee1f70cd Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Thu, 29 Oct 2020 12:58:35 +0200 Subject: [PATCH 07/40] Updated changlog --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 6263aa0d9..9aadc06e4 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -44,6 +44,8 @@ ## Breaking Changes (Read before upgrading!) - **Deprecated** `first` and `last` query params for documents list route in the database API - **Deprecated** Deprectaed Pubjabi Translations ('pn') +- **Deprecated** `PATCH /account/prefs` is now updating the prefs payload and not just merging it +- **Deprecated** `PATCH /users/:userId/prefs` is now updating the prefs payload and not just merging it - Switched order of limit and offset params in all the SDKs `listDocuments` method for better consistency - Default `limit` param value in all the SDKs `listDocuments` method is now 25 for better consistency From 6bf8be791253fd558ff3fcc486a4154e1a16c580 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Thu, 29 Oct 2020 12:58:48 +0200 Subject: [PATCH 08/40] Added missing SDK command --- Dockerfile | 1 + app/config/events.php | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/Dockerfile b/Dockerfile index 9a1003cba..1503f2a36 100755 --- a/Dockerfile +++ b/Dockerfile @@ -158,6 +158,7 @@ RUN chmod +x /usr/local/bin/doctor && \ chmod +x /usr/local/bin/install && \ chmod +x /usr/local/bin/migrate && \ chmod +x /usr/local/bin/schedule && \ + chmod +x /usr/local/bin/sdks && \ chmod +x /usr/local/bin/ssl && \ chmod +x /usr/local/bin/test && \ chmod +x /usr/local/bin/vars && \ diff --git a/app/config/events.php b/app/config/events.php index aeee6849f..34c4a4f2d 100644 --- a/app/config/events.php +++ b/app/config/events.php @@ -55,4 +55,16 @@ return [ 'storage.files.delete' => [ 'description' => 'This event triggers when a storage file is deleted.', ], + 'users.create' => [ + 'description' => 'This event triggers when a user is created from the users API.', + ], + 'users.update.status' => [ + 'description' => 'This event triggers when a user status is updated from the users API.', + ], + 'users.delete' => [ + 'description' => 'This event triggers when a user is deleted from users API.', + ], + 'users.sessions.delete' => [ + 'description' => 'This event triggers when a user session is deleted from users API.', + ], ]; \ No newline at end of file From 55932594d01d0b753643572cfe53cead2add9e74 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Thu, 29 Oct 2020 13:22:46 +0200 Subject: [PATCH 09/40] Updated migration script --- app/tasks/migrate.php | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/app/tasks/migrate.php b/app/tasks/migrate.php index e44488ce0..abfd295d8 100644 --- a/app/tasks/migrate.php +++ b/app/tasks/migrate.php @@ -7,15 +7,18 @@ use Utopia\CLI\Console; use Appwrite\Database\Database; use Appwrite\Database\Document; use Appwrite\Database\Validator\Authorization; +use Appwrite\Database\Adapter\MySQL as MySQLAdapter; +use Appwrite\Database\Adapter\Redis as RedisAdapter; $callbacks = [ '0.4.0' => function() { Console::log('I got nothing to do.'); }, - '0.5.0' => function($project) use ($register, $projectDB, $requset) { + + '0.5.0' => function($project) use ($register, $projectDB) { $db = $register->get('db'); - Console::log('Migrating project: '.$project->getId()); + Console::log('Migrating project: '.$project->getAttribute('name').' ('.$project->getId().')'); // Update all documents $uid -> $id @@ -46,6 +49,7 @@ $callbacks = [ try { $new = $projectDB->overwriteDocument($document->getArrayCopy()); } catch (\Throwable $th) { + var_dump($document); Console::error('Failed to update document: '.$th->getMessage()); continue; } @@ -107,6 +111,14 @@ function fixDocument(Document $document) { } } + if($document->getAttribute('$collection') === Database::SYSTEM_COLLECTION_WEBHOOKS){ + $document->setAttribute('security', ($document->getAttribute('security')) ? true : false); + } + + if($document->getAttribute('$collection') === Database::SYSTEM_COLLECTION_TASKS){ + $document->setAttribute('security', ($document->getAttribute('security')) ? true : false); + } + if($document->getAttribute('$collection') === Database::SYSTEM_COLLECTION_USERS) { foreach($providers as $key => $provider) { if(!empty($document->getAttribute('oauth'.\ucfirst($key)))) { @@ -165,26 +177,38 @@ function fixDocument(Document $document) { $cli ->task('migrate') - ->action(function () use ($console, $projectDB, $consoleDB, $callbacks) { + ->action(function () use ($register, $callbacks) { Console::success('Starting Data Migration'); + $consoleDB = new Database(); + $consoleDB->setAdapter(new RedisAdapter(new MySQLAdapter($register), $register)); + $consoleDB->setNamespace('app_console'); // Main DB + $consoleDB->setMocks(Config::getParam('collections', [])); + + $projectDB = new Database(); + $projectDB->setAdapter(new RedisAdapter(new MySQLAdapter($register), $register)); + $projectDB->setMocks(Config::getParam('collections', [])); + + $console = $consoleDB->getDocument('console'); + Authorization::disable(); $limit = 30; $sum = 30; $offset = 0; $projects = [$console]; + $count = 0; while ($sum >= 30) { foreach($projects as $project) { + $projectDB->setNamespace('app_'.$project->getId()); try { - $callbacks['0.5.0']($project); + $callbacks['0.5.0']($project, $projectDB); } catch (\Throwable $th) { + throw $th; Console::error('Failed to update project ("'.$project->getId().'") version with error: '.$th->getMessage()); - $projectDB->setNamespace('app_console'); - $projectDB->deleteDocument($project->getId()); } } @@ -201,8 +225,9 @@ $cli $sum = \count($projects); $offset = $offset + $limit; + $count = $count + $sum; - Console::log('Fetched '.$sum.' projects...'); + Console::log('Fetched '.$count.'/'.$consoleDB->getSum().' projects...'); } Console::success('Data Migration Completed'); From ef3822e6d8ea7f97c8b42036e52e2b4b40b45aa1 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Thu, 29 Oct 2020 13:24:46 +0200 Subject: [PATCH 10/40] Added missing bin file --- bin/sdks | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 bin/sdks diff --git a/bin/sdks b/bin/sdks new file mode 100644 index 000000000..bf117125f --- /dev/null +++ b/bin/sdks @@ -0,0 +1,3 @@ +#!/bin/sh + +php /usr/src/code/app/cli.php sdk $@ \ No newline at end of file From 5fd13990aa88001816d1230d66d6ed8d2c472b35 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Thu, 29 Oct 2020 13:25:42 +0200 Subject: [PATCH 11/40] Fixed command --- bin/sdks | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/sdks b/bin/sdks index bf117125f..ab7341482 100644 --- a/bin/sdks +++ b/bin/sdks @@ -1,3 +1,3 @@ #!/bin/sh -php /usr/src/code/app/cli.php sdk $@ \ No newline at end of file +php /usr/src/code/app/cli.php sdks $@ \ No newline at end of file From 8d909539a8990b2653983941edb2f3ac37ca6691 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Thu, 29 Oct 2020 13:30:34 +0200 Subject: [PATCH 12/40] Missing table delete --- src/Appwrite/Database/Adapter/MySQL.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Appwrite/Database/Adapter/MySQL.php b/src/Appwrite/Database/Adapter/MySQL.php index d361433df..313a9075f 100644 --- a/src/Appwrite/Database/Adapter/MySQL.php +++ b/src/Appwrite/Database/Adapter/MySQL.php @@ -459,6 +459,7 @@ class MySQL extends Adapter throw new Exception('Empty namespace'); } + $unique = 'app_'.$namespace.'.database.unique'; $documents = 'app_'.$namespace.'.database.documents'; $properties = 'app_'.$namespace.'.database.properties'; $relationships = 'app_'.$namespace.'.database.relationships'; @@ -466,6 +467,7 @@ class MySQL extends Adapter $abuse = 'app_'.$namespace.'.abuse.abuse'; try { + $this->getPDO()->prepare('DROP TABLE `'.$unique.'`;')->execute(); $this->getPDO()->prepare('DROP TABLE `'.$documents.'`;')->execute(); $this->getPDO()->prepare('DROP TABLE `'.$properties.'`;')->execute(); $this->getPDO()->prepare('DROP TABLE `'.$relationships.'`;')->execute(); From a56ca3535ae4ebb62c9ce0e633b45fd7de501a50 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Thu, 29 Oct 2020 13:32:39 +0200 Subject: [PATCH 13/40] Updated document missing encode/decode action --- src/Appwrite/Database/Database.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Appwrite/Database/Database.php b/src/Appwrite/Database/Database.php index 70725a89d..51b46d265 100644 --- a/src/Appwrite/Database/Database.php +++ b/src/Appwrite/Database/Database.php @@ -158,7 +158,7 @@ class Database $results = $this->adapter->getCollection($options); foreach ($results as &$node) { - $node = new Document($node); + $node = $this->decode(new Document($node)); } return $results; @@ -317,13 +317,19 @@ class Database throw new AuthorizationException($validator->getDescription()); // var_dump($validator->getDescription()); return false; } + $new = $this->encode($new); + $validator = new Structure($this); if (!$validator->isValid($new)) { // Make sure updated structure still apply collection rules (if any) throw new StructureException($validator->getDescription()); // var_dump($validator->getDescription()); return false; } - return new Document($this->adapter->updateDocument($data)); + $new = new Document($this->adapter->updateDocument($new->getArrayCopy())); + + $new = $this->decode($new); + + return $new; } /** From 0450604d27d858bf7d5fcff75bb938d5d4d79424 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Thu, 29 Oct 2020 15:07:56 +0200 Subject: [PATCH 14/40] Added external swoole lib and extended response class --- app/controllers/api/account.php | 22 +- app/controllers/api/database.php | 2 +- app/controllers/api/locale.php | 2 +- app/controllers/api/storage.php | 4 +- app/controllers/api/teams.php | 2 +- app/controllers/general.php | 10 +- app/controllers/shared/api.php | 2 +- app/controllers/shared/web.php | 2 +- app/controllers/web/home.php | 2 +- app/http.php | 4 +- app/init.php | 8 +- composer.json | 1 + src/Appwrite/Swoole/Files.php | 176 --------- src/Appwrite/Swoole/Request.php | 339 ------------------ src/Appwrite/Swoole/Response.php | 138 ------- src/Appwrite/Utopia/Response.php | 172 +++++++-- src/Appwrite/Utopia/Response/Model.php | 12 +- src/Appwrite/Utopia/Response/Model/Any.php | 34 ++ .../Utopia/Response/Model/BaseList.php | 35 +- .../Utopia/Response/Model/Collection.php | 68 ++++ .../Utopia/Response/Model/Continent.php | 45 +++ .../Utopia/Response/Model/Country.php | 45 +++ .../Utopia/Response/Model/Currency.php | 76 ++++ src/Appwrite/Utopia/Response/Model/Domain.php | 60 ++++ .../Utopia/Response/Model/Execution.php | 80 +++++ src/Appwrite/Utopia/Response/Model/File.php | 41 ++- src/Appwrite/Utopia/Response/Model/Func.php | 108 ++++++ src/Appwrite/Utopia/Response/Model/Key.php | 57 +++ .../Utopia/Response/Model/Language.php | 50 +++ src/Appwrite/Utopia/Response/Model/Log.php | 105 +++++- .../Utopia/Response/Model/MembershipList.php | 41 --- .../Utopia/Response/Model/Permissions.php | 47 +++ src/Appwrite/Utopia/Response/Model/Phone.php | 50 +++ .../Utopia/Response/Model/Platform.php | 77 ++++ .../Utopia/Response/Model/Project.php | 166 +++++++++ src/Appwrite/Utopia/Response/Model/Rule.php | 83 +++++ .../Utopia/Response/Model/Session.php | 96 ++++- src/Appwrite/Utopia/Response/Model/Tag.php | 60 ++++ src/Appwrite/Utopia/Response/Model/Task.php | 125 +++++++ .../Utopia/Response/Model/TeamList.php | 41 --- src/Appwrite/Utopia/Response/Model/User.php | 7 +- .../Utopia/Response/Model/Webhook.php | 74 ++++ tests/unit/Swoole/FilesTest.php | 48 --- 43 files changed, 1759 insertions(+), 858 deletions(-) delete mode 100644 src/Appwrite/Swoole/Files.php delete mode 100644 src/Appwrite/Swoole/Request.php delete mode 100644 src/Appwrite/Swoole/Response.php create mode 100644 src/Appwrite/Utopia/Response/Model/Any.php create mode 100644 src/Appwrite/Utopia/Response/Model/Collection.php create mode 100644 src/Appwrite/Utopia/Response/Model/Continent.php create mode 100644 src/Appwrite/Utopia/Response/Model/Country.php create mode 100644 src/Appwrite/Utopia/Response/Model/Currency.php create mode 100644 src/Appwrite/Utopia/Response/Model/Domain.php create mode 100644 src/Appwrite/Utopia/Response/Model/Execution.php create mode 100644 src/Appwrite/Utopia/Response/Model/Func.php create mode 100644 src/Appwrite/Utopia/Response/Model/Key.php create mode 100644 src/Appwrite/Utopia/Response/Model/Language.php delete mode 100644 src/Appwrite/Utopia/Response/Model/MembershipList.php create mode 100644 src/Appwrite/Utopia/Response/Model/Permissions.php create mode 100644 src/Appwrite/Utopia/Response/Model/Phone.php create mode 100644 src/Appwrite/Utopia/Response/Model/Platform.php create mode 100644 src/Appwrite/Utopia/Response/Model/Project.php create mode 100644 src/Appwrite/Utopia/Response/Model/Rule.php create mode 100644 src/Appwrite/Utopia/Response/Model/Tag.php create mode 100644 src/Appwrite/Utopia/Response/Model/Task.php delete mode 100644 src/Appwrite/Utopia/Response/Model/TeamList.php create mode 100644 src/Appwrite/Utopia/Response/Model/Webhook.php delete mode 100644 tests/unit/Swoole/FilesTest.php diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 9d6785309..658b200ec 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -55,7 +55,7 @@ App::post('/v1/account') ->param('password', '', new Password(), 'User password. Must be between 6 to 32 chars.') ->param('name', '', new Text(128), 'User name. Max length: 128 chars.', true) ->action(function ($email, $password, $name, $request, $response, $project, $projectDB, $webhooks, $audits) use ($oauth2Keys) { - /** @var Utopia\Request $request */ + /** @var Utopia\Swoole\Request $request */ /** @var Utopia\Response $response */ /** @var Appwrite\Database\Document $project */ /** @var Appwrite\Database\Database $projectDB */ @@ -160,7 +160,7 @@ App::post('/v1/account/sessions') ->param('email', '', new Email(), 'User email.') ->param('password', '', new Password(), 'User password. Must be between 6 to 32 chars.') ->action(function ($email, $password, $request, $response, $projectDB, $webhooks, $audits) { - /** @var Appwrite\Swoole\Request $request */ + /** @var Utopia\Swoole\Request $request */ /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $projectDB */ /** @var Appwrite\Event\Event $webhooks */ @@ -261,7 +261,7 @@ App::get('/v1/account/sessions/oauth2/:provider') ->param('failure', $oauthDefaultFailure, function ($clients) { return new Host($clients); }, 'URL to redirect back to your app after a failed login attempt. Only URLs from hostnames in your project platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API.', true, ['clients']) ->param('scopes', [], new ArrayList(new Text(128)), 'A list of custom OAuth2 scopes. Check each provider internal docs for a list of supported scopes.', true) ->action(function ($provider, $success, $failure, $scopes, $request, $response, $project) { - /** @var Utopia\Request $request */ + /** @var Utopia\Swoole\Request $request */ /** @var Utopia\Response $response */ /** @var Appwrite\Database\Document $project */ @@ -306,7 +306,7 @@ App::get('/v1/account/sessions/oauth2/callback/:provider/:projectId') ->param('code', '', new Text(1024), 'OAuth2 code.') ->param('state', '', new Text(2048), 'Login state params.', true) ->action(function ($projectId, $provider, $code, $state, $request, $response) { - /** @var Utopia\Request $request */ + /** @var Utopia\Swoole\Request $request */ /** @var Utopia\Response $response */ $domain = $request->getHostname(); @@ -331,7 +331,7 @@ App::post('/v1/account/sessions/oauth2/callback/:provider/:projectId') ->param('code', '', new Text(1024), 'OAuth2 code.') ->param('state', '', new Text(2048), 'Login state params.', true) ->action(function ($projectId, $provider, $code, $state, $request, $response) { - /** @var Utopia\Request $request */ + /** @var Utopia\Swoole\Request $request */ /** @var Utopia\Response $response */ $domain = $request->getHostname(); @@ -357,7 +357,7 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect') ->param('code', '', new Text(1024), 'OAuth2 code.') ->param('state', '', new Text(2048), 'OAuth2 state params.', true) ->action(function ($provider, $code, $state, $request, $response, $project, $user, $projectDB, $audits) use ($oauthDefaultSuccess) { - /** @var Utopia\Request $request */ + /** @var Utopia\Swoole\Request $request */ /** @var Utopia\Response $response */ /** @var Appwrite\Database\Document $project */ /** @var Appwrite\Database\Document $user */ @@ -944,7 +944,7 @@ App::delete('/v1/account') ->label('sdk.method', 'delete') ->label('sdk.description', '/docs/references/account/delete.md') ->action(function ($request, $response, $user, $projectDB, $audits, $webhooks) { - /** @var Utopia\Request $request */ + /** @var Utopia\Swoole\Request $request */ /** @var Utopia\Response $response */ /** @var Appwrite\Database\Document $user */ /** @var Appwrite\Database\Database $projectDB */ @@ -1007,7 +1007,7 @@ App::delete('/v1/account/sessions/:sessionId') ->label('abuse-limit', 100) ->param('sessionId', null, new UID(), 'Session unique ID. Use the string \'current\' to delete the current device session.') ->action(function ($sessionId, $request, $response, $user, $projectDB, $audits, $webhooks) { - /** @var Utopia\Request $request */ + /** @var Utopia\Swoole\Request $request */ /** @var Utopia\Response $response */ /** @var Appwrite\Database\Document $user */ /** @var Appwrite\Database\Database $projectDB */ @@ -1071,7 +1071,7 @@ App::delete('/v1/account/sessions') ->label('sdk.description', '/docs/references/account/delete-sessions.md') ->label('abuse-limit', 100) ->action(function ($request, $response, $user, $projectDB, $audits, $webhooks) { - /** @var Utopia\Request $request */ + /** @var Utopia\Swoole\Request $request */ /** @var Utopia\Response $response */ /** @var Appwrite\Database\Document $user */ /** @var Appwrite\Database\Database $projectDB */ @@ -1129,7 +1129,7 @@ App::post('/v1/account/recovery') ->param('email', '', new Email(), 'User email.') ->param('url', '', function ($clients) { return new Host($clients); }, 'URL to redirect the user back to your app from the recovery email. Only URLs from hostnames in your project platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API.', false, ['clients']) ->action(function ($email, $url, $request, $response, $projectDB, $project, $locale, $mails, $audits) { - /** @var Utopia\Request $request */ + /** @var Utopia\Swoole\Request $request */ /** @var Utopia\Response $response */ /** @var Appwrite\Database\Database $projectDB */ /** @var Appwrite\Database\Document $project */ @@ -1306,7 +1306,7 @@ App::post('/v1/account/verification') ->label('abuse-key', 'url:{url},email:{param-email}') ->param('url', '', function ($clients) { return new Host($clients); }, 'URL to redirect the user back to your app from the verification email. Only URLs from hostnames in your project platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API.', false, ['clients']) // TODO add built-in confirm page ->action(function ($url, $request, $response, $project, $user, $projectDB, $locale, $audits, $mails) { - /** @var Utopia\Request $request */ + /** @var Utopia\Swoole\Request $request */ /** @var Utopia\Response $response */ /** @var Appwrite\Database\Document $project */ /** @var Appwrite\Database\Document $user */ diff --git a/app/controllers/api/database.php b/app/controllers/api/database.php index bd1993575..a24de8088 100644 --- a/app/controllers/api/database.php +++ b/app/controllers/api/database.php @@ -529,7 +529,7 @@ App::get('/v1/database/collections/:collectionId/documents/:documentId') ->param('collectionId', null, new UID(), 'Collection unique ID. You can create a new collection with validation rules using the Database service [server integration](/docs/server/database#createCollection).') ->param('documentId', null, new UID(), 'Document unique ID.') ->action(function ($collectionId, $documentId, $request, $response, $projectDB) { - /** @var Utopia\Request $request */ + /** @var Utopia\Swoole\Request $request */ /** @var Utopia\Response $response */ /** @var Appwrite\Database\Database $projectDB */ diff --git a/app/controllers/api/locale.php b/app/controllers/api/locale.php index aa6fa9278..26b90cfea 100644 --- a/app/controllers/api/locale.php +++ b/app/controllers/api/locale.php @@ -12,7 +12,7 @@ App::get('/v1/locale') ->label('sdk.method', 'get') ->label('sdk.description', '/docs/references/locale/get-locale.md') ->action(function ($request, $response, $locale, $geodb) { - /** @var Utopia\Request $request */ + /** @var Utopia\Swoole\Request $request */ /** @var 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 18cfb58f4..55ae74037 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -37,7 +37,7 @@ App::post('/v1/storage/files') ->param('read', [], new ArrayList(new Text(64)), 'An array of strings with read permissions. By default no user is granted with any read permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions.') ->param('write', [], 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.') ->action(function ($file, $read, $write, $request, $response, $user, $projectDB, $webhooks, $audits, $usage) { - /** @var Utopia\Request $request */ + /** @var Utopia\Swoole\Request $request */ /** @var Utopia\Response $response */ /** @var Appwrite\Database\Document $user */ /** @var Appwrite\Database\Database $projectDB */ @@ -233,7 +233,7 @@ App::get('/v1/storage/files/:fileId/preview') ->param('background', '', new HexColor(), 'Preview image background color. Only works with transparent images (png). Use a valid HEX color, no # is needed for prefix.', true) ->param('output', '', new WhiteList(\array_keys(Config::getParam('storage-outputs')), true), 'Output format type (jpeg, jpg, png, gif and webp).', true) ->action(function ($fileId, $width, $height, $quality, $background, $output, $request, $response, $project, $projectDB) { - /** @var Utopia\Request $request */ + /** @var Utopia\Swoole\Request $request */ /** @var Utopia\Response $response */ /** @var Appwrite\Database\Document $project */ /** @var Appwrite\Database\Database $projectDB */ diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index ae9e44015..ab0db7a25 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -480,7 +480,7 @@ App::patch('/v1/teams/:teamId/memberships/:inviteId/status') ->param('userId', '', new UID(), 'User unique ID.') ->param('secret', '', new Text(256), 'Secret key.') ->action(function ($teamId, $inviteId, $userId, $secret, $request, $response, $user, $projectDB, $audits) { - /** @var Utopia\Request $request */ + /** @var Utopia\Swoole\Request $request */ /** @var Utopia\Response $response */ /** @var Appwrite\Database\Document $user */ /** @var Appwrite\Database\Database $projectDB */ diff --git a/app/controllers/general.php b/app/controllers/general.php index 5aae62ac3..b83630a23 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -3,7 +3,7 @@ require_once __DIR__.'/../init.php'; use Utopia\App; -use Appwrite\Swoole\Request; +use Utopia\Swoole\Request; use Appwrite\Utopia\Response; use Utopia\View; use Utopia\Exception; @@ -22,7 +22,7 @@ Config::setParam('cookieDomain', 'localhost'); Config::setParam('cookieSamesite', Response::COOKIE_SAMESITE_NONE); App::init(function ($utopia, $request, $response, $console, $project, $user, $locale, $webhooks, $audits, $usage, $clients) { - /** @var Appwrite\Swoole\Request $request */ + /** @var Utopia\Swoole\Request $request */ /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Document $console */ /** @var Appwrite\Database\Document $project */ @@ -246,7 +246,7 @@ App::init(function ($utopia, $request, $response, $console, $project, $user, $lo App::shutdown(function ($utopia, $request, $response, $project, $webhooks, $audits, $usage, $deletes, $mode) { /** @var Utopia\App $utopia */ - /** @var Utopia\Request $request */ + /** @var Utopia\Swoole\Request $request */ /** @var Utopia\Response $response */ /** @var Appwrite\Database\Document $project */ /** @var Appwrite\Event\Event $webhooks */ @@ -282,7 +282,7 @@ App::shutdown(function ($utopia, $request, $response, $project, $webhooks, $audi }, ['utopia', 'request', 'response', 'project', 'webhooks', 'audits', 'usage', 'deletes', 'mode']); App::options(function ($request, $response) { - /** @var Appwrite\Swoole\Request $request */ + /** @var Utopia\Swoole\Request $request */ /** @var Appwrite\Utopia\Response $response */ $origin = $request->getOrigin(); @@ -300,7 +300,7 @@ App::options(function ($request, $response) { App::error(function ($error, $utopia, $request, $response, $layout, $project) { /** @var Exception $error */ /** @var Utopia\App $utopia */ - /** @var Utopia\Request $request */ + /** @var Utopia\Swoole\Request $request */ /** @var Appwrite\Utopia\Response $response */ /** @var Utopia\View $layout */ /** @var Appwrite\Database\Document $project */ diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index 3fdca7cf1..a1a4d6cf6 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -7,7 +7,7 @@ use Utopia\Abuse\Adapters\TimeLimit; App::init(function ($utopia, $request, $response, $project, $user, $register) { /** @var Utopia\App $utopia */ - /** @var Utopia\Request $request */ + /** @var Utopia\Swoole\Request $request */ /** @var Utopia\Response $response */ /** @var Appwrite\Database\Document $project */ /** @var Appwrite\Database\Document $user */ diff --git a/app/controllers/shared/web.php b/app/controllers/shared/web.php index 3452cd353..383685e0d 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\Request $request */ + /** @var Utopia\Swoole\Request $request */ /** @var Utopia\Response $response */ /** @var Utopia\View $layout */ diff --git a/app/controllers/web/home.php b/app/controllers/web/home.php index a6c2491c0..f2cf21ffd 100644 --- a/app/controllers/web/home.php +++ b/app/controllers/web/home.php @@ -189,7 +189,7 @@ App::get('/open-api-2.json') ->param('tests', 0, new Range(0, 1), 'Include only test services.', true) ->action(function ($platform, $extensions, $tests, $utopia, $request, $response) { /** @var Utopia\App $utopia */ - /** @var Utopia\Request $request */ + /** @var Utopia\Swoole\Request $request */ /** @var Utopia\Response $response */ $security = [ diff --git a/app/http.php b/app/http.php index 89b3d1f9e..5bbdc87df 100644 --- a/app/http.php +++ b/app/http.php @@ -3,8 +3,8 @@ require_once __DIR__.'/../vendor/autoload.php'; use Appwrite\Swoole\Files; -use Appwrite\Swoole\Request; -use Appwrite\Swoole\Response; +use Utopia\Swoole\Request; +use Appwrite\Utopia\Response; use Swoole\Process; use Swoole\Http\Server; use Swoole\Http\Request as SwooleRequest; diff --git a/app/init.php b/app/init.php index d24ca9d28..8c3457dd3 100644 --- a/app/init.php +++ b/app/init.php @@ -361,7 +361,7 @@ App::setResource('clients', function($console, $project) { }, ['console', 'project']); App::setResource('user', function($mode, $project, $console, $request, $response, $projectDB, $consoleDB) { - /** @var Utopia\Request $request */ + /** @var Utopia\Swoole\Request $request */ /** @var Utopia\Response $response */ /** @var Appwrite\Database\Document $project */ /** @var Appwrite\Database\Database $consoleDB */ @@ -423,7 +423,7 @@ App::setResource('user', function($mode, $project, $console, $request, $response }, ['mode', 'project', 'console', 'request', 'response', 'projectDB', 'consoleDB']); App::setResource('project', function($consoleDB, $request) { - /** @var Appwrite\Swoole\Request $request */ + /** @var Utopia\Swoole\Request $request */ /** @var Appwrite\Database\Database $consoleDB */ Authorization::disable(); @@ -460,11 +460,11 @@ App::setResource('projectDB', function($register, $project) { }, ['register', 'project']); App::setResource('mode', function($request) { - /** @var Utopia\Request $request */ + /** @var Utopia\Swoole\Request $request */ return $request->getParam('mode', $request->getHeader('x-appwrite-mode', 'default')); }, ['request']); App::setResource('geodb', function($request) { - /** @var Utopia\Request $request */ + /** @var Utopia\Swoole\Request $request */ return new Reader(__DIR__.'/db/DBIP/dbip-country-lite-2020-01.mmdb'); }, ['request']); diff --git a/composer.json b/composer.json index bf121686a..1a60237d4 100644 --- a/composer.json +++ b/composer.json @@ -44,6 +44,7 @@ "utopia-php/registry": "0.2.*", "utopia-php/preloader": "0.2.*", "utopia-php/domains": "0.2.*", + "utopia-php/swoole": "0.2.*", "resque/php-resque": "1.3.6", "piwik/device-detector": "3.13.0", diff --git a/src/Appwrite/Swoole/Files.php b/src/Appwrite/Swoole/Files.php deleted file mode 100644 index 7971beba2..000000000 --- a/src/Appwrite/Swoole/Files.php +++ /dev/null @@ -1,176 +0,0 @@ - 'text/css', - 'js' => 'text/javascript', - 'svg' => 'image/svg+xml', - ]; - - /** - * Add MimeType - * - * @var string $mimeType - * - * @return void - */ - public static function addMimeType(string $mimeType): void - { - self::$mimeTypes[$mimeType] = true; - } - - /** - * Remove MimeType - * - * @var string $mimeType - * - * @return void - */ - public static function removeMimeType(string $mimeType): void - { - if(isset(self::$mimeTypes[$mimeType])) { - unset(self::$mimeTypes[$mimeType]); - } - } - - /** - * Get MimeType List - * - * @return array - */ - public static function getMimeTypes(): array - { - return self::$mimeTypes; - } - - /** - * Get Files Loaded Count - * - * @return int - */ - public static function getCount(): int - { - return self::$count; - } - - /** - * Load - * - * @var string $path - * - * @return void - */ - public static function load(string $directory, string $root = null): void - { - if(!is_readable($directory)) { - throw new Exception('Failed to load directory: '.$directory); - } - - $directory = realpath($directory); - - $root = ($root) ? $root : $directory; - - $handle = opendir($directory); - - while ($path = readdir($handle)) { - $extension = pathinfo($path, PATHINFO_EXTENSION); - - if (in_array($path, ['.', '..'])) { - continue; - } - - if (in_array($extension, ['php', 'phtml'])) { - continue; - } - - if(substr($path, 0, 1) === '.') { - continue; - } - - if (is_dir($directory.'/'.$path)) { - self::load($directory.'/'.$path, $root); - continue; - } - - self::$count++; - - self::$loaded[substr($directory.'/'.$path , strlen($root))] = [ - 'contents' => file_get_contents($directory.'/'.$path), - 'mimeType' => (array_key_exists($extension, self::$extensions)) - ? self::$extensions[$extension] - : mime_content_type($directory.'/'.$path) - ]; - } - - closedir($handle); - - if($directory === $root) { - echo '[Static Files] Loadded '.self::$count.' files'.PHP_EOL; - } - } - - /** - * Is File Loaded - * - * @var string $uri - */ - public static function isFileLoaded(string $uri): bool - { - if(!array_key_exists($uri, self::$loaded)) { - return false; - } - - return true; - } - - /** - * Get File Contants - * - * @var string $uri - */ - public static function getFileContents(string $uri): string - { - if(!array_key_exists($uri, self::$loaded)) { - throw new Exception('File not found or not loaded: '.$uri); - } - - return self::$loaded[$uri]['contents']; - } - - /** - * Get File MimeType - * - * @var string $uri - */ - public static function getFileMimeType(string $uri): string - { - if(!array_key_exists($uri, self::$loaded)) { - throw new Exception('File not found or not loaded: '.$uri); - } - - return self::$loaded[$uri]['mimeType']; - } -} diff --git a/src/Appwrite/Swoole/Request.php b/src/Appwrite/Swoole/Request.php deleted file mode 100644 index 453592468..000000000 --- a/src/Appwrite/Swoole/Request.php +++ /dev/null @@ -1,339 +0,0 @@ -swoole = $request; - } - - /** - * Get Param - * - * Get param by current method name - * - * @param string $key - * @param mixed $default - * @return mixed - */ - public function getParam(string $key, $default = null) - { - 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); - } - } - - /** - * Get Params - * - * Get all params of current method - * - * @return array - */ - public function getParams(): array - { - switch($this->getMethod()) { - case self::METHOD_GET: - return (!empty($this->swoole->get)) ? $this->swoole->get : []; - break; - case self::METHOD_POST: - case self::METHOD_PUT: - case self::METHOD_PATCH: - case self::METHOD_DELETE: - return $this->generateInput(); - break; - default: - return (!empty($this->swoole->get)) ? $this->swoole->get : []; - } - - return []; - } - - /** - * Get Query - * - * Method for querying HTTP GET request parameters. If $key is not found $default value will be returned. - * - * @param string $key - * @param mixed $default - * @return mixed - */ - public function getQuery(string $key, $default = null) - { - return (isset($this->swoole->get[$key])) ? $this->swoole->get[$key] : $default; - } - - /** - * Get payload - * - * Method for querying HTTP request payload parameters. If $key is not found $default value will be returned. - * - * @param string $key - * @param mixed $default - * @return mixed - */ - public function getPayload(string $key, $default = null) - { - $payload = $this->generateInput(); - - return (isset($payload[$key])) ? $payload[$key] : $default; - } - - /** - * Get server - * - * Method for querying server parameters. If $key is not found $default value will be returned. - * - * @param string $key - * @param mixed $default - * @return mixed - */ - public function getServer(string $key, $default = null) - { - return (isset($this->swoole->server) && isset($this->swoole->server[$key])) ? $this->swoole->server[$key] : $default; - } - - /** - * Get IP - * - * Returns users IP address. - * Support HTTP_X_FORWARDED_FOR header usually return - * from different proxy servers or PHP default REMOTE_ADDR - */ - public function getIP(): string - { - return $this->getHeader('x-forwarded-for', $this->getServer('remote_addr', '0.0.0.0')); - } - - /** - * Get Protocol - * - * Returns request protocol. - * Support HTTP_X_FORWARDED_PROTO header usually return - * from different proxy servers or PHP default REQUEST_SCHEME - * - * @return string - */ - public function getProtocol(): string - { - $protocol = $this->getHeader('x-forwarded-proto', $this->getServer('server_protocol', 'https')); - - if($protocol === 'HTTP/1.1') { - return 'http'; - } - - return $protocol; - } - - /** - * Get Port - * - * Returns request port. - * - * @return string - */ - public function getPort(): string - { - return $this->getHeader('x-forwarded-port', (string)\parse_url($this->getProtocol().'://'.$this->getHeader('x-forwarded-host', $this->getHeader('host')), PHP_URL_PORT)); - } - - /** - * Get Hostname - * - * Returns request hostname. - * - * @return string - */ - public function getHostname(): string - { - return \parse_url($this->getProtocol().'://'.$this->getHeader('x-forwarded-host', $this->getHeader('host')), PHP_URL_HOST); - } - - /** - * Get Method - * - * Return HTTP request method - * - * @return string - */ - public function getMethod(): string - { - return $this->getServer('request_method', 'UNKNOWN'); - } - - /** - * Get URI - * - * Return HTTP request URI - * - * @return string - */ - public function getURI(): string - { - return $this->getServer('request_uri', ''); - } - - /** - * Get Referer - * - * Return HTTP referer header - * - * @return string - */ - public function getReferer(string $default = ''): string - { - return $this->getHeader('referer', ''); - } - - /** - * Get Origin - * - * Return HTTP origin header - * - * @return string - */ - public function getOrigin(string $default = ''): string - { - return $this->getHeader('origin', $default); - } - - /** - * Get User Agent - * - * Return HTTP user agent header - * - * @return string - */ - public function getUserAgent(string $default = ''): string - { - return $this->getHeader('user-agent', $default); - } - - /** - * Get Accept - * - * Return HTTP accept header - * - * @return string - */ - public function getAccept(string $default = ''): string - { - return $this->getHeader('accept', $default); - } - - /** - * Get files - * - * Method for querying upload files data. If $key is not found empty array will be returned. - * - * @param string $key - * @return array - */ - public function getFiles($key): array - { - $key = strtolower($key); - return (isset($this->swoole->files[$key])) ? $this->swoole->files[$key] : []; - } - - /** - * Get cookie - * - * Method for querying HTTP cookie parameters. If $key is not found $default value will be returned. - * - * @param string $key - * @param string $default - * - * @return string - */ - public function getCookie(string $key, string $default = ''): string - { - $key = strtolower($key); - return (isset($this->swoole->cookie[$key])) ? $this->swoole->cookie[$key] : $default; - } - - /** - * Get header - * - * Method for querying HTTP header parameters. If $key is not found $default value will be returned. - * - * @param string $key - * @param string $default - * @return string - */ - public function getHeader(string $key, string $default = ''): string - { - return (isset($this->swoole->header[$key])) ? $this->swoole->header[$key] : $default; - } - - /** - * Generate input - * - * Generate PHP input stream and parse it as an array in order to handle different content type of requests - * - * @return array - */ - protected function generateInput(): array - { - if (null === $this->payload) { - $contentType = $this->getHeader('content-type'); - - // Get content-type without the charset - $length = strpos($contentType, ';'); - $length = (empty($length)) ? strlen($contentType) : $length; - $contentType = substr($contentType, 0, $length); - - switch ($contentType) { - case 'application/json': - $this->payload = json_decode($this->swoole->rawContent(), true); - break; - - default: - $this->payload = $this->swoole->post; - break; - } - - if(empty($this->payload)) { // Make sure we return same data type even if json payload is empty or failed - $this->payload = []; - } - } - - return $this->payload; - } - - /** - * Generate headers - * - * Parse request headers as an array for easy querying using the getHeader method - * - * @return array - */ - protected function generateHeaders(): array - { - return $this->swoole->header; - } -} \ No newline at end of file diff --git a/src/Appwrite/Swoole/Response.php b/src/Appwrite/Swoole/Response.php deleted file mode 100644 index 766101146..000000000 --- a/src/Appwrite/Swoole/Response.php +++ /dev/null @@ -1,138 +0,0 @@ - true, - 'text/css' => true, - 'text/javascript' => true, - 'application/javascript' => true, - 'text/html' => true, - 'text/html; charset=UTF-8' => true, - 'application/json' => true, - 'application/json; charset=UTF-8' => true, - 'image/svg+xml' => true, - 'application/xml+rss' => true, - ]; - - /** - * Response constructor. - */ - public function __construct(SwooleResponse $response) - { - $this->swoole = $response; - parent::__construct(\microtime(true)); - } - - /** - * Output response - * - * Generate HTTP response output including the response header (+cookies) and body and prints them. - * - * @param string $body - * @param int $exit exit code or don't exit if code is null - * - * @return void - */ - public function send(string $body = '', int $exit = null): void - { - if(!$this->disablePayload) { - $this->addHeader('X-Debug-Speed', (string)(microtime(true) - $this->startTime)); - - $this - ->appendCookies() - ->appendHeaders() - ; - - $chunk = 2000000; // Max chunk of 2 mb - $length = strlen($body); - - $this->size = $this->size + strlen(implode("\n", $this->headers)) + $length; - - if(array_key_exists( - $this->contentType, - $this->compressed - ) && ($length <= $chunk)) { // Dont compress with GZIP / Brotli if header is not listed and size is bigger than 2mb - $this->swoole->end($body); - } - else { - for ($i=0; $i < ceil($length / $chunk); $i++) { - $this->swoole->write(substr($body, ($i * $chunk), min((($i * $chunk) + $chunk), $length))); - } - - $this->swoole->end(); - } - - $this->disablePayload(); - } - } - - /** - * Append headers - * - * Iterating over response headers to generate them using native PHP header function. - * This method is also responsible for generating the response and content type headers. - * - * @return self - */ - protected function appendHeaders(): self - { - // Send status code header - $this->swoole->status((string)$this->statusCode); - - // Send content type header - $this - ->addHeader('Content-Type', $this->contentType) - ; - - // Set application headers - foreach ($this->headers as $key => $value) { - $this->swoole->header($key, $value); - } - - return $this; - } - - /** - * Append cookies - * - * Iterating over response cookies to generate them using native PHP cookie function. - * - * @return self - */ - protected function appendCookies(): self - { - foreach ($this->cookies as $cookie) { - $this->swoole->cookie( - $cookie['name'], - $cookie['value'], - $cookie['expire'], - $cookie['path'], - $cookie['domain'], - $cookie['secure'], - $cookie['httponly'], - $cookie['samesite'], - ); - } - - return $this; - } -} \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response.php b/src/Appwrite/Utopia/Response.php index b2a9f5b5d..66d1eaf18 100644 --- a/src/Appwrite/Utopia/Response.php +++ b/src/Appwrite/Utopia/Response.php @@ -3,46 +3,79 @@ namespace Appwrite\Utopia; use Exception; +use Utopia\Swoole\Response as SwooleResponse; +use Swoole\Http\Response as SwooleHTTPResponse; use Appwrite\Database\Document; use Appwrite\Utopia\Response\Model; +use Appwrite\Utopia\Response\Model\Any; +use Appwrite\Utopia\Response\Model\BaseList; +use Appwrite\Utopia\Response\Model\Collection; +use Appwrite\Utopia\Response\Model\Continent; +use Appwrite\Utopia\Response\Model\Country; +use Appwrite\Utopia\Response\Model\Currency; +use Appwrite\Utopia\Response\Model\Domain; use Appwrite\Utopia\Response\Model\Error; use Appwrite\Utopia\Response\Model\ErrorDev; +use Appwrite\Utopia\Response\Model\Execution; +use Appwrite\Utopia\Response\Model\File; +use Appwrite\Utopia\Response\Model\Func; +use Appwrite\Utopia\Response\Model\Key; +use Appwrite\Utopia\Response\Model\Language; use Appwrite\Utopia\Response\Model\User; use Appwrite\Utopia\Response\Model\Session; use Appwrite\Utopia\Response\Model\Team; -use Appwrite\Utopia\Response\Model\TeamList; use Appwrite\Utopia\Response\Model\Locale; +use Appwrite\Utopia\Response\Model\Log; use Appwrite\Utopia\Response\Model\Membership; -use Appwrite\Utopia\Response\Model\MembershipList; -use Utopia\Response as UtopiaResponse; +use Appwrite\Utopia\Response\Model\Phone; +use Appwrite\Utopia\Response\Model\Platform; +use Appwrite\Utopia\Response\Model\Project; +use Appwrite\Utopia\Response\Model\Rule; +use Appwrite\Utopia\Response\Model\Tag; +use Appwrite\Utopia\Response\Model\Task; +use Appwrite\Utopia\Response\Model\Webhook; -class Response extends UtopiaResponse +class Response extends SwooleResponse { // General - const MODEL_LOG = 'log'; // - Missing + const MODEL_ANY = 'any'; + const MODEL_LOG = 'log'; + const MODEL_LOG_LIST = 'logList'; const MODEL_ERROR = 'error'; const MODEL_ERROR_DEV = 'errorDev'; const MODEL_BASE_LIST = 'baseList'; + const MODEL_PERMISSIONS = 'permissions'; + // Database + const MODEL_COLLECTION = 'collection'; + const MODEL_COLLECTION_LIST = 'collectionList'; + const MODEL_RULE = 'rule'; + const MODEL_DOCUMENT_LIST = 'documentList'; + // Users const MODEL_USER = 'user'; + const MODEL_USER_LIST = 'userList'; const MODEL_SESSION = 'session'; + const MODEL_SESSION_LIST = 'sessionList'; const MODEL_TOKEN = 'token'; // - Missing - - // Database - const MODEL_COLLECTION = 'collection'; // - Missing + // Storage + const MODEL_FILE = 'file'; + const MODEL_FILE_LIST = 'fileList'; + const MODEL_BUCKET = 'bucket'; // - Missing + // Locale const MODEL_LOCALE = 'locale'; - const MODEL_COUNTRY = 'country'; // - Missing - const MODEL_CONTINENT = 'continent'; // - Missing - const MODEL_CURRENCY = 'currency'; // - Missing - const MODEL_LANGUAGE = 'langauge'; // - Missing - const MODEL_PHONE = 'phone'; // - Missing - - // Storage - const MODEL_FILE = 'file'; // - Missing - const MODEL_BUCKET = 'bucket'; // - Missing + const MODEL_COUNTRY = 'country'; + const MODEL_COUNTRY_LIST = 'countryList'; + const MODEL_CONTINENT = 'continent'; + const MODEL_CONTINENT_LIST = 'continentList'; + const MODEL_CURRENCY = 'currency'; + const MODEL_CURRENCY_LIST = 'currencyList'; + const MODEL_LANGUAGE = 'langauge'; + const MODEL_LANGUAGE_LIST = 'langaugeList'; + const MODEL_PHONE = 'phone'; + const MODEL_PHONE_LIST = 'phoneList'; // Teams const MODEL_TEAM = 'team'; @@ -50,26 +83,97 @@ class Response extends UtopiaResponse const MODEL_MEMBERSHIP = 'membership'; const MODEL_MEMBERSHIP_LIST = 'membershipList'; + // Functions + const MODEL_FUNCTION = 'function'; + const MODEL_FUNCTION_LIST = 'functionList'; + const MODEL_TAG = 'tag'; + const MODEL_TAG_LIST = 'tagList'; + const MODEL_EXECUTION = 'execution'; + const MODEL_EXECUTION_LIST = 'executionList'; + + // Project + const MODEL_PROJECT = 'project'; + const MODEL_PROJECT_LIST = 'projectsList'; + const MODEL_WEBHOOK = 'webhook'; + const MODEL_WEBHOOK_LIST = 'webhookList'; + const MODEL_KEY = 'key'; + const MODEL_KEY_LIST = 'keyList'; + const MODEL_TASK = 'task'; + const MODEL_TASK_LIST = 'taskList'; + const MODEL_PLATFORM = 'platform'; + const MODEL_PLATFORM_LIST = 'platformList'; + const MODEL_DOMAIN = 'domain'; + const MODEL_DOMAIN_LIST = 'domainList'; + + /** + * @var array + */ + protected $payload = []; + /** * Response constructor. * * @param float $time */ - public function __construct(float $time = 0) + public function __construct(SwooleHTTPResponse $response) { $this + // General ->setModel(new Error()) ->setModel(new ErrorDev()) + // Lists + ->setModel(new BaseList('Collections List', self::MODEL_COLLECTION_LIST, 'collections', self::MODEL_COLLECTION)) + ->setModel(new BaseList('Documents List', self::MODEL_DOCUMENT_LIST, 'documents', self::MODEL_ANY)) + ->setModel(new BaseList('Users List', self::MODEL_USER_LIST, 'users', self::MODEL_USER)) + ->setModel(new BaseList('Sessions List', self::MODEL_SESSION_LIST, 'sessions', self::MODEL_SESSION)) + ->setModel(new BaseList('Logs List', self::MODEL_LOG_LIST, 'logs', self::MODEL_LOG, false)) + ->setModel(new BaseList('Files List', self::MODEL_FILE_LIST, 'files', self::MODEL_FILE)) + ->setModel(new BaseList('Teams List', self::MODEL_TEAM_LIST, 'teams', self::MODEL_TEAM)) + ->setModel(new BaseList('Memberships List', self::MODEL_MEMBERSHIP_LIST, 'memberships', self::MODEL_MEMBERSHIP)) + ->setModel(new BaseList('Functions List', self::MODEL_FUNCTION_LIST, 'functions', self::MODEL_FUNCTION)) + ->setModel(new BaseList('Tags List', self::MODEL_TAG_LIST, 'tags', self::MODEL_TAG)) + ->setModel(new BaseList('Executions List', self::MODEL_EXECUTION_LIST, 'executions', self::MODEL_EXECUTION)) + ->setModel(new BaseList('Projects List', self::MODEL_PROJECT_LIST, 'projects', self::MODEL_PROJECT)) + ->setModel(new BaseList('Webhooks List', self::MODEL_WEBHOOK_LIST, 'webhooks', self::MODEL_WEBHOOK)) + ->setModel(new BaseList('API Keys List', self::MODEL_KEY_LIST, 'keys', self::MODEL_KEY)) + ->setModel(new BaseList('Tasks List', self::MODEL_TASK_LIST, 'tasks', self::MODEL_TASK)) + ->setModel(new BaseList('Platforms List', self::MODEL_PLATFORM_LIST, 'platforms', self::MODEL_PLATFORM)) + ->setModel(new BaseList('Domains List', self::MODEL_DOMAIN_LIST, 'domains', self::MODEL_DOMAIN)) + ->setModel(new BaseList('Countries List', self::MODEL_COUNTRY_LIST, 'countries', self::MODEL_COUNTRY)) + ->setModel(new BaseList('Continents List', self::MODEL_CONTINENT_LIST, 'continents', self::MODEL_CONTINENT)) + ->setModel(new BaseList('Languages List', self::MODEL_LANGUAGE_LIST, 'languages', self::MODEL_LANGUAGE)) + ->setModel(new BaseList('Currencies List', self::MODEL_CURRENCY_LIST, 'currencies', self::MODEL_CURRENCY)) + ->setModel(new BaseList('Phones List', self::MODEL_PHONE_LIST, 'phones', self::MODEL_PHONE)) + // Entities + ->setModel(new Any()) + ->setModel(new Collection()) + ->setModel(new Rule()) + ->setModel(new Log()) ->setModel(new User()) ->setModel(new Session()) ->setModel(new Locale()) + ->setModel(new File()) ->setModel(new Team()) - ->setModel(new TeamList()) ->setModel(new Membership()) - ->setModel(new MembershipList()) + ->setModel(new Func()) + ->setModel(new Tag()) + ->setModel(new Execution()) + ->setModel(new Project()) + ->setModel(new Webhook()) + ->setModel(new Key()) + ->setModel(new Task()) + ->setModel(new Domain()) + ->setModel(new Platform()) + ->setModel(new Country()) + ->setModel(new Continent()) + ->setModel(new Language()) + ->setModel(new Currency()) + ->setModel(new Phone()) + // Verification + // Recovery ; - parent::__construct($time); + parent::__construct($response); } /** @@ -120,29 +224,37 @@ class Response extends UtopiaResponse /** * Generate valid response object from document data */ - protected function output(Document $document, string $model): array + public function output(Document $document, string $model): array { $data = $document; $model = $this->getModel($model); $output = []; + if($model->isAny()) { + return $document->getArrayCopy(); + } + foreach($model->getRules() as $key => $rule) { if(!$document->isSet($key)) { if(!is_null($rule['default'])) { $document->setAttribute($key, $rule['default']); } else { - throw new Exception('Missing response key: '.$key); + throw new Exception('Model '.$model->getName().' is missing response key: '.$key); } } if($rule['array']) { if(!is_array($data[$key])) { - throw new Exception($key.' must be an array of '.$rule['type'].' types'); + throw new Exception($key.' must be an array of type '.$rule['type']); } foreach ($data[$key] as &$item) { - if(array_key_exists($rule['type'], $this->models) && $item instanceof Document) { + if($item instanceof Document) { + if(!array_key_exists($rule['type'], $this->models)) { + throw new Exception('Missing model for rule: '. $rule['type']); + } + $item = $this->output($item, $rule['type']); } } @@ -151,6 +263,8 @@ class Response extends UtopiaResponse $output[$key] = $data[$key]; } + $this->payload = $output; + return $output; } @@ -177,4 +291,12 @@ class Response extends UtopiaResponse ->send(yaml_emit($data, YAML_UTF8_ENCODING)) ; } + + /** + * @return array + */ + public function getPayload():array + { + return $this->payload; + } } diff --git a/src/Appwrite/Utopia/Response/Model.php b/src/Appwrite/Utopia/Response/Model.php index 36a2745e0..225aa685b 100644 --- a/src/Appwrite/Utopia/Response/Model.php +++ b/src/Appwrite/Utopia/Response/Model.php @@ -5,7 +5,12 @@ namespace Appwrite\Utopia\Response; abstract class Model { /** - * @return array + * @var bool + */ + protected $any = false; + + /** + * @var array */ protected $rules = []; @@ -48,4 +53,9 @@ abstract class Model return $this; } + + public function isAny(): bool + { + return $this->any; + } } \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Model/Any.php b/src/Appwrite/Utopia/Response/Model/Any.php new file mode 100644 index 000000000..1a5defec6 --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/Any.php @@ -0,0 +1,34 @@ +addRule('sum', [ + $this->name = $name; + $this->type = $type; + + if($paging) { + $this->addRule('sum', [ 'type' => 'integer', 'description' => 'Total sum of items in the list.', 'example' => '5', - ]) - ; + ]); + } + $this->addRule($key, [ + 'type' => $model, + 'description' => 'List of '.$key.'.', + 'example' => [], + 'array' => true, + ]); } /** @@ -25,7 +44,7 @@ abstract class BaseList extends Model */ public function getName():string { - return 'Base List'; + return $this->name; } /** @@ -35,6 +54,6 @@ abstract class BaseList extends Model */ public function getType():string { - return Response::MODEL_BASE_LIST; + return $this->type; } } \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Model/Collection.php b/src/Appwrite/Utopia/Response/Model/Collection.php new file mode 100644 index 000000000..9c6dd15d6 --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/Collection.php @@ -0,0 +1,68 @@ +addRule('$id', [ + 'type' => 'string', + 'description' => 'Collection ID.', + 'example' => '5e5ea5c16897e', + ]) + ->addRule('$permissions', [ + 'type' => Response::MODEL_PERMISSIONS, + 'description' => 'Collection permissions.', + 'example' => new \stdClass, + 'array' => false, + ]) + ->addRule('name', [ + 'type' => 'string', + 'description' => 'Collection name.', + 'example' => 'Movies', + ]) + ->addRule('dateCreated', [ + 'type' => 'integer', + 'description' => 'Collection creation date in Unix timestamp.', + 'example' => 1592981250, + ]) + ->addRule('dateUpdated', [ + 'type' => 'integer', + 'description' => 'Collection creation date in Unix timestamp.', + 'example' => 1592981550, + ]) + ->addRule('rules', [ + 'type' => Response::MODEL_RULE, + 'description' => 'Collection rules.', + 'example' => [], + 'default' => [], + 'array' => true, + ]) + ; + } + + /** + * Get Name + * + * @return string + */ + public function getName():string + { + return 'Collection'; + } + + /** + * Get Collection + * + * @return string + */ + public function getType():string + { + return Response::MODEL_COLLECTION; + } +} \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Model/Continent.php b/src/Appwrite/Utopia/Response/Model/Continent.php new file mode 100644 index 000000000..a42b39e9e --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/Continent.php @@ -0,0 +1,45 @@ +addRule('name', [ + 'type' => 'string', + 'description' => 'Continent name.', + 'example' => 'Europe', + ]) + ->addRule('code', [ + 'type' => 'string', + 'description' => 'Continent two letter code.', + 'example' => 'EU', + ]) + ; + } + + /** + * Get Name + * + * @return string + */ + public function getName():string + { + return 'Continent'; + } + + /** + * Get Collection + * + * @return string + */ + public function getType():string + { + return Response::MODEL_CONTINENT; + } +} \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Model/Country.php b/src/Appwrite/Utopia/Response/Model/Country.php new file mode 100644 index 000000000..b5ba0f74f --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/Country.php @@ -0,0 +1,45 @@ +addRule('name', [ + 'type' => 'string', + 'description' => 'Country name.', + 'example' => 'United States', + ]) + ->addRule('code', [ + 'type' => 'string', + 'description' => 'Country two-character ISO 3166-1 alpha code.', + 'example' => 'US', + ]) + ; + } + + /** + * Get Name + * + * @return string + */ + public function getName():string + { + return 'Country'; + } + + /** + * Get Collection + * + * @return string + */ + public function getType():string + { + return Response::MODEL_COUNTRY; + } +} \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Model/Currency.php b/src/Appwrite/Utopia/Response/Model/Currency.php new file mode 100644 index 000000000..29b3d78f9 --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/Currency.php @@ -0,0 +1,76 @@ +addRule('symbol', [ + 'type' => 'string', + 'description' => 'Currency symbol.', + 'example' => '$', + ]) + ->addRule('name', [ + 'type' => 'string', + 'description' => 'Currency name.', + 'example' => 'US dollar', + ]) + ->addRule('symbolNative', [ + 'type' => 'string', + 'description' => 'Currency native symbol.', + 'example' => '$', + ]) + ->addRule('decimalDigits', [ + 'type' => 'integer', + 'description' => 'Number of decimal digits.', + 'example' => 2, + ]) + ->addRule('rounding', [ + 'type' => 'float', + 'description' => 'Currency digit rounding.', + 'example' => 0, + ]) + ->addRule('code', [ + 'type' => 'string', + 'description' => 'Currency code in [ISO 4217-1](http://en.wikipedia.org/wiki/ISO_4217) three-character format.', + 'example' => 'USD', + ]) + ->addRule('namePlural', [ + 'type' => 'string', + 'description' => 'Currency plural name', + 'example' => 'US dollars', + ]) + // ->addRule('locations', [ + // 'type' => 'string', + // 'description' => 'Currency locations list. List of location in two-character ISO 3166-1 alpha code.', + // 'example' => ['US'], + // 'array' => true, + // ]) + ; + } + + /** + * Get Name + * + * @return string + */ + public function getName():string + { + return 'Currency'; + } + + /** + * Get Collection + * + * @return string + */ + public function getType():string + { + return Response::MODEL_CURRENCY; + } +} \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Model/Domain.php b/src/Appwrite/Utopia/Response/Model/Domain.php new file mode 100644 index 000000000..f8273ff87 --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/Domain.php @@ -0,0 +1,60 @@ +addRule('$id', [ + 'type' => 'string', + 'description' => 'Domain ID.', + 'example' => '5e5ea5c16897e', + ]) + ->addRule('domain', [ + 'type' => 'string', + 'description' => 'Domain name.', + 'example' => 'appwrite.company.com', + ]) + ->addRule('registerable', [ + 'type' => 'string', + 'description' => 'Registerable domain name.', + 'example' => 'company.com', + ]) + ->addRule('tld', [ + 'type' => 'string', + 'description' => 'TLD name.', + 'example' => 'com', + ]) + ->addRule('verification', [ + 'type' => 'boolean', + 'description' => 'Verification process status.', + 'example' => true, + ]) + ; + } + + /** + * Get Name + * + * @return string + */ + public function getName():string + { + return 'Domain'; + } + + /** + * Get Collection + * + * @return string + */ + public function getType():string + { + return Response::MODEL_DOMAIN; + } +} \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Model/Execution.php b/src/Appwrite/Utopia/Response/Model/Execution.php new file mode 100644 index 000000000..92a00208d --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/Execution.php @@ -0,0 +1,80 @@ +addRule('$id', [ + 'type' => 'string', + 'description' => 'Execution ID.', + 'example' => '5e5ea5c16897e', + ]) + ->addRule('functionId', [ + 'type' => 'string', + 'description' => 'Function ID.', + 'example' => '5e5ea6g16897e', + ]) + ->addRule('dateCreated', [ + 'type' => 'integer', + 'description' => 'The execution creation date in Unix timestamp.', + 'example' => 1592981250, + ]) + ->addRule('trigger', [ + 'type' => 'string', + 'description' => 'The trigger that caused the function to execute. Possible values can be: `http`, `schedule`, or `event`.', + 'example' => 'http', + ]) + ->addRule('status', [ + 'type' => 'string', + 'description' => 'The status of the function execution. Possible values can be: `waiting`, `processing`, `completed`, or `failed`.', + 'example' => 'processing', + ]) + ->addRule('exitCode', [ + 'type' => 'integer', + 'description' => 'The script exit code.', + 'example' => 0, + ]) + ->addRule('stdout', [ + 'type' => 'string', + 'description' => 'The script stdout output string.', + 'example' => '', + ]) + ->addRule('stderr', [ + 'type' => 'string', + 'description' => 'The script stderr output string.', + 'example' => '', + ]) + ->addRule('time', [ + 'type' => 'float', + 'description' => 'The script execution time in seconds.', + 'example' => 0.400, + ]) + ; + } + + /** + * Get Name + * + * @return string + */ + public function getName():string + { + return 'Execution'; + } + + /** + * Get Collection + * + * @return string + */ + public function getType():string + { + return Response::MODEL_EXECUTION; + } +} \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Model/File.php b/src/Appwrite/Utopia/Response/Model/File.php index 875c6f4bd..416a02ac5 100644 --- a/src/Appwrite/Utopia/Response/Model/File.php +++ b/src/Appwrite/Utopia/Response/Model/File.php @@ -9,7 +9,44 @@ class File extends Model { public function __construct() { - + $this + ->addRule('$id', [ + 'type' => 'string', + 'description' => 'File ID.', + 'example' => '5e5ea5c16897e', + ]) + ->addRule('$permissions', [ + 'type' => Response::MODEL_PERMISSIONS, + 'description' => 'File permissions.', + 'example' => new \stdClass, + 'array' => false, + ]) + ->addRule('name', [ + 'type' => 'string', + 'description' => 'File name.', + 'example' => 'Pink.png', + ]) + ->addRule('dateCreated', [ + 'type' => 'integer', + 'description' => 'File creation date in Unix timestamp.', + 'example' => 1592981250, + ]) + ->addRule('signature', [ + 'type' => 'string', + 'description' => 'File MD5 signature.', + 'example' => '5d529fd02b544198ae075bd57c1762bb', + ]) + ->addRule('mimeType', [ + 'type' => 'string', + 'description' => 'File mime type.', + 'example' => 'image/png', + ]) + ->addRule('sizeOriginal', [ + 'type' => 'integer', + 'description' => 'File original size in bytes.', + 'example' => 17890, + ]) + ; } /** @@ -29,6 +66,6 @@ class File extends Model */ public function getType():string { - return Response::MODEL_LOCALE; + return Response::MODEL_FILE; } } \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Model/Func.php b/src/Appwrite/Utopia/Response/Model/Func.php new file mode 100644 index 000000000..e0d359535 --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/Func.php @@ -0,0 +1,108 @@ +addRule('$id', [ + 'type' => 'string', + 'description' => 'Function ID.', + 'example' => '5e5ea5c16897e', + ]) + ->addRule('name', [ + 'type' => 'string', + 'description' => 'Function name.', + 'example' => 'My Function', + ]) + ->addRule('dateCreated', [ + 'type' => 'integer', + 'description' => 'Function creation date in Unix timestamp.', + 'example' => 1592981250, + ]) + ->addRule('dateUpdated', [ + 'type' => 'integer', + 'description' => 'Function update date in Unix timestamp.', + 'example' => 1592981257, + ]) + ->addRule('status', [ + 'type' => 'string', + 'description' => 'Function status. Possible values: disabled, enabled', + 'example' => 'enabled', + ]) + ->addRule('env', [ + 'type' => 'string', + 'description' => 'Function execution environment.', + 'example' => 'python-3.8', + ]) + ->addRule('tag', [ + 'type' => 'string', + 'description' => 'Function active tag ID.', + 'default' => '', + 'example' => '5e5ea5c16897e', + ]) + ->addRule('vars', [ + 'type' => 'json', + 'description' => 'Function environment variables.', + 'default' => new \stdClass, + 'example' => ['key' => 'value'], + ]) + ->addRule('events', [ + 'type' => 'string', + 'description' => 'Function trigger events.', + 'default' => [], + 'example' => ['account.create'], + 'array' => true, + ]) + ->addRule('schedule', [ + 'type' => 'string', + 'description' => 'Function execution schedult in CRON format.', + 'default' => '', + 'example' => '5 4 * * *', + ]) + ->addRule('scheduleNext', [ + 'type' => 'integer', + 'description' => 'Function next scheduled execution date in Unix timestamp.', + 'example' => 1592981292, + 'default' => 0, + ]) + ->addRule('schedulePrevious', [ + 'type' => 'integer', + 'description' => 'Function next scheduled execution date in Unix timestamp.', + 'example' => 1592981237, + 'default' => 0, + ]) + ->addRule('timeout', [ + 'type' => 'integer', + 'description' => 'Function execution timeout in seconds.', + 'default' => 15, + 'example' => 1592981237, + ]) + ; + } + + /** + * Get Name + * + * @return string + */ + public function getName():string + { + return 'Function'; + } + + /** + * Get Collection + * + * @return string + */ + public function getType():string + { + return Response::MODEL_FUNCTION; + } +} \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Model/Key.php b/src/Appwrite/Utopia/Response/Model/Key.php new file mode 100644 index 000000000..99abb38d5 --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/Key.php @@ -0,0 +1,57 @@ +addRule('$id', [ + 'type' => 'string', + 'description' => 'Key ID.', + 'example' => '5e5ea5c16897e', + ]) + ->addRule('name', [ + 'type' => 'string', + 'description' => 'Key name.', + 'example' => 'My API Key', + ]) + ->addRule('scopes', [ + 'type' => 'string', + 'description' => 'Allowed permission scopes.', + 'default' => [], + 'example' => ['users.read', 'documents.write'], + 'array' => true, + ]) + ->addRule('secret', [ + 'type' => 'string', + 'description' => 'Secret key.', + 'example' => '919c2d18fb5d4...a2ae413da83346ad2', + ]) + ; + } + + /** + * Get Name + * + * @return string + */ + public function getName():string + { + return 'Key'; + } + + /** + * Get Collection + * + * @return string + */ + public function getType():string + { + return Response::MODEL_KEY; + } +} \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Model/Language.php b/src/Appwrite/Utopia/Response/Model/Language.php new file mode 100644 index 000000000..966efa7e7 --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/Language.php @@ -0,0 +1,50 @@ +addRule('name', [ + 'type' => 'string', + 'description' => 'Language name.', + 'example' => 'Italian', + ]) + ->addRule('code', [ + 'type' => 'string', + 'description' => 'Language two-character ISO 639-1 codes.', + 'example' => 'it', + ]) + ->addRule('nativeName', [ + 'type' => 'string', + 'description' => 'Language native name.', + 'example' => 'Italiano', + ]) + ; + } + + /** + * Get Name + * + * @return string + */ + public function getName():string + { + return 'Language'; + } + + /** + * Get Collection + * + * @return string + */ + public function getType():string + { + return Response::MODEL_LANGUAGE; + } +} \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Model/Log.php b/src/Appwrite/Utopia/Response/Model/Log.php index 93e7e88ef..35040d018 100644 --- a/src/Appwrite/Utopia/Response/Model/Log.php +++ b/src/Appwrite/Utopia/Response/Model/Log.php @@ -9,6 +9,107 @@ class Log extends Model { public function __construct() { + $this + ->addRule('event', [ + 'type' => 'string', + 'description' => 'Event name.', + 'example' => 'account.sessions.create', + ]) + ->addRule('ip', [ + 'type' => 'string', + 'description' => 'IP session in use when the session was created.', + 'example' => '127.0.0.1', + ]) + ->addRule('time', [ + 'type' => 'integer', + 'description' => 'Log creation time in Unix timestamp.', + 'example' => 1592981250, + ]) + ->addRule('osCode', [ + 'type' => 'string', + 'description' => 'Operating system code name. View list of [available options](https://github.com/appwrite/appwrite/blob/master/docs/lists/os.json).', + 'default' => '', + 'example' => 'Mac', + ]) + ->addRule('osName', [ + 'type' => 'string', + 'description' => 'Operating system name.', + 'default' => '', + 'example' => 'Mac', + ]) + ->addRule('osVersion', [ + 'type' => 'string', + 'description' => 'Operating system version.', + 'default' => '', + 'example' => 'Mac', + ]) + ->addRule('clientType', [ + 'type' => 'string', + 'description' => 'Client type.', + 'default' => '', + 'example' => 'browser', + ]) + ->addRule('clientCode', [ + 'type' => 'string', + 'description' => 'Client code name. View list of [available options](https://github.com/appwrite/appwrite/blob/master/docs/lists/clients.json).', + 'default' => '', + 'example' => 'CM', + ]) + ->addRule('clientName', [ + 'type' => 'string', + 'description' => 'Client name.', + 'default' => '', + 'example' => 'Chrome Mobile iOS', + ]) + ->addRule('clientVersion', [ + 'type' => 'string', + 'description' => 'Client version.', + 'default' => '', + 'example' => '84.0', + ]) + ->addRule('clientEngine', [ + 'type' => 'string', + 'description' => 'Client engine name.', + 'default' => '', + 'example' => 'WebKit', + ]) + ->addRule('clientEngineVersion', [ + 'type' => 'string', + 'description' => 'Client engine name.', + 'default' => '', + 'example' => '605.1.15', + ]) + ->addRule('deviceName', [ + 'type' => 'string', + 'description' => 'Device name.', + 'default' => '', + 'example' => 'smartphone', + ]) + ->addRule('deviceBrand', [ + 'type' => 'string', + 'description' => 'Device brand name.', + 'default' => '', + 'example' => 'Google', + ]) + ->addRule('deviceModel', [ + 'type' => 'string', + 'description' => 'Device model name.', + 'default' => '', + 'example' => 'Nexus 5', + ]) + ->addRule('countryCode', [ + 'type' => 'string', + 'description' => 'Country two-character ISO 3166-1 alpha code.', + 'default' => '', + 'example' => 'US', + ]) + ->addRule('countryName', [ + 'type' => 'string', + 'description' => 'Country name.', + 'default' => '', + 'example' => 'United States', + ]) + ; } /** @@ -18,7 +119,7 @@ class Log extends Model */ public function getName():string { - return 'Session'; + return 'Log'; } /** @@ -28,6 +129,6 @@ class Log extends Model */ public function getType():string { - return Response::MODEL_LOCALE; + return Response::MODEL_LOG; } } \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Model/MembershipList.php b/src/Appwrite/Utopia/Response/Model/MembershipList.php deleted file mode 100644 index 56937c8d3..000000000 --- a/src/Appwrite/Utopia/Response/Model/MembershipList.php +++ /dev/null @@ -1,41 +0,0 @@ -addRule('memberships', [ - 'type' => Response::MODEL_MEMBERSHIP, - 'description' => 'List of memberships.', - 'example' => [], - 'array' => true, - ]) - ; - } - - /** - * Get Name - * - * @return string - */ - public function getName():string - { - return 'Membership List'; - } - - /** - * Get Collection - * - * @return string - */ - public function getType():string - { - return Response::MODEL_MEMBERSHIP_LIST; - } -} \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Model/Permissions.php b/src/Appwrite/Utopia/Response/Model/Permissions.php new file mode 100644 index 000000000..8f14ccb86 --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/Permissions.php @@ -0,0 +1,47 @@ +addRule('read', [ + 'type' => 'string', + 'description' => 'Read permissions.', + 'example' => ['*', 'user:5e5ea5c16897e'], + 'array' => true, + ]) + ->addRule('write', [ + 'type' => 'string', + 'description' => 'Write permissions.', + 'example' => ['*', 'user:5e5ea5c16897e'], + 'array' => true, + ]) + ; + } + + /** + * Get Name + * + * @return string + */ + public function getName():string + { + return 'Permissions'; + } + + /** + * Get Collection + * + * @return string + */ + public function getType():string + { + return Response::MODEL_PERMISSIONS; + } +} \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Model/Phone.php b/src/Appwrite/Utopia/Response/Model/Phone.php new file mode 100644 index 000000000..e0242981e --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/Phone.php @@ -0,0 +1,50 @@ +addRule('code', [ + 'type' => 'string', + 'description' => 'Phone code.', + 'example' => '+1', + ]) + ->addRule('countryCode', [ + 'type' => 'string', + 'description' => 'Country two-character ISO 3166-1 alpha code.', + 'example' => 'US', + ]) + ->addRule('countryName', [ + 'type' => 'string', + 'description' => 'Country name.', + 'example' => 'United States', + ]) + ; + } + + /** + * Get Name + * + * @return string + */ + public function getName():string + { + return 'Phone'; + } + + /** + * Get Collection + * + * @return string + */ + public function getType():string + { + return Response::MODEL_PHONE; + } +} \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Model/Platform.php b/src/Appwrite/Utopia/Response/Model/Platform.php new file mode 100644 index 000000000..861300f88 --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/Platform.php @@ -0,0 +1,77 @@ +addRule('$id', [ + 'type' => 'string', + 'description' => 'Platform ID.', + 'example' => '5e5ea5c16897e', + ]) + ->addRule('name', [ + 'type' => 'string', + 'description' => 'Platform name.', + 'example' => 'My Web App', + ]) + ->addRule('type', [ + 'type' => 'string', + 'description' => 'Platform type. Possible values are: web, flutter-ios, flutter-android, ios, android, and unity.', + 'example' => 'My Web App', + ]) + ->addRule('key', [ + 'type' => 'string', + 'description' => 'Platform Key. iOS bundle ID or Android package name. Empty string for other platforms.', + 'example' => 'com.company.appname', + ]) + // ->addRule('store', [ + // 'type' => 'string', + // 'description' => 'Link to platform store.', + // 'example' => '', + // ]) + ->addRule('hostname', [ + 'type' => 'string', + 'description' => 'Web app hostname. Empty string for other platforms.', + 'example' => true, + ]) + ->addRule('httpUser', [ + 'type' => 'string', + 'description' => 'HTTP basic authentication username.', + 'default' => '', + 'example' => 'username', + ]) + ->addRule('httpPass', [ + 'type' => 'string', + 'description' => 'HTTP basic authentication password.', + 'default' => '', + 'example' => 'password', + ]) + ; + } + + /** + * Get Name + * + * @return string + */ + public function getName():string + { + return 'Platform'; + } + + /** + * Get Collection + * + * @return string + */ + public function getType():string + { + return Response::MODEL_PLATFORM; + } +} \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Model/Project.php b/src/Appwrite/Utopia/Response/Model/Project.php new file mode 100644 index 000000000..af5cad3eb --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/Project.php @@ -0,0 +1,166 @@ +addRule('$id', [ + 'type' => 'string', + 'description' => 'Project ID.', + 'example' => '5e5ea5c16897e', + ]) + ->addRule('name', [ + 'type' => 'string', + 'description' => 'Project name.', + 'default' => '', + 'example' => 'New Project', + ]) + ->addRule('description', [ + 'type' => 'string', + 'description' => 'Project description.', + 'default' => '', + 'example' => 'This is a new project.', + ]) + ->addRule('teamId', [ + 'type' => 'string', + 'description' => 'Project team ID.', + 'example' => '1592981250', + ]) + ->addRule('logo', [ + 'type' => 'string', + 'description' => 'Project logo file ID.', + 'default' => '', + 'example' => '5f5c451b403cb', + ]) + ->addRule('url', [ + 'type' => 'string', + 'description' => 'Project website URL.', + 'default' => '', + 'example' => '5f5c451b403cb', + ]) + ->addRule('legalName', [ + 'type' => 'string', + 'description' => 'Company legal name.', + 'default' => '', + 'example' => 'Company LTD.', + ]) + ->addRule('legalCountry', [ + 'type' => 'string', + 'description' => 'Country code in [ISO 3166-1](http://en.wikipedia.org/wiki/ISO_3166-1) two-character format.', + 'default' => '', + 'example' => 'US', + ]) + ->addRule('legalState', [ + 'type' => 'string', + 'description' => 'State name.', + 'default' => '', + 'example' => 'New York', + ]) + ->addRule('legalCity', [ + 'type' => 'string', + 'description' => 'City name.', + 'default' => '', + 'example' => 'New York City.', + ]) + ->addRule('legalAddress', [ + 'type' => 'string', + 'description' => 'Company Address.', + 'default' => '', + 'example' => '620 Eighth Avenue, New York, NY 10018', + ]) + ->addRule('legalTaxId', [ + 'type' => 'string', + 'description' => 'Company Tax ID.', + 'default' => '', + 'example' => '131102020', + ]) + ->addRule('platforms', [ + 'type' => Response::MODEL_PLATFORM, + 'description' => 'List of Platforms.', + 'default' => [], + 'example' => [], + 'array' => true, + ]) + ->addRule('webhooks', [ + 'type' => Response::MODEL_WEBHOOK, + 'description' => 'List of Webhooks.', + 'default' => [], + 'example' => [], + 'array' => true, + ]) + ->addRule('keys', [ + 'type' => Response::MODEL_KEY, + 'description' => 'List of API Keys.', + 'default' => [], + 'example' => [], + 'array' => true, + ]) + ->addRule('domains', [ + 'type' => Response::MODEL_DOMAIN, + 'description' => 'List of Domains.', + 'default' => [], + 'example' => [], + 'array' => true, + ]) + ->addRule('tasks', [ + 'type' => Response::MODEL_TASK, + 'description' => 'List of Tasks.', + 'default' => [], + 'example' => [], + 'array' => true, + ]) + ; + + $providers = Config::getParam('providers', []); + + foreach ($providers as $index => $provider) { + if (!$provider['enabled']) { + continue; + } + + $name = (isset($provider['name'])) ? $provider['name'] : 'Unknown'; + + $this + ->addRule('usersOauth2'.\ucfirst($index).'Appid', [ + 'type' => 'string', + 'description' => $name.' OAuth app ID.', + 'example' => '123247283472834787438', + 'default' => '', + ]) + ->addRule('usersOauth2'.\ucfirst($index).'Secret', [ + 'type' => 'string', + 'description' => $name.' OAuth secret ID.', + 'example' => 'djsgudsdsewe43434343dd34...', + 'default' => '', + ]) + ; + } + } + + /** + * Get Name + * + * @return string + */ + public function getName():string + { + return 'Project'; + } + + /** + * Get Collection + * + * @return string + */ + public function getType():string + { + return Response::MODEL_PROJECT; + } +} \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Model/Rule.php b/src/Appwrite/Utopia/Response/Model/Rule.php new file mode 100644 index 000000000..234377c43 --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/Rule.php @@ -0,0 +1,83 @@ +addRule('$id', [ + 'type' => 'string', + 'description' => 'Rule ID.', + 'example' => '5e5ea5c16897e', + ]) + ->addRule('$collection', [ // TODO remove this from public response + 'type' => 'string', + 'description' => 'Rule Collection.', + 'example' => '5e5e66c16897e', + ]) + ->addRule('type', [ + 'type' => 'string', + 'description' => 'Rule type. Possible values: ', + 'example' => 'title', + ]) + ->addRule('key', [ + 'type' => 'string', + 'description' => 'Rule key.', + 'example' => 'title', + ]) + ->addRule('label', [ + 'type' => 'string', + 'description' => 'Rule label.', + 'example' => 'Title', + ]) + ->addRule('default', [ // TODO should be of mixed types + 'type' => 'string', + 'description' => 'Rule default value.', + 'example' => 'Movie Name', + 'default' => '', + ]) + ->addRule('array', [ + 'type' => 'boolean', + 'description' => 'Is array?', + 'example' => false, + ]) + ->addRule('required', [ + 'type' => 'boolean', + 'description' => 'Is required?', + 'example' => true, + ]) + ->addRule('list', [ + 'type' => 'string', + 'description' => 'List of allowed values', + 'array' => true, + 'default' => [], + 'example' => ['5e5ea5c168099'], + ]) + ; + } + + /** + * Get Name + * + * @return string + */ + public function getName():string + { + return 'Rule'; + } + + /** + * Get Collection + * + * @return string + */ + public function getType():string + { + return Response::MODEL_RULE; + } +} \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Model/Session.php b/src/Appwrite/Utopia/Response/Model/Session.php index 6146feb31..2e22513fd 100644 --- a/src/Appwrite/Utopia/Response/Model/Session.php +++ b/src/Appwrite/Utopia/Response/Model/Session.php @@ -16,15 +16,107 @@ class Session extends Model 'example' => '5e5ea5c16897e', ]) ->addRule('expire', [ - 'type' => 'string', + 'type' => 'integer', 'description' => 'Session expiration date in Unix timestamp.', + 'default' => 0, 'example' => 1592981250, ]) ->addRule('ip', [ 'type' => 'string', - 'description' => 'IP session in use when the session was created.', + 'description' => 'IP in use when the session was created.', + 'default' => '', 'example' => '127.0.0.1', ]) + ->addRule('osCode', [ + 'type' => 'string', + 'description' => 'Operating system code name. View list of [available options](https://github.com/appwrite/appwrite/blob/master/docs/lists/os.json).', + 'default' => '', + 'example' => 'Mac', + ]) + ->addRule('osName', [ + 'type' => 'string', + 'description' => 'Operating system name.', + 'default' => '', + 'example' => 'Mac', + ]) + ->addRule('osVersion', [ + 'type' => 'string', + 'description' => 'Operating system version.', + 'default' => '', + 'example' => 'Mac', + ]) + ->addRule('clientType', [ + 'type' => 'string', + 'description' => 'Client type.', + 'default' => '', + 'example' => 'browser', + ]) + ->addRule('clientCode', [ + 'type' => 'string', + 'description' => 'Client code name. View list of [available options](https://github.com/appwrite/appwrite/blob/master/docs/lists/clients.json).', + 'default' => '', + 'example' => 'CM', + ]) + ->addRule('clientName', [ + 'type' => 'string', + 'description' => 'Client name.', + 'default' => '', + 'example' => 'Chrome Mobile iOS', + ]) + ->addRule('clientVersion', [ + 'type' => 'string', + 'description' => 'Client version.', + 'default' => '', + 'example' => '84.0', + ]) + ->addRule('clientEngine', [ + 'type' => 'string', + 'description' => 'Client engine name.', + 'default' => '', + 'example' => 'WebKit', + ]) + ->addRule('clientEngineVersion', [ + 'type' => 'string', + 'description' => 'Client engine name.', + 'default' => '', + 'example' => '605.1.15', + ]) + ->addRule('deviceName', [ + 'type' => 'string', + 'description' => 'Device name.', + 'default' => '', + 'example' => 'smartphone', + ]) + ->addRule('deviceBrand', [ + 'type' => 'string', + 'description' => 'Device brand name.', + 'default' => '', + 'example' => 'Google', + ]) + ->addRule('deviceModel', [ + 'type' => 'string', + 'description' => 'Device model name.', + 'default' => '', + 'example' => 'Nexus 5', + ]) + ->addRule('countryCode', [ + 'type' => 'string', + 'description' => 'Country two-character ISO 3166-1 alpha code.', + 'default' => '', + 'example' => 'US', + ]) + ->addRule('countryName', [ + 'type' => 'string', + 'description' => 'Country name.', + 'default' => '', + 'example' => 'United States', + ]) + ->addRule('current', [ + 'type' => 'boolean', + 'description' => 'Returns true if this the current user session.', + 'default' => '', + 'example' => true, + ]) ; } diff --git a/src/Appwrite/Utopia/Response/Model/Tag.php b/src/Appwrite/Utopia/Response/Model/Tag.php new file mode 100644 index 000000000..4b6facab8 --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/Tag.php @@ -0,0 +1,60 @@ +addRule('$id', [ + 'type' => 'string', + 'description' => 'Tag ID.', + 'example' => '5e5ea5c16897e', + ]) + ->addRule('functionId', [ + 'type' => 'string', + 'description' => 'Function ID.', + 'example' => '5e5ea6g16897e', + ]) + ->addRule('dateCreated', [ + 'type' => 'integer', + 'description' => 'The tag creation date in Unix timestamp.', + 'example' => 1592981250, + ]) + ->addRule('command', [ + 'type' => 'string', + 'description' => 'The entrypoint command in use to execute the tag code.', + 'example' => 'enabled', + ]) + ->addRule('size', [ + 'type' => 'string', + 'description' => 'The code size in bytes.', + 'example' => 'python-3.8', + ]) + ; + } + + /** + * Get Name + * + * @return string + */ + public function getName():string + { + return 'Tag'; + } + + /** + * Get Collection + * + * @return string + */ + public function getType():string + { + return Response::MODEL_TAG; + } +} \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Model/Task.php b/src/Appwrite/Utopia/Response/Model/Task.php new file mode 100644 index 000000000..e2ab652fe --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/Task.php @@ -0,0 +1,125 @@ +addRule('$id', [ + 'type' => 'string', + 'description' => 'Task ID.', + 'example' => '5e5ea5c16897e', + ]) + ->addRule('name', [ + 'type' => 'string', + 'description' => 'Task name.', + 'example' => 'My Task', + ]) + ->addRule('security', [ + 'type' => 'boolean', + 'description' => 'Indicated if SSL / TLS Certificate verification is enabled.', + 'example' => true, + ]) + ->addRule('httpMethod', [ + 'type' => 'string', + 'description' => 'Task HTTP Method.', + 'example' => 'POST', + ]) + ->addRule('httpUrl', [ + 'type' => 'string', + 'description' => 'Task HTTP URL.', + 'example' => 'https://example.com/task', + ]) + ->addRule('httpHeaders', [ + 'type' => 'string', + 'description' => 'Task HTTP headers.', + 'default' => [], + 'example' => ['key:value'], + 'array' => true, + ]) + ->addRule('httpUser', [ + 'type' => 'string', + 'description' => 'HTTP basic authentication username.', + 'default' => '', + 'example' => 'username', + ]) + ->addRule('httpPass', [ + 'type' => 'string', + 'description' => 'HTTP basic authentication password.', + 'default' => '', + 'example' => 'password', + ]) + ->addRule('duration', [ + 'type' => 'float', + 'description' => 'Task duration in seconds.', + 'default' => 0, + 'example' => 1.2, + ]) + ->addRule('delay', [ + 'type' => 'float', + 'description' => 'Task delay time in seconds.', + 'default' => 0, + 'example' => 1.2, + ]) + ->addRule('failures', [ + 'type' => 'integer', + 'description' => 'Number of recurring task failures.', + 'default' => 0, + 'example' => 0, + ]) + ->addRule('schedule', [ + 'type' => 'string', + 'description' => 'Task schedule in CRON syntax.', + 'example' => '* * * * *', + ]) + ->addRule('status', [ + 'type' => 'string', + 'description' => 'Task status. Possible values: play, pause', // TODO - change to enabled disabled + 'example' => 'enabled', + ]) + ->addRule('updated', [ + 'type' => 'integer', + 'description' => 'Task last updated time in Unix timestamp.', + 'default' => 0, + 'example' => 1592981250, + ]) + ->addRule('previous', [ + 'type' => 'integer', + 'description' => 'Task previous run time in Unix timestamp.', + 'default' => 0, + 'example' => 1592981250, + ]) + ->addRule('next', [ + 'type' => 'integer', + 'description' => 'Task next run time in Unix timestamp.', + 'default' => 0, + 'example' => 1592981650, + ]) + ; + } + + /** + * Get Name + * + * @return string + */ + public function getName():string + { + return 'Task'; + } + + /** + * Get Collection + * + * @return string + */ + public function getType():string + { + return Response::MODEL_TASK; + } +} \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Model/TeamList.php b/src/Appwrite/Utopia/Response/Model/TeamList.php deleted file mode 100644 index c96e4cd0d..000000000 --- a/src/Appwrite/Utopia/Response/Model/TeamList.php +++ /dev/null @@ -1,41 +0,0 @@ -addRule('teams', [ - 'type' => Response::MODEL_TEAM, - 'description' => 'List of teams.', - 'example' => [], - 'array' => true, - ]) - ; - } - - /** - * Get Name - * - * @return string - */ - public function getName():string - { - return 'Team List'; - } - - /** - * Get Collection - * - * @return string - */ - public function getType():string - { - return Response::MODEL_TEAM_LIST; - } -} \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Model/User.php b/src/Appwrite/Utopia/Response/Model/User.php index 56af2156c..25b50cfa2 100644 --- a/src/Appwrite/Utopia/Response/Model/User.php +++ b/src/Appwrite/Utopia/Response/Model/User.php @@ -18,7 +18,6 @@ class User extends Model ->addRule('name', [ 'type' => 'string', 'description' => 'User name.', - 'default' => '', 'example' => 'John Doe', ]) ->addRule('registration', [ @@ -29,13 +28,11 @@ class User extends Model ->addRule('status', [ 'type' => 'integer', 'description' => 'User status. 0 for Unavtivated, 1 for active and 2 is blocked.', - 'default' => false, - 'example' => true, + 'example' => 0, ]) ->addRule('email', [ 'type' => 'string', 'description' => 'User email address.', - 'default' => '', 'example' => 'john@appwrite.io', ]) ->addRule('emailVerification', [ @@ -48,7 +45,7 @@ class User extends Model 'type' => 'json', 'description' => 'User preferences as a key-value object', 'default' => new \stdClass, - 'example' => ['theme' => 'dark', 'timezone' => 'UTC'], + 'example' => ['theme' => 'pink', 'timezone' => 'UTC'], ]) ->addRule('roles', [ 'type' => 'string', diff --git a/src/Appwrite/Utopia/Response/Model/Webhook.php b/src/Appwrite/Utopia/Response/Model/Webhook.php new file mode 100644 index 000000000..e3fe565af --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/Webhook.php @@ -0,0 +1,74 @@ +addRule('$id', [ + 'type' => 'string', + 'description' => 'Webhook ID.', + 'example' => '5e5ea5c16897e', + ]) + ->addRule('name', [ + 'type' => 'string', + 'description' => 'Webhook name.', + 'example' => 'My Webhook', + ]) + ->addRule('url', [ + 'type' => 'string', + 'description' => 'Webhook URL endpoint.', + 'example' => 'https://example.com/webhook', + ]) + ->addRule('events', [ + 'type' => 'string', + 'description' => 'Webhook trigger events.', + 'default' => [], + 'example' => ['database.collections.update', 'database.collections.delete'], + 'array' => true, + ]) + ->addRule('security', [ + 'type' => 'boolean', + 'description' => 'Indicated if SSL / TLS Certificate verification is enabled.', + 'example' => true, + ]) + ->addRule('httpUser', [ + 'type' => 'string', + 'description' => 'HTTP basic authentication username.', + 'default' => '', + 'example' => 'username', + ]) + ->addRule('httpPass', [ + 'type' => 'string', + 'description' => 'HTTP basic authentication password.', + 'default' => '', + 'example' => 'password', + ]) + ; + } + + /** + * Get Name + * + * @return string + */ + public function getName():string + { + return 'Webhook'; + } + + /** + * Get Collection + * + * @return string + */ + public function getType():string + { + return Response::MODEL_WEBHOOK; + } +} \ No newline at end of file diff --git a/tests/unit/Swoole/FilesTest.php b/tests/unit/Swoole/FilesTest.php deleted file mode 100644 index adcf4b4fc..000000000 --- a/tests/unit/Swoole/FilesTest.php +++ /dev/null @@ -1,48 +0,0 @@ -assertGreaterThan(100, Files::getCount()); - $this->assertLessThan(250, Files::getCount()); - - $this->assertEquals(false, Files::isFileLoaded('/index.php')); - $this->assertEquals(false, Files::isFileLoaded('/unknown.jpg')); - $this->assertEquals(true, Files::isFileLoaded('/scripts/app.js')); - $this->assertEquals(true, Files::isFileLoaded('/styles/default.less')); - $this->assertEquals(true, Files::isFileLoaded('/dist/scripts/app.js')); - $this->assertEquals(true, Files::isFileLoaded('/dist/styles/default-ltr.css')); - $this->assertEquals(true, Files::isFileLoaded('/dist/styles/default-rtl.css')); - - $this->assertEquals('application/vnd.ms-fontobject', Files::getFileMimeType('/fonts/poppins-v9-latin-100.eot')); - $this->assertEquals('image/svg+xml', Files::getFileMimeType('/fonts/poppins-v9-latin-100.svg')); - $this->assertEquals('font/sfnt', Files::getFileMimeType('/fonts/poppins-v9-latin-100.ttf')); - $this->assertEquals('application/octet-stream', Files::getFileMimeType('/fonts/poppins-v9-latin-100.woff')); - $this->assertEquals('application/octet-stream', Files::getFileMimeType('/fonts/poppins-v9-latin-100.woff2')); - $this->assertEquals('image/png', Files::getFileMimeType('/images/apple.png')); - $this->assertEquals('text/javascript', Files::getFileMimeType('/dist/scripts/app.js')); - $this->assertEquals('text/javascript', Files::getFileMimeType('/dist/scripts/app.js')); - $this->assertEquals('text/css', Files::getFileMimeType('/dist/styles/default-ltr.css')); - $this->assertEquals('text/css', Files::getFileMimeType('/dist/styles/default-rtl.css')); - - $this->assertNotEmpty(Files::getFileContents('/fonts/poppins-v9-latin-100.eot')); - $this->assertNotEmpty(Files::getFileContents('/fonts/poppins-v9-latin-100.svg')); - $this->assertNotEmpty(Files::getFileContents('/fonts/poppins-v9-latin-100.ttf')); - $this->assertNotEmpty(Files::getFileContents('/fonts/poppins-v9-latin-100.woff')); - $this->assertNotEmpty(Files::getFileMimeType('/fonts/poppins-v9-latin-100.woff2')); - $this->assertNotEmpty(Files::getFileContents('/images/apple.png')); - $this->assertNotEmpty(Files::getFileContents('/dist/scripts/app.js')); - $this->assertNotEmpty(Files::getFileContents('/dist/scripts/app.js')); - $this->assertNotEmpty(Files::getFileContents('/dist/styles/default-ltr.css')); - $this->assertNotEmpty(Files::getFileContents('/dist/styles/default-rtl.css')); - - } -} \ No newline at end of file From afa210f4a25b37db36634980410ab8dac6047684 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Thu, 29 Oct 2020 15:18:21 +0200 Subject: [PATCH 15/40] Updated static files class --- app/http.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/http.php b/app/http.php index 5bbdc87df..07e0fff45 100644 --- a/app/http.php +++ b/app/http.php @@ -2,7 +2,7 @@ require_once __DIR__.'/../vendor/autoload.php'; -use Appwrite\Swoole\Files; +use Utopia\Swoole\Files; use Utopia\Swoole\Request; use Appwrite\Utopia\Response; use Swoole\Process; From 07b79c31035e8a9cbd4d8c5f900f5f0a0e6800fb Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Thu, 29 Oct 2020 15:50:49 +0200 Subject: [PATCH 16/40] Updated docs --- app/controllers/api/account.php | 40 ++++++++++---------- app/controllers/api/avatars.php | 10 ++--- app/controllers/api/database.php | 20 +++++----- app/controllers/api/functions.php | 2 +- app/controllers/api/health.php | 28 +++++++------- app/controllers/api/locale.php | 14 +++---- app/controllers/api/projects.php | 62 +++++++++++++++---------------- app/controllers/api/storage.php | 16 ++++---- app/controllers/api/teams.php | 18 ++++----- app/controllers/api/users.php | 22 +++++------ app/controllers/general.php | 4 +- app/controllers/shared/api.php | 2 +- app/controllers/shared/web.php | 2 +- app/controllers/web/console.php | 4 +- app/controllers/web/home.php | 6 +-- app/init.php | 2 +- 16 files changed, 126 insertions(+), 126 deletions(-) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 658b200ec..ac6d1a550 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -56,7 +56,7 @@ App::post('/v1/account') ->param('name', '', new Text(128), 'User name. Max length: 128 chars.', true) ->action(function ($email, $password, $name, $request, $response, $project, $projectDB, $webhooks, $audits) use ($oauth2Keys) { /** @var Utopia\Swoole\Request $request */ - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Document $project */ /** @var Appwrite\Database\Database $projectDB */ /** @var Appwrite\Event\Event $webhooks */ @@ -262,7 +262,7 @@ App::get('/v1/account/sessions/oauth2/:provider') ->param('scopes', [], new ArrayList(new Text(128)), 'A list of custom OAuth2 scopes. Check each provider internal docs for a list of supported scopes.', true) ->action(function ($provider, $success, $failure, $scopes, $request, $response, $project) { /** @var Utopia\Swoole\Request $request */ - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Document $project */ $protocol = $request->getProtocol(); @@ -307,7 +307,7 @@ App::get('/v1/account/sessions/oauth2/callback/:provider/:projectId') ->param('state', '', new Text(2048), 'Login state params.', true) ->action(function ($projectId, $provider, $code, $state, $request, $response) { /** @var Utopia\Swoole\Request $request */ - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ $domain = $request->getHostname(); $protocol = $request->getProtocol(); @@ -332,7 +332,7 @@ App::post('/v1/account/sessions/oauth2/callback/:provider/:projectId') ->param('state', '', new Text(2048), 'Login state params.', true) ->action(function ($projectId, $provider, $code, $state, $request, $response) { /** @var Utopia\Swoole\Request $request */ - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ $domain = $request->getHostname(); $protocol = $request->getProtocol(); @@ -358,7 +358,7 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect') ->param('state', '', new Text(2048), 'OAuth2 state params.', true) ->action(function ($provider, $code, $state, $request, $response, $project, $user, $projectDB, $audits) use ($oauthDefaultSuccess) { /** @var Utopia\Swoole\Request $request */ - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Document $project */ /** @var Appwrite\Database\Document $user */ /** @var Appwrite\Database\Database $projectDB */ @@ -553,7 +553,7 @@ App::get('/v1/account') ->label('sdk.description', '/docs/references/account/get.md') ->label('sdk.response', ['200' => 'user']) ->action(function ($response, $user) use ($oauth2Keys) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Document $user */ $response->json(\array_merge($user->getArrayCopy(\array_merge( @@ -577,7 +577,7 @@ App::get('/v1/account/prefs') ->label('sdk.method', 'getPrefs') ->label('sdk.description', '/docs/references/account/get-prefs.md') ->action(function ($response, $user) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Document $user */ $prefs = $user->getAttribute('prefs', '{}'); @@ -601,7 +601,7 @@ App::get('/v1/account/sessions') ->label('sdk.method', 'getSessions') ->label('sdk.description', '/docs/references/account/get-sessions.md') ->action(function ($response, $user, $locale, $geodb) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Document $user */ /** @var Utopia\Locale\Locale $locale */ /** @var MaxMind\Db\Reader $geodb */ @@ -669,7 +669,7 @@ App::get('/v1/account/logs') ->label('sdk.method', 'getLogs') ->label('sdk.description', '/docs/references/account/get-logs.md') ->action(function ($response, $register, $project, $user, $locale, $geodb) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Document $project */ /** @var Appwrite\Database\Document $user */ /** @var Utopia\Locale\Locale $locale */ @@ -753,7 +753,7 @@ App::patch('/v1/account/name') ->label('sdk.description', '/docs/references/account/update-name.md') ->param('name', '', new Text(128), 'User name. Max length: 128 chars.') ->action(function ($name, $response, $user, $projectDB, $audits) use ($oauth2Keys) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Document $user */ /** @var Appwrite\Database\Database $projectDB */ /** @var Appwrite\Event\Event $audits */ @@ -795,7 +795,7 @@ App::patch('/v1/account/password') ->param('password', '', new Password(), 'New user password. Must be between 6 to 32 chars.') ->param('oldPassword', '', new Password(), 'Old user password. Must be between 6 to 32 chars.') ->action(function ($password, $oldPassword, $response, $user, $projectDB, $audits) use ($oauth2Keys) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Document $user */ /** @var Appwrite\Database\Database $projectDB */ /** @var Appwrite\Event\Event $audits */ @@ -841,7 +841,7 @@ App::patch('/v1/account/email') ->param('email', '', new Email(), 'User email.') ->param('password', '', new Password(), 'User password. Must be between 6 to 32 chars.') ->action(function ($email, $password, $response, $user, $projectDB, $audits) use ($oauth2Keys) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Document $user */ /** @var Appwrite\Database\Database $projectDB */ /** @var Appwrite\Event\Event $audits */ @@ -901,7 +901,7 @@ App::patch('/v1/account/prefs') ->param('prefs', '', new Assoc(), 'Prefs key-value JSON object.') ->label('sdk.description', '/docs/references/account/update-prefs.md') ->action(function ($prefs, $response, $user, $projectDB, $audits) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Document $user */ /** @var Appwrite\Database\Database $projectDB */ /** @var Appwrite\Event\Event $audits */ @@ -945,7 +945,7 @@ App::delete('/v1/account') ->label('sdk.description', '/docs/references/account/delete.md') ->action(function ($request, $response, $user, $projectDB, $audits, $webhooks) { /** @var Utopia\Swoole\Request $request */ - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Document $user */ /** @var Appwrite\Database\Database $projectDB */ /** @var Appwrite\Event\Event $audits */ @@ -1008,7 +1008,7 @@ App::delete('/v1/account/sessions/:sessionId') ->param('sessionId', null, new UID(), 'Session unique ID. Use the string \'current\' to delete the current device session.') ->action(function ($sessionId, $request, $response, $user, $projectDB, $audits, $webhooks) { /** @var Utopia\Swoole\Request $request */ - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Document $user */ /** @var Appwrite\Database\Database $projectDB */ /** @var Appwrite\Event\Event $audits */ @@ -1072,7 +1072,7 @@ App::delete('/v1/account/sessions') ->label('abuse-limit', 100) ->action(function ($request, $response, $user, $projectDB, $audits, $webhooks) { /** @var Utopia\Swoole\Request $request */ - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Document $user */ /** @var Appwrite\Database\Database $projectDB */ /** @var Appwrite\Event\Event $audits */ @@ -1130,7 +1130,7 @@ App::post('/v1/account/recovery') ->param('url', '', function ($clients) { return new Host($clients); }, 'URL to redirect the user back to your app from the recovery email. Only URLs from hostnames in your project platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API.', false, ['clients']) ->action(function ($email, $url, $request, $response, $projectDB, $project, $locale, $mails, $audits) { /** @var Utopia\Swoole\Request $request */ - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $projectDB */ /** @var Appwrite\Database\Document $project */ /** @var Utopia\Locale\Locale $locale */ @@ -1237,7 +1237,7 @@ App::put('/v1/account/recovery') ->param('password', '', new Password(), 'New password. Must be between 6 to 32 chars.') ->param('passwordAgain', '', new Password(), 'New password again. Must be between 6 to 32 chars.') ->action(function ($userId, $secret, $password, $passwordAgain, $response, $projectDB, $audits) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $projectDB */ /** @var Appwrite\Event\Event $audits */ @@ -1307,7 +1307,7 @@ App::post('/v1/account/verification') ->param('url', '', function ($clients) { return new Host($clients); }, 'URL to redirect the user back to your app from the verification email. Only URLs from hostnames in your project platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API.', false, ['clients']) // TODO add built-in confirm page ->action(function ($url, $request, $response, $project, $user, $projectDB, $locale, $audits, $mails) { /** @var Utopia\Swoole\Request $request */ - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Document $project */ /** @var Appwrite\Database\Document $user */ /** @var Appwrite\Database\Database $projectDB */ @@ -1402,7 +1402,7 @@ App::put('/v1/account/verification') ->param('userId', '', new UID(), 'User unique ID.') ->param('secret', '', new Text(256), 'Valid verification token.') ->action(function ($userId, $secret, $response, $user, $projectDB, $audits) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Document $user */ /** @var Appwrite\Database\Database $projectDB */ /** @var Appwrite\Event\Event $audits */ diff --git a/app/controllers/api/avatars.php b/app/controllers/api/avatars.php index 5a3e9e48d..5b75073f2 100644 --- a/app/controllers/api/avatars.php +++ b/app/controllers/api/avatars.php @@ -17,7 +17,7 @@ use chillerlan\QRCode\QRCode; use chillerlan\QRCode\QROptions; $avatarCallback = function ($type, $code, $width, $height, $quality, $response) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ $code = \strtolower($code); $type = \strtolower($type); @@ -143,7 +143,7 @@ App::get('/v1/avatars/image') ->param('width', 400, new Range(0, 2000), 'Resize preview image width, Pass an integer between 0 to 2000.', true) ->param('height', 400, new Range(0, 2000), 'Resize preview image height, Pass an integer between 0 to 2000.', true) ->action(function ($url, $width, $height, $response) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ $quality = 80; $output = 'png'; @@ -207,7 +207,7 @@ App::get('/v1/avatars/favicon') ->label('sdk.description', '/docs/references/avatars/get-favicon.md') ->param('url', '', new URL(), 'Website URL which you want to fetch the favicon from.') ->action(function ($url, $response) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ $width = 56; $height = 56; @@ -360,7 +360,7 @@ App::get('/v1/avatars/qr') ->param('margin', 1, new Range(0, 10), 'Margin from edge. Pass an integer between 0 to 10. Defaults to 1.', true) ->param('download', false, new Boolean(true), 'Return resulting image with \'Content-Disposition: attachment \' headers for the browser to start downloading it. Pass 0 for no header, or 1 for otherwise. Default value is set to 0.', true) ->action(function ($text, $size, $margin, $download, $response) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ $download = ($download === '1' || $download === 'true' || $download === 1 || $download === true); $options = new QROptions([ @@ -396,7 +396,7 @@ App::get('/v1/avatars/initials') ->param('color', '', new HexColor(), 'Changes text color. By default a random color will be picked and stay will persistent to the given name.', true) ->param('background', '', new HexColor(), 'Changes background color. By default a random color will be picked and stay will persistent to the given name.', true) ->action(function ($name, $width, $height, $color, $background, $response, $user) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Document $user */ $themes = [ diff --git a/app/controllers/api/database.php b/app/controllers/api/database.php index a24de8088..b535bb489 100644 --- a/app/controllers/api/database.php +++ b/app/controllers/api/database.php @@ -35,7 +35,7 @@ App::post('/v1/database/collections') ->param('write', [], 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('rules', [], function ($projectDB) { return new ArrayList(new Collection($projectDB, [Database::SYSTEM_COLLECTION_RULES], ['$collection' => Database::SYSTEM_COLLECTION_RULES, '$permissions' => ['read' => [], 'write' => []]])); }, 'Array of [rule objects](/docs/rules). Each rule define a collection field name, data type and validation.', false, ['projectDB']) ->action(function ($name, $read, $write, $rules, $response, $projectDB, $webhooks, $audits) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $projectDB */ /** @var Appwrite\Event\Event $webhooks */ /** @var Appwrite\Event\Event $audits */ @@ -111,7 +111,7 @@ App::get('/v1/database/collections') ->param('offset', 0, new Range(0, 40000), 'Results offset. The default value is 0. Use this param to manage pagination.', true) ->param('orderType', 'ASC', new WhiteList(['ASC', 'DESC'], true), 'Order result by ASC or DESC order.', true) ->action(function ($search, $limit, $offset, $orderType, $response, $projectDB) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $projectDB */ $results = $projectDB->getCollection([ @@ -139,7 +139,7 @@ App::get('/v1/database/collections/:collectionId') ->label('sdk.description', '/docs/references/database/get-collection.md') ->param('collectionId', '', new UID(), 'Collection unique ID.') ->action(function ($collectionId, $response, $projectDB) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $projectDB */ $collection = $projectDB->getDocument($collectionId, false); @@ -231,7 +231,7 @@ App::put('/v1/database/collections/:collectionId') ->param('write', [], 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('rules', [], function ($projectDB) { return new ArrayList(new Collection($projectDB, [Database::SYSTEM_COLLECTION_RULES], ['$collection' => Database::SYSTEM_COLLECTION_RULES, '$permissions' => ['read' => [], 'write' => []]])); }, 'Array of [rule objects](/docs/rules). Each rule define a collection field name, data type and validation.', true, ['projectDB']) ->action(function ($collectionId, $name, $read, $write, $rules, $response, $projectDB, $webhooks, $audits) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $projectDB */ /** @var Appwrite\Event\Event $webhooks */ /** @var Appwrite\Event\Event $audits */ @@ -303,7 +303,7 @@ App::delete('/v1/database/collections/:collectionId') ->label('sdk.description', '/docs/references/database/delete-collection.md') ->param('collectionId', '', new UID(), 'Collection unique ID.') ->action(function ($collectionId, $response, $projectDB, $webhooks, $audits) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $projectDB */ /** @var Appwrite\Event\Event $webhooks */ /** @var Appwrite\Event\Event $audits */ @@ -350,7 +350,7 @@ App::post('/v1/database/collections/:collectionId/documents') ->param('parentProperty', '', 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, new WhiteList([Document::SET_TYPE_ASSIGN, Document::SET_TYPE_APPEND, Document::SET_TYPE_PREPEND], true), '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) ->action(function ($collectionId, $data, $read, $write, $parentDocument, $parentProperty, $parentPropertyType, $response, $projectDB, $webhooks, $audits) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $projectDB */ /** @var Appwrite\Event\Event $webhooks */ /** @var Appwrite\Event\Event $audits */ @@ -474,7 +474,7 @@ App::get('/v1/database/collections/:collectionId/documents') ->param('orderCast', 'string', new WhiteList(['int', 'string', 'date', 'time', 'datetime'], true), 'Order field type casting. Possible values are int, string, date, time or datetime. The database will attempt to cast the order field to the value you pass here. The default value is a string.', true) ->param('search', '', new Text(256), 'Search query. Enter any free text search. The database will try to find a match against all document attributes and children. Max length: 256 chars.', true) ->action(function ($collectionId, $filters, $limit, $offset, $orderField, $orderType, $orderCast, $search, $response, $projectDB) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $projectDB */ $collection = $projectDB->getDocument($collectionId, false); @@ -530,7 +530,7 @@ App::get('/v1/database/collections/:collectionId/documents/:documentId') ->param('documentId', null, new UID(), 'Document unique ID.') ->action(function ($collectionId, $documentId, $request, $response, $projectDB) { /** @var Utopia\Swoole\Request $request */ - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $projectDB */ $document = $projectDB->getDocument($documentId, false); @@ -581,7 +581,7 @@ App::patch('/v1/database/collections/:collectionId/documents/:documentId') ->param('read', [], new ArrayList(new Text(64)), 'An array of strings with read permissions. By default no user is granted with any read permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions.') ->param('write', [], 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.') ->action(function ($collectionId, $documentId, $data, $read, $write, $response, $projectDB, $webhooks, $audits) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $projectDB */ /** @var Appwrite\Event\Event $webhooks */ /** @var Appwrite\Event\Event $audits */ @@ -661,7 +661,7 @@ App::delete('/v1/database/collections/:collectionId/documents/:documentId') ->param('collectionId', null, new UID(), 'Collection unique ID. You can create a new collection with validation rules using the Database service [server integration](/docs/server/database#createCollection).') ->param('documentId', null, new UID(), 'Document unique ID.') ->action(function ($collectionId, $documentId, $response, $projectDB, $webhooks, $audits) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $projectDB */ /** @var Appwrite\Event\Event $webhooks */ /** @var Appwrite\Event\Event $audits */ diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 039eeb3f5..d2e1c7079 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -416,7 +416,7 @@ App::post('/v1/functions/:functionId/executions') ->param('functionId', '', new UID(), 'Function unique ID.') ->param('async', 1, new Range(0, 1), 'Execute code asynchronously. Pass 1 for true, 0 for false. Default value is 1.', true) ->action(function ($functionId, $async, $response, $project, $projectDB) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Document $project */ /** @var Appwrite\Database\Database $projectDB */ diff --git a/app/controllers/api/health.php b/app/controllers/api/health.php index 5ef4f2b9c..8b146167d 100644 --- a/app/controllers/api/health.php +++ b/app/controllers/api/health.php @@ -15,7 +15,7 @@ App::get('/v1/health') ->label('sdk.method', 'get') ->label('sdk.description', '/docs/references/health/get.md') ->action(function ($response) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ $response->json(['status' => 'OK']); }, ['response']); @@ -25,7 +25,7 @@ App::get('/v1/health/version') ->groups(['api', 'health']) ->label('scope', 'public') ->action(function ($response) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ $response->json(['version' => APP_VERSION_STABLE]); }, ['response']); @@ -39,7 +39,7 @@ App::get('/v1/health/db') ->label('sdk.method', 'getDB') ->label('sdk.description', '/docs/references/health/get-db.md') ->action(function ($response, $register) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Utopia\Registry\Registry $register */ $register->get('db'); /* @var $db PDO */ @@ -56,7 +56,7 @@ App::get('/v1/health/cache') ->label('sdk.method', 'getCache') ->label('sdk.description', '/docs/references/health/get-cache.md') ->action(function ($response, $register) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Utopia\Registry\Registry $register */ $register->get('cache'); /* @var $cache Predis\Client */ @@ -72,7 +72,7 @@ App::get('/v1/health/time') ->label('sdk.method', 'getTime') ->label('sdk.description', '/docs/references/health/get-time.md') ->action(function ($response) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /* * Code from: @see https://www.beliefmedia.com.au/query-ntp-time-server @@ -120,7 +120,7 @@ App::get('/v1/health/queue/webhooks') ->label('sdk.method', 'getQueueWebhooks') ->label('sdk.description', '/docs/references/health/get-queue-webhooks.md') ->action(function ($response) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ $response->json(['size' => Resque::size('v1-webhooks')]); }, ['response']); @@ -134,7 +134,7 @@ App::get('/v1/health/queue/tasks') ->label('sdk.method', 'getQueueTasks') ->label('sdk.description', '/docs/references/health/get-queue-tasks.md') ->action(function ($response) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ $response->json(['size' => Resque::size('v1-tasks')]); }, ['response']); @@ -148,7 +148,7 @@ App::get('/v1/health/queue/logs') ->label('sdk.method', 'getQueueLogs') ->label('sdk.description', '/docs/references/health/get-queue-logs.md') ->action(function ($response) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ $response->json(['size' => Resque::size('v1-audit')]); }, ['response']); @@ -162,7 +162,7 @@ App::get('/v1/health/queue/usage') ->label('sdk.method', 'getQueueUsage') ->label('sdk.description', '/docs/references/health/get-queue-usage.md') ->action(function ($response) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ $response->json(['size' => Resque::size('v1-usage')]); }, ['response']); @@ -176,7 +176,7 @@ App::get('/v1/health/queue/certificates') ->label('sdk.method', 'getQueueCertificates') ->label('sdk.description', '/docs/references/health/get-queue-certificates.md') ->action(function ($response) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ $response->json(['size' => Resque::size('v1-certificates')]); }, ['response']); @@ -190,7 +190,7 @@ App::get('/v1/health/queue/functions') ->label('sdk.method', 'getQueueFunctions') ->label('sdk.description', '/docs/references/health/get-queue-functions.md') ->action(function ($response) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ $response->json(['size' => Resque::size('v1-functions')]); }, ['response']); @@ -204,7 +204,7 @@ App::get('/v1/health/storage/local') ->label('sdk.method', 'getStorageLocal') ->label('sdk.description', '/docs/references/health/get-storage-local.md') ->action(function ($response) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ foreach ([ 'Uploads' => APP_STORAGE_UPLOADS, @@ -235,7 +235,7 @@ App::get('/v1/health/anti-virus') ->label('sdk.method', 'getAntiVirus') ->label('sdk.description', '/docs/references/health/get-storage-anti-virus.md') ->action(function ($response) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ if (App::getEnv('_APP_STORAGE_ANTIVIRUS') === 'disabled') { // Check if scans are enabled throw new Exception('Anitvirus is disabled'); @@ -258,7 +258,7 @@ App::get('/v1/health/stats') // Currently only used internally // ->label('sdk.method', 'getStats') ->label('docs', false) ->action(function ($response, $register) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Utopia\Registry\Registry $register */ $device = Storage::getDevice('files'); diff --git a/app/controllers/api/locale.php b/app/controllers/api/locale.php index 26b90cfea..7be2a5ce4 100644 --- a/app/controllers/api/locale.php +++ b/app/controllers/api/locale.php @@ -13,7 +13,7 @@ App::get('/v1/locale') ->label('sdk.description', '/docs/references/locale/get-locale.md') ->action(function ($request, $response, $locale, $geodb) { /** @var Utopia\Swoole\Request $request */ - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Utopia\Locale\Locale $locale */ /** @var MaxMind\Db\Reader $geodb */ @@ -69,7 +69,7 @@ App::get('/v1/locale/countries') ->label('sdk.method', 'getCountries') ->label('sdk.description', '/docs/references/locale/get-countries.md') ->action(function ($response, $locale) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Utopia\Locale\Locale $locale */ $list = $locale->getText('countries'); /* @var $list array */ @@ -88,7 +88,7 @@ App::get('/v1/locale/countries/eu') ->label('sdk.method', 'getCountriesEU') ->label('sdk.description', '/docs/references/locale/get-countries-eu.md') ->action(function ($response, $locale) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Utopia\Locale\Locale $locale */ $countries = $locale->getText('countries'); /* @var $countries array */ @@ -115,7 +115,7 @@ App::get('/v1/locale/countries/phones') ->label('sdk.method', 'getCountriesPhones') ->label('sdk.description', '/docs/references/locale/get-countries-phones.md') ->action(function ($response, $locale) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Utopia\Locale\Locale $locale */ $list = Config::getParam('locale-phones'); /* @var $list array */ @@ -142,7 +142,7 @@ App::get('/v1/locale/continents') ->label('sdk.method', 'getContinents') ->label('sdk.description', '/docs/references/locale/get-continents.md') ->action(function ($response, $locale) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Utopia\Locale\Locale $locale */ $list = $locale->getText('continents'); /* @var $list array */ @@ -161,7 +161,7 @@ App::get('/v1/locale/currencies') ->label('sdk.method', 'getCurrencies') ->label('sdk.description', '/docs/references/locale/get-currencies.md') ->action(function ($response) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ $currencies = Config::getParam('locale-currencies'); @@ -178,7 +178,7 @@ App::get('/v1/locale/languages') ->label('sdk.method', 'getLanguages') ->label('sdk.description', '/docs/references/locale/get-languages.md') ->action(function ($response) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ $languages = Config::getParam('locale-languages'); diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 3f62a66c6..5037624b2 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -38,7 +38,7 @@ App::post('/v1/projects') ->param('legalAddress', '', new Text(256), 'Project legal Address. Max length: 256 chars.', true) ->param('legalTaxId', '', new Text(256), 'Project legal Tax ID. Max length: 256 chars.', true) ->action(function ($name, $teamId, $description, $logo, $url, $legalName, $legalCountry, $legalState, $legalCity, $legalAddress, $legalTaxId, $response, $consoleDB, $projectDB) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $consoleDB */ /** @var Appwrite\Database\Database $projectDB */ @@ -96,7 +96,7 @@ App::get('/v1/projects') ->param('offset', 0, new Range(0, 2000), 'Results offset. The default value is 0. Use this param to manage pagination.', true) ->param('orderType', 'ASC', new WhiteList(['ASC', 'DESC'], true), 'Order result by ASC or DESC order.', true) ->action(function ($search, $limit, $offset, $orderType, $response, $consoleDB) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $consoleDB */ $results = $consoleDB->getCollection([ @@ -122,7 +122,7 @@ App::get('/v1/projects/:projectId') ->label('sdk.method', 'get') ->param('projectId', '', new UID(), 'Project unique ID.') ->action(function ($projectId, $response, $consoleDB) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $consoleDB */ $project = $consoleDB->getDocument($projectId); @@ -143,7 +143,7 @@ App::get('/v1/projects/:projectId/usage') ->param('projectId', '', new UID(), 'Project unique ID.') ->param('range', 'last30', new WhiteList(['daily', 'monthly', 'last30', 'last90'], true), 'Date range.', true) ->action(function ($projectId, $range, $response, $consoleDB, $projectDB, $register) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $consoleDB */ /** @var Appwrite\Database\Database $projectDB */ /** @var Utopia\Registry\Registry $register */ @@ -326,7 +326,7 @@ App::patch('/v1/projects/:projectId') ->param('legalAddress', '', new Text(256), 'Project legal address. Max length: 256 chars.', true) ->param('legalTaxId', '', new Text(256), 'Project legal tax ID. Max length: 256 chars.', true) ->action(function ($projectId, $name, $description, $logo, $url, $legalName, $legalCountry, $legalState, $legalCity, $legalAddress, $legalTaxId, $response, $consoleDB) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $consoleDB */ $project = $consoleDB->getDocument($projectId); @@ -366,7 +366,7 @@ App::patch('/v1/projects/:projectId/oauth2') ->param('appId', '', new Text(256), 'Provider app ID. Max length: 256 chars.', true) ->param('secret', '', new text(512), 'Provider secret key. Max length: 512 chars.', true) ->action(function ($projectId, $provider, $appId, $secret, $response, $consoleDB) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $consoleDB */ $project = $consoleDB->getDocument($projectId); @@ -396,7 +396,7 @@ App::delete('/v1/projects/:projectId') ->param('projectId', '', new UID(), 'Project unique ID.') ->param('password', '', new UID(), 'Your user password for confirmation. Must be between 6 to 32 chars.') ->action(function ($projectId, $password, $response, $user, $consoleDB, $deletes) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Document $user */ /** @var Appwrite\Database\Database $consoleDB */ /** @var Appwrite\Event\Event $deletes */ @@ -450,7 +450,7 @@ App::post('/v1/projects/:projectId/webhooks') ->param('httpUser', '', new Text(256), 'Webhook HTTP user. Max length: 256 chars.', true) ->param('httpPass', '', new Text(256), 'Webhook HTTP password. Max length: 256 chars.', true) ->action(function ($projectId, $name, $events, $url, $security, $httpUser, $httpPass, $response, $consoleDB) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $consoleDB */ $project = $consoleDB->getDocument($projectId); @@ -501,7 +501,7 @@ App::get('/v1/projects/:projectId/webhooks') ->label('sdk.method', 'listWebhooks') ->param('projectId', '', new UID(), 'Project unique ID.') ->action(function ($projectId, $response, $consoleDB) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $consoleDB */ $project = $consoleDB->getDocument($projectId); @@ -524,7 +524,7 @@ App::get('/v1/projects/:projectId/webhooks/:webhookId') ->param('projectId', null, new UID(), 'Project unique ID.') ->param('webhookId', null, new UID(), 'Webhook unique ID.') ->action(function ($projectId, $webhookId, $response, $consoleDB) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $consoleDB */ $project = $consoleDB->getDocument($projectId); @@ -557,7 +557,7 @@ App::put('/v1/projects/:projectId/webhooks/:webhookId') ->param('httpUser', '', new Text(256), 'Webhook HTTP user. Max length: 256 chars.', true) ->param('httpPass', '', new Text(256), 'Webhook HTTP password. Max length: 256 chars.', true) ->action(function ($projectId, $webhookId, $name, $events, $url, $security, $httpUser, $httpPass, $response, $consoleDB) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $consoleDB */ $project = $consoleDB->getDocument($projectId); @@ -599,7 +599,7 @@ App::delete('/v1/projects/:projectId/webhooks/:webhookId') ->param('projectId', null, new UID(), 'Project unique ID.') ->param('webhookId', null, new UID(), 'Webhook unique ID.') ->action(function ($projectId, $webhookId, $response, $consoleDB) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $consoleDB */ $project = $consoleDB->getDocument($projectId); @@ -633,7 +633,7 @@ App::post('/v1/projects/:projectId/keys') ->param('name', null, new Text(128), 'Key name. Max length: 128 chars.') ->param('scopes', null, new ArrayList(new WhiteList(Config::getParam('scopes'), true)), 'Key scopes list.') ->action(function ($projectId, $name, $scopes, $response, $consoleDB) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $consoleDB */ $project = $consoleDB->getDocument($projectId); @@ -679,7 +679,7 @@ App::get('/v1/projects/:projectId/keys') ->label('sdk.method', 'listKeys') ->param('projectId', null, new UID(), 'Project unique ID.') ->action(function ($projectId, $response, $consoleDB) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $consoleDB */ $project = $consoleDB->getDocument($projectId); @@ -726,7 +726,7 @@ App::put('/v1/projects/:projectId/keys/:keyId') ->param('name', null, new Text(128), 'Key name. Max length: 128 chars.') ->param('scopes', null, new ArrayList(new WhiteList(Config::getParam('scopes'), true)), 'Key scopes list') ->action(function ($projectId, $keyId, $name, $scopes, $response, $consoleDB) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $consoleDB */ $project = $consoleDB->getDocument($projectId); @@ -762,7 +762,7 @@ App::delete('/v1/projects/:projectId/keys/:keyId') ->param('projectId', null, new UID(), 'Project unique ID.') ->param('keyId', null, new UID(), 'Key unique ID.') ->action(function ($projectId, $keyId, $response, $consoleDB) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $consoleDB */ $project = $consoleDB->getDocument($projectId); @@ -803,7 +803,7 @@ App::post('/v1/projects/:projectId/tasks') ->param('httpUser', '', new Text(256), 'Task HTTP user. Max length: 256 chars.', true) ->param('httpPass', '', new Text(256), 'Task HTTP password. Max length: 256 chars.', true) ->action(function ($projectId, $name, $status, $schedule, $security, $httpMethod, $httpUrl, $httpHeaders, $httpUser, $httpPass, $response, $consoleDB) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $consoleDB */ $project = $consoleDB->getDocument($projectId); @@ -869,7 +869,7 @@ App::get('/v1/projects/:projectId/tasks') ->label('sdk.method', 'listTasks') ->param('projectId', '', new UID(), 'Project unique ID.') ->action(function ($projectId, $response, $consoleDB) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $consoleDB */ $project = $consoleDB->getDocument($projectId); @@ -892,7 +892,7 @@ App::get('/v1/projects/:projectId/tasks/:taskId') ->param('projectId', null, new UID(), 'Project unique ID.') ->param('taskId', null, new UID(), 'Task unique ID.') ->action(function ($projectId, $taskId, $response, $consoleDB) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $consoleDB */ $project = $consoleDB->getDocument($projectId); @@ -928,7 +928,7 @@ App::put('/v1/projects/:projectId/tasks/:taskId') ->param('httpUser', '', new Text(256), 'Task HTTP user. Max length: 256 chars.', true) ->param('httpPass', '', new Text(256), 'Task HTTP password. Max length: 256 chars.', true) ->action(function ($projectId, $taskId, $name, $status, $schedule, $security, $httpMethod, $httpUrl, $httpHeaders, $httpUser, $httpPass, $response, $consoleDB) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $consoleDB */ $project = $consoleDB->getDocument($projectId); @@ -982,7 +982,7 @@ App::delete('/v1/projects/:projectId/tasks/:taskId') ->param('projectId', null, new UID(), 'Project unique ID.') ->param('taskId', null, new UID(), 'Task unique ID.') ->action(function ($projectId, $taskId, $response, $consoleDB) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $consoleDB */ $project = $consoleDB->getDocument($projectId); @@ -1019,7 +1019,7 @@ App::post('/v1/projects/:projectId/platforms') ->param('store', '', new Text(256), 'App store or Google Play store ID. Max length: 256 chars.', true) ->param('hostname', '', new Text(256), 'Platform client hostname. Max length: 256 chars.', true) ->action(function ($projectId, $type, $name, $key, $store, $hostname, $response, $consoleDB) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $consoleDB */ $project = $consoleDB->getDocument($projectId); @@ -1069,7 +1069,7 @@ App::get('/v1/projects/:projectId/platforms') ->label('sdk.method', 'listPlatforms') ->param('projectId', '', new UID(), 'Project unique ID.') ->action(function ($projectId, $response, $consoleDB) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $consoleDB */ $project = $consoleDB->getDocument($projectId); @@ -1092,7 +1092,7 @@ App::get('/v1/projects/:projectId/platforms/:platformId') ->param('projectId', null, new UID(), 'Project unique ID.') ->param('platformId', null, new UID(), 'Platform unique ID.') ->action(function ($projectId, $platformId, $response, $consoleDB) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $consoleDB */ $project = $consoleDB->getDocument($projectId); @@ -1123,7 +1123,7 @@ App::put('/v1/projects/:projectId/platforms/:platformId') ->param('store', '', new Text(256), 'App store or Google Play store ID. Max length: 256 chars.', true) ->param('hostname', '', new Text(256), 'Platform client URL. Max length: 256 chars.', true) ->action(function ($projectId, $platformId, $name, $key, $store, $hostname, $response, $consoleDB) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $consoleDB */ $project = $consoleDB->getDocument($projectId); @@ -1162,7 +1162,7 @@ App::delete('/v1/projects/:projectId/platforms/:platformId') ->param('projectId', null, new UID(), 'Project unique ID.') ->param('platformId', null, new UID(), 'Platform unique ID.') ->action(function ($projectId, $platformId, $response, $consoleDB) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $consoleDB */ $project = $consoleDB->getDocument($projectId); @@ -1195,7 +1195,7 @@ App::post('/v1/projects/:projectId/domains') ->param('projectId', null, new UID(), 'Project unique ID.') ->param('domain', null, new DomainValidator(), 'Domain name.') ->action(function ($projectId, $domain, $response, $consoleDB) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $consoleDB */ $project = $consoleDB->getDocument($projectId); @@ -1258,7 +1258,7 @@ App::get('/v1/projects/:projectId/domains') ->label('sdk.method', 'listDomains') ->param('projectId', '', new UID(), 'Project unique ID.') ->action(function ($projectId, $response, $consoleDB) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $consoleDB */ $project = $consoleDB->getDocument($projectId); @@ -1281,7 +1281,7 @@ App::get('/v1/projects/:projectId/domains/:domainId') ->param('projectId', null, new UID(), 'Project unique ID.') ->param('domainId', null, new UID(), 'Domain unique ID.') ->action(function ($projectId, $domainId, $response, $consoleDB) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $consoleDB */ $project = $consoleDB->getDocument($projectId); @@ -1308,7 +1308,7 @@ App::patch('/v1/projects/:projectId/domains/:domainId/verification') ->param('projectId', null, new UID(), 'Project unique ID.') ->param('domainId', null, new UID(), 'Domain unique ID.') ->action(function ($projectId, $domainId, $response, $consoleDB) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $consoleDB */ $project = $consoleDB->getDocument($projectId); @@ -1366,7 +1366,7 @@ App::delete('/v1/projects/:projectId/domains/:domainId') ->param('projectId', null, new UID(), 'Project unique ID.') ->param('domainId', null, new UID(), 'Domain unique ID.') ->action(function ($projectId, $domainId, $response, $consoleDB) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $consoleDB */ $project = $consoleDB->getDocument($projectId); diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index 55ae74037..2add12c61 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -38,7 +38,7 @@ App::post('/v1/storage/files') ->param('write', [], 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.') ->action(function ($file, $read, $write, $request, $response, $user, $projectDB, $webhooks, $audits, $usage) { /** @var Utopia\Swoole\Request $request */ - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Document $user */ /** @var Appwrite\Database\Database $projectDB */ /** @var Appwrite\Event\Event $webhooks */ @@ -172,7 +172,7 @@ App::get('/v1/storage/files') ->param('offset', 0, new Range(0, 2000), 'Results offset. The default value is 0. Use this param to manage pagination.', true) ->param('orderType', 'ASC', new WhiteList(['ASC', 'DESC'], true), 'Order result by ASC or DESC order.', true) ->action(function ($search, $limit, $offset, $orderType, $response, $projectDB) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $projectDB */ $results = $projectDB->getCollection([ @@ -204,7 +204,7 @@ App::get('/v1/storage/files/:fileId') ->label('sdk.description', '/docs/references/storage/get-file.md') ->param('fileId', '', new UID(), 'File unique ID.') ->action(function ($fileId, $response, $projectDB) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $projectDB */ $file = $projectDB->getDocument($fileId); @@ -234,7 +234,7 @@ App::get('/v1/storage/files/:fileId/preview') ->param('output', '', new WhiteList(\array_keys(Config::getParam('storage-outputs')), true), 'Output format type (jpeg, jpg, png, gif and webp).', true) ->action(function ($fileId, $width, $height, $quality, $background, $output, $request, $response, $project, $projectDB) { /** @var Utopia\Swoole\Request $request */ - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Document $project */ /** @var Appwrite\Database\Database $projectDB */ @@ -354,7 +354,7 @@ App::get('/v1/storage/files/:fileId/download') ->label('sdk.methodType', 'location') ->param('fileId', '', new UID(), 'File unique ID.') ->action(function ($fileId, $response, $projectDB) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $projectDB */ $file = $projectDB->getDocument($fileId); @@ -410,7 +410,7 @@ App::get('/v1/storage/files/:fileId/view') ->param('fileId', '', new UID(), 'File unique ID.') ->param('as', '', new WhiteList(['pdf', /*'html',*/ 'text'], true), 'Choose a file format to convert your file to. Currently you can only convert word and pdf files to pdf or txt. This option is currently experimental only, use at your own risk.', true) ->action(function ($fileId, $as, $response, $projectDB) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $projectDB */ $file = $projectDB->getDocument($fileId); @@ -483,7 +483,7 @@ App::put('/v1/storage/files/:fileId') ->param('read', [], new ArrayList(new Text(64)), 'An array of strings with read permissions. By default no user is granted with any read permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions.') ->param('write', [], 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.') ->action(function ($fileId, $read, $write, $response, $projectDB, $webhooks, $audits) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $projectDB */ /** @var Appwrite\Event\Event $webhooks */ /** @var Appwrite\Event\Event $audits */ @@ -529,7 +529,7 @@ App::delete('/v1/storage/files/:fileId') ->label('sdk.description', '/docs/references/storage/delete-file.md') ->param('fileId', '', new UID(), 'File unique ID.') ->action(function ($fileId, $response, $projectDB, $webhooks, $audits, $usage) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $projectDB */ /** @var Appwrite\Event\Event $webhooks */ /** @var Appwrite\Event\Event $audits */ diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index ab0db7a25..75cfd0c06 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -30,7 +30,7 @@ App::post('/v1/teams') ->param('name', null, new Text(128), 'Team name. Max length: 128 chars.') ->param('roles', ['owner'], new ArrayList(new Key()), 'Array of strings. Use this param to set the roles in the team for the user who created it. The default role is **owner**. A role can be any string. Learn more about [roles and permissions](/docs/permissions). Max length for each role is 32 chars.', true) ->action(function ($name, $roles, $response, $user, $projectDB, $mode) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Document $user */ /** @var Appwrite\Database\Database $projectDB */ /** @var bool $mode */ @@ -99,7 +99,7 @@ App::get('/v1/teams') ->param('offset', 0, new Range(0, 2000), 'Results offset. The default value is 0. Use this param to manage pagination.', true) ->param('orderType', 'ASC', new WhiteList(['ASC', 'DESC'], true), 'Order result by ASC or DESC order.', true) ->action(function ($search, $limit, $offset, $orderType, $response, $projectDB) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $projectDB */ $results = $projectDB->getCollection([ @@ -127,7 +127,7 @@ App::get('/v1/teams/:teamId') ->label('sdk.description', '/docs/references/teams/get-team.md') ->param('teamId', '', new UID(), 'Team unique ID.') ->action(function ($teamId, $response, $projectDB) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $projectDB */ $team = $projectDB->getDocument($teamId); @@ -150,7 +150,7 @@ App::put('/v1/teams/:teamId') ->param('teamId', '', new UID(), 'Team unique ID.') ->param('name', null, new Text(128), 'Team name. Max length: 128 chars.') ->action(function ($teamId, $name, $response, $projectDB) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $projectDB */ $team = $projectDB->getDocument($teamId); @@ -180,7 +180,7 @@ App::delete('/v1/teams/:teamId') ->label('sdk.description', '/docs/references/teams/delete-team.md') ->param('teamId', '', new UID(), 'Team unique ID.') ->action(function ($teamId, $response, $projectDB) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $projectDB */ $team = $projectDB->getDocument($teamId); @@ -225,7 +225,7 @@ App::post('/v1/teams/:teamId/memberships') ->param('roles', [], new ArrayList(new Key()), 'Array of strings. Use this param to set the user roles in the team. A role can be any string. Learn more about [roles and permissions](/docs/permissions). Max length for each role is 32 chars.') ->param('url', '', function ($clients) { return new Host($clients); }, 'URL to redirect the user back to your app from the invitation email. Only URLs from hostnames in your project platform list are allowed. This requirement helps to prevent an [open redirect](https://cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API.', false, ['clients']) // TODO add our own built-in confirm page ->action(function ($teamId, $email, $name, $roles, $url, $response, $project, $user, $projectDB, $locale, $audits, $mails, $mode) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Document $project */ /** @var Appwrite\Database\Document $user */ /** @var Appwrite\Database\Database $projectDB */ @@ -422,7 +422,7 @@ App::get('/v1/teams/:teamId/memberships') ->param('offset', 0, new Range(0, 2000), 'Results offset. The default value is 0. Use this param to manage pagination.', true) ->param('orderType', 'ASC', new WhiteList(['ASC', 'DESC'], true), 'Order result by ASC or DESC order.', true) ->action(function ($teamId, $search, $limit, $offset, $orderType, $response, $projectDB) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $projectDB */ $team = $projectDB->getDocument($teamId); @@ -481,7 +481,7 @@ App::patch('/v1/teams/:teamId/memberships/:inviteId/status') ->param('secret', '', new Text(256), 'Secret key.') ->action(function ($teamId, $inviteId, $userId, $secret, $request, $response, $user, $projectDB, $audits) { /** @var Utopia\Swoole\Request $request */ - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Document $user */ /** @var Appwrite\Database\Database $projectDB */ /** @var Appwrite\Event\Event $audits */ @@ -608,7 +608,7 @@ App::delete('/v1/teams/:teamId/memberships/:inviteId') ->param('teamId', '', new UID(), 'Team unique ID.') ->param('inviteId', '', new UID(), 'Invite unique ID.') ->action(function ($teamId, $inviteId, $response, $projectDB, $audits) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $projectDB */ /** @var Appwrite\Event\Event $audits */ diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index 741d0c661..89e828018 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -30,7 +30,7 @@ App::post('/v1/users') ->param('password', '', new Password(), 'User password. Must be between 6 to 32 chars.') ->param('name', '', new Text(128), 'User name. Max length: 128 chars.', true) ->action(function ($email, $password, $name, $response, $projectDB) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $projectDB */ $profile = $projectDB->getCollectionFirst([ // Get user by email address @@ -101,7 +101,7 @@ App::get('/v1/users') ->param('offset', 0, new Range(0, 2000), 'Results offset. The default value is 0. Use this param to manage pagination.', true) ->param('orderType', 'ASC', new WhiteList(['ASC', 'DESC'], true), 'Order result by ASC or DESC order.', true) ->action(function ($search, $limit, $offset, $orderType, $response, $projectDB) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $projectDB */ $results = $projectDB->getCollection([ @@ -154,7 +154,7 @@ App::get('/v1/users/:userId') ->label('sdk.description', '/docs/references/users/get-user.md') ->param('userId', '', new UID(), 'User unique ID.') ->action(function ($userId, $response, $projectDB) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $projectDB */ $user = $projectDB->getDocument($userId); @@ -197,7 +197,7 @@ App::get('/v1/users/:userId/prefs') ->label('sdk.description', '/docs/references/users/get-user-prefs.md') ->param('userId', '', new UID(), 'User unique ID.') ->action(function ($userId, $response, $projectDB) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $projectDB */ $user = $projectDB->getDocument($userId); @@ -228,7 +228,7 @@ App::get('/v1/users/:userId/sessions') ->label('sdk.description', '/docs/references/users/get-user-sessions.md') ->param('userId', '', new UID(), 'User unique ID.') ->action(function ($userId, $response, $projectDB, $locale, $geodb) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $projectDB */ /** @var Utopia\Locale\Locale $locale */ /** @var MaxMind\Db\Reader $geodb */ @@ -301,7 +301,7 @@ App::get('/v1/users/:userId/logs') ->label('sdk.description', '/docs/references/users/get-user-logs.md') ->param('userId', '', new UID(), 'User unique ID.') ->action(function ($userId, $response, $register, $project, $projectDB, $locale, $geodb) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Utopia\Registry\Registry $register */ /** @var Appwrite\Database\Document $project */ /** @var Appwrite\Database\Database $projectDB */ @@ -393,7 +393,7 @@ App::patch('/v1/users/:userId/status') ->param('userId', '', new UID(), 'User unique ID.') ->param('status', '', new WhiteList([Auth::USER_STATUS_ACTIVATED, Auth::USER_STATUS_BLOCKED, Auth::USER_STATUS_UNACTIVATED], true), 'User Status code. To activate the user pass '.Auth::USER_STATUS_ACTIVATED.', to block the user pass '.Auth::USER_STATUS_BLOCKED.' and for disabling the user pass '.Auth::USER_STATUS_UNACTIVATED) ->action(function ($userId, $status, $response, $projectDB) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $projectDB */ $user = $projectDB->getDocument($userId); @@ -443,7 +443,7 @@ App::patch('/v1/users/:userId/prefs') ->param('userId', '', new UID(), 'User unique ID.') ->param('prefs', '', new Assoc(), 'Prefs key-value JSON object.') ->action(function ($userId, $prefs, $response, $projectDB) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $projectDB */ $user = $projectDB->getDocument($userId); @@ -487,7 +487,7 @@ App::delete('/v1/users/:userId/sessions/:sessionId') ->param('userId', '', new UID(), 'User unique ID.') ->param('sessionId', null, new UID(), 'User unique session ID.') ->action(function ($userId, $sessionId, $response, $projectDB) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $projectDB */ $user = $projectDB->getDocument($userId); @@ -520,7 +520,7 @@ App::delete('/v1/users/:userId/sessions') ->label('abuse-limit', 100) ->param('userId', '', new UID(), 'User unique ID.') ->action(function ($userId, $response, $projectDB) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $projectDB */ $user = $projectDB->getDocument($userId); @@ -551,7 +551,7 @@ App::delete('/v1/users/:userId') ->label('abuse-limit', 100) ->param('userId', '', function () {return new UID();}, 'User unique ID.') ->action(function ($userId, $response, $projectDB, $deletes) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Database $projectDB */ /** @var Appwrite\Event\Event $deletes */ diff --git a/app/controllers/general.php b/app/controllers/general.php index b83630a23..0f283d3f5 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -247,7 +247,7 @@ App::init(function ($utopia, $request, $response, $console, $project, $user, $lo App::shutdown(function ($utopia, $request, $response, $project, $webhooks, $audits, $usage, $deletes, $mode) { /** @var Utopia\App $utopia */ /** @var Utopia\Swoole\Request $request */ - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Document $project */ /** @var Appwrite\Event\Event $webhooks */ /** @var Appwrite\Event\Event $audits */ @@ -387,7 +387,7 @@ App::get('/manifest.json') ->label('scope', 'public') ->label('docs', false) ->action(function ($response) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ $response->json([ 'name' => APP_NAME, diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index a1a4d6cf6..d64c46a2c 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -8,7 +8,7 @@ use Utopia\Abuse\Adapters\TimeLimit; App::init(function ($utopia, $request, $response, $project, $user, $register) { /** @var Utopia\App $utopia */ /** @var Utopia\Swoole\Request $request */ - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Document $project */ /** @var Appwrite\Database\Document $user */ /** @var Utopia\Registry\Registry $register */ diff --git a/app/controllers/shared/web.php b/app/controllers/shared/web.php index 383685e0d..42d2a18c5 100644 --- a/app/controllers/shared/web.php +++ b/app/controllers/shared/web.php @@ -6,7 +6,7 @@ use Utopia\Config\Config; App::init(function ($utopia, $request, $response, $layout) { /** @var Utopia\App $utopia */ /** @var Utopia\Swoole\Request $request */ - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Utopia\View $layout */ /* AJAX check */ diff --git a/app/controllers/web/console.php b/app/controllers/web/console.php index 6c2f7ba44..47e1848a6 100644 --- a/app/controllers/web/console.php +++ b/app/controllers/web/console.php @@ -19,7 +19,7 @@ App::init(function ($layout) { }, ['layout'], 'console'); App::shutdown(function ($response, $layout) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Utopia\View $layout */ $header = new View(__DIR__.'/../../views/console/comps/header.phtml'); @@ -213,7 +213,7 @@ App::get('/console/database/collection') ->label('scope', 'console') ->param('id', '', new UID(), 'Collection unique ID.') ->action(function ($id, $response, $layout, $projectDB) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Utopia\View $layout */ /** @var Appwrite\Database\Database $projectDB */ diff --git a/app/controllers/web/home.php b/app/controllers/web/home.php index f2cf21ffd..7f7f41970 100644 --- a/app/controllers/web/home.php +++ b/app/controllers/web/home.php @@ -28,7 +28,7 @@ App::init(function ($layout) { }, ['layout'], 'home'); App::shutdown(function ($response, $layout) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Utopia\View $layout */ $response->html($layout->render()); @@ -39,7 +39,7 @@ App::get('/') ->label('permission', 'public') ->label('scope', 'home') ->action(function ($response) { - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ $response->redirect('/auth/signin'); }, ['response']); @@ -190,7 +190,7 @@ App::get('/open-api-2.json') ->action(function ($platform, $extensions, $tests, $utopia, $request, $response) { /** @var Utopia\App $utopia */ /** @var Utopia\Swoole\Request $request */ - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ $security = [ APP_PLATFORM_CLIENT => ['Project' => []], diff --git a/app/init.php b/app/init.php index 8c3457dd3..d372c62e6 100644 --- a/app/init.php +++ b/app/init.php @@ -362,7 +362,7 @@ App::setResource('clients', function($console, $project) { App::setResource('user', function($mode, $project, $console, $request, $response, $projectDB, $consoleDB) { /** @var Utopia\Swoole\Request $request */ - /** @var Utopia\Response $response */ + /** @var Appwrite\Utopia\Response $response */ /** @var Appwrite\Database\Document $project */ /** @var Appwrite\Database\Database $consoleDB */ /** @var Appwrite\Database\Database $projectDB */ From bbcebfe20a0f9f0a8ad2de247b8afd05df17e85c Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Thu, 29 Oct 2020 16:08:09 +0200 Subject: [PATCH 17/40] Faster geo DB --- app/init.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/init.php b/app/init.php index d372c62e6..b392d9470 100644 --- a/app/init.php +++ b/app/init.php @@ -199,6 +199,9 @@ $register->set('smtp', function () { return $mail; }); +$register->set('geodb', function () { + return new Reader(__DIR__.'/db/DBIP/dbip-country-lite-2020-01.mmdb'); +}); $register->set('queue-webhooks', function () { return new Event('v1-webhooks', 'WebhooksV1'); }); @@ -466,5 +469,5 @@ App::setResource('mode', function($request) { App::setResource('geodb', function($request) { /** @var Utopia\Swoole\Request $request */ - return new Reader(__DIR__.'/db/DBIP/dbip-country-lite-2020-01.mmdb'); + return $register->get('geodb'); }, ['request']); From bf1993ebe48b4790d9e381f769318b4788f4c021 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Thu, 29 Oct 2020 16:11:06 +0200 Subject: [PATCH 18/40] Updated cache buster --- app/init.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/init.php b/app/init.php index b392d9470..c3b28530b 100644 --- a/app/init.php +++ b/app/init.php @@ -36,7 +36,7 @@ const APP_EMAIL_SECURITY = 'security@localhost.test'; // Default security email const APP_USERAGENT = APP_NAME.'-Server v%s. Please report abuse at %s'; const APP_MODE_ADMIN = 'admin'; const APP_PAGING_LIMIT = 12; -const APP_CACHE_BUSTER = 127; +const APP_CACHE_BUSTER = 138; const APP_VERSION_STABLE = '0.7.0'; const APP_STORAGE_UPLOADS = '/storage/uploads'; const APP_STORAGE_FUNCTIONS = '/storage/functions'; From 1f8cb94b33a56b8fdcf845a52dccf7df374e799e Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Thu, 29 Oct 2020 17:44:21 +0200 Subject: [PATCH 19/40] Fixed wrong method call --- app/init.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/init.php b/app/init.php index c3b28530b..7efa47f40 100644 --- a/app/init.php +++ b/app/init.php @@ -467,7 +467,7 @@ App::setResource('mode', function($request) { return $request->getParam('mode', $request->getHeader('x-appwrite-mode', 'default')); }, ['request']); -App::setResource('geodb', function($request) { +App::setResource('geodb', function($register) { /** @var Utopia\Swoole\Request $request */ return $register->get('geodb'); }, ['request']); From 2a819b2af7fc2b9deac991c6ce5efc291e4e1164 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Thu, 29 Oct 2020 17:54:36 +0200 Subject: [PATCH 20/40] Fixed registry call --- app/init.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/init.php b/app/init.php index 7efa47f40..03d1c94ca 100644 --- a/app/init.php +++ b/app/init.php @@ -468,6 +468,6 @@ App::setResource('mode', function($request) { }, ['request']); App::setResource('geodb', function($register) { - /** @var Utopia\Swoole\Request $request */ + /** @var Utopia\Registry\Registry $register */ return $register->get('geodb'); -}, ['request']); +}, ['register']); From c177c6452adc168c9e4acaafbf1b96ba707f6610 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Thu, 29 Oct 2020 18:39:03 +0200 Subject: [PATCH 21/40] Trigger CI --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a04ad6665..c1242c2fc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -39,4 +39,4 @@ script: - docker-compose logs appwrite - docker exec appwrite doctor - docker exec appwrite vars -- docker exec appwrite test \ No newline at end of file +- docker exec appwrite test From fc8cbb5088ee16181b391b1c151e1ba21957f172 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Thu, 29 Oct 2020 22:11:16 +0200 Subject: [PATCH 22/40] Templates sync --- app/init.php | 1 - app/tasks/doctor.php | 3 +-- app/views/console/comps/header.phtml | 18 ------------------ app/views/console/database/collection.phtml | 4 ++-- app/views/console/database/index.phtml | 2 +- app/views/console/database/rules/array.phtml | 2 +- app/views/console/index.phtml | 2 +- app/views/console/tasks/index.phtml | 2 +- app/views/console/webhooks/index.phtml | 2 +- 9 files changed, 8 insertions(+), 28 deletions(-) diff --git a/app/init.php b/app/init.php index 03d1c94ca..281bc743c 100644 --- a/app/init.php +++ b/app/init.php @@ -447,7 +447,6 @@ App::setResource('consoleDB', function($register) { $consoleDB = new Database(); $consoleDB->setAdapter(new RedisAdapter(new MySQLAdapter($register), $register)); $consoleDB->setNamespace('app_console'); // Should be replaced with param if we want to have parent projects - $consoleDB->setMocks(Config::getParam('collections', [])); return $consoleDB; diff --git a/app/tasks/doctor.php b/app/tasks/doctor.php index 0ab19f290..27479bb30 100644 --- a/app/tasks/doctor.php +++ b/app/tasks/doctor.php @@ -213,7 +213,6 @@ $cli Console::error('🔴 ' . $message); } } - try { Console::log(''); @@ -232,4 +231,4 @@ $cli } catch (\Throwable $th) { Console::error('Failed to check for a newer version'."\n"); } - }); \ No newline at end of file + }); diff --git a/app/views/console/comps/header.phtml b/app/views/console/comps/header.phtml index ead2423b2..5aeb0c0bd 100644 --- a/app/views/console/comps/header.phtml +++ b/app/views/console/comps/header.phtml @@ -183,24 +183,6 @@ data-name="projects" data-scope="console"> -
- -
- -
-
Appwrite Light Logo diff --git a/app/views/console/database/collection.phtml b/app/views/console/database/collection.phtml index fc9f99351..faab1fb44 100644 --- a/app/views/console/database/collection.phtml +++ b/app/views/console/database/collection.phtml @@ -501,7 +501,7 @@ $maxCells = 10;