From 6f540fec0f2e9b586b63e26866fa6b91a4f4d399 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Fri, 6 Aug 2021 13:46:53 +0545 Subject: [PATCH] restructuring auth method keys --- app/config/auth.php | 10 +++++----- app/controllers/shared/api.php | 8 ++++---- src/Appwrite/Utopia/Response/Model/Project.php | 6 +++--- .../Services/Projects/ProjectsConsoleClientTest.php | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/app/config/auth.php b/app/config/auth.php index 11b89dd9ec..6257c08c2b 100644 --- a/app/config/auth.php +++ b/app/config/auth.php @@ -5,35 +5,35 @@ return [ 'email-password' => [ 'name' => 'Email/Password', - 'key' => 'usersAuthEmailPassword', + 'key' => 'emailPassword', 'icon' => '/images/users/email.png', 'docs' => 'https://appwrite.io/docs/client/account?sdk=web#accountCreateSession', 'enabled' => true, ], 'anonymous' => [ 'name' => 'Anonymous', - 'key' => 'usersAuthAnonymous', + 'key' => 'anonymous', 'icon' => '/images/users/anonymous.png', 'docs' => 'https://appwrite.io/docs/client/account?sdk=web#accountCreateAnonymousSession', 'enabled' => true, ], 'invites' => [ 'name' => 'Invites', - 'key' => 'usersAuthInvites', + 'key' => 'invites', 'icon' => '/images/users/invites.png', 'docs' => 'https://appwrite.io/docs/client/teams?sdk=web#teamsCreateMembership', 'enabled' => true, ], 'jwt' => [ 'name' => 'JWT', - 'key' => 'usersAuthJWT', + 'key' => 'JWT', 'icon' => '/images/users/jwt.png', 'docs' => 'https://appwrite.io/docs/client/account?sdk=web#accountCreateJWT', 'enabled' => true, ], 'phone' => [ 'name' => 'Phone', - 'key' => 'usersAuthPhone', + 'key' => 'phone', 'icon' => '/images/users/phone.png', 'docs' => 'https://appwrite.io/docs/client/account?sdk=web#accountCreatePhoneSession', 'docs' => '', diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index eea8a61dd1..36ac0dab58 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -140,25 +140,25 @@ App::init(function ($utopia, $request, $response, $project, $user) { $auths = $project->getAttribute('auths', []); switch ($route->getLabel('auth.type', '')) { case 'emailPassword': - if(($auths['usersAuthEmailPassword'] ?? true) === false) { + if(($auths['emailPassword'] ?? true) === false) { throw new Exception('Email / Password authentication is disabled for this project', 501); } break; case 'anonymous': - if(($auths['usersAuthAnonymous'] ?? true) === false) { + if(($auths['anonymous'] ?? true) === false) { throw new Exception('Anonymous authentication is disabled for this project', 501); } break; case 'invites': - if(($auths['usersAuthInvites'] ?? true) === false) { + if(($auths['invites'] ?? true) === false) { throw new Exception('Invites authentication is disabled for this project', 501); } break; case 'jwt': - if(($auths['usersAuthJWT'] ?? true) === false) { + if(($auths['JWT'] ?? true) === false) { throw new Exception('JWT authentication is disabled for this project', 501); } break; diff --git a/src/Appwrite/Utopia/Response/Model/Project.php b/src/Appwrite/Utopia/Response/Model/Project.php index 417b640c0d..f079801f2c 100644 --- a/src/Appwrite/Utopia/Response/Model/Project.php +++ b/src/Appwrite/Utopia/Response/Model/Project.php @@ -158,7 +158,7 @@ class Project extends Model $key = $method['key'] ?? ''; $this - ->addRule($key, [ + ->addRule('auth' . ucfirst($key), [ 'type' => self::TYPE_BOOLEAN, 'description' => $name.' auth method status', 'example' => true, @@ -229,9 +229,9 @@ class Project extends Model $auth = Config::getParam('auth', []); foreach ($auth as $index => $method) { - $key = $method['key'] ?? ''; + $key = $method['key']; $value = $authValues[$key] ?? true; - $document->setAttribute($key, $value); + $document->setAttribute('auth' . ucfirst($key), $value); } return $document; diff --git a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php index faa8cd954b..709966558e 100644 --- a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php +++ b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php @@ -351,7 +351,7 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals(200, $response['headers']['status-code']); $this->assertNotEmpty($response['body']['$id']); - $this->assertEquals(false, $response['body'][$method['key']]); + $this->assertEquals(false, $response['body']['auth'. ucfirst($method['key'])]); } $email = uniqid().'user@localhost.test';