1
0
Fork 0
mirror of synced 2024-07-01 20:50:49 +12:00

Merge branch 'master' into refactor-functions

This commit is contained in:
Torsten Dittmann 2022-05-31 10:54:03 +02:00 committed by GitHub
commit 0fdd785ba9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 54 additions and 138 deletions

View file

@ -3,12 +3,17 @@
use Appwrite\Auth\Auth;
use Appwrite\Auth\Validator\Password;
use Appwrite\Detector\Detector;
use Appwrite\Event\Delete;
use Appwrite\Event\Event;
use Appwrite\Event\Audit as EventAudit;
use Appwrite\Network\Validator\Email;
use Appwrite\Stats\Stats;
use Appwrite\Utopia\Database\Validator\CustomId;
use Appwrite\Utopia\Response;
use Utopia\App;
use Utopia\Audit\Audit;
use Utopia\Config\Config;
use Utopia\Locale\Locale;
use Appwrite\Extend\Exception;
use Utopia\Database\Document;
use Utopia\Database\Exception\Duplicate;
@ -21,6 +26,7 @@ use Utopia\Validator\WhiteList;
use Utopia\Validator\Text;
use Utopia\Validator\Range;
use Utopia\Validator\Boolean;
use MaxMind\Db\Reader;
App::post('/v1/users')
->desc('Create User')
@ -42,11 +48,7 @@ App::post('/v1/users')
->inject('dbForProject')
->inject('usage')
->inject('events')
->action(function ($userId, $email, $password, $name, $response, $dbForProject, $usage, $events) {
/** @var Appwrite\Utopia\Response $response */
/** @var Utopia\Database\Database $dbForProject */
/** @var Appwrite\Stats\Stats $usage */
/** @var Appwrite\Event\Event $events */
->action(function (string $userId, string $email, string $password, string $name, Response $response, Database $dbForProject, Stats $usage, Event $events) {
$email = \strtolower($email);
@ -106,10 +108,7 @@ App::get('/v1/users')
->inject('response')
->inject('dbForProject')
->inject('usage')
->action(function ($search, $limit, $offset, $cursor, $cursorDirection, $orderType, $response, $dbForProject, $usage) {
/** @var Appwrite\Utopia\Response $response */
/** @var Utopia\Database\Database $dbForProject */
/** @var Appwrite\Stats\Stats $usage */
->action(function (string $search, int $limit, int $offset, string $cursor, string $cursorDirection, string $orderType, Response $response, Database $dbForProject, Stats $usage) {
if (!empty($cursor)) {
$cursorUser = $dbForProject->getDocument('users', $cursor);
@ -150,10 +149,7 @@ App::get('/v1/users/:userId')
->inject('response')
->inject('dbForProject')
->inject('usage')
->action(function ($userId, $response, $dbForProject, $usage) {
/** @var Appwrite\Utopia\Response $response */
/** @var Utopia\Database\Database $dbForProject */
/** @var Appwrite\Stats\Stats $usage */
->action(function (string $userId, Response $response, Database $dbForProject, Stats $usage) {
$user = $dbForProject->getDocument('users', $userId);
@ -182,10 +178,7 @@ App::get('/v1/users/:userId/prefs')
->inject('response')
->inject('dbForProject')
->inject('usage')
->action(function ($userId, $response, $dbForProject, $usage) {
/** @var Appwrite\Utopia\Response $response */
/** @var Utopia\Database\Database $dbForProject */
/** @var Appwrite\Stats\Stats $usage */
->action(function (string $userId, Response $response, Database $dbForProject, Stats $usage) {
$user = $dbForProject->getDocument('users', $userId);
@ -217,11 +210,7 @@ App::get('/v1/users/:userId/sessions')
->inject('dbForProject')
->inject('locale')
->inject('usage')
->action(function ($userId, $response, $dbForProject, $locale, $usage) {
/** @var Appwrite\Utopia\Response $response */
/** @var Utopia\Database\Database $dbForProject */
/** @var Utopia\Locale\Locale $locale */
/** @var Appwrite\Stats\Stats $usage */
->action(function (string $userId, Response $response, Database $dbForProject, Locale $locale, Stats $usage) {
$user = $dbForProject->getDocument('users', $userId);
@ -264,10 +253,7 @@ App::get('/v1/users/:userId/memberships')
->param('userId', '', new UID(), 'User ID.')
->inject('response')
->inject('dbForProject')
->action(function ($userId, $response, $dbForProject) {
/** @var string $userId */
/** @var Appwrite\Utopia\Response $response */
/** @var Utopia\Database\Database $dbForProject */
->action(function (string $userId, Response $response, Database $dbForProject) {
$user = $dbForProject->getDocument('users', $userId);
@ -311,13 +297,7 @@ App::get('/v1/users/:userId/logs')
->inject('locale')
->inject('geodb')
->inject('usage')
->action(function ($userId, $limit, $offset, $response, $dbForProject, $locale, $geodb, $usage) {
/** @var Appwrite\Utopia\Response $response */
/** @var Utopia\Database\Document $project */
/** @var Utopia\Database\Database $dbForProject */
/** @var Utopia\Locale\Locale $locale */
/** @var MaxMind\Db\Reader $geodb */
/** @var Appwrite\Stats\Stats $usage */
->action(function (string $userId, int $limit, int $offset, Response $response, Database $dbForProject, Locale $locale, Reader $geodb, Stats $usage) {
$user = $dbForProject->getDocument('users', $userId);
@ -398,11 +378,7 @@ App::patch('/v1/users/:userId/status')
->inject('dbForProject')
->inject('usage')
->inject('events')
->action(function ($userId, $status, $response, $dbForProject, $usage, $events) {
/** @var Appwrite\Utopia\Response $response */
/** @var Utopia\Database\Database $dbForProject */
/** @var Appwrite\Stats\Stats $usage */
/** @var Appwrite\Event\Event $events */
->action(function (string $userId, bool $status, Response $response, Database $dbForProject, Stats $usage, Event $events) {
$user = $dbForProject->getDocument('users', $userId);
@ -441,11 +417,7 @@ App::patch('/v1/users/:userId/verification')
->inject('dbForProject')
->inject('usage')
->inject('events')
->action(function ($userId, $emailVerification, $response, $dbForProject, $usage, $events) {
/** @var Appwrite\Utopia\Response $response */
/** @var Utopia\Database\Database $dbForProject */
/** @var Appwrite\Stats\Stats $usage */
/** @var Appwrite\Event\Event $events */
->action(function (string $userId, bool $emailVerification, Response $response, Database $dbForProject, Stats $usage, Event $events) {
$user = $dbForProject->getDocument('users', $userId);
@ -484,11 +456,7 @@ App::patch('/v1/users/:userId/name')
->inject('dbForProject')
->inject('audits')
->inject('events')
->action(function ($userId, $name, $response, $dbForProject, $audits, $events) {
/** @var Appwrite\Utopia\Response $response */
/** @var Utopia\Database\Database $dbForProject */
/** @var Appwrite\Event\Audit $audits */
/** @var Appwrite\Event\Event $events */
->action(function (string $userId, string $name, Response $response, Database $dbForProject, EventAudit $audits, Event $events) {
$user = $dbForProject->getDocument('users', $userId);
@ -532,11 +500,7 @@ App::patch('/v1/users/:userId/password')
->inject('dbForProject')
->inject('audits')
->inject('events')
->action(function ($userId, $password, $response, $dbForProject, $audits, $events) {
/** @var Appwrite\Utopia\Response $response */
/** @var Utopia\Database\Database $dbForProject */
/** @var Appwrite\Event\Audit $audits */
/** @var Appwrite\Event\Event $events */
->action(function (string $userId, string $password, Response $response, Database $dbForProject, EventAudit $audits, Event $events) {
$user = $dbForProject->getDocument('users', $userId);
@ -579,11 +543,7 @@ App::patch('/v1/users/:userId/email')
->inject('dbForProject')
->inject('audits')
->inject('events')
->action(function ($userId, $email, $response, $dbForProject, $audits, $events) {
/** @var Appwrite\Utopia\Response $response */
/** @var Utopia\Database\Database $dbForProject */
/** @var Appwrite\Event\Audit $audits */
/** @var Appwrite\Event\Event $events */
->action(function (string $userId, string $email, Response $response, Database $dbForProject, EventAudit $audits, Event $events) {
$user = $dbForProject->getDocument('users', $userId);
@ -639,11 +599,7 @@ App::patch('/v1/users/:userId/prefs')
->inject('dbForProject')
->inject('usage')
->inject('events')
->action(function ($userId, $prefs, $response, $dbForProject, $usage, $events) {
/** @var Appwrite\Utopia\Response $response */
/** @var Utopia\Database\Database $dbForProject */
/** @var Appwrite\Stats\Stats $usage */
/** @var Appwrite\Event\Event $events */
->action(function (string $userId, array $prefs, Response $response, Database $dbForProject, Stats $usage, Event $events) {
$user = $dbForProject->getDocument('users', $userId);
@ -681,11 +637,7 @@ App::delete('/v1/users/:userId/sessions/:sessionId')
->inject('dbForProject')
->inject('events')
->inject('usage')
->action(function ($userId, $sessionId, $response, $dbForProject, $events, $usage) {
/** @var Appwrite\Utopia\Response $response */
/** @var Utopia\Database\Database $dbForProject */
/** @var Appwrite\Event\Event $events */
/** @var Appwrite\Stats\Stats $usage */
->action(function (string $userId, string $sessionId, Response $response, Database $dbForProject, Event $events, Stats $usage) {
$user = $dbForProject->getDocument('users', $userId);
@ -732,11 +684,7 @@ App::delete('/v1/users/:userId/sessions')
->inject('dbForProject')
->inject('events')
->inject('usage')
->action(function ($userId, $response, $dbForProject, $events, $usage) {
/** @var Appwrite\Utopia\Response $response */
/** @var Utopia\Database\Database $dbForProject */
/** @var Appwrite\Event\Event $events */
/** @var Appwrite\Stats\Stats $usage */
->action(function (string $userId, Response $response, Database $dbForProject, Event $events, Stats $usage) {
$user = $dbForProject->getDocument('users', $userId);
@ -783,12 +731,7 @@ App::delete('/v1/users/:userId')
->inject('events')
->inject('deletes')
->inject('usage')
->action(function ($userId, $response, $dbForProject, $events, $deletes, $usage) {
/** @var Appwrite\Utopia\Response $response */
/** @var Utopia\Database\Database $dbForProject */
/** @var Appwrite\Event\Event $events */
/** @var Appwrite\Event\Delete $deletes */
/** @var Appwrite\Stats\Stats $usage */
->action(function (string $userId, Response $response, Database $dbForProject, Event $events, Delete $deletes, Stats $usage) {
$user = $dbForProject->getDocument('users', $userId);
@ -833,9 +776,7 @@ App::get('/v1/users/usage')
->inject('response')
->inject('dbForProject')
->inject('register')
->action(function ($range, $provider, $response, $dbForProject) {
/** @var Appwrite\Utopia\Response $response */
/** @var Utopia\Database\Database $dbForProject */
->action(function (string $range, string $provider, Response $response, Database $dbForProject) {
$usage = [];
if (App::getEnv('_APP_USAGE_STATS', 'enabled') == 'enabled') {

View file

@ -2,12 +2,11 @@
use Utopia\App;
use Utopia\Config\Config;
use Appwrite\Utopia\Response;
use Appwrite\Utopia\Request;
use Appwrite\Utopia\View;
App::init(function ($utopia, $request, $response, $layout) {
/** @var Utopia\App $utopia */
/** @var Appwrite\Utopia\Request $request */
/** @var Appwrite\Utopia\Response $response */
/** @var Appwrite\Utopia\View $layout */
App::init(function (App $utopia, Request $request, Response $response, View $layout) {
/* AJAX check */
if (!empty($request->getQuery('version', ''))) {

View file

@ -1,6 +1,7 @@
<?php
use Appwrite\Extend\Exception;
use Appwrite\Utopia\Response;
use Appwrite\Utopia\View;
use Utopia\App;
use Utopia\Config\Config;
@ -8,8 +9,7 @@ use Utopia\Domains\Domain;
use Utopia\Database\Validator\UID;
use Utopia\Storage\Storage;
App::init(function ($layout) {
/** @var Appwrite\Utopia\View $layout */
App::init(function (View $layout) {
$layout
->setParam('description', 'Appwrite Console allows you to easily manage, monitor, and control your entire backend API and tools.')
@ -17,9 +17,7 @@ App::init(function ($layout) {
;
}, ['layout'], 'console');
App::shutdown(function ($response, $layout) {
/** @var Appwrite\Utopia\Response $response */
/** @var Appwrite\Utopia\View $layout */
App::shutdown(function (Response $response, View $layout) {
$header = new View(__DIR__.'/../../views/console/comps/header.phtml');
$footer = new View(__DIR__.'/../../views/console/comps/footer.phtml');
@ -43,8 +41,7 @@ App::get('/error/:code')
->label('scope', 'home')
->param('code', null, new \Utopia\Validator\Numeric(), 'Valid status code number', false)
->inject('layout')
->action(function ($code, $layout) {
/** @var Appwrite\Utopia\View $layout */
->action(function (int $code, View $layout) {
$page = new View(__DIR__.'/../../views/error.phtml');
@ -62,8 +59,7 @@ App::get('/console')
->label('permission', 'public')
->label('scope', 'console')
->inject('layout')
->action(function ($layout) {
/** @var Appwrite\Utopia\View $layout */
->action(function (View $layout) {
$page = new View(__DIR__.'/../../views/console/index.phtml');
@ -81,8 +77,7 @@ App::get('/console/account')
->label('permission', 'public')
->label('scope', 'console')
->inject('layout')
->action(function ($layout) {
/** @var Appwrite\Utopia\View $layout */
->action(function (View $layout) {
$page = new View(__DIR__.'/../../views/console/account/index.phtml');
@ -102,8 +97,7 @@ App::get('/console/notifications')
->label('permission', 'public')
->label('scope', 'console')
->inject('layout')
->action(function ($layout) {
/** @var Appwrite\Utopia\View $layout */
->action(function (View $layout) {
$page = new View(__DIR__.'/../../views/v1/console/notifications/index.phtml');
@ -117,8 +111,7 @@ App::get('/console/home')
->label('permission', 'public')
->label('scope', 'console')
->inject('layout')
->action(function ($layout) {
/** @var Appwrite\Utopia\View $layout */
->action(function (View $layout) {
$page = new View(__DIR__.'/../../views/console/home/index.phtml');
$page
@ -133,8 +126,7 @@ App::get('/console/settings')
->label('permission', 'public')
->label('scope', 'console')
->inject('layout')
->action(function ($layout) {
/** @var Appwrite\Utopia\View $layout */
->action(function (View $layout) {
$target = new Domain(App::getEnv('_APP_DOMAIN_TARGET', ''));
@ -157,8 +149,7 @@ App::get('/console/webhooks')
->label('permission', 'public')
->label('scope', 'console')
->inject('layout')
->action(function ($layout) {
/** @var Appwrite\Utopia\View $layout */
->action(function (View $layout) {
$page = new View(__DIR__.'/../../views/console/webhooks/index.phtml');
@ -175,8 +166,7 @@ App::get('/console/webhooks/webhook')
->label('scope', 'console')
->param('id', '', new UID(), 'Webhook unique ID.')
->inject('layout')
->action(function ($id, $layout) {
/** @var Appwrite\Utopia\View $layout */
->action(function (string $id, View $layout) {
$page = new View(__DIR__.'/../../views/console/webhooks/webhook.phtml');
@ -195,8 +185,7 @@ App::get('/console/webhooks/webhook/new')
->label('permission', 'public')
->label('scope', 'console')
->inject('layout')
->action(function ($layout) {
/** @var Appwrite\Utopia\View $layout */
->action(function (View $layout) {
$page = new View(__DIR__.'/../../views/console/webhooks/webhook.phtml');
@ -215,8 +204,7 @@ App::get('/console/keys')
->label('permission', 'public')
->label('scope', 'console')
->inject('layout')
->action(function ($layout) {
/** @var Appwrite\Utopia\View $layout */
->action(function (View $layout) {
$scopes = array_keys(Config::getParam('scopes'));
$page = new View(__DIR__.'/../../views/console/keys/index.phtml');
@ -233,8 +221,7 @@ App::get('/console/database')
->label('permission', 'public')
->label('scope', 'console')
->inject('layout')
->action(function ($layout) {
/** @var Appwrite\Utopia\View $layout */
->action(function (View $layout) {
$page = new View(__DIR__.'/../../views/console/database/index.phtml');
@ -250,9 +237,7 @@ App::get('/console/database/collection')
->param('id', '', new UID(), 'Collection unique ID.')
->inject('response')
->inject('layout')
->action(function ($id, $response, $layout) {
/** @var Appwrite\Utopia\Response $response */
/** @var Appwrite\Utopia\View $layout */
->action(function (string $id, Response $response, View $layout) {
$logs = new View(__DIR__.'/../../views/console/comps/logs.phtml');
@ -286,8 +271,7 @@ App::get('/console/database/document')
->label('scope', 'console')
->param('collection', '', new UID(), 'Collection unique ID.')
->inject('layout')
->action(function ($collection, $layout) {
/** @var Appwrite\Utopia\View $layout */
->action(function (string $collection, View $layout) {
$logs = new View(__DIR__.'/../../views/console/comps/logs.phtml');
@ -319,8 +303,7 @@ App::get('/console/database/document/new')
->label('scope', 'console')
->param('collection', '', new UID(), 'Collection unique ID.')
->inject('layout')
->action(function ($collection, $layout) {
/** @var Appwrite\Utopia\View $layout */
->action(function (string $collection, View $layout) {
$page = new View(__DIR__.'/../../views/console/database/document.phtml');
@ -340,8 +323,8 @@ App::get('/console/storage')
->label('permission', 'public')
->label('scope', 'console')
->inject('layout')
->action(function ($layout) {
/** @var Appwrite\Utopia\View $layout */
->action(function (View $layout) {
$page = new View(__DIR__.'/../../views/console/storage/index.phtml');
$page
@ -362,9 +345,7 @@ App::get('/console/storage/bucket')
->param('id', '', new UID(), 'Bucket unique ID.')
->inject('response')
->inject('layout')
->action(function ($id, $response, $layout) {
/** @var Appwrite\Utopia\Response $response */
/** @var Utopia\View $layout */
->action(function (string $id, Response $response, View $layout) {
$page = new View(__DIR__.'/../../views/console/storage/bucket.phtml');
$page
@ -390,8 +371,7 @@ App::get('/console/users')
->label('permission', 'public')
->label('scope', 'console')
->inject('layout')
->action(function ($layout) {
/** @var Appwrite\Utopia\View $layout */
->action(function (View $layout) {
$page = new View(__DIR__.'/../../views/console/users/index.phtml');
@ -411,8 +391,7 @@ App::get('/console/users/user')
->label('permission', 'public')
->label('scope', 'console')
->inject('layout')
->action(function ($layout) {
/** @var Appwrite\Utopia\View $layout */
->action(function (View $layout) {
$page = new View(__DIR__.'/../../views/console/users/user.phtml');
@ -426,8 +405,7 @@ App::get('/console/users/teams/team')
->label('permission', 'public')
->label('scope', 'console')
->inject('layout')
->action(function ($layout) {
/** @var Appwrite\Utopia\View $layout */
->action(function (View $layout) {
$page = new View(__DIR__.'/../../views/console/users/team.phtml');
@ -442,7 +420,7 @@ App::get('/console/functions')
->label('permission', 'public')
->label('scope', 'console')
->inject('layout')
->action(function ($layout) {
->action(function (View $layout) {
$page = new View(__DIR__.'/../../views/console/functions/index.phtml');
$page
@ -460,7 +438,7 @@ App::get('/console/functions/function')
->label('permission', 'public')
->label('scope', 'console')
->inject('layout')
->action(function ($layout) {
->action(function (View $layout) {
$page = new View(__DIR__.'/../../views/console/functions/function.phtml');
$page

View file

@ -26,9 +26,7 @@ class CNAMETest extends TestCase
$this->assertEquals($this->object->isValid(''), false);
$this->assertEquals($this->object->isValid(null), false);
$this->assertEquals($this->object->isValid(false), false);
// $this->assertEquals($this->object->isValid('test1.appwrite.io'), true);
// $this->assertEquals($this->object->isValid('test1.appwrite.io'), true);
// $this->assertEquals($this->object->isValid('test1.appwrite.org'), false);
// $this->assertEquals($this->object->isValid('test1.appwrite.org'), false);
$this->assertEquals($this->object->isValid('cname-unit-test.appwrite.org'), true);
$this->assertEquals($this->object->isValid('test1.appwrite.org'), false);
}
}