From 94db437d562c7847aeaf187e8f445c5220437a3e Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Wed, 24 Jun 2020 08:14:26 +0300 Subject: [PATCH 01/25] Added team models --- app/controllers/api/teams.php | 12 +++---- app/controllers/web/home.php | 62 ++++++++++++++++------------------- 2 files changed, 34 insertions(+), 40 deletions(-) diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index b8e0bf1194..b8d6d41383 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -3,7 +3,6 @@ global $utopia, $register, $request, $response, $projectDB, $project, $user, $audit, $mail, $mode, $clients; use Utopia\Exception; -use Utopia\Response; use Utopia\Config\Config; use Utopia\Validator\Email; use Utopia\Validator\Text; @@ -19,6 +18,7 @@ use Appwrite\Database\Validator\UID; use Appwrite\Database\Validator\Authorization; use Appwrite\Database\Exception\Duplicate; use Appwrite\Template\Template; +use Appwrite\Utopia\Response; include_once __DIR__ . '/../shared/api.php'; @@ -78,10 +78,8 @@ $utopia->post('/v1/teams') } } - $response - ->setStatusCode(Response::STATUS_CODE_CREATED) - ->json($team->getArrayCopy()) - ; + $response->setStatusCode(Response::STATUS_CODE_CREATED); + $response->dynamic($team, Response::MODEL_TEAM); } ); @@ -130,7 +128,7 @@ $utopia->get('/v1/teams/:teamId') throw new Exception('Team not found', 404); } - $response->json($team->getArrayCopy([])); + $response->dynamic($team, Response::MODEL_TEAM); } ); @@ -159,7 +157,7 @@ $utopia->put('/v1/teams/:teamId') throw new Exception('Failed saving team to DB', 500); } - $response->json($team->getArrayCopy()); + $response->dynamic($team, Response::MODEL_TEAM); } ); diff --git a/app/controllers/web/home.php b/app/controllers/web/home.php index cfec346b91..64c2eb1af8 100644 --- a/app/controllers/web/home.php +++ b/app/controllers/web/home.php @@ -303,27 +303,27 @@ $utopia->get('/open-api-2.json') 'securityDefinitions' => $keys[$platform], 'paths' => [], 'definitions' => [ - // 'Pet' => [ - // 'required' => ['id', 'name'], - // 'properties' => [ - // 'id' => [ - // 'type' => 'integer', - // 'format' => 'int64', - // ], - // 'name' => [ - // 'type' => 'string', - // ], - // 'tag' => [ - // 'type' => 'string', - // ], - // ], - // ], - // 'Pets' => array( - // 'type' => 'array', - // 'items' => array( - // '$ref' => '#/definitions/Pet', - // ), - // ), + 'Pet' => [ + 'required' => ['id', 'name'], + 'properties' => [ + 'id' => [ + 'type' => 'integer', + 'format' => 'int64', + ], + 'name' => [ + 'type' => 'string', + ], + 'tag' => [ + 'type' => 'string', + ], + ], + ], + 'Pets' => array( + 'type' => 'array', + 'items' => array( + '$ref' => '#/definitions/Pet', + ), + ), 'Error' => array( 'required' => array( 0 => 'code', @@ -396,14 +396,14 @@ $utopia->get('/open-api-2.json') 'tags' => [$route->getLabel('sdk.namespace', 'default')], 'description' => ($desc) ? \file_get_contents($desc) : '', - // 'responses' => [ - // 200 => [ - // 'description' => 'An paged array of pets', - // 'schema' => [ - // '$ref' => '#/definitions/Pet', - // ], - // ], - // ], + 'responses' => [ + 200 => [ + 'description' => 'An paged array of pets', + 'schema' => [ + '$ref' => '#/definitions/Pet', + ], + ], + ], ]; if ($extensions) { @@ -546,10 +546,6 @@ $utopia->get('/open-api-2.json') } } - /*foreach ($consoleDB->getMocks() as $mock) { - var_dump($mock['name']); - }*/ - \ksort($output['paths']); $response From dc2d990c29f79d2f52bdcd2d037fffe4fdf962fd Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Wed, 24 Jun 2020 08:14:42 +0300 Subject: [PATCH 02/25] Added team model --- src/Appwrite/Utopia/Response.php | 8 ++- .../Utopia/Response/Model/BaseList.php | 40 +++++++++++++ src/Appwrite/Utopia/Response/Model/Team.php | 58 +++++++++++++++++++ .../Utopia/Response/Model/TeamList.php | 40 +++++++++++++ 4 files changed, 145 insertions(+), 1 deletion(-) create mode 100644 src/Appwrite/Utopia/Response/Model/BaseList.php create mode 100644 src/Appwrite/Utopia/Response/Model/Team.php create mode 100644 src/Appwrite/Utopia/Response/Model/TeamList.php diff --git a/src/Appwrite/Utopia/Response.php b/src/Appwrite/Utopia/Response.php index a0dff6e767..ded28945dc 100644 --- a/src/Appwrite/Utopia/Response.php +++ b/src/Appwrite/Utopia/Response.php @@ -8,6 +8,8 @@ use Appwrite\Utopia\Response\Model; use Appwrite\Utopia\Response\Model\Error; use Appwrite\Utopia\Response\Model\ErrorDev; use Appwrite\Utopia\Response\Model\User; +use Appwrite\Utopia\Response\Model\Team; +use Appwrite\Utopia\Response\Model\TeamList; use Appwrite\Utopia\Response\Model\Locale; use Utopia\Response as UtopiaResponse; @@ -17,6 +19,7 @@ class Response extends UtopiaResponse const MODEL_LOG = 'log'; const MODEL_ERROR = 'error'; const MODEL_ERROR_DEV = 'errorDev'; + const MODEL_BASE_LIST = 'baseList'; // Users const MODEL_USER = 'user'; @@ -40,7 +43,9 @@ class Response extends UtopiaResponse // Teams const MODEL_TEAM = 'team'; + const MODEL_TEAM_LIST = 'teamList'; const MODEL_MEMBERSHIP = 'membership'; + const MODEL_MEMBERSHIP_LIST = 'membershipList'; public function __construct() { @@ -49,6 +54,8 @@ class Response extends UtopiaResponse ->setModel(new ErrorDev()) ->setModel(new User()) ->setModel(new Locale()) + ->setModel(new Team()) + ->setModel(new TeamList()) ; } @@ -116,7 +123,6 @@ class Response extends UtopiaResponse } return $this->json($output); - //return $this->yaml($output); } /** diff --git a/src/Appwrite/Utopia/Response/Model/BaseList.php b/src/Appwrite/Utopia/Response/Model/BaseList.php new file mode 100644 index 0000000000..1e7c8050bd --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/BaseList.php @@ -0,0 +1,40 @@ +addRule('sum', [ + 'type' => 'intgere', + 'description' => 'Total sum of items in the list.', + 'example' => '5e5ea5c16897e', + ]) + ; + } + + /** + * Get Name + * + * @return string + */ + public function getName():string + { + return 'Base List'; + } + + /** + * Get Collection + * + * @return string + */ + public function getType():string + { + return Response::MODEL_BASE_LIST; + } +} \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Model/Team.php b/src/Appwrite/Utopia/Response/Model/Team.php new file mode 100644 index 0000000000..1c538506ad --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/Team.php @@ -0,0 +1,58 @@ +addRule('$id', [ + 'type' => 'string', + 'description' => 'Team ID.', + 'example' => '5e5ea5c16897e', + ]) + ->addRule('name', [ + 'type' => 'string', + 'description' => 'Team name.', + 'default' => '', + 'example' => 'VIP', + ]) + ->addRule('dateCreated', [ + 'type' => 'integer', + 'description' => 'Team creation date in unix timestamp.', + 'default' => false, + 'example' => true, + ]) + ->addRule('sum', [ // TODO change key name? + 'type' => 'integer', + 'description' => 'Total sum of team members.', + 'default' => false, + 'example' => true, + ]) + ; + } + + /** + * Get Name + * + * @return string + */ + public function getName():string + { + return 'Team'; + } + + /** + * Get Collection + * + * @return string + */ + public function getType():string + { + return Response::MODEL_TEAM; + } +} \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Model/TeamList.php b/src/Appwrite/Utopia/Response/Model/TeamList.php new file mode 100644 index 0000000000..2c1951cfab --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/TeamList.php @@ -0,0 +1,40 @@ +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 From dd2c6efbc9ea85a68515c7a9b059a2987f0ec6ea Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Wed, 24 Jun 2020 09:05:43 +0300 Subject: [PATCH 03/25] Added team dynamic response --- app/controllers/api/teams.php | 5 +++- src/Appwrite/Database/Document.php | 16 +++++++++-- src/Appwrite/Utopia/Response.php | 28 +++++++++++++++---- .../Utopia/Response/Model/BaseList.php | 4 +-- .../Utopia/Response/Model/TeamList.php | 1 + 5 files changed, 43 insertions(+), 11 deletions(-) diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index b8d6d41383..8e91f42dbd 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -108,7 +108,10 @@ $utopia->get('/v1/teams') ], ]); - $response->json(['sum' => $projectDB->getSum(), 'teams' => $results]); + $response->dynamic(new Document([ + 'sum' => $projectDB->getSum(), + 'teams' => $results + ]), Response::MODEL_TEAM_LIST); } ); diff --git a/src/Appwrite/Database/Document.php b/src/Appwrite/Database/Document.php index a0445702e4..9b7b281455 100644 --- a/src/Appwrite/Database/Document.php +++ b/src/Appwrite/Database/Document.php @@ -25,11 +25,11 @@ class Document extends ArrayObject { foreach ($input as $key => &$value) { if (\is_array($value)) { - if (isset($value['$id']) || isset($value['$collection'])) { + if ((isset($value['$id']) || isset($value['$collection'])) && (!$value instanceof self)) { $input[$key] = new self($value); } else { foreach ($value as $childKey => $child) { - if (isset($child['$id']) || isset($child['$collection'])) { + if ((isset($child['$id']) || isset($child['$collection'])) && (!$child instanceof self)) { $value[$childKey] = new self($child); } } @@ -193,6 +193,18 @@ class Document extends ArrayObject return empty($this->getId()); } + /** + * Checks if a document key is set. + * + * @param $key + * + * @return bool + */ + public function isSet($key) + { + return isset($this[$key]); + } + /** * Get Array Copy. * diff --git a/src/Appwrite/Utopia/Response.php b/src/Appwrite/Utopia/Response.php index ded28945dc..8650c3533d 100644 --- a/src/Appwrite/Utopia/Response.php +++ b/src/Appwrite/Utopia/Response.php @@ -101,28 +101,44 @@ class Response extends UtopiaResponse */ public function dynamic(Document $document, string $model) { - $data = $document->getArrayCopy(); + return $this->json($this->output($document, $model)); + } + + /** + * Generate valid response object from document data + */ + protected function output(Document $document, string $model): array + { + $data = $document; $model = $this->getModel($model); $output = []; foreach($model->getRules() as $key => $rule) { - if(!isset($data[$key])) { + if(!$document->isSet($key)) { if(!is_null($rule['default'])) { - $data[$key] = $rule['default']; + $document->setAttribute($key, $rule['default']); } else { throw new Exception('Missing response key: '.$key); } } - if($rule['array'] && !is_array($data[$key])) { - throw new Exception($key.' must be an array of '.$rule['type'].' types'); + 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) { + $item = $this->output($item, $rule['type']); + } + } } $output[$key] = $data[$key]; } - return $this->json($output); + return $output; } /** diff --git a/src/Appwrite/Utopia/Response/Model/BaseList.php b/src/Appwrite/Utopia/Response/Model/BaseList.php index 1e7c8050bd..24f0a76486 100644 --- a/src/Appwrite/Utopia/Response/Model/BaseList.php +++ b/src/Appwrite/Utopia/Response/Model/BaseList.php @@ -11,9 +11,9 @@ abstract class BaseList extends Model { $this ->addRule('sum', [ - 'type' => 'intgere', + 'type' => 'integer', 'description' => 'Total sum of items in the list.', - 'example' => '5e5ea5c16897e', + 'example' => '5', ]) ; } diff --git a/src/Appwrite/Utopia/Response/Model/TeamList.php b/src/Appwrite/Utopia/Response/Model/TeamList.php index 2c1951cfab..c96e4cd0d4 100644 --- a/src/Appwrite/Utopia/Response/Model/TeamList.php +++ b/src/Appwrite/Utopia/Response/Model/TeamList.php @@ -8,6 +8,7 @@ class TeamList extends BaseList { public function __construct() { + parent::__construct(); $this ->addRule('teams', [ 'type' => Response::MODEL_TEAM, From 228b2ec506c240edfede7237791ef8ff1fa1a99b Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Wed, 24 Jun 2020 09:41:00 +0300 Subject: [PATCH 04/25] Updated session --- src/Appwrite/Utopia/Response/Model/Session.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Appwrite/Utopia/Response/Model/Session.php b/src/Appwrite/Utopia/Response/Model/Session.php index ccbed6536d..a35703654d 100644 --- a/src/Appwrite/Utopia/Response/Model/Session.php +++ b/src/Appwrite/Utopia/Response/Model/Session.php @@ -9,6 +9,13 @@ class Session extends Model { public function __construct() { + $this->addRule('roles', [ + 'type' => 'string', + 'description' => 'User list of roles', + 'default' => [], + 'example' => [], + 'array' => true, + ]); } /** @@ -28,6 +35,6 @@ class Session extends Model */ public function getType():string { - return Response::MODEL_LOCALE; + return Response::MODEL_SESSION; } } \ No newline at end of file From 5298c1697169315795c9697fdb65ae3c605cf171 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Wed, 24 Jun 2020 09:53:13 +0300 Subject: [PATCH 05/25] Updated session model --- .../Utopia/Response/Model/Session.php | 24 +++++++++++++------ src/Appwrite/Utopia/Response/Model/Team.php | 6 ++--- src/Appwrite/Utopia/Response/Model/User.php | 3 +-- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/Appwrite/Utopia/Response/Model/Session.php b/src/Appwrite/Utopia/Response/Model/Session.php index a35703654d..1beabb851e 100644 --- a/src/Appwrite/Utopia/Response/Model/Session.php +++ b/src/Appwrite/Utopia/Response/Model/Session.php @@ -9,13 +9,23 @@ class Session extends Model { public function __construct() { - $this->addRule('roles', [ - 'type' => 'string', - 'description' => 'User list of roles', - 'default' => [], - 'example' => [], - 'array' => true, - ]); + $this + ->addRule('$id', [ + 'type' => 'string', + 'description' => 'Session ID.', + 'example' => '5e5ea5c16897e', + ]) + ->addRule('expire', [ + 'type' => 'string', + 'description' => 'Session expiration date in unix timestamp.', + 'example' => 1592981250, + ]) + ->addRule('ip', [ + 'type' => 'string', + 'description' => 'IP session in use when the session was created.', + 'example' => '127.0.0.1', + ]) + ; } /** diff --git a/src/Appwrite/Utopia/Response/Model/Team.php b/src/Appwrite/Utopia/Response/Model/Team.php index 1c538506ad..38ab909db1 100644 --- a/src/Appwrite/Utopia/Response/Model/Team.php +++ b/src/Appwrite/Utopia/Response/Model/Team.php @@ -24,14 +24,12 @@ class Team extends Model ->addRule('dateCreated', [ 'type' => 'integer', 'description' => 'Team creation date in unix timestamp.', - 'default' => false, - 'example' => true, + 'example' => 1592981250, ]) ->addRule('sum', [ // TODO change key name? 'type' => 'integer', 'description' => 'Total sum of team members.', - 'default' => false, - 'example' => true, + 'example' => 7, ]) ; } diff --git a/src/Appwrite/Utopia/Response/Model/User.php b/src/Appwrite/Utopia/Response/Model/User.php index 6720f31d9f..d68a11bac5 100644 --- a/src/Appwrite/Utopia/Response/Model/User.php +++ b/src/Appwrite/Utopia/Response/Model/User.php @@ -24,8 +24,7 @@ class User extends Model ->addRule('registration', [ 'type' => 'integer', 'description' => 'User registration date in unix timestamp.', - 'default' => false, - 'example' => true, + 'example' => 1592981250, ]) ->addRule('status', [ 'type' => 'integer', From 8efff7f1e96a7b097dad75330772486ff1850925 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Wed, 24 Jun 2020 10:35:59 +0300 Subject: [PATCH 06/25] Fixed session response --- src/Appwrite/Utopia/Response.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Appwrite/Utopia/Response.php b/src/Appwrite/Utopia/Response.php index 8650c3533d..5dd5339e7e 100644 --- a/src/Appwrite/Utopia/Response.php +++ b/src/Appwrite/Utopia/Response.php @@ -8,6 +8,7 @@ use Appwrite\Utopia\Response\Model; use Appwrite\Utopia\Response\Model\Error; use Appwrite\Utopia\Response\Model\ErrorDev; use Appwrite\Utopia\Response\Model\User; +use Appwrite\Utopia\Response\Model\Session; use Appwrite\Utopia\Response\Model\Team; use Appwrite\Utopia\Response\Model\TeamList; use Appwrite\Utopia\Response\Model\Locale; @@ -53,6 +54,7 @@ class Response extends UtopiaResponse ->setModel(new Error()) ->setModel(new ErrorDev()) ->setModel(new User()) + ->setModel(new Session()) ->setModel(new Locale()) ->setModel(new Team()) ->setModel(new TeamList()) From 75026ffa8c23c6ac0a2c4bbdfff45e1f202d577a Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Wed, 24 Jun 2020 14:18:33 +0300 Subject: [PATCH 07/25] unix is Unix --- public/scripts/services/date.js | 2 +- src/Appwrite/Database/Adapter.php | 2 +- src/Appwrite/Database/Adapter/MySQL.php | 2 +- src/Appwrite/Database/Adapter/Redis.php | 2 +- src/Appwrite/Database/Database.php | 2 +- src/Appwrite/Utopia/Response/Model/Session.php | 2 +- src/Appwrite/Utopia/Response/Model/Team.php | 2 +- src/Appwrite/Utopia/Response/Model/User.php | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/public/scripts/services/date.js b/public/scripts/services/date.js index 7ef5985bed..e395a83514 100644 --- a/public/scripts/services/date.js +++ b/public/scripts/services/date.js @@ -320,7 +320,7 @@ var _date = function (format, timestamp) { jsdate = (timestamp === undefined ? new Date() // Not provided : (timestamp instanceof Date) ? new Date(timestamp) // JS Date() - : new Date(timestamp * 1000) // UNIX timestamp (auto-convert to int) + : new Date(timestamp * 1000) // Unix timestamp (auto-convert to int) ) return format.replace(formatChr, formatChrCb) } diff --git a/src/Appwrite/Database/Adapter.php b/src/Appwrite/Database/Adapter.php index 6fa79cbdcd..9818a1f0b5 100644 --- a/src/Appwrite/Database/Adapter.php +++ b/src/Appwrite/Database/Adapter.php @@ -127,7 +127,7 @@ abstract class Adapter /** * Last Modified. * - * Return unix timestamp of last time a node queried in corrent session has been changed + * Return Unix timestamp of last time a node queried in corrent session has been changed * * @return int */ diff --git a/src/Appwrite/Database/Adapter/MySQL.php b/src/Appwrite/Database/Adapter/MySQL.php index 461d2a29ef..53bcec6af0 100644 --- a/src/Appwrite/Database/Adapter/MySQL.php +++ b/src/Appwrite/Database/Adapter/MySQL.php @@ -774,7 +774,7 @@ class MySQL extends Adapter /** * Last Modified. * - * Return unix timestamp of last time a node queried in corrent session has been changed + * Return Unix timestamp of last time a node queried in corrent session has been changed * * @return int */ diff --git a/src/Appwrite/Database/Adapter/Redis.php b/src/Appwrite/Database/Adapter/Redis.php index 15a7a887d8..a3b12e2ecc 100644 --- a/src/Appwrite/Database/Adapter/Redis.php +++ b/src/Appwrite/Database/Adapter/Redis.php @@ -221,7 +221,7 @@ class Redis extends Adapter /** * Last Modified. * - * Return unix timestamp of last time a node queried in current session has been changed + * Return Unix timestamp of last time a node queried in current session has been changed * * @return int */ diff --git a/src/Appwrite/Database/Database.php b/src/Appwrite/Database/Database.php index e75eb01b51..b19872dfb1 100644 --- a/src/Appwrite/Database/Database.php +++ b/src/Appwrite/Database/Database.php @@ -367,7 +367,7 @@ class Database /** * Get Last Modified. * - * Return unix timestamp of last time a node queried in current session has been changed + * Return Unix timestamp of last time a node queried in current session has been changed * * @return int */ diff --git a/src/Appwrite/Utopia/Response/Model/Session.php b/src/Appwrite/Utopia/Response/Model/Session.php index 1beabb851e..6146feb31d 100644 --- a/src/Appwrite/Utopia/Response/Model/Session.php +++ b/src/Appwrite/Utopia/Response/Model/Session.php @@ -17,7 +17,7 @@ class Session extends Model ]) ->addRule('expire', [ 'type' => 'string', - 'description' => 'Session expiration date in unix timestamp.', + 'description' => 'Session expiration date in Unix timestamp.', 'example' => 1592981250, ]) ->addRule('ip', [ diff --git a/src/Appwrite/Utopia/Response/Model/Team.php b/src/Appwrite/Utopia/Response/Model/Team.php index 38ab909db1..f86ff22e5d 100644 --- a/src/Appwrite/Utopia/Response/Model/Team.php +++ b/src/Appwrite/Utopia/Response/Model/Team.php @@ -23,7 +23,7 @@ class Team extends Model ]) ->addRule('dateCreated', [ 'type' => 'integer', - 'description' => 'Team creation date in unix timestamp.', + 'description' => 'Team creation date in Unix timestamp.', 'example' => 1592981250, ]) ->addRule('sum', [ // TODO change key name? diff --git a/src/Appwrite/Utopia/Response/Model/User.php b/src/Appwrite/Utopia/Response/Model/User.php index d68a11bac5..56af2156cf 100644 --- a/src/Appwrite/Utopia/Response/Model/User.php +++ b/src/Appwrite/Utopia/Response/Model/User.php @@ -23,7 +23,7 @@ class User extends Model ]) ->addRule('registration', [ 'type' => 'integer', - 'description' => 'User registration date in unix timestamp.', + 'description' => 'User registration date in Unix timestamp.', 'example' => 1592981250, ]) ->addRule('status', [ From 6e472d4ef33ab9db592b757a07fd878016cba106 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Wed, 24 Jun 2020 14:18:59 +0300 Subject: [PATCH 08/25] Added membership and membership list models --- app/controllers/api/teams.php | 53 ++++-------- src/Appwrite/Utopia/Response.php | 28 ++++--- .../Utopia/Response/Model/Membership.php | 84 +++++++++++++++++++ .../Utopia/Response/Model/MembershipList.php | 41 +++++++++ 4 files changed, 155 insertions(+), 51 deletions(-) create mode 100644 src/Appwrite/Utopia/Response/Model/Membership.php create mode 100644 src/Appwrite/Utopia/Response/Model/MembershipList.php diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index 8e91f42dbd..6ee9afb817 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -362,21 +362,12 @@ $utopia->post('/v1/teams/:teamId/memberships') ->setParam('resource', 'teams/'.$teamId) ; - $response - ->setStatusCode(Response::STATUS_CODE_CREATED) // TODO change response of this endpoint - ->json(\array_merge($membership->getArrayCopy([ - '$id', - 'userId', - 'teamId', - 'roles', - 'invited', - 'joined', - 'confirm', - ]), [ - 'email' => $email, - 'name' => $name, - ])) - ; + $response->setStatusCode(Response::STATUS_CODE_CREATED); // TODO change response of this endpoint + + $response->dynamic(new Document(\array_merge($membership->getArrayCopy(), [ + 'email' => $email, + 'name' => $name, + ])), Response::MODEL_MEMBERSHIP); } ); @@ -422,19 +413,10 @@ $utopia->get('/v1/teams/:teamId/memberships') $temp = $projectDB->getDocument($membership->getAttribute('userId', null))->getArrayCopy(['email', 'name']); - $users[] = \array_merge($temp, $membership->getArrayCopy([ - '$id', - 'userId', - 'teamId', - 'roles', - 'invited', - 'joined', - 'confirm', - ])); + $users[] = new Document(\array_merge($temp, $membership->getArrayCopy())); } - $response->json(['sum' => $projectDB->getSum(), 'memberships' => $users]); - + $response->dynamic(new Document(['sum' => $projectDB->getSum(), 'memberships' => $users]), Response::MODEL_MEMBERSHIP_LIST); } ); @@ -554,19 +536,12 @@ $utopia->patch('/v1/teams/:teamId/memberships/:inviteId/status') $response ->addCookie(Auth::$cookieName.'_legacy', Auth::encodeSession($user->getId(), $secret), $expiry, '/', COOKIE_DOMAIN, ('https' == $protocol), true, null) ->addCookie(Auth::$cookieName, Auth::encodeSession($user->getId(), $secret), $expiry, '/', COOKIE_DOMAIN, ('https' == $protocol), true, COOKIE_SAMESITE) - ->json(\array_merge($membership->getArrayCopy([ - '$id', - 'userId', - 'teamId', - 'roles', - 'invited', - 'joined', - 'confirm', - ]), [ - 'email' => $user->getAttribute('email'), - 'name' => $user->getAttribute('name'), - ])) ; + + $response->dynamic(new Document(\array_merge($membership->getArrayCopy(), [ + 'email' => $user->getAttribute('email'), + 'name' => $user->getAttribute('name'), + ])), Response::MODEL_MEMBERSHIP); } ); @@ -619,4 +594,4 @@ $utopia->delete('/v1/teams/:teamId/memberships/:inviteId') $response->noContent(); } - ); + ); \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response.php b/src/Appwrite/Utopia/Response.php index 5dd5339e7e..86cf771bee 100644 --- a/src/Appwrite/Utopia/Response.php +++ b/src/Appwrite/Utopia/Response.php @@ -12,12 +12,14 @@ 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\Membership; +use Appwrite\Utopia\Response\Model\MembershipList; use Utopia\Response as UtopiaResponse; class Response extends UtopiaResponse { // General - const MODEL_LOG = 'log'; + const MODEL_LOG = 'log'; // - Missing const MODEL_ERROR = 'error'; const MODEL_ERROR_DEV = 'errorDev'; const MODEL_BASE_LIST = 'baseList'; @@ -25,28 +27,28 @@ class Response extends UtopiaResponse // Users const MODEL_USER = 'user'; const MODEL_SESSION = 'session'; - const MODEL_TOKEN = 'token'; + const MODEL_TOKEN = 'token'; // - Missing // Database - const MODEL_COLLECTION = 'collection'; + const MODEL_COLLECTION = 'collection'; // - Missing // Locale const MODEL_LOCALE = 'locale'; - const MODEL_COUNTRY = 'country'; - const MODEL_CONTINENT = 'continent'; - const MODEL_CURRENCY = 'currency'; - const MODEL_LANGUAGE = 'langauge'; - const MODEL_PHONE = 'phone'; + 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'; - const MODEL_BUCKET = 'bucket'; + const MODEL_FILE = 'file'; // - Missing + const MODEL_BUCKET = 'bucket'; // - Missing // Teams const MODEL_TEAM = 'team'; const MODEL_TEAM_LIST = 'teamList'; - const MODEL_MEMBERSHIP = 'membership'; - const MODEL_MEMBERSHIP_LIST = 'membershipList'; + const MODEL_MEMBERSHIP = 'membership'; // - Missing + const MODEL_MEMBERSHIP_LIST = 'membershipList'; // - Missing public function __construct() { @@ -58,6 +60,8 @@ class Response extends UtopiaResponse ->setModel(new Locale()) ->setModel(new Team()) ->setModel(new TeamList()) + ->setModel(new Membership()) + ->setModel(new MembershipList()) ; } diff --git a/src/Appwrite/Utopia/Response/Model/Membership.php b/src/Appwrite/Utopia/Response/Model/Membership.php new file mode 100644 index 0000000000..ef239d2afa --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/Membership.php @@ -0,0 +1,84 @@ +addRule('$id', [ + 'type' => 'string', + 'description' => 'Membership ID.', + 'example' => '5e5ea5c16897e', + ]) + ->addRule('userId', [ + 'type' => 'string', + 'description' => 'User ID.', + 'example' => '5e5ea5c16897e', + ]) + ->addRule('userId', [ + 'type' => 'string', + 'description' => 'Team ID.', + 'example' => '5e5ea5c16897e', + ]) + ->addRule('name', [ + 'type' => 'string', + 'description' => 'User name.', + 'default' => '', + 'example' => 'VIP', + ]) + ->addRule('email', [ + 'type' => 'string', + 'description' => 'User email address.', + 'default' => '', + 'example' => 'john@appwrite.io', + ]) + ->addRule('invited', [ + 'type' => 'integer', + 'description' => 'Date, the user has been invited to join the team in Unix timestamp.', + 'example' => 1592981250, + ]) + ->addRule('joined', [ + 'type' => 'integer', + 'description' => 'Date, the user has accepted the invitation to join the team in Unix timestamp.', + 'example' => 1592981250, + ]) + ->addRule('confirm', [ + 'type' => 'boolean', + 'description' => 'User confirmation status, true if the user has joined the team or false otherwise.', + 'example' => false, + ]) + ->addRule('roles', [ + 'type' => 'string', + 'description' => 'User list of roles', + 'default' => [], + 'example' => [], + 'array' => true, + ]) + ; + } + + /** + * Get Name + * + * @return string + */ + public function getName():string + { + return 'Membership'; + } + + /** + * Get Collection + * + * @return string + */ + public function getType():string + { + return Response::MODEL_MEMBERSHIP; + } +} \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Model/MembershipList.php b/src/Appwrite/Utopia/Response/Model/MembershipList.php new file mode 100644 index 0000000000..56937c8d33 --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/MembershipList.php @@ -0,0 +1,41 @@ +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 From a43bb0643ed3e725561c13bb462f6bd7cb0f2980 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Wed, 24 Jun 2020 14:30:29 +0300 Subject: [PATCH 09/25] Fixed missing attribute --- src/Appwrite/Utopia/Response/Model/Membership.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Utopia/Response/Model/Membership.php b/src/Appwrite/Utopia/Response/Model/Membership.php index ef239d2afa..717cc005a0 100644 --- a/src/Appwrite/Utopia/Response/Model/Membership.php +++ b/src/Appwrite/Utopia/Response/Model/Membership.php @@ -20,7 +20,7 @@ class Membership extends Model 'description' => 'User ID.', 'example' => '5e5ea5c16897e', ]) - ->addRule('userId', [ + ->addRule('teamId', [ 'type' => 'string', 'description' => 'Team ID.', 'example' => '5e5ea5c16897e', From f0261ba2d2f5421f29e10c55b7732846f9fecc73 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Wed, 24 Jun 2020 23:26:34 +0300 Subject: [PATCH 10/25] Removed global settings --- app/controllers/shared/web.php | 47 +++++++++++++++------------------- public/index.php | 1 - 2 files changed, 21 insertions(+), 27 deletions(-) diff --git a/app/controllers/shared/web.php b/app/controllers/shared/web.php index fced2de4db..15d904559c 100644 --- a/app/controllers/shared/web.php +++ b/app/controllers/shared/web.php @@ -2,36 +2,31 @@ use Utopia\View; use Utopia\Config\Config; -use Utopia\Locale\Locale; - -Locale::$exceptions = false; - -$roles = [ - ['type' => 'owner', 'label' => 'Owner'], - ['type' => 'developer', 'label' => 'Developer'], - ['type' => 'admin', 'label' => 'Admin'], -]; $layout = new View(__DIR__.'/../../views/layouts/default.phtml'); -/* AJAX check */ -if (!empty($request->getQuery('version', ''))) { - $layout->setPath(__DIR__.'/../../views/layouts/empty.phtml'); -} - -$layout - ->setParam('title', APP_NAME) - ->setParam('protocol', Config::getParam('protocol')) - ->setParam('domain', $domain) - ->setParam('home', $request->getServer('_APP_HOME')) - ->setParam('setup', $request->getServer('_APP_SETUP')) - ->setParam('class', 'unknown') - ->setParam('icon', '/images/favicon.png') - ->setParam('roles', $roles) - ->setParam('env', $utopia->getMode()) -; - $utopia->init(function () use ($utopia, $response, $request, $layout) { + + /* AJAX check */ + if (!empty($request->getQuery('version', ''))) { + $layout->setPath(__DIR__.'/../../views/layouts/empty.phtml'); + } + $layout + ->setParam('title', APP_NAME) + ->setParam('protocol', Config::getParam('protocol')) + ->setParam('domain', Config::getParam('domain')) + ->setParam('home', $request->getServer('_APP_HOME')) + ->setParam('setup', $request->getServer('_APP_SETUP')) + ->setParam('class', 'unknown') + ->setParam('icon', '/images/favicon.png') + ->setParam('roles', [ + ['type' => 'owner', 'label' => 'Owner'], + ['type' => 'developer', 'label' => 'Developer'], + ['type' => 'admin', 'label' => 'Admin'], + ]) + ->setParam('env', $utopia->getMode()) + ; + $time = (60 * 60 * 24 * 45); // 45 days cache $isDev = (\Utopia\App::MODE_TYPE_DEVELOPMENT == Config::getParam('env')); diff --git a/public/index.php b/public/index.php index f6cd63710c..9e30f0ef56 100644 --- a/public/index.php +++ b/public/index.php @@ -16,7 +16,6 @@ ini_set('display_errors', 0); // error_reporting(E_ALL); $path = (isset($_GET['q'])) ? explode('/', $_GET['q']) : []; -$domain = (isset($_SERVER['HTTP_HOST'])) ? $_SERVER['HTTP_HOST'] : ''; array_shift($path); $version = array_shift($path); From 2bc0bef105e47cfc76ffdf12b8c350cfc13099c3 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Wed, 24 Jun 2020 23:32:33 +0300 Subject: [PATCH 11/25] Removed unwanted exit functions --- app/controllers/api/avatars.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/app/controllers/api/avatars.php b/app/controllers/api/avatars.php index 4bff678c5d..6c38cbd8b5 100644 --- a/app/controllers/api/avatars.php +++ b/app/controllers/api/avatars.php @@ -86,8 +86,6 @@ $avatarCallback = function ($type, $code, $width, $height, $quality) use ($types echo $data; unset($resize); - - exit(0); }; $utopia->get('/v1/avatars/credit-cards/:code') @@ -199,8 +197,6 @@ $utopia->get('/v1/avatars/image') echo $data; unset($resize); - - exit(0); } ); @@ -353,8 +349,6 @@ $utopia->get('/v1/avatars/favicon') echo $data; unset($resize); - - exit(0); } ); From d17954d4fb990892d2d366f3709160ecad412080 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Wed, 24 Jun 2020 23:38:18 +0300 Subject: [PATCH 12/25] Removed unsued var --- CONTRIBUTING.md | 1 + app/controllers/api/avatars.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d497b3652b..58ebad92ae 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -169,6 +169,7 @@ Improve PHP exeution time by using [fully-qualified function calls](https://veew ```bash php-cs-fixer fix src/ --rules=native_function_invocation --allow-risky=yes +php-cs-fixer fix src/ --rules=no_unused_imports --dry-run ``` ## Tutorials diff --git a/app/controllers/api/avatars.php b/app/controllers/api/avatars.php index 6c38cbd8b5..c41b7418b4 100644 --- a/app/controllers/api/avatars.php +++ b/app/controllers/api/avatars.php @@ -26,7 +26,7 @@ $types = [ 'flags' => include __DIR__.'/../../config/avatars/flags.php', ]; -$avatarCallback = function ($type, $code, $width, $height, $quality) use ($types, $response, $request) { +$avatarCallback = function ($type, $code, $width, $height, $quality) use ($types, $response) { $code = \strtolower($code); $type = \strtolower($type); From 8e484d32d8a98cb43aef3508bcb805075de0a1c3 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Wed, 24 Jun 2020 23:38:36 +0300 Subject: [PATCH 13/25] Removed comment --- CONTRIBUTING.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 58ebad92ae..d497b3652b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -169,7 +169,6 @@ Improve PHP exeution time by using [fully-qualified function calls](https://veew ```bash php-cs-fixer fix src/ --rules=native_function_invocation --allow-risky=yes -php-cs-fixer fix src/ --rules=no_unused_imports --dry-run ``` ## Tutorials From c7366c745319fb07ca9cbf4a8a7010d940f6ade2 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Wed, 24 Jun 2020 23:59:04 +0300 Subject: [PATCH 14/25] Updated coding standards --- app/controllers/api/account.php | 13 ++++++------- app/controllers/api/avatars.php | 11 +++++++---- app/controllers/api/database.php | 2 +- app/controllers/api/health.php | 3 +-- app/controllers/api/projects.php | 10 +++++----- app/controllers/api/storage.php | 6 +++--- app/controllers/api/teams.php | 10 ++++------ app/controllers/mock.php | 31 ++++++++++--------------------- app/controllers/shared/api.php | 4 +--- app/controllers/web/console.php | 1 - app/controllers/web/home.php | 14 +++++++------- 11 files changed, 45 insertions(+), 60 deletions(-) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index a7c1c2c534..3327ef24e8 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -45,7 +45,6 @@ $utopia->init(function() use (&$oauth2Keys) { $oauth2Keys[] = 'oauth2'.\ucfirst($key); $oauth2Keys[] = 'oauth2'.\ucfirst($key).'AccessToken'; } - }); $utopia->post('/v1/account') @@ -223,7 +222,7 @@ $utopia->post('/v1/account/sessions') ->setParam('resource', 'users/'.$profile->getId()) ; - if(!Config::getParam('domainVerification')) { + if (!Config::getParam('domainVerification')) { $response ->addHeader('X-Fallback-Cookies', \json_encode([Auth::$cookieName => Auth::encodeSession($profile->getId(), $secret)])) ; @@ -500,13 +499,13 @@ $utopia->get('/v1/account/sessions/oauth2/:provider/redirect') ->setParam('data', ['provider' => $provider]) ; - if(!Config::getParam('domainVerification')) { + if (!Config::getParam('domainVerification')) { $response ->addHeader('X-Fallback-Cookies', \json_encode([Auth::$cookieName => Auth::encodeSession($user->getId(), $secret)])) ; } - if($state['success'] === $oauthDefaultSuccess) { // Add keys for non-web platforms + if ($state['success'] === $oauthDefaultSuccess) { // Add keys for non-web platforms $state['success'] = URLParser::parse($state['success']); $query = URLParser::parseQuery($state['success']['query']); $query['project'] = $project->getId(); @@ -920,7 +919,7 @@ $utopia->delete('/v1/account') ]) ; - if(!Config::getParam('domainVerification')) { + if (!Config::getParam('domainVerification')) { $response ->addHeader('X-Fallback-Cookies', \json_encode([])) ; @@ -972,7 +971,7 @@ $utopia->delete('/v1/account/sessions/:sessionId') ]) ; - if(!Config::getParam('domainVerification')) { + if (!Config::getParam('domainVerification')) { $response ->addHeader('X-Fallback-Cookies', \json_encode([])) ; @@ -1025,7 +1024,7 @@ $utopia->delete('/v1/account/sessions') ]) ; - if(!Config::getParam('domainVerification')) { + if (!Config::getParam('domainVerification')) { $response ->addHeader('X-Fallback-Cookies', \json_encode([])) ; diff --git a/app/controllers/api/avatars.php b/app/controllers/api/avatars.php index c41b7418b4..289167c6ad 100644 --- a/app/controllers/api/avatars.php +++ b/app/controllers/api/avatars.php @@ -100,7 +100,8 @@ $utopia->get('/v1/avatars/credit-cards/:code') ->label('sdk.method', 'getCreditCard') ->label('sdk.methodType', 'location') ->label('sdk.description', '/docs/references/avatars/get-credit-card.md') - ->action(function ($code, $width, $height, $quality) use ($avatarCallback) { return $avatarCallback('credit-cards', $code, $width, $height, $quality); + ->action(function ($code, $width, $height, $quality) use ($avatarCallback) { + return $avatarCallback('credit-cards', $code, $width, $height, $quality); }); $utopia->get('/v1/avatars/browsers/:code') @@ -115,7 +116,8 @@ $utopia->get('/v1/avatars/browsers/:code') ->label('sdk.method', 'getBrowser') ->label('sdk.methodType', 'location') ->label('sdk.description', '/docs/references/avatars/get-browser.md') - ->action(function ($code, $width, $height, $quality) use ($avatarCallback) { return $avatarCallback('browsers', $code, $width, $height, $quality); + ->action(function ($code, $width, $height, $quality) use ($avatarCallback) { + return $avatarCallback('browsers', $code, $width, $height, $quality); }); $utopia->get('/v1/avatars/flags/:code') @@ -130,7 +132,8 @@ $utopia->get('/v1/avatars/flags/:code') ->label('sdk.method', 'getFlag') ->label('sdk.methodType', 'location') ->label('sdk.description', '/docs/references/avatars/get-flag.md') - ->action(function ($code, $width, $height, $quality) use ($avatarCallback) { return $avatarCallback('flags', $code, $width, $height, $quality); + ->action(function ($code, $width, $height, $quality) use ($avatarCallback) { + return $avatarCallback('flags', $code, $width, $height, $quality); }); $utopia->get('/v1/avatars/image') @@ -424,7 +427,7 @@ $utopia->get('/v1/avatars/initials') $initials .= (isset($w[0])) ? $w[0] : ''; $code += (isset($w[0])) ? \ord($w[0]) : 0; - if($key == 1) { + if ($key == 1) { break; } } diff --git a/app/controllers/api/database.php b/app/controllers/api/database.php index d8ecedab84..5deb70f760 100644 --- a/app/controllers/api/database.php +++ b/app/controllers/api/database.php @@ -425,7 +425,7 @@ $utopia->post('/v1/database/collections/:collectionId/documents') $key = (isset($rule['key'])) ? $rule['key'] : ''; $default = (isset($rule['default'])) ? $rule['default'] : null; - if(!isset($data[$key])) { + if (!isset($data[$key])) { $data[$key] = $default; } } diff --git a/app/controllers/api/health.php b/app/controllers/api/health.php index 94c99bc82b..0cf4098f1b 100644 --- a/app/controllers/api/health.php +++ b/app/controllers/api/health.php @@ -193,7 +193,6 @@ $utopia->get('/v1/health/storage/local') ->label('sdk.description', '/docs/references/health/get-storage-local.md') ->action( function () use ($response) { - foreach ([ 'Uploads' => APP_STORAGE_UPLOADS, 'Cache' => APP_STORAGE_CACHE, @@ -224,7 +223,7 @@ $utopia->get('/v1/health/anti-virus') ->label('sdk.description', '/docs/references/health/get-storage-anti-virus.md') ->action( function () use ($request, $response) { - if($request->getServer('_APP_STORAGE_ANTIVIRUS') === 'disabled') { // Check if scans are enabled + if ($request->getServer('_APP_STORAGE_ANTIVIRUS') === 'disabled') { // Check if scans are enabled throw new Exception('Anitvirus is disabled'); } diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 4511c34807..f95f89a958 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -415,7 +415,7 @@ $utopia->delete('/v1/projects/:projectId') $deletes->setParam('document', $project->getArrayCopy()); - foreach(['keys', 'webhooks', 'tasks', 'platforms', 'domains'] as $key) { // Delete all children (keys, webhooks, tasks [stop tasks?], platforms) + foreach (['keys', 'webhooks', 'tasks', 'platforms', 'domains'] as $key) { // Delete all children (keys, webhooks, tasks [stop tasks?], platforms) $list = $project->getAttribute('webhooks', []); foreach ($list as $document) { /* @var $document Document */ @@ -1250,7 +1250,7 @@ $utopia->post('/v1/projects/:projectId/domains') $target = new Domain($request->getServer('_APP_DOMAIN_TARGET', '')); - if(!$target->isKnown() || $target->isTest()) { + if (!$target->isKnown() || $target->isTest()) { throw new Exception('Unreachable CNAME target ('.$target->get().'), plesse use a domain with a public suffix.', 500); } @@ -1357,18 +1357,18 @@ $utopia->patch('/v1/projects/:projectId/domains/:domainId/verification') $target = new Domain($request->getServer('_APP_DOMAIN_TARGET', '')); - if(!$target->isKnown() || $target->isTest()) { + if (!$target->isKnown() || $target->isTest()) { throw new Exception('Unreachable CNAME target ('.$target->get().'), plesse use a domain with a public suffix.', 500); } - if($domain->getAttribute('verification') === true) { + if ($domain->getAttribute('verification') === true) { return $response->json($domain->getArrayCopy()); } // Verify Domain with DNS records $validator = new CNAME($target->get()); - if(!$validator->isValid($domain->getAttribute('domain', ''))) { + if (!$validator->isValid($domain->getAttribute('domain', ''))) { throw new Exception('Failed to verify domain', 401); } diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index 6ffcfbf985..d5a4ec2c2b 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -198,7 +198,7 @@ $utopia->post('/v1/storage/files') $mimeType = $device->getFileMimeType($path); // Get mime-type before compression and encryption - if($request->getServer('_APP_STORAGE_ANTIVIRUS') === 'enabled') { // Check if scans are enabled + if ($request->getServer('_APP_STORAGE_ANTIVIRUS') === 'enabled') { // Check if scans are enabled $antiVirus = new Network('clamav', 3310); // Check if file size is exceeding allowed limit @@ -216,7 +216,7 @@ $utopia->post('/v1/storage/files') $iv = OpenSSL::randomPseudoBytes(OpenSSL::cipherIVLength(OpenSSL::CIPHER_AES_128_GCM)); $data = OpenSSL::encrypt($data, OpenSSL::CIPHER_AES_128_GCM, $key, 0, $iv, $tag); - if(!$device->write($path, $data)) { + if (!$device->write($path, $data)) { throw new Exception('Failed to save file', 500); } @@ -370,7 +370,7 @@ $utopia->get('/v1/storage/files/:fileId/preview') $cipher = $file->getAttribute('fileOpenSSLCipher'); $mime = $file->getAttribute('mimeType'); - if(!\in_array($mime, $inputs)) { + if (!\in_array($mime, $inputs)) { $path = (\array_key_exists($mime, $fileLogos)) ? $fileLogos[$mime] : $fileLogos['default']; $algorithm = null; $cipher = null; diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index b8e0bf1194..8aad25bc82 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -306,12 +306,11 @@ $utopia->post('/v1/teams/:teamId/memberships') 'secret' => Auth::hash($secret), ]); - if(APP_MODE_ADMIN === $mode) { // Allow admin to create membership + if (APP_MODE_ADMIN === $mode) { // Allow admin to create membership Authorization::disable(); $membership = $projectDB->createDocument($membership->getArrayCopy()); Authorization::reset(); - } - else { + } else { $membership = $projectDB->createDocument($membership->getArrayCopy()); } @@ -344,7 +343,7 @@ $utopia->post('/v1/teams/:teamId/memberships') ->setParam('{{text-cta}}', '#ffffff') ; - if(APP_MODE_ADMIN !== $mode) { // No need in comfirmation when in admin mode + if (APP_MODE_ADMIN !== $mode) { // No need in comfirmation when in admin mode $mail ->setParam('event', 'teams.membership.create') ->setParam('recipient', $email) @@ -433,7 +432,6 @@ $utopia->get('/v1/teams/:teamId/memberships') } $response->json(['sum' => $projectDB->getSum(), 'memberships' => $users]); - } ); @@ -544,7 +542,7 @@ $utopia->patch('/v1/teams/:teamId/memberships/:inviteId/status') ->setParam('resource', 'teams/'.$teamId) ; - if(!Config::getParam('domainVerification')) { + if (!Config::getParam('domainVerification')) { $response ->addHeader('X-Fallback-Cookies', \json_encode([Auth::$cookieName => Auth::encodeSession($user->getId(), $secret)])) ; diff --git a/app/controllers/mock.php b/app/controllers/mock.php index 67e0776a90..d0848d2861 100644 --- a/app/controllers/mock.php +++ b/app/controllers/mock.php @@ -22,7 +22,6 @@ $utopia->get('/v1/mock/tests/foo') ->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param') ->action( function ($x, $y, $z) { - } ); @@ -37,7 +36,6 @@ $utopia->post('/v1/mock/tests/foo') ->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param') ->action( function ($x, $y, $z) { - } ); @@ -52,7 +50,6 @@ $utopia->patch('/v1/mock/tests/foo') ->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param') ->action( function ($x, $y, $z) { - } ); @@ -67,7 +64,6 @@ $utopia->put('/v1/mock/tests/foo') ->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param') ->action( function ($x, $y, $z) { - } ); @@ -82,7 +78,6 @@ $utopia->delete('/v1/mock/tests/foo') ->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param') ->action( function ($x, $y, $z) { - } ); @@ -97,7 +92,6 @@ $utopia->get('/v1/mock/tests/bar') ->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param') ->action( function ($x, $y, $z) { - } ); @@ -112,7 +106,6 @@ $utopia->post('/v1/mock/tests/bar') ->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param') ->action( function ($x, $y, $z) { - } ); @@ -127,7 +120,6 @@ $utopia->patch('/v1/mock/tests/bar') ->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param') ->action( function ($x, $y, $z) { - } ); @@ -142,7 +134,6 @@ $utopia->put('/v1/mock/tests/bar') ->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param') ->action( function ($x, $y, $z) { - } ); @@ -157,7 +148,6 @@ $utopia->delete('/v1/mock/tests/bar') ->param('z', null, function () { return new ArrayList(new Text(256)); }, 'Sample array param') ->action( function ($x, $y, $z) { - } ); @@ -180,19 +170,19 @@ $utopia->post('/v1/mock/tests/general/upload') $file['size'] = (\is_array($file['size'])) ? $file['size'] : [$file['size']]; foreach ($file['name'] as $i => $name) { - if($name !== 'file.png') { + if ($name !== 'file.png') { throw new Exception('Wrong file name', 400); } } foreach ($file['size'] as $i => $size) { - if($size !== 38756) { + if ($size !== 38756) { throw new Exception('Wrong file size', 400); } } foreach ($file['tmp_name'] as $i => $tmpName) { - if(\md5(\file_get_contents($tmpName)) !== 'd80e7e6999a3eb2ae0d631a96fe135a4') { + if (\md5(\file_get_contents($tmpName)) !== 'd80e7e6999a3eb2ae0d631a96fe135a4') { throw new Exception('Wrong file uploaded', 400); } } @@ -242,7 +232,7 @@ $utopia->get('/v1/mock/tests/general/get-cookie') ->label('sdk.description', 'Mock a get cookie request for SDK tests') ->action( function () use ($request) { - if($request->getCookie('cookieName', '') !== 'cookieValue') { + if ($request->getCookie('cookieName', '') !== 'cookieValue') { throw new Exception('Missing cookie value', 400); } } @@ -285,15 +275,15 @@ $utopia->get('/v1/mock/tests/general/oauth2/token') ->param('code', '', function () { return new Text(100); }, 'OAuth2 state.') ->action( function ($clientId, $redirectURI, $clientSecret, $code) use ($response) { - if($clientId != '1') { + if ($clientId != '1') { throw new Exception('Invalid client ID'); } - if($clientSecret != '123456') { + if ($clientSecret != '123456') { throw new Exception('Invalid client secret'); } - if($code != 'abcdef') { + if ($code != 'abcdef') { throw new Exception('Invalid token'); } @@ -308,7 +298,7 @@ $utopia->get('/v1/mock/tests/general/oauth2/user') ->param('token', '', function () { return new Text(100); }, 'OAuth2 Access Token.') ->action( function ($token) use ($response) { - if($token != '123456') { + if ($token != '123456') { throw new Exception('Invalid token'); } @@ -345,12 +335,11 @@ $utopia->get('/v1/mock/tests/general/oauth2/failure') ); $utopia->shutdown(function() use ($response, $request, &$result, $utopia) { - $route = $utopia->match($request); $path = APP_STORAGE_CACHE.'/tests.json'; $tests = (\file_exists($path)) ? \json_decode(\file_get_contents($path), true) : []; - if(!\is_array($tests)) { + if (!\is_array($tests)) { throw new Exception('Failed to read results', 500); } @@ -358,7 +347,7 @@ $utopia->shutdown(function() use ($response, $request, &$result, $utopia) { $tests = \array_merge($tests, $result); - if(!\file_put_contents($path, \json_encode($tests), LOCK_EX)) { + if (!\file_put_contents($path, \json_encode($tests), LOCK_EX)) { throw new Exception('Failed to save resutls', 500); } diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index 97da51031d..d74f6939f9 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -7,10 +7,9 @@ use Utopia\Abuse\Adapters\TimeLimit; global $utopia, $request, $response, $register, $user, $project; $utopia->init(function () use ($utopia, $request, $response, $register, $user, $project) { - $route = $utopia->match($request); - if(empty($project->getId()) && $route->getLabel('abuse-limit', 0) > 0) { // Abuse limit requires an active project scope + if (empty($project->getId()) && $route->getLabel('abuse-limit', 0) > 0) { // Abuse limit requires an active project scope throw new Exception('Missing or unknown project ID', 400); } @@ -37,7 +36,6 @@ $utopia->init(function () use ($utopia, $request, $response, $register, $user, $ $abuse = new Abuse($timeLimit); if ($timeLimit->limit()) { - $response ->addHeader('X-RateLimit-Limit', $timeLimit->limit()) ->addHeader('X-RateLimit-Remaining', $timeLimit->remaining()) diff --git a/app/controllers/web/console.php b/app/controllers/web/console.php index ff59b03072..ead5017e6b 100644 --- a/app/controllers/web/console.php +++ b/app/controllers/web/console.php @@ -213,7 +213,6 @@ $utopia->get('/console/database/collection') ->addHeader('Expires', 0) ->addHeader('Pragma', 'no-cache') ; - }); $utopia->get('/console/database/document') diff --git a/app/controllers/web/home.php b/app/controllers/web/home.php index cfec346b91..ced983bca5 100644 --- a/app/controllers/web/home.php +++ b/app/controllers/web/home.php @@ -183,11 +183,11 @@ $utopia->get('/open-api-2.json') } foreach ($services as $service) { /* @noinspection PhpIncludeInspection */ - if($tests && !isset($service['tests'])) { + if ($tests && !isset($service['tests'])) { continue; } - if($tests && !$service['tests']) { + if ($tests && !$service['tests']) { continue; } @@ -347,19 +347,19 @@ $utopia->get('/open-api-2.json') ]; if ($extensions) { - if(isset($output['securityDefinitions']['Project'])) { + if (isset($output['securityDefinitions']['Project'])) { $output['securityDefinitions']['Project']['extensions'] = ['demo' => '5df5acd0d48c2']; } - if(isset($output['securityDefinitions']['Key'])) { + if (isset($output['securityDefinitions']['Key'])) { $output['securityDefinitions']['Key']['extensions'] = ['demo' => '919c2d18fb5d4...a2ae413da83346ad2']; } - if(isset($output['securityDefinitions']['Locale'])) { + if (isset($output['securityDefinitions']['Locale'])) { $output['securityDefinitions']['Locale']['extensions'] = ['demo' => 'en']; } - if(isset($output['securityDefinitions']['Mode'])) { + if (isset($output['securityDefinitions']['Mode'])) { $output['securityDefinitions']['Mode']['extensions'] = ['demo' => '']; } } @@ -374,7 +374,7 @@ $utopia->get('/open-api-2.json') continue; } - if($platform !== APP_PLATFORM_CONSOLE && !\in_array($platforms[$platform], $route->getLabel('sdk.platform', []))) { + if ($platform !== APP_PLATFORM_CONSOLE && !\in_array($platforms[$platform], $route->getLabel('sdk.platform', []))) { continue; } From e89004c7f4581e25f5ff678b0a01d5671f962f6f Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Wed, 24 Jun 2020 23:59:57 +0300 Subject: [PATCH 15/25] Updated docs --- CONTRIBUTING.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d497b3652b..b722a0b198 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -171,6 +171,16 @@ Improve PHP exeution time by using [fully-qualified function calls](https://veew php-cs-fixer fix src/ --rules=native_function_invocation --allow-risky=yes ``` +Coding Standards: + +```bash +php-cs-fixer fix app/controllers --rules='{"braces": {"allow_single_line_closure": true}}' +``` + +```bash +php-cs-fixer fix src --rules='{"braces": {"allow_single_line_closure": true}}' +``` + ## Tutorials From time to time, our team will add tutorials that will help contributors find their way in the Appwrite source code. Below is a list of currently available tutorials: From dcf4e948e743f286863962f1122b3025276ef29c Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Thu, 25 Jun 2020 00:02:27 +0300 Subject: [PATCH 16/25] Fixed coding standards --- src/Appwrite/Auth/OAuth2.php | 12 ++++++------ src/Appwrite/Auth/OAuth2/Apple.php | 7 ++++--- src/Appwrite/Auth/OAuth2/GitHub.php | 1 - src/Appwrite/Auth/OAuth2/Slack.php | 1 - src/Appwrite/Database/Adapter/MySQL.php | 6 +++--- src/Appwrite/Database/Document.php | 2 +- src/Appwrite/Database/Validator/Authorization.php | 3 ++- src/Appwrite/Database/Validator/DocumentId.php | 8 ++++---- src/Appwrite/Database/Validator/Key.php | 2 +- src/Appwrite/Network/Validator/CNAME.php | 6 +++--- src/Appwrite/Network/Validator/Origin.php | 8 ++++---- src/Appwrite/Storage/Device/Local.php | 9 ++++----- src/Appwrite/Storage/Validator/FileType.php | 2 +- 13 files changed, 33 insertions(+), 34 deletions(-) diff --git a/src/Appwrite/Auth/OAuth2.php b/src/Appwrite/Auth/OAuth2.php index 8547edc758..14c6c94a4a 100644 --- a/src/Appwrite/Auth/OAuth2.php +++ b/src/Appwrite/Auth/OAuth2.php @@ -44,7 +44,7 @@ abstract class OAuth2 $this->appSecret = $appSecret; $this->callback = $callback; $this->state = $state; - foreach($scopes as $scope) { + foreach ($scopes as $scope) { $this->addScope($scope); } } @@ -95,15 +95,15 @@ abstract class OAuth2 protected function addScope(string $scope):OAuth2 { // Add a scope to the scopes array if it isn't already present - if (!\in_array($scope, $this->scopes)){ - $this->scopes[] = $scope; + if (!\in_array($scope, $this->scopes)) { + $this->scopes[] = $scope; } return $this; } - /** - * @return array - */ + /** + * @return array + */ protected function getScopes():array { return $this->scopes; diff --git a/src/Appwrite/Auth/OAuth2/Apple.php b/src/Appwrite/Auth/OAuth2/Apple.php index 9fdf2ab222..097cbea936 100644 --- a/src/Appwrite/Auth/OAuth2/Apple.php +++ b/src/Appwrite/Auth/OAuth2/Apple.php @@ -166,7 +166,9 @@ class Apple extends OAuth2 $success = \openssl_sign($payload, $signature, $pkey, OPENSSL_ALGO_SHA256); - if (!$success) return ''; + if (!$success) { + return ''; + } return $payload.'.'.$this->encode($this->fromDER($signature, 64)); } @@ -205,8 +207,7 @@ class Apple extends OAuth2 if ('81' === \mb_substr($hex, 2, 2, '8bit')) { // LENGTH > 128 $hex = \mb_substr($hex, 6, null, '8bit'); - } - else { + } else { $hex = \mb_substr($hex, 4, null, '8bit'); } if ('02' !== \mb_substr($hex, 0, 2, '8bit')) { // INTEGER diff --git a/src/Appwrite/Auth/OAuth2/GitHub.php b/src/Appwrite/Auth/OAuth2/GitHub.php index 9f571da3a5..882f2d3f2a 100644 --- a/src/Appwrite/Auth/OAuth2/GitHub.php +++ b/src/Appwrite/Auth/OAuth2/GitHub.php @@ -37,7 +37,6 @@ class Github extends OAuth2 'scope' => \implode(' ', $this->getScopes()), 'state' => \json_encode($this->state) ]); - } /** diff --git a/src/Appwrite/Auth/OAuth2/Slack.php b/src/Appwrite/Auth/OAuth2/Slack.php index 6848046868..c5d8f7c53b 100644 --- a/src/Appwrite/Auth/OAuth2/Slack.php +++ b/src/Appwrite/Auth/OAuth2/Slack.php @@ -125,7 +125,6 @@ class Slack extends OAuth2 */ protected function getUser(string $accessToken):array { - if (empty($this->user)) { // https://api.slack.com/methods/users.identity $user = $this->request( diff --git a/src/Appwrite/Database/Adapter/MySQL.php b/src/Appwrite/Database/Adapter/MySQL.php index 461d2a29ef..f766666306 100644 --- a/src/Appwrite/Database/Adapter/MySQL.php +++ b/src/Appwrite/Database/Adapter/MySQL.php @@ -175,7 +175,7 @@ class MySQL extends Adapter $result = $st->fetch(); - if($result && isset($result['signature'])) { + if ($result && isset($result['signature'])) { $oldSignature = $result['signature']; if ($signature === $oldSignature) { @@ -187,14 +187,14 @@ class MySQL extends Adapter /** * Check Unique Keys */ - foreach($unique as $key => $value) { + foreach ($unique as $key => $value) { $st = $this->getPDO()->prepare('INSERT INTO `'.$this->getNamespace().'.database.unique` SET `key` = :key; '); $st->bindValue(':key', \md5($data['$collection'].':'.$key.'='.$value), PDO::PARAM_STR); - if(!$st->execute()) { + if (!$st->execute()) { throw new Duplicate('Duplicated Property: '.$key.'='.$value); } } diff --git a/src/Appwrite/Database/Document.php b/src/Appwrite/Database/Document.php index a0445702e4..bd085c2fa5 100644 --- a/src/Appwrite/Database/Document.php +++ b/src/Appwrite/Database/Document.php @@ -134,7 +134,7 @@ class Document extends ArrayObject */ public function removeAttribute($key) { - if(isset($this[$key])) { + if (isset($this[$key])) { unset($this[$key]); } diff --git a/src/Appwrite/Database/Validator/Authorization.php b/src/Appwrite/Database/Validator/Authorization.php index 3225251bb7..fdadd05109 100644 --- a/src/Appwrite/Database/Validator/Authorization.php +++ b/src/Appwrite/Database/Validator/Authorization.php @@ -121,7 +121,8 @@ class Authorization extends Validator * This will be used for the * value set on the self::reset() method */ - public static function setDefaultStatus($status) { + public static function setDefaultStatus($status) + { self::$statusDefault = $status; self::$status = $status; } diff --git a/src/Appwrite/Database/Validator/DocumentId.php b/src/Appwrite/Database/Validator/DocumentId.php index 0c89e88651..56041dc34b 100644 --- a/src/Appwrite/Database/Validator/DocumentId.php +++ b/src/Appwrite/Database/Validator/DocumentId.php @@ -60,19 +60,19 @@ class DocumentId extends Validator { $document = $this->database->getDocument($id); - if(!$document) { + if (!$document) { return false; } - if(!$document instanceof Document) { + if (!$document instanceof Document) { return false; } - if(!$document->getId()) { + if (!$document->getId()) { return false; } - if($document->getCollection() !== $this->collection) { + if ($document->getCollection() !== $this->collection) { return false; } diff --git a/src/Appwrite/Database/Validator/Key.php b/src/Appwrite/Database/Validator/Key.php index a71425a52a..53cdc3eb77 100644 --- a/src/Appwrite/Database/Validator/Key.php +++ b/src/Appwrite/Database/Validator/Key.php @@ -34,7 +34,7 @@ class Key extends Validator */ public function isValid($value) { - if(!\is_string($value)) { + if (!\is_string($value)) { return false; } diff --git a/src/Appwrite/Network/Validator/CNAME.php b/src/Appwrite/Network/Validator/CNAME.php index f9a8e5a13f..708396e81c 100644 --- a/src/Appwrite/Network/Validator/CNAME.php +++ b/src/Appwrite/Network/Validator/CNAME.php @@ -39,12 +39,12 @@ class CNAME extends Validator return false; } - if(!$records || !\is_array($records)) { + if (!$records || !\is_array($records)) { return false; } - foreach($records as $record) { - if(isset($record['target']) && $record['target'] === $this->target) { + foreach ($records as $record) { + if (isset($record['target']) && $record['target'] === $this->target) { return true; } } diff --git a/src/Appwrite/Network/Validator/Origin.php b/src/Appwrite/Network/Validator/Origin.php index a0c06503af..eb838367e1 100644 --- a/src/Appwrite/Network/Validator/Origin.php +++ b/src/Appwrite/Network/Validator/Origin.php @@ -56,7 +56,7 @@ class Origin extends Validator */ public function __construct($platforms) { - foreach($platforms as $platform) { + foreach ($platforms as $platform) { $type = (isset($platform['type'])) ? $platform['type'] : ''; switch ($type) { @@ -81,7 +81,7 @@ class Origin extends Validator public function getDescription() { - if(!\array_key_exists($this->client, $this->platforms)) { + if (!\array_key_exists($this->client, $this->platforms)) { return 'Unsupported platform'; } @@ -105,11 +105,11 @@ class Origin extends Validator $this->host = $host; $this->client = $scheme; - if(empty($host)) { + if (empty($host)) { return true; } - if(\in_array($host, $this->clients)) { + if (\in_array($host, $this->clients)) { return true; } diff --git a/src/Appwrite/Storage/Device/Local.php b/src/Appwrite/Storage/Device/Local.php index 961daee38e..d786e2b076 100644 --- a/src/Appwrite/Storage/Device/Local.php +++ b/src/Appwrite/Storage/Device/Local.php @@ -157,16 +157,15 @@ class Local extends Device */ public function delete(string $path, bool $recursive = false):bool { - if(\is_dir($path) && $recursive) { + if (\is_dir($path) && $recursive) { $files = \glob($path.'*', GLOB_MARK); // GLOB_MARK adds a slash to directories returned - foreach($files as $file) { - $this->delete($file, true); + foreach ($files as $file) { + $this->delete($file, true); } \rmdir($path); - } - elseif(\is_file($path)) { + } elseif (\is_file($path)) { return \unlink($path); } diff --git a/src/Appwrite/Storage/Validator/FileType.php b/src/Appwrite/Storage/Validator/FileType.php index c66631e73b..164e59924b 100644 --- a/src/Appwrite/Storage/Validator/FileType.php +++ b/src/Appwrite/Storage/Validator/FileType.php @@ -64,7 +64,7 @@ class FileType extends Validator */ public function isValid($path) { - if(!\is_readable($path)) { + if (!\is_readable($path)) { return false; } From 65c08825a547757c0629dce8b43d1ffe2381ef31 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Thu, 25 Jun 2020 00:05:16 +0300 Subject: [PATCH 17/25] Updated coding standards --- src/Appwrite/Auth/OAuth2.php | 4 +-- src/Appwrite/Auth/OAuth2/Apple.php | 2 +- src/Appwrite/Auth/OAuth2/Facebook.php | 2 +- src/Appwrite/Auth/OAuth2/Gitlab.php | 2 +- src/Appwrite/Auth/OAuth2/Google.php | 2 +- src/Appwrite/Auth/OAuth2/Microsoft.php | 2 +- src/Appwrite/Auth/OAuth2/Mock.php | 2 +- src/Appwrite/Auth/OAuth2/Slack.php | 4 +-- src/Appwrite/Auth/OAuth2/Spotify.php | 7 ++-- src/Appwrite/Auth/OAuth2/Twitch.php | 7 ++-- src/Appwrite/Auth/OAuth2/Yahoo.php | 7 ++-- .../Database/Validator/Authorization.php | 4 +-- src/Appwrite/Network/Validator/CNAME.php | 2 +- src/Appwrite/Network/Validator/Origin.php | 2 +- src/Appwrite/Storage/Storage.php | 2 +- src/Appwrite/URL/URL.php | 34 +++++++++---------- 16 files changed, 47 insertions(+), 38 deletions(-) diff --git a/src/Appwrite/Auth/OAuth2.php b/src/Appwrite/Auth/OAuth2.php index 14c6c94a4a..2882746608 100644 --- a/src/Appwrite/Auth/OAuth2.php +++ b/src/Appwrite/Auth/OAuth2.php @@ -89,12 +89,12 @@ abstract class OAuth2 /** * @param $scope - * + * * @return $this */ protected function addScope(string $scope):OAuth2 { - // Add a scope to the scopes array if it isn't already present + // Add a scope to the scopes array if it isn't already present if (!\in_array($scope, $this->scopes)) { $this->scopes[] = $scope; } diff --git a/src/Appwrite/Auth/OAuth2/Apple.php b/src/Appwrite/Auth/OAuth2/Apple.php index 097cbea936..11a0b0c694 100644 --- a/src/Appwrite/Auth/OAuth2/Apple.php +++ b/src/Appwrite/Auth/OAuth2/Apple.php @@ -19,7 +19,7 @@ class Apple extends OAuth2 * @var array */ protected $scopes = [ - "name", + "name", "email" ]; diff --git a/src/Appwrite/Auth/OAuth2/Facebook.php b/src/Appwrite/Auth/OAuth2/Facebook.php index 6a2982242b..543fbaa1d7 100644 --- a/src/Appwrite/Auth/OAuth2/Facebook.php +++ b/src/Appwrite/Auth/OAuth2/Facebook.php @@ -58,7 +58,7 @@ class Facebook extends OAuth2 'redirect_uri' => $this->callback, 'client_secret' => $this->appSecret, 'code' => $code - ]) + ]) ); $accessToken = \json_decode($accessToken, true); diff --git a/src/Appwrite/Auth/OAuth2/Gitlab.php b/src/Appwrite/Auth/OAuth2/Gitlab.php index 93f27db510..369fe0e56c 100644 --- a/src/Appwrite/Auth/OAuth2/Gitlab.php +++ b/src/Appwrite/Auth/OAuth2/Gitlab.php @@ -4,7 +4,7 @@ namespace Appwrite\Auth\OAuth2; use Appwrite\Auth\OAuth2; -// Reference Material +// Reference Material // https://docs.gitlab.com/ee/api/oauth2.html class Gitlab extends OAuth2 diff --git a/src/Appwrite/Auth/OAuth2/Google.php b/src/Appwrite/Auth/OAuth2/Google.php index 2f4a4febc0..5066809109 100644 --- a/src/Appwrite/Auth/OAuth2/Google.php +++ b/src/Appwrite/Auth/OAuth2/Google.php @@ -4,7 +4,7 @@ namespace Appwrite\Auth\OAuth2; use Appwrite\Auth\OAuth2; -// Reference Material +// Reference Material // https://developers.google.com/oauthplayground/ // https://developers.google.com/identity/protocols/OAuth2 // https://developers.google.com/identity/protocols/OAuth2WebServer diff --git a/src/Appwrite/Auth/OAuth2/Microsoft.php b/src/Appwrite/Auth/OAuth2/Microsoft.php index 8f543c7962..349446ead3 100644 --- a/src/Appwrite/Auth/OAuth2/Microsoft.php +++ b/src/Appwrite/Auth/OAuth2/Microsoft.php @@ -19,7 +19,7 @@ class Microsoft extends OAuth2 * @var array */ protected $scopes = [ - 'offline_access', + 'offline_access', 'user.read' ]; diff --git a/src/Appwrite/Auth/OAuth2/Mock.php b/src/Appwrite/Auth/OAuth2/Mock.php index e1744343fb..d7f9962937 100644 --- a/src/Appwrite/Auth/OAuth2/Mock.php +++ b/src/Appwrite/Auth/OAuth2/Mock.php @@ -134,4 +134,4 @@ class Mock extends OAuth2 return $this->user; } -} \ No newline at end of file +} diff --git a/src/Appwrite/Auth/OAuth2/Slack.php b/src/Appwrite/Auth/OAuth2/Slack.php index c5d8f7c53b..20a67456e4 100644 --- a/src/Appwrite/Auth/OAuth2/Slack.php +++ b/src/Appwrite/Auth/OAuth2/Slack.php @@ -15,8 +15,8 @@ class Slack extends OAuth2 * @var array */ protected $scopes = [ - 'identity.avatar', - 'identity.basic', + 'identity.avatar', + 'identity.basic', 'identity.email', 'identity.team' ]; diff --git a/src/Appwrite/Auth/OAuth2/Spotify.php b/src/Appwrite/Auth/OAuth2/Spotify.php index 1bc3d51909..7962386b08 100644 --- a/src/Appwrite/Auth/OAuth2/Spotify.php +++ b/src/Appwrite/Auth/OAuth2/Spotify.php @@ -137,8 +137,11 @@ class Spotify extends OAuth2 protected function getUser(string $accessToken) { if (empty($this->user)) { - $this->user = \json_decode($this->request('GET', - $this->resourceEndpoint . "me", ['Authorization: Bearer '.\urlencode($accessToken)]), true); + $this->user = \json_decode($this->request( + 'GET', + $this->resourceEndpoint . "me", + ['Authorization: Bearer '.\urlencode($accessToken)] + ), true); } return $this->user; diff --git a/src/Appwrite/Auth/OAuth2/Twitch.php b/src/Appwrite/Auth/OAuth2/Twitch.php index 94f735b505..463bbf9175 100644 --- a/src/Appwrite/Auth/OAuth2/Twitch.php +++ b/src/Appwrite/Auth/OAuth2/Twitch.php @@ -139,8 +139,11 @@ class Twitch extends OAuth2 protected function getUser(string $accessToken) { if (empty($this->user)) { - $this->user = \json_decode($this->request('GET', - $this->resourceEndpoint, ['Authorization: Bearer '.\urlencode($accessToken)]), true)['data']['0']; + $this->user = \json_decode($this->request( + 'GET', + $this->resourceEndpoint, + ['Authorization: Bearer '.\urlencode($accessToken)] + ), true)['data']['0']; } return $this->user; diff --git a/src/Appwrite/Auth/OAuth2/Yahoo.php b/src/Appwrite/Auth/OAuth2/Yahoo.php index 41100132f8..8593c41ce8 100644 --- a/src/Appwrite/Auth/OAuth2/Yahoo.php +++ b/src/Appwrite/Auth/OAuth2/Yahoo.php @@ -153,8 +153,11 @@ class Yahoo extends OAuth2 protected function getUser(string $accessToken) { if (empty($this->user)) { - $this->user = \json_decode($this->request('GET', - $this->resourceEndpoint, ['Authorization: Bearer '.\urlencode($accessToken)]), true); + $this->user = \json_decode($this->request( + 'GET', + $this->resourceEndpoint, + ['Authorization: Bearer '.\urlencode($accessToken)] + ), true); } return $this->user; diff --git a/src/Appwrite/Database/Validator/Authorization.php b/src/Appwrite/Database/Validator/Authorization.php index fdadd05109..444f651be0 100644 --- a/src/Appwrite/Database/Validator/Authorization.php +++ b/src/Appwrite/Database/Validator/Authorization.php @@ -111,7 +111,7 @@ class Authorization extends Validator /** * Default value in case we need * to reset Authorization status - * + * * @var bool */ public static $statusDefault = true; @@ -119,7 +119,7 @@ class Authorization extends Validator /** * Change default status. * This will be used for the - * value set on the self::reset() method + * value set on the self::reset() method */ public static function setDefaultStatus($status) { diff --git a/src/Appwrite/Network/Validator/CNAME.php b/src/Appwrite/Network/Validator/CNAME.php index 708396e81c..54e4987f16 100644 --- a/src/Appwrite/Network/Validator/CNAME.php +++ b/src/Appwrite/Network/Validator/CNAME.php @@ -26,7 +26,7 @@ class CNAME extends Validator /** * Check if CNAME record target value matches selected target - * + * * @param string $domain * * @return bool diff --git a/src/Appwrite/Network/Validator/Origin.php b/src/Appwrite/Network/Validator/Origin.php index eb838367e1..d1368a1c3e 100644 --- a/src/Appwrite/Network/Validator/Origin.php +++ b/src/Appwrite/Network/Validator/Origin.php @@ -92,7 +92,7 @@ class Origin extends Validator /** * Check if Origin has been whiltlisted * for access to the API - * + * * @param string $origin * * @return bool diff --git a/src/Appwrite/Storage/Storage.php b/src/Appwrite/Storage/Storage.php index 800c90b430..40c2889738 100644 --- a/src/Appwrite/Storage/Storage.php +++ b/src/Appwrite/Storage/Storage.php @@ -78,7 +78,7 @@ class Storage * * @return string */ - static public function human($bytes, $decimals = 2) + public static function human($bytes, $decimals = 2) { $units = array('B','kB','MB','GB','TB','PB','EB','ZB','YB'); $step = 1024; diff --git a/src/Appwrite/URL/URL.php b/src/Appwrite/URL/URL.php index b4e55039e4..5f2b54a65e 100644 --- a/src/Appwrite/URL/URL.php +++ b/src/Appwrite/URL/URL.php @@ -6,14 +6,14 @@ class URL { /** * Parse URL - * + * * Take a URL string and split it to array parts - * + * * @param string $url - * + * * @return array */ - static public function parse(string $url):array + public static function parse(string $url):array { $default = [ 'scheme' => '', @@ -31,15 +31,15 @@ class URL /** * Un-Parse URL - * + * * Take URL parts and combine them to a valid string - * + * * @param array $url * @param array $ommit - * + * * @return string */ - static public function unparse(array $url, array $ommit = []):string + public static function unparse(array $url, array $ommit = []):string { if (isset($url['path']) && \mb_substr($url['path'], 0, 1) !== '/') { $url['path'] = '/'.$url['path']; @@ -78,14 +78,14 @@ class URL /** * Parse Query String - * + * * Convert query string to array - * + * * @param string $query - * + * * @return array */ - static public function parseQuery(string $query):array + public static function parseQuery(string $query):array { \parse_str($query, $result); @@ -94,15 +94,15 @@ class URL /** * Un-Parse Query String - * + * * Convert query string array to string - * + * * @param string $query - * + * * @return array */ - static public function unparseQuery(array $query):string + public static function unparseQuery(array $query):string { return \http_build_query($query); } -} \ No newline at end of file +} From 86e9d03e07b9004e21f9b447a98d9171c67067d7 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Thu, 25 Jun 2020 00:10:52 +0300 Subject: [PATCH 18/25] Removed isDev global param --- app/controllers/api/database.php | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/app/controllers/api/database.php b/app/controllers/api/database.php index 5deb70f760..13646414a4 100644 --- a/app/controllers/api/database.php +++ b/app/controllers/api/database.php @@ -27,8 +27,6 @@ use GeoIp2\Database\Reader; include_once __DIR__ . '/../shared/api.php'; -$isDev = (App::MODE_TYPE_PRODUCTION !== $utopia->getMode()); - $utopia->post('/v1/database/collections') ->desc('Create Collection') ->label('webhook', 'database.collections.create') @@ -180,7 +178,7 @@ $utopia->get('/v1/database/collections/:collectionId') // ->param('collectionId', '', function () { return new UID(); }, 'Collection unique ID.') // ->action( // function ($collectionId) use ($response, $register, $projectDB, $project) { -// $collection = $projectDB->getDocument($collectionId); +// $collection = $projectDB->getDocument($collectionId, false); // if (empty($collection->getId()) || Database::SYSTEM_COLLECTION_COLLECTIONS != $collection->getCollection()) { // throw new Exception('Collection not found', 404); @@ -370,7 +368,7 @@ $utopia->post('/v1/database/collections/:collectionId/documents') throw new Exception('$id is not allowed for creating new documents, try update instead', 400); } - $collection = $projectDB->getDocument($collectionId/*, $isDev*/); + $collection = $projectDB->getDocument($collectionId, false); if (\is_null($collection->getId()) || Database::SYSTEM_COLLECTION_COLLECTIONS != $collection->getCollection()) { throw new Exception('Collection not found', 404); @@ -385,7 +383,7 @@ $utopia->post('/v1/database/collections/:collectionId/documents') // Read parent document + validate not 404 + validate read / write permission like patch method // Add payload to parent document property if ((!empty($parentDocument)) && (!empty($parentProperty))) { - $parentDocument = $projectDB->getDocument($parentDocument); + $parentDocument = $projectDB->getDocument($parentDocument, false); if (empty($parentDocument->getArrayCopy())) { // Check empty throw new Exception('No parent document found', 404); @@ -480,8 +478,8 @@ $utopia->get('/v1/database/collections/:collectionId/documents') ->param('first', 0, function () { return new Range(0, 1); }, 'Return only the first document. Pass 1 for true or 0 for false. The default value is 0.', true) ->param('last', 0, function () { return new Range(0, 1); }, 'Return only the last document. Pass 1 for true or 0 for false. The default value is 0.', true) ->action( - function ($collectionId, $filters, $offset, $limit, $orderField, $orderType, $orderCast, $search, $first, $last) use ($response, $projectDB, $isDev) { - $collection = $projectDB->getDocument($collectionId, $isDev); + function ($collectionId, $filters, $offset, $limit, $orderField, $orderType, $orderCast, $search, $first, $last) use ($response, $projectDB, $utopia) { + $collection = $projectDB->getDocument($collectionId, false); if (\is_null($collection->getId()) || Database::SYSTEM_COLLECTION_COLLECTIONS != $collection->getCollection()) { throw new Exception('Collection not found', 404); @@ -504,7 +502,7 @@ $utopia->get('/v1/database/collections/:collectionId/documents') if ($first || $last) { $response->json((!empty($list) ? $list->getArrayCopy() : [])); } else { - if ($isDev) { + if ($utopia->isDevelopment()) { $collection ->setAttribute('debug', $projectDB->getDebug()) ->setAttribute('limit', $limit) @@ -539,9 +537,9 @@ $utopia->get('/v1/database/collections/:collectionId/documents/:documentId') ->param('collectionId', null, function () { return 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, function () { return new UID(); }, 'Document unique ID.') ->action( - function ($collectionId, $documentId) use ($response, $request, $projectDB, $isDev) { - $document = $projectDB->getDocument($documentId, $isDev); - $collection = $projectDB->getDocument($collectionId, $isDev); + function ($collectionId, $documentId) use ($response, $request, $projectDB) { + $document = $projectDB->getDocument($documentId, false); + $collection = $projectDB->getDocument($collectionId, false); if (empty($document->getArrayCopy()) || $document->getCollection() != $collection->getId()) { // Check empty throw new Exception('No document found', 404); @@ -588,9 +586,9 @@ $utopia->patch('/v1/database/collections/:collectionId/documents/:documentId') ->param('read', [], function () { return 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', [], function () { return new ArrayList(new Text(64)); }, 'An array of strings with write permissions. By default no user is granted with any write permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions.') ->action( - function ($collectionId, $documentId, $data, $read, $write) use ($response, $projectDB, &$output, $webhook, $audit, $isDev) { - $collection = $projectDB->getDocument($collectionId/*, $isDev*/); - $document = $projectDB->getDocument($documentId, $isDev); + function ($collectionId, $documentId, $data, $read, $write) use ($response, $projectDB, $webhook, $audit) { + $collection = $projectDB->getDocument($collectionId, false); + $document = $projectDB->getDocument($documentId, false); $data = (\is_string($data)) ? \json_decode($data, true) : $data; // Cast to JSON array @@ -664,9 +662,9 @@ $utopia->delete('/v1/database/collections/:collectionId/documents/:documentId') ->param('collectionId', null, function () { return 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, function () { return new UID(); }, 'Document unique ID.') ->action( - function ($collectionId, $documentId) use ($response, $projectDB, $audit, $webhook, $isDev) { - $collection = $projectDB->getDocument($collectionId, $isDev); - $document = $projectDB->getDocument($documentId, $isDev); + function ($collectionId, $documentId) use ($response, $projectDB, $audit, $webhook) { + $collection = $projectDB->getDocument($collectionId, false); + $document = $projectDB->getDocument($documentId, false); if (empty($document->getArrayCopy()) || $document->getCollection() != $collectionId) { // Check empty throw new Exception('No document found', 404); From dacbf8bc3da400d14c380e0f1e54410d4d8a245d Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Thu, 25 Jun 2020 00:16:03 +0300 Subject: [PATCH 19/25] Added init for console --- app/controllers/web/home.php | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/app/controllers/web/home.php b/app/controllers/web/home.php index ced983bca5..11a7e43b89 100644 --- a/app/controllers/web/home.php +++ b/app/controllers/web/home.php @@ -9,21 +9,23 @@ use Utopia\Config\Config; use Utopia\Validator\WhiteList; use Utopia\Validator\Range; -$header = new View(__DIR__.'/../../views/home/comps/header.phtml'); -$footer = new View(__DIR__.'/../../views/home/comps/footer.phtml'); +$utopia->init(function () use ($layout) { + $header = new View(__DIR__.'/../../views/home/comps/header.phtml'); + $footer = new View(__DIR__.'/../../views/home/comps/footer.phtml'); -$footer - ->setParam('version', Config::getParam('version')) -; + $footer + ->setParam('version', Config::getParam('version')) + ; -$layout - ->setParam('title', APP_NAME) - ->setParam('description', '') - ->setParam('class', 'home') - ->setParam('platforms', Config::getParam('platforms')) - ->setParam('header', [$header]) - ->setParam('footer', [$footer]) -; + $layout + ->setParam('title', APP_NAME) + ->setParam('description', '') + ->setParam('class', 'home') + ->setParam('platforms', Config::getParam('platforms')) + ->setParam('header', [$header]) + ->setParam('footer', [$footer]) + ; +}); $utopia->shutdown(function () use ($response, $layout) { $response->send($layout->render()); From 1e3472b724253ccadb7d2c257b6f2e963f886cbf Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Thu, 25 Jun 2020 08:20:26 +0300 Subject: [PATCH 20/25] Fixed tests --- tests/e2e/Services/Health/HealthCustomServerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/Services/Health/HealthCustomServerTest.php b/tests/e2e/Services/Health/HealthCustomServerTest.php index bf55b41a39..572ad2906c 100644 --- a/tests/e2e/Services/Health/HealthCustomServerTest.php +++ b/tests/e2e/Services/Health/HealthCustomServerTest.php @@ -173,7 +173,7 @@ class HealthCustomClientTest extends Scope $this->assertEquals(200, $response['headers']['status-code']); $this->assertIsInt($response['body']['size']); - $this->assertLessThan(100, $response['body']['size']); + $this->assertLessThan(120, $response['body']['size']); /** * Test for FAILURE From 2f566e81579a9644ebe05ba095caedec4c4831ac Mon Sep 17 00:00:00 2001 From: Justin Noel Date: Thu, 25 Jun 2020 05:54:34 -0500 Subject: [PATCH 21/25] docs: fix minor grammatical errors --- docs/references/account/create-verification.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/references/account/create-verification.md b/docs/references/account/create-verification.md index eaf6a402e9..54e0bf77be 100644 --- a/docs/references/account/create-verification.md +++ b/docs/references/account/create-verification.md @@ -1,3 +1,3 @@ -Use this endpoint to send a verification message to your user email address to confirm they are the valid owners of that address. Both the **userId** and **secret** arguments will be passed as query parameters to the URL you have provider to be attached to the verification email. The provided URL should redirect the user back for your app and allow you to complete the verification process by verifying both the **userId** and **secret** parameters. Learn more about how to [complete the verification process](/docs/client/account#updateAccountVerification). +Use this endpoint to send a verification message to your user email address to confirm they are the valid owners of that address. Both the **userId** and **secret** arguments will be passed as query parameters to the URL you have provided to be attached to the verification email. The provided URL should redirect the user back to your app and allow you to complete the verification process by verifying both the **userId** and **secret** parameters. Learn more about how to [complete the verification process](/docs/client/account#updateAccountVerification). -Please note that in order to avoid a [Redirect Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md) the only valid redirect URLs are the ones from domains you have set when adding your platforms in the console interface. \ No newline at end of file +Please note that in order to avoid a [Redirect Attack](https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md), the only valid redirect URLs are the ones from domains you have set when adding your platforms in the console interface. From 7a277c3b6a57eaf0bf80e778dc2dd40163c8508a Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Thu, 25 Jun 2020 14:31:27 +0300 Subject: [PATCH 22/25] Use all controllers --- app/app.php | 12 +++--------- public/index.php | 12 +----------- 2 files changed, 4 insertions(+), 20 deletions(-) diff --git a/app/app.php b/app/app.php index 64a4967568..49bedfed2b 100644 --- a/app/app.php +++ b/app/app.php @@ -3,7 +3,7 @@ // Init require_once __DIR__.'/init.php'; -global $utopia, $request, $response, $register, $consoleDB, $project, $service; +global $utopia, $request, $response, $register, $consoleDB, $project; use Utopia\App; use Utopia\Request; @@ -426,14 +426,8 @@ $utopia->get('/.well-known/acme-challenge') } ); -$name = APP_NAME; - -if (\array_key_exists($service, $services)) { /** @noinspection PhpIncludeInspection */ - include_once $services[$service]['controller']; - $name = APP_NAME.' '.\ucfirst($services[$service]['name']); -} else { - /** @noinspection PhpIncludeInspection */ - include_once $services['/']['controller']; +foreach($services as $key => $service) { + include_once $services[$key]['controller']; } $utopia->run($request, $response); \ No newline at end of file diff --git a/public/index.php b/public/index.php index 9e30f0ef56..c87b14a26e 100644 --- a/public/index.php +++ b/public/index.php @@ -20,14 +20,4 @@ $path = (isset($_GET['q'])) ? explode('/', $_GET['q']) : []; array_shift($path); $version = array_shift($path); -switch ($version) { // Switch between API version - case 'v1': - $service = $version . '/' . array_shift($path); - include __DIR__ . '/../app/app.php'; - break; - case 'console': - default: - $service = $version . '/'; - include __DIR__ . '/../app/app.php'; - break; -} +include __DIR__ . '/../app/app.php'; From 539ea96ca0ab1ca48637f829e44c1d5e1630b077 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Thu, 25 Jun 2020 21:32:12 +0300 Subject: [PATCH 23/25] Adding group support, upgraded FW --- app/controllers/api/account.php | 23 ++++++++++++++++- app/controllers/api/avatars.php | 7 +++++ app/controllers/api/database.php | 11 ++++++++ app/controllers/api/graphql.php | 1 + app/controllers/api/health.php | 14 ++++++++++ app/controllers/api/locale.php | 7 +++++ app/controllers/api/projects.php | 32 +++++++++++++++++++++++ app/controllers/api/storage.php | 11 ++++++-- app/controllers/api/teams.php | 9 +++++++ app/controllers/api/users.php | 10 ++++++++ app/controllers/mock.php | 2 +- app/controllers/shared/api.php | 2 +- app/controllers/shared/web.php | 2 +- app/controllers/web/console.php | 34 ++++++++++++------------ app/controllers/web/home.php | 24 +++++++++-------- composer.json | 2 +- composer.lock | 44 ++++++++++++++++---------------- 17 files changed, 179 insertions(+), 56 deletions(-) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 3327ef24e8..7757990c69 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -45,10 +45,11 @@ $utopia->init(function() use (&$oauth2Keys) { $oauth2Keys[] = 'oauth2'.\ucfirst($key); $oauth2Keys[] = 'oauth2'.\ucfirst($key).'AccessToken'; } -}); +}, 'account'); $utopia->post('/v1/account') ->desc('Create Account') + ->groups(['api', 'account']) ->label('webhook', 'account.create') ->label('scope', 'public') ->label('sdk.platform', [APP_PLATFORM_CLIENT]) @@ -149,6 +150,7 @@ $utopia->post('/v1/account') $utopia->post('/v1/account/sessions') ->desc('Create Account Session') + ->groups(['api', 'account']) ->label('webhook', 'account.sessions.create') ->label('scope', 'public') ->label('sdk.platform', [APP_PLATFORM_CLIENT]) @@ -239,6 +241,7 @@ $utopia->post('/v1/account/sessions') $utopia->get('/v1/account/sessions/oauth2/:provider') ->desc('Create Account Session with OAuth2') + ->groups(['api', 'account']) ->label('error', __DIR__.'/../../views/general/error.phtml') ->label('scope', 'public') ->label('sdk.platform', [APP_PLATFORM_CLIENT]) @@ -289,6 +292,7 @@ $utopia->get('/v1/account/sessions/oauth2/:provider') $utopia->get('/v1/account/sessions/oauth2/callback/:provider/:projectId') ->desc('OAuth2 Callback') + ->groups(['api', 'account']) ->label('error', __DIR__.'/../../views/general/error.phtml') ->label('scope', 'public') ->label('docs', false) @@ -311,6 +315,7 @@ $utopia->get('/v1/account/sessions/oauth2/callback/:provider/:projectId') $utopia->post('/v1/account/sessions/oauth2/callback/:provider/:projectId') ->desc('OAuth2 Callback') + ->groups(['api', 'account']) ->label('error', __DIR__.'/../../views/general/error.phtml') ->label('scope', 'public') ->label('origin', '*') @@ -334,6 +339,7 @@ $utopia->post('/v1/account/sessions/oauth2/callback/:provider/:projectId') $utopia->get('/v1/account/sessions/oauth2/:provider/redirect') ->desc('OAuth2 Redirect') + ->groups(['api', 'account']) ->label('error', __DIR__.'/../../views/general/error.phtml') ->label('webhook', 'account.sessions.create') ->label('scope', 'public') @@ -528,6 +534,7 @@ $utopia->get('/v1/account/sessions/oauth2/:provider/redirect') $utopia->get('/v1/account') ->desc('Get Account') + ->groups(['api', 'account']) ->label('scope', 'account') ->label('sdk.platform', [APP_PLATFORM_CLIENT]) ->label('sdk.namespace', 'account') @@ -551,6 +558,7 @@ $utopia->get('/v1/account') $utopia->get('/v1/account/prefs') ->desc('Get Account Preferences') + ->groups(['api', 'account']) ->label('scope', 'account') ->label('sdk.platform', [APP_PLATFORM_CLIENT]) ->label('sdk.namespace', 'account') @@ -573,6 +581,7 @@ $utopia->get('/v1/account/prefs') $utopia->get('/v1/account/sessions') ->desc('Get Account Sessions') + ->groups(['api', 'account']) ->label('scope', 'account') ->label('sdk.platform', [APP_PLATFORM_CLIENT]) ->label('sdk.namespace', 'account') @@ -631,6 +640,7 @@ $utopia->get('/v1/account/sessions') $utopia->get('/v1/account/logs') ->desc('Get Account Logs') + ->groups(['api', 'account']) ->label('scope', 'account') ->label('sdk.platform', [APP_PLATFORM_CLIENT]) ->label('sdk.namespace', 'account') @@ -703,6 +713,7 @@ $utopia->get('/v1/account/logs') $utopia->patch('/v1/account/name') ->desc('Update Account Name') + ->groups(['api', 'account']) ->label('webhook', 'account.update.name') ->label('scope', 'account') ->label('sdk.platform', [APP_PLATFORM_CLIENT]) @@ -740,6 +751,7 @@ $utopia->patch('/v1/account/name') $utopia->patch('/v1/account/password') ->desc('Update Account Password') + ->groups(['api', 'account']) ->label('webhook', 'account.update.password') ->label('scope', 'account') ->label('sdk.platform', [APP_PLATFORM_CLIENT]) @@ -782,6 +794,7 @@ $utopia->patch('/v1/account/password') $utopia->patch('/v1/account/email') ->desc('Update Account Email') + ->groups(['api', 'account']) ->label('webhook', 'account.update.email') ->label('scope', 'account') ->label('sdk.platform', [APP_PLATFORM_CLIENT]) @@ -840,6 +853,7 @@ $utopia->patch('/v1/account/email') $utopia->patch('/v1/account/prefs') ->desc('Update Account Preferences') + ->groups(['api', 'account']) ->label('webhook', 'account.update.prefs') ->label('scope', 'account') ->label('sdk.platform', [APP_PLATFORM_CLIENT]) @@ -880,6 +894,7 @@ $utopia->patch('/v1/account/prefs') $utopia->delete('/v1/account') ->desc('Delete Account') + ->groups(['api', 'account']) ->label('webhook', 'account.delete') ->label('scope', 'account') ->label('sdk.platform', [APP_PLATFORM_CLIENT]) @@ -935,6 +950,7 @@ $utopia->delete('/v1/account') $utopia->delete('/v1/account/sessions/:sessionId') ->desc('Delete Account Session') + ->groups(['api', 'account']) ->label('scope', 'account') ->label('webhook', 'account.sessions.delete') ->label('sdk.platform', [APP_PLATFORM_CLIENT]) @@ -994,6 +1010,7 @@ $utopia->delete('/v1/account/sessions/:sessionId') $utopia->delete('/v1/account/sessions') ->desc('Delete All Account Sessions') + ->groups(['api', 'account']) ->label('scope', 'account') ->label('webhook', 'account.sessions.delete') ->label('sdk.platform', [APP_PLATFORM_CLIENT]) @@ -1044,6 +1061,7 @@ $utopia->delete('/v1/account/sessions') $utopia->post('/v1/account/recovery') ->desc('Create Password Recovery') + ->groups(['api', 'account']) ->label('scope', 'public') ->label('sdk.platform', [APP_PLATFORM_CLIENT]) ->label('sdk.namespace', 'account') @@ -1143,6 +1161,7 @@ $utopia->post('/v1/account/recovery') $utopia->put('/v1/account/recovery') ->desc('Complete Password Recovery') + ->groups(['api', 'account']) ->label('scope', 'public') ->label('sdk.platform', [APP_PLATFORM_CLIENT]) ->label('sdk.namespace', 'account') @@ -1213,6 +1232,7 @@ $utopia->put('/v1/account/recovery') $utopia->post('/v1/account/verification') ->desc('Create Email Verification') + ->groups(['api', 'account']) ->label('scope', 'account') ->label('sdk.platform', [APP_PLATFORM_CLIENT]) ->label('sdk.namespace', 'account') @@ -1299,6 +1319,7 @@ $utopia->post('/v1/account/verification') $utopia->put('/v1/account/verification') ->desc('Complete Email Verification') + ->groups(['api', 'account']) ->label('scope', 'public') ->label('sdk.platform', [APP_PLATFORM_CLIENT]) ->label('sdk.namespace', 'account') diff --git a/app/controllers/api/avatars.php b/app/controllers/api/avatars.php index 289167c6ad..a4d9a9d79d 100644 --- a/app/controllers/api/avatars.php +++ b/app/controllers/api/avatars.php @@ -90,6 +90,7 @@ $avatarCallback = function ($type, $code, $width, $height, $quality) use ($types $utopia->get('/v1/avatars/credit-cards/:code') ->desc('Get Credit Card Icon') + ->groups(['api', 'avatars']) ->param('code', '', function () use ($types) { return new WhiteList(\array_keys($types['credit-cards'])); }, 'Credit Card Code. Possible values: '.\implode(', ', \array_keys($types['credit-cards'])).'.') ->param('width', 100, function () { return new Range(0, 2000); }, 'Image width. Pass an integer between 0 to 2000. Defaults to 100.', true) ->param('height', 100, function () { return new Range(0, 2000); }, 'Image height. Pass an integer between 0 to 2000. Defaults to 100.', true) @@ -106,6 +107,7 @@ $utopia->get('/v1/avatars/credit-cards/:code') $utopia->get('/v1/avatars/browsers/:code') ->desc('Get Browser Icon') + ->groups(['api', 'avatars']) ->param('code', '', function () use ($types) { return new WhiteList(\array_keys($types['browsers'])); }, 'Browser Code.') ->param('width', 100, function () { return new Range(0, 2000); }, 'Image width. Pass an integer between 0 to 2000. Defaults to 100.', true) ->param('height', 100, function () { return new Range(0, 2000); }, 'Image height. Pass an integer between 0 to 2000. Defaults to 100.', true) @@ -122,6 +124,7 @@ $utopia->get('/v1/avatars/browsers/:code') $utopia->get('/v1/avatars/flags/:code') ->desc('Get Country Flag') + ->groups(['api', 'avatars']) ->param('code', '', function () use ($types) { return new WhiteList(\array_keys($types['flags'])); }, 'Country Code. ISO Alpha-2 country code format.') ->param('width', 100, function () { return new Range(0, 2000); }, 'Image width. Pass an integer between 0 to 2000. Defaults to 100.', true) ->param('height', 100, function () { return new Range(0, 2000); }, 'Image height. Pass an integer between 0 to 2000. Defaults to 100.', true) @@ -138,6 +141,7 @@ $utopia->get('/v1/avatars/flags/:code') $utopia->get('/v1/avatars/image') ->desc('Get Image from URL') + ->groups(['api', 'avatars']) ->param('url', '', function () { return new URL(); }, 'Image URL which you want to crop.') ->param('width', 400, function () { return new Range(0, 2000); }, 'Resize preview image width, Pass an integer between 0 to 2000.', true) ->param('height', 400, function () { return new Range(0, 2000); }, 'Resize preview image height, Pass an integer between 0 to 2000.', true) @@ -205,6 +209,7 @@ $utopia->get('/v1/avatars/image') $utopia->get('/v1/avatars/favicon') ->desc('Get Favicon') + ->groups(['api', 'avatars']) ->param('url', '', function () { return new URL(); }, 'Website URL which you want to fetch the favicon from.') ->label('scope', 'avatars.read') ->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER]) @@ -357,6 +362,7 @@ $utopia->get('/v1/avatars/favicon') $utopia->get('/v1/avatars/qr') ->desc('Get QR Code') + ->groups(['api', 'avatars']) ->param('text', '', function () { return new Text(512); }, 'Plain text to be converted to QR code image.') ->param('size', 400, function () { return new Range(0, 1000); }, 'QR code size. Pass an integer between 0 to 1000. Defaults to 400.', true) ->param('margin', 1, function () { return new Range(0, 10); }, 'Margin from edge. Pass an integer between 0 to 10. Defaults to 1.', true) @@ -390,6 +396,7 @@ $utopia->get('/v1/avatars/qr') $utopia->get('/v1/avatars/initials') ->desc('Get User Initials') + ->groups(['api', 'avatars']) ->param('name', '', function () { return new Text(512); }, 'Full Name. When empty, current user name or email will be used.', true) ->param('width', 500, function () { return new Range(0, 2000); }, 'Image width. Pass an integer between 0 to 2000. Defaults to 100.', true) ->param('height', 500, function () { return new Range(0, 2000); }, 'Image height. Pass an integer between 0 to 2000. Defaults to 100.', true) diff --git a/app/controllers/api/database.php b/app/controllers/api/database.php index 13646414a4..06c707745f 100644 --- a/app/controllers/api/database.php +++ b/app/controllers/api/database.php @@ -29,6 +29,7 @@ include_once __DIR__ . '/../shared/api.php'; $utopia->post('/v1/database/collections') ->desc('Create Collection') + ->groups(['api', 'database']) ->label('webhook', 'database.collections.create') ->label('scope', 'collections.write') ->label('sdk.namespace', 'database') @@ -102,6 +103,7 @@ $utopia->post('/v1/database/collections') $utopia->get('/v1/database/collections') ->desc('List Collections') + ->groups(['api', 'database']) ->label('scope', 'collections.read') ->label('sdk.namespace', 'database') ->label('sdk.platform', [APP_PLATFORM_SERVER]) @@ -150,6 +152,7 @@ $utopia->get('/v1/database/collections') $utopia->get('/v1/database/collections/:collectionId') ->desc('Get Collection') + ->groups(['api', 'database']) ->label('scope', 'collections.read') ->label('sdk.namespace', 'database') ->label('sdk.platform', [APP_PLATFORM_SERVER]) @@ -170,6 +173,7 @@ $utopia->get('/v1/database/collections/:collectionId') // $utopia->get('/v1/database/collections/:collectionId/logs') // ->desc('Get Collection Logs') +// ->groups(['api', 'database']) // ->label('scope', 'collections.read') // ->label('sdk.platform', [APP_PLATFORM_SERVER]) // ->label('sdk.namespace', 'database') @@ -234,6 +238,7 @@ $utopia->get('/v1/database/collections/:collectionId') $utopia->put('/v1/database/collections/:collectionId') ->desc('Update Collection') + ->groups(['api', 'database']) ->label('scope', 'collections.write') ->label('webhook', 'database.collections.update') ->label('sdk.namespace', 'database') @@ -306,6 +311,7 @@ $utopia->put('/v1/database/collections/:collectionId') $utopia->delete('/v1/database/collections/:collectionId') ->desc('Delete Collection') + ->groups(['api', 'database']) ->label('scope', 'collections.write') ->label('webhook', 'database.collections.delete') ->label('sdk.namespace', 'database') @@ -343,6 +349,7 @@ $utopia->delete('/v1/database/collections/:collectionId') $utopia->post('/v1/database/collections/:collectionId/documents') ->desc('Create Document') + ->groups(['api', 'database']) ->label('webhook', 'database.documents.create') ->label('scope', 'documents.write') ->label('sdk.namespace', 'database') @@ -462,6 +469,7 @@ $utopia->post('/v1/database/collections/:collectionId/documents') $utopia->get('/v1/database/collections/:collectionId/documents') ->desc('List Documents') + ->groups(['api', 'database']) ->label('scope', 'documents.read') ->label('sdk.namespace', 'database') ->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER]) @@ -529,6 +537,7 @@ $utopia->get('/v1/database/collections/:collectionId/documents') $utopia->get('/v1/database/collections/:collectionId/documents/:documentId') ->desc('Get Document') + ->groups(['api', 'database']) ->label('scope', 'documents.read') ->label('sdk.namespace', 'database') ->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER]) @@ -574,6 +583,7 @@ $utopia->get('/v1/database/collections/:collectionId/documents/:documentId') $utopia->patch('/v1/database/collections/:collectionId/documents/:documentId') ->desc('Update Document') + ->groups(['api', 'database']) ->label('webhook', 'database.documents.update') ->label('scope', 'documents.write') ->label('sdk.namespace', 'database') @@ -653,6 +663,7 @@ $utopia->patch('/v1/database/collections/:collectionId/documents/:documentId') $utopia->delete('/v1/database/collections/:collectionId/documents/:documentId') ->desc('Delete Document') + ->groups(['api', 'database']) ->label('scope', 'documents.write') ->label('webhook', 'database.documents.delete') ->label('sdk.namespace', 'database') diff --git a/app/controllers/api/graphql.php b/app/controllers/api/graphql.php index ce39d8e799..0eecb23e15 100644 --- a/app/controllers/api/graphql.php +++ b/app/controllers/api/graphql.php @@ -14,6 +14,7 @@ global $utopia; $utopia->post('/v1/graphql') ->desc('GraphQL Endpoint') + ->groups(['api', 'graphql']) ->label('scope', 'public') ->action( function () { diff --git a/app/controllers/api/health.php b/app/controllers/api/health.php index 0cf4098f1b..76727563ae 100644 --- a/app/controllers/api/health.php +++ b/app/controllers/api/health.php @@ -9,6 +9,7 @@ use Appwrite\ClamAV\Network; $utopia->get('/v1/health') ->desc('Get HTTP') + ->groups(['api', 'health']) ->label('scope', 'health.read') ->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'health') @@ -22,6 +23,7 @@ $utopia->get('/v1/health') $utopia->get('/v1/health/version') ->desc('Get Version') + ->groups(['api', 'health']) ->label('scope', 'public') ->action( function () use ($response) { @@ -31,6 +33,7 @@ $utopia->get('/v1/health/version') $utopia->get('/v1/health/db') ->desc('Get DB') + ->groups(['api', 'health']) ->label('scope', 'health.read') ->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'health') @@ -46,6 +49,7 @@ $utopia->get('/v1/health/db') $utopia->get('/v1/health/cache') ->desc('Get Cache') + ->groups(['api', 'health']) ->label('scope', 'health.read') ->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'health') @@ -61,6 +65,7 @@ $utopia->get('/v1/health/cache') $utopia->get('/v1/health/time') ->desc('Get Time') + ->groups(['api', 'health']) ->label('scope', 'health.read') ->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'health') @@ -108,6 +113,7 @@ $utopia->get('/v1/health/time') $utopia->get('/v1/health/queue/webhooks') ->desc('Get Webhooks Queue') + ->groups(['api', 'health']) ->label('scope', 'health.read') ->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'health') @@ -121,6 +127,7 @@ $utopia->get('/v1/health/queue/webhooks') $utopia->get('/v1/health/queue/tasks') ->desc('Get Tasks Queue') + ->groups(['api', 'health']) ->label('scope', 'health.read') ->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'health') @@ -134,6 +141,7 @@ $utopia->get('/v1/health/queue/tasks') $utopia->get('/v1/health/queue/logs') ->desc('Get Logs Queue') + ->groups(['api', 'health']) ->label('scope', 'health.read') ->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'health') @@ -147,6 +155,7 @@ $utopia->get('/v1/health/queue/logs') $utopia->get('/v1/health/queue/usage') ->desc('Get Usage Queue') + ->groups(['api', 'health']) ->label('scope', 'health.read') ->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'health') @@ -160,6 +169,7 @@ $utopia->get('/v1/health/queue/usage') $utopia->get('/v1/health/queue/certificates') ->desc('Get Certificate Queue') + ->groups(['api', 'health']) ->label('scope', 'health.read') ->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'health') @@ -173,6 +183,7 @@ $utopia->get('/v1/health/queue/certificates') $utopia->get('/v1/health/queue/functions') ->desc('Get Functions Queue') + ->groups(['api', 'health']) ->label('scope', 'health.read') ->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'health') @@ -186,6 +197,7 @@ $utopia->get('/v1/health/queue/functions') $utopia->get('/v1/health/storage/local') ->desc('Get Local Storage') + ->groups(['api', 'health']) ->label('scope', 'health.read') ->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'health') @@ -216,6 +228,7 @@ $utopia->get('/v1/health/storage/local') $utopia->get('/v1/health/anti-virus') ->desc('Get Anti virus') + ->groups(['api', 'health']) ->label('scope', 'health.read') ->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'health') @@ -238,6 +251,7 @@ $utopia->get('/v1/health/anti-virus') $utopia->get('/v1/health/stats') // Currently only used internally ->desc('Get System Stats') + ->groups(['api', 'health']) ->label('scope', 'god') // ->label('sdk.platform', [APP_PLATFORM_SERVER]) // ->label('sdk.namespace', 'health') diff --git a/app/controllers/api/locale.php b/app/controllers/api/locale.php index 30a1211e91..caf9de0f4a 100644 --- a/app/controllers/api/locale.php +++ b/app/controllers/api/locale.php @@ -10,6 +10,7 @@ include_once __DIR__ . '/../shared/api.php'; $utopia->get('/v1/locale') ->desc('Get User Locale') + ->groups(['api', 'locale']) ->label('scope', 'locale.read') ->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'locale') @@ -68,6 +69,7 @@ $utopia->get('/v1/locale') $utopia->get('/v1/locale/countries') ->desc('List Countries') + ->groups(['api', 'locale']) ->label('scope', 'locale.read') ->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'locale') @@ -85,6 +87,7 @@ $utopia->get('/v1/locale/countries') $utopia->get('/v1/locale/countries/eu') ->desc('List EU Countries') + ->groups(['api', 'locale']) ->label('scope', 'locale.read') ->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'locale') @@ -110,6 +113,7 @@ $utopia->get('/v1/locale/countries/eu') $utopia->get('/v1/locale/countries/phones') ->desc('List Countries Phone Codes') + ->groups(['api', 'locale']) ->label('scope', 'locale.read') ->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'locale') @@ -135,6 +139,7 @@ $utopia->get('/v1/locale/countries/phones') $utopia->get('/v1/locale/continents') ->desc('List Continents') + ->groups(['api', 'locale']) ->label('scope', 'locale.read') ->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'locale') @@ -153,6 +158,7 @@ $utopia->get('/v1/locale/continents') $utopia->get('/v1/locale/currencies') ->desc('List Currencies') + ->groups(['api', 'locale']) ->label('scope', 'locale.read') ->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'locale') @@ -169,6 +175,7 @@ $utopia->get('/v1/locale/currencies') $utopia->get('/v1/locale/languages') ->desc('List Languages') + ->groups(['api', 'locale']) ->label('scope', 'locale.read') ->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'locale') diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index f95f89a958..d2633985a8 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -27,6 +27,7 @@ $scopes = include __DIR__.'/../../../app/config/scopes.php'; $utopia->post('/v1/projects') ->desc('Create Project') + ->groups(['api', 'projects']) ->label('scope', 'projects.write') ->label('sdk.namespace', 'projects') ->label('sdk.method', 'create') @@ -89,6 +90,7 @@ $utopia->post('/v1/projects') $utopia->get('/v1/projects') ->desc('List Projects') + ->groups(['api', 'projects']) ->label('scope', 'projects.read') ->label('sdk.namespace', 'projects') ->label('sdk.method', 'list') @@ -122,6 +124,7 @@ $utopia->get('/v1/projects') $utopia->get('/v1/projects/:projectId') ->desc('Get Project') + ->groups(['api', 'projects']) ->label('scope', 'projects.read') ->label('sdk.namespace', 'projects') ->label('sdk.method', 'get') @@ -149,6 +152,7 @@ $utopia->get('/v1/projects/:projectId') $utopia->get('/v1/projects/:projectId/usage') ->desc('Get Project') + ->groups(['api', 'projects']) ->label('scope', 'projects.read') ->label('sdk.namespace', 'projects') ->label('sdk.method', 'getUsage') @@ -310,6 +314,7 @@ $utopia->get('/v1/projects/:projectId/usage') $utopia->patch('/v1/projects/:projectId') ->desc('Update Project') + ->groups(['api', 'projects']) ->label('scope', 'projects.write') ->label('sdk.namespace', 'projects') ->label('sdk.method', 'update') @@ -355,6 +360,7 @@ $utopia->patch('/v1/projects/:projectId') $utopia->patch('/v1/projects/:projectId/oauth2') ->desc('Update Project OAuth2') + ->groups(['api', 'projects']) ->label('scope', 'projects.write') ->label('sdk.namespace', 'projects') ->label('sdk.method', 'updateOAuth2') @@ -396,6 +402,7 @@ $utopia->patch('/v1/projects/:projectId/oauth2') $utopia->delete('/v1/projects/:projectId') ->desc('Delete Project') + ->groups(['api', 'projects']) ->label('scope', 'projects.write') ->label('sdk.namespace', 'projects') ->label('sdk.method', 'delete') @@ -441,6 +448,7 @@ $utopia->delete('/v1/projects/:projectId') $utopia->post('/v1/projects/:projectId/webhooks') ->desc('Create Webhook') + ->groups(['api', 'projects']) ->label('scope', 'projects.write') ->label('sdk.namespace', 'projects') ->label('sdk.method', 'createWebhook') @@ -505,6 +513,7 @@ $utopia->post('/v1/projects/:projectId/webhooks') $utopia->get('/v1/projects/:projectId/webhooks') ->desc('List Webhooks') + ->groups(['api', 'projects']) ->label('scope', 'projects.read') ->label('sdk.namespace', 'projects') ->label('sdk.method', 'listWebhooks') @@ -537,6 +546,7 @@ $utopia->get('/v1/projects/:projectId/webhooks') $utopia->get('/v1/projects/:projectId/webhooks/:webhookId') ->desc('Get Webhook') + ->groups(['api', 'projects']) ->label('scope', 'projects.read') ->label('sdk.namespace', 'projects') ->label('sdk.method', 'getWebhook') @@ -570,6 +580,7 @@ $utopia->get('/v1/projects/:projectId/webhooks/:webhookId') $utopia->put('/v1/projects/:projectId/webhooks/:webhookId') ->desc('Update Webhook') + ->groups(['api', 'projects']) ->label('scope', 'projects.write') ->label('sdk.namespace', 'projects') ->label('sdk.method', 'updateWebhook') @@ -625,6 +636,7 @@ $utopia->put('/v1/projects/:projectId/webhooks/:webhookId') $utopia->delete('/v1/projects/:projectId/webhooks/:webhookId') ->desc('Delete Webhook') + ->groups(['api', 'projects']) ->label('scope', 'projects.write') ->label('sdk.namespace', 'projects') ->label('sdk.method', 'deleteWebhook') @@ -656,6 +668,7 @@ $utopia->delete('/v1/projects/:projectId/webhooks/:webhookId') $utopia->post('/v1/projects/:projectId/keys') ->desc('Create Key') + ->groups(['api', 'projects']) ->label('scope', 'projects.write') ->label('sdk.namespace', 'projects') ->label('sdk.method', 'createKey') @@ -702,6 +715,7 @@ $utopia->post('/v1/projects/:projectId/keys') $utopia->get('/v1/projects/:projectId/keys') ->desc('List Keys') + ->groups(['api', 'projects']) ->label('scope', 'projects.read') ->label('sdk.namespace', 'projects') ->label('sdk.method', 'listKeys') @@ -720,6 +734,7 @@ $utopia->get('/v1/projects/:projectId/keys') $utopia->get('/v1/projects/:projectId/keys/:keyId') ->desc('Get Key') + ->groups(['api', 'projects']) ->label('scope', 'projects.read') ->label('sdk.namespace', 'projects') ->label('sdk.method', 'getKey') @@ -745,6 +760,7 @@ $utopia->get('/v1/projects/:projectId/keys/:keyId') $utopia->put('/v1/projects/:projectId/keys/:keyId') ->desc('Update Key') + ->groups(['api', 'projects']) ->label('scope', 'projects.write') ->label('sdk.namespace', 'projects') ->label('sdk.method', 'updateKey') @@ -781,6 +797,7 @@ $utopia->put('/v1/projects/:projectId/keys/:keyId') $utopia->delete('/v1/projects/:projectId/keys/:keyId') ->desc('Delete Key') + ->groups(['api', 'projects']) ->label('scope', 'projects.write') ->label('sdk.namespace', 'projects') ->label('sdk.method', 'deleteKey') @@ -812,6 +829,7 @@ $utopia->delete('/v1/projects/:projectId/keys/:keyId') $utopia->post('/v1/projects/:projectId/tasks') ->desc('Create Task') + ->groups(['api', 'projects']) ->label('scope', 'projects.write') ->label('sdk.namespace', 'projects') ->label('sdk.method', 'createTask') @@ -894,6 +912,7 @@ $utopia->post('/v1/projects/:projectId/tasks') $utopia->get('/v1/projects/:projectId/tasks') ->desc('List Tasks') + ->groups(['api', 'projects']) ->label('scope', 'projects.read') ->label('sdk.namespace', 'projects') ->label('sdk.method', 'listTasks') @@ -926,6 +945,7 @@ $utopia->get('/v1/projects/:projectId/tasks') $utopia->get('/v1/projects/:projectId/tasks/:taskId') ->desc('Get Task') + ->groups(['api', 'projects']) ->label('scope', 'projects.read') ->label('sdk.namespace', 'projects') ->label('sdk.method', 'getTask') @@ -958,6 +978,7 @@ $utopia->get('/v1/projects/:projectId/tasks/:taskId') $utopia->put('/v1/projects/:projectId/tasks/:taskId') ->desc('Update Task') + ->groups(['api', 'projects']) ->label('scope', 'projects.write') ->label('sdk.namespace', 'projects') ->label('sdk.method', 'updateTask') @@ -1028,6 +1049,7 @@ $utopia->put('/v1/projects/:projectId/tasks/:taskId') $utopia->delete('/v1/projects/:projectId/tasks/:taskId') ->desc('Delete Task') + ->groups(['api', 'projects']) ->label('scope', 'projects.write') ->label('sdk.namespace', 'projects') ->label('sdk.method', 'deleteTask') @@ -1059,6 +1081,7 @@ $utopia->delete('/v1/projects/:projectId/tasks/:taskId') $utopia->post('/v1/projects/:projectId/platforms') ->desc('Create Platform') + ->groups(['api', 'projects']) ->label('scope', 'projects.write') ->label('sdk.namespace', 'projects') ->label('sdk.method', 'createPlatform') @@ -1112,6 +1135,7 @@ $utopia->post('/v1/projects/:projectId/platforms') $utopia->get('/v1/projects/:projectId/platforms') ->desc('List Platforms') + ->groups(['api', 'projects']) ->label('scope', 'projects.read') ->label('sdk.namespace', 'projects') ->label('sdk.method', 'listPlatforms') @@ -1132,6 +1156,7 @@ $utopia->get('/v1/projects/:projectId/platforms') $utopia->get('/v1/projects/:projectId/platforms/:platformId') ->desc('Get Platform') + ->groups(['api', 'projects']) ->label('scope', 'projects.read') ->label('sdk.namespace', 'projects') ->label('sdk.method', 'getPlatform') @@ -1157,6 +1182,7 @@ $utopia->get('/v1/projects/:projectId/platforms/:platformId') $utopia->put('/v1/projects/:projectId/platforms/:platformId') ->desc('Update Platform') + ->groups(['api', 'projects']) ->label('scope', 'projects.write') ->label('sdk.namespace', 'projects') ->label('sdk.method', 'updatePlatform') @@ -1198,6 +1224,7 @@ $utopia->put('/v1/projects/:projectId/platforms/:platformId') $utopia->delete('/v1/projects/:projectId/platforms/:platformId') ->desc('Delete Platform') + ->groups(['api', 'projects']) ->label('scope', 'projects.write') ->label('sdk.namespace', 'projects') ->label('sdk.method', 'deletePlatform') @@ -1229,6 +1256,7 @@ $utopia->delete('/v1/projects/:projectId/platforms/:platformId') $utopia->post('/v1/projects/:projectId/domains') ->desc('Create Domain') + ->groups(['api', 'projects']) ->label('scope', 'projects.write') ->label('sdk.namespace', 'projects') ->label('sdk.method', 'createDomain') @@ -1291,6 +1319,7 @@ $utopia->post('/v1/projects/:projectId/domains') $utopia->get('/v1/projects/:projectId/domains') ->desc('List Domains') + ->groups(['api', 'projects']) ->label('scope', 'projects.read') ->label('sdk.namespace', 'projects') ->label('sdk.method', 'listDomains') @@ -1311,6 +1340,7 @@ $utopia->get('/v1/projects/:projectId/domains') $utopia->get('/v1/projects/:projectId/domains/:domainId') ->desc('Get Domain') + ->groups(['api', 'projects']) ->label('scope', 'projects.read') ->label('sdk.namespace', 'projects') ->label('sdk.method', 'getDomain') @@ -1336,6 +1366,7 @@ $utopia->get('/v1/projects/:projectId/domains/:domainId') $utopia->patch('/v1/projects/:projectId/domains/:domainId/verification') ->desc('Update Domain Verification Status') + ->groups(['api', 'projects']) ->label('scope', 'projects.write') ->label('sdk.namespace', 'projects') ->label('sdk.method', 'updateDomainVerification') @@ -1392,6 +1423,7 @@ $utopia->patch('/v1/projects/:projectId/domains/:domainId/verification') $utopia->delete('/v1/projects/:projectId/domains/:domainId') ->desc('Delete Domain') + ->groups(['api', 'projects']) ->label('scope', 'projects.write') ->label('sdk.namespace', 'projects') ->label('sdk.method', 'deleteDomain') diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index d5a4ec2c2b..b02461626d 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -135,6 +135,7 @@ $mimes = [ $utopia->post('/v1/storage/files') ->desc('Create File') + ->groups(['api', 'storage']) ->label('scope', 'files.write') ->label('webhook', 'storage.files.create') ->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER]) @@ -271,6 +272,7 @@ $utopia->post('/v1/storage/files') $utopia->get('/v1/storage/files') ->desc('List Files') + ->groups(['api', 'storage']) ->label('scope', 'files.read') ->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'storage') @@ -304,6 +306,7 @@ $utopia->get('/v1/storage/files') $utopia->get('/v1/storage/files/:fileId') ->desc('Get File') + ->groups(['api', 'storage']) ->label('scope', 'files.read') ->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'storage') @@ -324,6 +327,7 @@ $utopia->get('/v1/storage/files/:fileId') $utopia->get('/v1/storage/files/:fileId/preview') ->desc('Get File Preview') + ->groups(['api', 'storage']) ->label('scope', 'files.read') ->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'storage') @@ -337,8 +341,6 @@ $utopia->get('/v1/storage/files/:fileId/preview') ->param('quality', 100, function () { return new Range(0, 100); }, 'Preview image quality. Pass an integer between 0 to 100. Defaults to 100.', true) ->param('background', '', function () { return 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', null, function () use ($outputs) { return new WhiteList(\array_merge(\array_keys($outputs), [null])); }, 'Output format type (jpeg, jpg, png, gif and webp).', true) - //->param('storage', 'local', function () {return new WhiteList(array('local'));}, 'Selected storage device. defaults to local') - //->param('token', '', function () {return new Text(128);}, 'Preview token', true) ->action( function ($fileId, $width, $height, $quality, $background, $output) use ($request, $response, $projectDB, $project, $inputs, $outputs, $fileLogos) { $storage = 'local'; @@ -448,6 +450,7 @@ $utopia->get('/v1/storage/files/:fileId/preview') $utopia->get('/v1/storage/files/:fileId/download') ->desc('Get File for Download') + ->groups(['api', 'storage']) ->label('scope', 'files.read') ->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'storage') @@ -501,6 +504,7 @@ $utopia->get('/v1/storage/files/:fileId/download') $utopia->get('/v1/storage/files/:fileId/view') ->desc('Get File for View') + ->groups(['api', 'storage']) ->label('scope', 'files.read') ->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'storage') @@ -571,6 +575,7 @@ $utopia->get('/v1/storage/files/:fileId/view') $utopia->put('/v1/storage/files/:fileId') ->desc('Update File') + ->groups(['api', 'storage']) ->label('scope', 'files.write') ->label('webhook', 'storage.files.update') ->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER]) @@ -616,6 +621,7 @@ $utopia->put('/v1/storage/files/:fileId') $utopia->delete('/v1/storage/files/:fileId') ->desc('Delete File') + ->groups(['api', 'storage']) ->label('scope', 'files.write') ->label('webhook', 'storage.files.delete') ->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER]) @@ -658,6 +664,7 @@ $utopia->delete('/v1/storage/files/:fileId') // $utopia->get('/v1/storage/files/:fileId/scan') // ->desc('Scan Storage') +// ->groups(['api', 'storage']) // ->label('scope', 'god') // ->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER]) // ->label('sdk.namespace', 'storage') diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index 8aad25bc82..9905508c31 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -24,6 +24,7 @@ include_once __DIR__ . '/../shared/api.php'; $utopia->post('/v1/teams') ->desc('Create Team') + ->groups(['api', 'teams']) ->label('scope', 'teams.write') ->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'teams') @@ -87,6 +88,7 @@ $utopia->post('/v1/teams') $utopia->get('/v1/teams') ->desc('List Teams') + ->groups(['api', 'teams']) ->label('scope', 'teams.read') ->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'teams') @@ -116,6 +118,7 @@ $utopia->get('/v1/teams') $utopia->get('/v1/teams/:teamId') ->desc('Get Team') + ->groups(['api', 'teams']) ->label('scope', 'teams.read') ->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'teams') @@ -136,6 +139,7 @@ $utopia->get('/v1/teams/:teamId') $utopia->put('/v1/teams/:teamId') ->desc('Update Team') + ->groups(['api', 'teams']) ->label('scope', 'teams.write') ->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'teams') @@ -165,6 +169,7 @@ $utopia->put('/v1/teams/:teamId') $utopia->delete('/v1/teams/:teamId') ->desc('Delete Team') + ->groups(['api', 'teams']) ->label('scope', 'teams.write') ->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'teams') @@ -204,6 +209,7 @@ $utopia->delete('/v1/teams/:teamId') $utopia->post('/v1/teams/:teamId/memberships') ->desc('Create Team Membership') + ->groups(['api', 'teams']) ->label('scope', 'teams.write') ->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'teams') @@ -380,6 +386,7 @@ $utopia->post('/v1/teams/:teamId/memberships') $utopia->get('/v1/teams/:teamId/memberships') ->desc('Get Team Memberships') + ->groups(['api', 'teams']) ->label('scope', 'teams.read') ->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'teams') @@ -437,6 +444,7 @@ $utopia->get('/v1/teams/:teamId/memberships') $utopia->patch('/v1/teams/:teamId/memberships/:inviteId/status') ->desc('Update Team Membership Status') + ->groups(['api', 'teams']) ->label('scope', 'public') ->label('sdk.platform', [APP_PLATFORM_CLIENT]) ->label('sdk.namespace', 'teams') @@ -569,6 +577,7 @@ $utopia->patch('/v1/teams/:teamId/memberships/:inviteId/status') $utopia->delete('/v1/teams/:teamId/memberships/:inviteId') ->desc('Delete Team Membership') + ->groups(['api', 'teams']) ->label('scope', 'teams.write') ->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'teams') diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index d032cef947..e29e40aded 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -25,6 +25,7 @@ include_once __DIR__ . '/../shared/api.php'; $utopia->post('/v1/users') ->desc('Create User') + ->groups(['api', 'users']) ->label('scope', 'users.write') ->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'users') @@ -94,6 +95,7 @@ $utopia->post('/v1/users') $utopia->get('/v1/users') ->desc('List Users') + ->groups(['api', 'users']) ->label('scope', 'users.read') ->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'users') @@ -148,6 +150,7 @@ $utopia->get('/v1/users') $utopia->get('/v1/users/:userId') ->desc('Get User') + ->groups(['api', 'users']) ->label('scope', 'users.read') ->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'users') @@ -189,6 +192,7 @@ $utopia->get('/v1/users/:userId') $utopia->get('/v1/users/:userId/prefs') ->desc('Get User Preferences') + ->groups(['api', 'users']) ->label('scope', 'users.read') ->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'users') @@ -218,6 +222,7 @@ $utopia->get('/v1/users/:userId/prefs') $utopia->get('/v1/users/:userId/sessions') ->desc('Get User Sessions') + ->groups(['api', 'users']) ->label('scope', 'users.read') ->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'users') @@ -281,6 +286,7 @@ $utopia->get('/v1/users/:userId/sessions') $utopia->get('/v1/users/:userId/logs') ->desc('Get User Logs') + ->groups(['api', 'users']) ->label('scope', 'users.read') ->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'users') @@ -361,6 +367,7 @@ $utopia->get('/v1/users/:userId/logs') $utopia->patch('/v1/users/:userId/status') ->desc('Update User Status') + ->groups(['api', 'users']) ->label('scope', 'users.write') ->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'users') @@ -409,6 +416,7 @@ $utopia->patch('/v1/users/:userId/status') $utopia->patch('/v1/users/:userId/prefs') ->desc('Update User Preferences') + ->groups(['api', 'users']) ->label('scope', 'users.write') ->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'users') @@ -451,6 +459,7 @@ $utopia->patch('/v1/users/:userId/prefs') $utopia->delete('/v1/users/:userId/sessions/:sessionId') ->desc('Delete User Session') + ->groups(['api', 'users']) ->label('scope', 'users.write') ->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'users') @@ -483,6 +492,7 @@ $utopia->delete('/v1/users/:userId/sessions/:sessionId') $utopia->delete('/v1/users/:userId/sessions') ->desc('Delete User Sessions') + ->groups(['api', 'users']) ->label('scope', 'users.write') ->label('sdk.platform', [APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'users') diff --git a/app/controllers/mock.php b/app/controllers/mock.php index d0848d2861..097501fbba 100644 --- a/app/controllers/mock.php +++ b/app/controllers/mock.php @@ -352,4 +352,4 @@ $utopia->shutdown(function() use ($response, $request, &$result, $utopia) { } $response->json(['result' => $route->getMethod() . ':' . $route->getURL() . ':passed']); -}); \ No newline at end of file +}, 'mock'); \ No newline at end of file diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index d74f6939f9..e911c2c556 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -46,4 +46,4 @@ $utopia->init(function () use ($utopia, $request, $response, $register, $user, $ if ($abuse->check() && $request->getServer('_APP_OPTIONS_ABUSE', 'enabled') !== 'disabled') { throw new Exception('Too many requests', 429); } -}); \ No newline at end of file +}, 'api'); \ No newline at end of file diff --git a/app/controllers/shared/web.php b/app/controllers/shared/web.php index 15d904559c..a2f85bcb0a 100644 --- a/app/controllers/shared/web.php +++ b/app/controllers/shared/web.php @@ -42,4 +42,4 @@ $utopia->init(function () use ($utopia, $response, $request, $layout) { ->setParam('isDev', $isDev) ->setParam('class', $scope) ; -}); +}, 'web'); diff --git a/app/controllers/web/console.php b/app/controllers/web/console.php index ead5017e6b..543794609a 100644 --- a/app/controllers/web/console.php +++ b/app/controllers/web/console.php @@ -17,7 +17,7 @@ $utopia->init(function () use ($layout) { ->setParam('description', 'Appwrite Console allows you to easily manage, monitor, and control your entire backend API and tools.') ->setParam('analytics', 'UA-26264668-5') ; -}); +}, 'console'); $utopia->shutdown(function () use ($response, $request, $layout) { $header = new View(__DIR__.'/../../views/console/comps/header.phtml'); @@ -34,10 +34,10 @@ $utopia->shutdown(function () use ($response, $request, $layout) { ; $response->send($layout->render()); -}); +}, 'console'); $utopia->get('/error/:code') - ->desc('Error page') + ->groups(['web', 'console']) ->label('permission', 'public') ->label('scope', 'home') ->param('code', null, new \Utopia\Validator\Numeric(), 'Valid status code number', false) @@ -54,6 +54,7 @@ $utopia->get('/error/:code') }); $utopia->get('/console') + ->groups(['web', 'console']) ->label('permission', 'public') ->label('scope', 'console') ->action(function () use ($layout, $request) { @@ -69,6 +70,7 @@ $utopia->get('/console') }); $utopia->get('/console/account') + ->groups(['web', 'console']) ->label('permission', 'public') ->label('scope', 'console') ->action(function () use ($layout) { @@ -86,7 +88,7 @@ $utopia->get('/console/account') }); $utopia->get('/console/notifications') - ->desc('Platform console notifications') + ->groups(['web', 'console']) ->label('permission', 'public') ->label('scope', 'console') ->action(function () use ($layout) { @@ -98,7 +100,7 @@ $utopia->get('/console/notifications') }); $utopia->get('/console/home') - ->desc('Platform console project home') + ->groups(['web', 'console']) ->label('permission', 'public') ->label('scope', 'console') ->action(function () use ($layout) { @@ -110,7 +112,7 @@ $utopia->get('/console/home') }); $utopia->get('/console/settings') - ->desc('Platform console project settings') + ->groups(['web', 'console']) ->label('permission', 'public') ->label('scope', 'console') ->action(function () use ($request, $layout) { @@ -129,7 +131,7 @@ $utopia->get('/console/settings') }); $utopia->get('/console/webhooks') - ->desc('Platform console project webhooks') + ->groups(['web', 'console']) ->label('permission', 'public') ->label('scope', 'console') ->action(function () use ($layout) { @@ -145,7 +147,7 @@ $utopia->get('/console/webhooks') }); $utopia->get('/console/keys') - ->desc('Platform console project keys') + ->groups(['web', 'console']) ->label('permission', 'public') ->label('scope', 'console') ->action(function () use ($layout) { @@ -160,7 +162,7 @@ $utopia->get('/console/keys') }); $utopia->get('/console/tasks') - ->desc('Platform console project tasks') + ->groups(['web', 'console']) ->label('permission', 'public') ->label('scope', 'console') ->action(function () use ($layout) { @@ -172,7 +174,7 @@ $utopia->get('/console/tasks') }); $utopia->get('/console/database') - ->desc('Platform console project settings') + ->groups(['web', 'console']) ->label('permission', 'public') ->label('scope', 'console') ->action(function () use ($layout) { @@ -184,7 +186,7 @@ $utopia->get('/console/database') }); $utopia->get('/console/database/collection') - ->desc('Platform console project database collection') + ->groups(['web', 'console']) ->label('permission', 'public') ->label('scope', 'console') ->param('id', '', function () { return new UID(); }, 'Collection unique ID.') @@ -216,7 +218,7 @@ $utopia->get('/console/database/collection') }); $utopia->get('/console/database/document') - ->desc('Platform console project database document') + ->groups(['web', 'console']) ->label('permission', 'public') ->label('scope', 'console') ->param('collection', '', function () { return new UID(); }, 'Collection unique ID.') @@ -246,7 +248,7 @@ $utopia->get('/console/database/document') }); $utopia->get('/console/storage') - ->desc('Platform console project settings') + ->groups(['web', 'console']) ->label('permission', 'public') ->label('scope', 'console') ->action(function () use ($request, $layout) { @@ -264,7 +266,7 @@ $utopia->get('/console/storage') }); $utopia->get('/console/users') - ->desc('Platform console project settings') + ->groups(['web', 'console']) ->label('permission', 'public') ->label('scope', 'console') ->action(function () use ($layout) { @@ -278,7 +280,7 @@ $utopia->get('/console/users') }); $utopia->get('/console/users/user') - ->desc('Platform console project user') + ->groups(['web', 'console']) ->label('permission', 'public') ->label('scope', 'console') ->action(function () use ($layout) { @@ -290,7 +292,7 @@ $utopia->get('/console/users/user') }); $utopia->get('/console/users/teams/team') - ->desc('Platform console project team') + ->groups(['web', 'console']) ->label('permission', 'public') ->label('scope', 'console') ->action(function () use ($layout) { diff --git a/app/controllers/web/home.php b/app/controllers/web/home.php index 11a7e43b89..f164c832d6 100644 --- a/app/controllers/web/home.php +++ b/app/controllers/web/home.php @@ -25,13 +25,14 @@ $utopia->init(function () use ($layout) { ->setParam('header', [$header]) ->setParam('footer', [$footer]) ; -}); +}, 'home'); $utopia->shutdown(function () use ($response, $layout) { $response->send($layout->render()); -}); +}, 'home'); $utopia->get('/') + ->groups(['web', 'home']) ->label('permission', 'public') ->label('scope', 'home') ->action( @@ -41,7 +42,7 @@ $utopia->get('/') ); $utopia->get('/auth/signin') - ->desc('Login page') + ->groups(['web', 'home']) ->label('permission', 'public') ->label('scope', 'home') ->action(function () use ($layout) { @@ -53,7 +54,7 @@ $utopia->get('/auth/signin') }); $utopia->get('/auth/signup') - ->desc('Registration page') + ->groups(['web', 'home']) ->label('permission', 'public') ->label('scope', 'home') ->action(function () use ($layout) { @@ -65,7 +66,7 @@ $utopia->get('/auth/signup') }); $utopia->get('/auth/recovery') - ->desc('Password recovery page') + ->groups(['web', 'home']) ->label('permission', 'public') ->label('scope', 'home') ->action(function () use ($request, $layout) { @@ -77,7 +78,7 @@ $utopia->get('/auth/recovery') }); $utopia->get('/auth/confirm') - ->desc('Account confirmation page') + ->groups(['web', 'home']) ->label('permission', 'public') ->label('scope', 'home') ->action(function () use ($layout) { @@ -89,7 +90,7 @@ $utopia->get('/auth/confirm') }); $utopia->get('/auth/join') - ->desc('Account team join page') + ->groups(['web', 'home']) ->label('permission', 'public') ->label('scope', 'home') ->action(function () use ($layout) { @@ -101,7 +102,7 @@ $utopia->get('/auth/join') }); $utopia->get('/auth/recovery/reset') - ->desc('Password recovery page') + ->groups(['web', 'home']) ->label('permission', 'public') ->label('scope', 'home') ->action(function () use ($layout) { @@ -114,7 +115,7 @@ $utopia->get('/auth/recovery/reset') $utopia->get('/auth/oauth2/success') - ->desc('Registration page') + ->groups(['web', 'home']) ->label('permission', 'public') ->label('scope', 'home') ->action(function () use ($layout) { @@ -129,7 +130,7 @@ $utopia->get('/auth/oauth2/success') }); $utopia->get('/auth/oauth2/failure') - ->desc('Registration page') + ->groups(['web', 'home']) ->label('permission', 'public') ->label('scope', 'home') ->action(function () use ($layout) { @@ -144,7 +145,7 @@ $utopia->get('/auth/oauth2/failure') }); $utopia->get('/error/:code') - ->desc('Error page') + ->groups(['web', 'home']) ->label('permission', 'public') ->label('scope', 'home') ->param('code', null, new \Utopia\Validator\Numeric(), 'Valid status code number', false) @@ -161,6 +162,7 @@ $utopia->get('/error/:code') }); $utopia->get('/open-api-2.json') + ->groups(['web', 'home']) ->label('scope', 'public') ->label('docs', false) ->param('platform', APP_PLATFORM_CLIENT, function () {return new WhiteList([APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER, APP_PLATFORM_CONSOLE]);}, 'Choose target platform.', true) diff --git a/composer.json b/composer.json index 8af76121cd..78b0fd76cc 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,7 @@ "appwrite/php-clamav": "1.0.*", - "utopia-php/framework": "0.3.5", + "utopia-php/framework": "0.4.0", "utopia-php/abuse": "0.2.*", "utopia-php/audit": "0.3.*", "utopia-php/cache": "0.2.*", diff --git a/composer.lock b/composer.lock index 459a9bd325..595045b9b5 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "9deec50e5a99197511b5efbcaa9593bd", + "content-hash": "7f6cbe77fe2e0f8bdff33c37a4d9ca11", "packages": [ { "name": "appwrite/php-clamav", @@ -459,24 +459,24 @@ "source": { "type": "git", "url": "https://github.com/guzzle/promises.git", - "reference": "89b1a76b7fda5853401297dc4b2a093cba1fda23" + "reference": "bbf3b200bc83c1e9298580a9f99b9be248543467" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/promises/zipball/89b1a76b7fda5853401297dc4b2a093cba1fda23", - "reference": "89b1a76b7fda5853401297dc4b2a093cba1fda23", + "url": "https://api.github.com/repos/guzzle/promises/zipball/bbf3b200bc83c1e9298580a9f99b9be248543467", + "reference": "bbf3b200bc83c1e9298580a9f99b9be248543467", "shasum": "" }, "require": { - "php": ">=5.6" + "php": ">=5.5" }, "require-dev": { - "phpunit/phpunit": "^5.7.27 || ^7.5" + "phpunit/phpunit": "^4.8.36 || ^5.7.27 || ^7.5" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.4-dev" + "dev-master": "1.3-dev" } }, "autoload": { @@ -502,7 +502,7 @@ "keywords": [ "promise" ], - "time": "2020-02-15T23:33:03+00:00" + "time": "2020-06-21T23:10:57+00:00" }, { "name": "guzzlehttp/psr7", @@ -1546,16 +1546,16 @@ }, { "name": "utopia-php/domains", - "version": "0.2.0", + "version": "0.2.1", "source": { "type": "git", "url": "https://github.com/utopia-php/domains.git", - "reference": "1665e1d9932afa3be63b5c1e0dcfe01fe77d8e73" + "reference": "98e85296867a59c9d712d6ed768a5c5b2b297b43" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/domains/zipball/1665e1d9932afa3be63b5c1e0dcfe01fe77d8e73", - "reference": "1665e1d9932afa3be63b5c1e0dcfe01fe77d8e73", + "url": "https://api.github.com/repos/utopia-php/domains/zipball/98e85296867a59c9d712d6ed768a5c5b2b297b43", + "reference": "98e85296867a59c9d712d6ed768a5c5b2b297b43", "shasum": "" }, "require": { @@ -1592,20 +1592,20 @@ "upf", "utopia" ], - "time": "2020-02-23T07:40:02+00:00" + "time": "2020-06-20T11:47:04+00:00" }, { "name": "utopia-php/framework", - "version": "0.3.5", + "version": "0.4.0", "source": { "type": "git", "url": "https://github.com/utopia-php/framework.git", - "reference": "ca2ebe37936983d786f57bae8ee6e006299f4942" + "reference": "30aeb2aeecf8ea2ab83242efad0f5f9fab8d4be5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/framework/zipball/ca2ebe37936983d786f57bae8ee6e006299f4942", - "reference": "ca2ebe37936983d786f57bae8ee6e006299f4942", + "url": "https://api.github.com/repos/utopia-php/framework/zipball/30aeb2aeecf8ea2ab83242efad0f5f9fab8d4be5", + "reference": "30aeb2aeecf8ea2ab83242efad0f5f9fab8d4be5", "shasum": "" }, "require": { @@ -1636,7 +1636,7 @@ "php", "upf" ], - "time": "2020-06-20T11:33:46+00:00" + "time": "2020-06-25T18:21:48+00:00" }, { "name": "utopia-php/locale", @@ -3307,12 +3307,12 @@ "source": { "type": "git", "url": "https://github.com/twigphp/Twig.git", - "reference": "3beabd64bdc91558b41f140cc4b14925f0416cb2" + "reference": "f32950c872a995a93807909bab69387f47afaa25" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/twigphp/Twig/zipball/3beabd64bdc91558b41f140cc4b14925f0416cb2", - "reference": "3beabd64bdc91558b41f140cc4b14925f0416cb2", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/f32950c872a995a93807909bab69387f47afaa25", + "reference": "f32950c872a995a93807909bab69387f47afaa25", "shasum": "" }, "require": { @@ -3364,7 +3364,7 @@ "keywords": [ "templating" ], - "time": "2020-06-08T10:41:25+00:00" + "time": "2020-06-22T15:25:21+00:00" }, { "name": "webmozart/assert", From ff6078fd7e5faffb8d11a7a3856c510358400ea0 Mon Sep 17 00:00:00 2001 From: Eldad Fux Date: Thu, 25 Jun 2020 22:53:36 +0300 Subject: [PATCH 24/25] Unified include calls --- app/app.php | 3 +++ app/controllers/api/account.php | 2 -- app/controllers/api/avatars.php | 2 -- app/controllers/api/database.php | 2 -- app/controllers/api/locale.php | 2 -- app/controllers/api/projects.php | 2 -- app/controllers/api/storage.php | 2 -- app/controllers/api/teams.php | 2 -- app/controllers/api/users.php | 2 -- app/controllers/web/console.php | 2 -- app/controllers/web/home.php | 2 -- public/index.php | 6 +++--- 12 files changed, 6 insertions(+), 23 deletions(-) diff --git a/app/app.php b/app/app.php index 49bedfed2b..bb4058b601 100644 --- a/app/app.php +++ b/app/app.php @@ -426,6 +426,9 @@ $utopia->get('/.well-known/acme-challenge') } ); +include_once __DIR__ . '/controllers/shared/api.php'; +include_once __DIR__ . '/controllers/shared/web.php'; + foreach($services as $key => $service) { include_once $services[$key]['controller']; } diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 7757990c69..3bce54eafa 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -29,8 +29,6 @@ use DeviceDetector\DeviceDetector; use GeoIp2\Database\Reader; use Utopia\Validator\ArrayList; -include_once __DIR__ . '/../shared/api.php'; - $oauthDefaultSuccess = $request->getServer('_APP_HOME').'/auth/oauth2/success'; $oauthDefaultFailure = $request->getServer('_APP_HOME').'/auth/oauth2/failure'; diff --git a/app/controllers/api/avatars.php b/app/controllers/api/avatars.php index a4d9a9d79d..90f8ac34c8 100644 --- a/app/controllers/api/avatars.php +++ b/app/controllers/api/avatars.php @@ -18,8 +18,6 @@ use BaconQrCode\Writer; use Utopia\Config\Config; use Utopia\Validator\HexColor; -include_once __DIR__ . '/../shared/api.php'; - $types = [ 'browsers' => include __DIR__.'/../../config/avatars/browsers.php', 'credit-cards' => include __DIR__.'/../../config/avatars/credit-cards.php', diff --git a/app/controllers/api/database.php b/app/controllers/api/database.php index 06c707745f..fafed2624b 100644 --- a/app/controllers/api/database.php +++ b/app/controllers/api/database.php @@ -25,8 +25,6 @@ use Appwrite\Database\Exception\Structure as StructureException; use DeviceDetector\DeviceDetector; use GeoIp2\Database\Reader; -include_once __DIR__ . '/../shared/api.php'; - $utopia->post('/v1/database/collections') ->desc('Create Collection') ->groups(['api', 'database']) diff --git a/app/controllers/api/locale.php b/app/controllers/api/locale.php index caf9de0f4a..148ee3e8e9 100644 --- a/app/controllers/api/locale.php +++ b/app/controllers/api/locale.php @@ -6,8 +6,6 @@ use Utopia\App; use Utopia\Locale\Locale; use GeoIp2\Database\Reader; -include_once __DIR__ . '/../shared/api.php'; - $utopia->get('/v1/locale') ->desc('Get User Locale') ->groups(['api', 'locale']) diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index d2633985a8..3311abbd0b 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -21,8 +21,6 @@ use Appwrite\OpenSSL\OpenSSL; use Appwrite\Network\Validator\CNAME; use Cron\CronExpression; -include_once __DIR__ . '/../shared/api.php'; - $scopes = include __DIR__.'/../../../app/config/scopes.php'; $utopia->post('/v1/projects') diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index b02461626d..9a12b56048 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -23,8 +23,6 @@ use Appwrite\Storage\Compression\Algorithms\GZIP; use Appwrite\Resize\Resize; use Appwrite\OpenSSL\OpenSSL; -include_once __DIR__ . '/../shared/api.php'; - Storage::addDevice('local', new Local(APP_STORAGE_UPLOADS.'/app-'.$project->getId())); $fileLogos = [ // Based on this list @see http://stackoverflow.com/a/4212908/2299554 diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index 9905508c31..67b4599b2d 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -20,8 +20,6 @@ use Appwrite\Database\Validator\Authorization; use Appwrite\Database\Exception\Duplicate; use Appwrite\Template\Template; -include_once __DIR__ . '/../shared/api.php'; - $utopia->post('/v1/teams') ->desc('Create Team') ->groups(['api', 'teams']) diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index e29e40aded..d1744bf48a 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -21,8 +21,6 @@ use Appwrite\Database\Validator\UID; use DeviceDetector\DeviceDetector; use GeoIp2\Database\Reader; -include_once __DIR__ . '/../shared/api.php'; - $utopia->post('/v1/users') ->desc('Create User') ->groups(['api', 'users']) diff --git a/app/controllers/web/console.php b/app/controllers/web/console.php index 543794609a..595d36d33a 100644 --- a/app/controllers/web/console.php +++ b/app/controllers/web/console.php @@ -1,7 +1,5 @@ Date: Thu, 25 Jun 2020 23:02:26 +0300 Subject: [PATCH 25/25] Removed debuging --- public/index.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/public/index.php b/public/index.php index a80a351324..c87b14a26e 100644 --- a/public/index.php +++ b/public/index.php @@ -11,9 +11,9 @@ error_reporting(0); ini_set('display_errors', 0); -ini_set('display_errors', 1); -ini_set('display_startup_errors', 1); -error_reporting(E_ALL); +// ini_set('display_errors', 1); +// ini_set('display_startup_errors', 1); +// error_reporting(E_ALL); $path = (isset($_GET['q'])) ? explode('/', $_GET['q']) : [];