From 8f624e115b04c354711993a523bffe3799ca898e Mon Sep 17 00:00:00 2001 From: Everly Precia Suresh Date: Wed, 25 May 2022 13:36:25 +0000 Subject: [PATCH 1/7] refactor users.php --- app/controllers/api/users.php | 105 ++++++++-------------------------- 1 file changed, 23 insertions(+), 82 deletions(-) diff --git a/app/controllers/api/users.php b/app/controllers/api/users.php index 95df53ad3..cbd2cebab 100644 --- a/app/controllers/api/users.php +++ b/app/controllers/api/users.php @@ -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') { From 0512c7f22f84b8bc58913ac61ff11adf2fdc31d5 Mon Sep 17 00:00:00 2001 From: Everly Precia Suresh <77877486+everly-gif@users.noreply.github.com> Date: Thu, 26 May 2022 03:05:04 +0530 Subject: [PATCH 2/7] update test : set stopOnFailure to false --- phpunit.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/phpunit.xml b/phpunit.xml index 11436083c..e3d583022 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -6,7 +6,7 @@ convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" - stopOnFailure="true" + stopOnFailure="false" > @@ -35,4 +35,4 @@ ./tests/e2e/Services/Functions/FunctionsCustomClientTest.php - \ No newline at end of file + From 5d3edc18d9228615fefb326dbbe2b11e753c2051 Mon Sep 17 00:00:00 2001 From: Everly Precia Suresh Date: Thu, 26 May 2022 10:52:23 +0000 Subject: [PATCH 3/7] remove failing cname tests --- tests/unit/Network/Validators/CNAMETest.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/unit/Network/Validators/CNAMETest.php b/tests/unit/Network/Validators/CNAMETest.php index d08656d84..93943fcdf 100644 --- a/tests/unit/Network/Validators/CNAMETest.php +++ b/tests/unit/Network/Validators/CNAMETest.php @@ -26,9 +26,9 @@ 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('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); } } From 7f0ecf59d0e428be54bed7a98588c07f2dce59dc Mon Sep 17 00:00:00 2001 From: Everly Precia Suresh Date: Thu, 26 May 2022 11:31:47 +0000 Subject: [PATCH 4/7] refactor web.php --- app/controllers/shared/web.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/controllers/shared/web.php b/app/controllers/shared/web.php index e45333808..4999578bb 100644 --- a/app/controllers/shared/web.php +++ b/app/controllers/shared/web.php @@ -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', ''))) { From ed695cf26c3d86f0bc16929576fecce95c21197a Mon Sep 17 00:00:00 2001 From: Everly Precia Suresh Date: Thu, 26 May 2022 12:49:05 +0000 Subject: [PATCH 5/7] refactor web.php --- phpunit.xml | 2 +- tests/unit/Network/Validators/CNAMETest.php | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/phpunit.xml b/phpunit.xml index 11436083c..9f5e42b84 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -6,7 +6,7 @@ convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" - stopOnFailure="true" + stopOnFailure="false" > diff --git a/tests/unit/Network/Validators/CNAMETest.php b/tests/unit/Network/Validators/CNAMETest.php index d08656d84..93943fcdf 100644 --- a/tests/unit/Network/Validators/CNAMETest.php +++ b/tests/unit/Network/Validators/CNAMETest.php @@ -26,9 +26,9 @@ 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('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); } } From 1602c06285db5a5c60be07f4350bef28ca73a1a9 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Mon, 30 May 2022 14:45:13 +0000 Subject: [PATCH 6/7] Update CNAME test domains --- tests/unit/Network/Validators/CNAMETest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/Network/Validators/CNAMETest.php b/tests/unit/Network/Validators/CNAMETest.php index d08656d84..3ddb6991e 100644 --- a/tests/unit/Network/Validators/CNAMETest.php +++ b/tests/unit/Network/Validators/CNAMETest.php @@ -26,8 +26,8 @@ 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('cname-unit-test.appwrite.org'), true); + $this->assertEquals($this->object->isValid('cname-unit-test.appwrite.org'), true); $this->assertEquals($this->object->isValid('test1.appwrite.org'), false); $this->assertEquals($this->object->isValid('test1.appwrite.org'), false); } From 3ae1f63679c20317409c31291a39a520eb4d20a4 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Mon, 30 May 2022 14:50:12 +0000 Subject: [PATCH 7/7] Remove duplicate tests --- tests/unit/Network/Validators/CNAMETest.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/unit/Network/Validators/CNAMETest.php b/tests/unit/Network/Validators/CNAMETest.php index 3ddb6991e..5aa7a69db 100644 --- a/tests/unit/Network/Validators/CNAMETest.php +++ b/tests/unit/Network/Validators/CNAMETest.php @@ -27,8 +27,6 @@ class CNAMETest extends TestCase $this->assertEquals($this->object->isValid(null), false); $this->assertEquals($this->object->isValid(false), false); $this->assertEquals($this->object->isValid('cname-unit-test.appwrite.org'), true); - $this->assertEquals($this->object->isValid('cname-unit-test.appwrite.org'), true); - $this->assertEquals($this->object->isValid('test1.appwrite.org'), false); $this->assertEquals($this->object->isValid('test1.appwrite.org'), false); } }