From 2459844e97e5d3cf86c146dbe66d94233be44fca Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Fri, 6 Aug 2021 12:50:20 +0545 Subject: [PATCH 1/8] fix merge sideeffect --- app/controllers/api/projects.php | 8 -------- 1 file changed, 8 deletions(-) diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 44fa614ad..c277a9971 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -31,14 +31,6 @@ App::init(function ($project) { } }, ['project'], 'projects'); -App::init(function ($project) { - /** @var Utopia\Database\Document $project */ - - if($project->getId() !== 'console') { - throw new Exception('Access to this API is forbidden.', 401); - } -}, ['project'], 'projects'); - App::post('/v1/projects') ->desc('Create Project') ->groups(['api', 'projects']) From 851a00e438957b6ae0b8f99654b44322a7135744 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Fri, 6 Aug 2021 13:27:31 +0545 Subject: [PATCH 2/8] group auth methods --- app/config/collections2.php | 25 ++++++++----------- app/controllers/api/projects.php | 19 ++++++++------ app/controllers/shared/api.php | 9 ++++--- .../Utopia/Response/Model/Project.php | 9 +++++++ 4 files changed, 36 insertions(+), 26 deletions(-) diff --git a/app/config/collections2.php b/app/config/collections2.php index 48b9018b4..56136a6e1 100644 --- a/app/config/collections2.php +++ b/app/config/collections2.php @@ -166,6 +166,17 @@ $collections = [ 'array' => false, 'filters' => ['json'], ], + [ + '$id' => 'auths', + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => 16384, + 'signed' => true, + 'required' => false, + 'default' => null, + 'array' => false, + 'filters' => ['json'], + ], [ '$id' => 'platforms', 'type' => Database::VAR_STRING, @@ -1427,18 +1438,4 @@ foreach ($providers as $index => $provider) { ]; } -foreach ($auth as $index => $method) { - $collections['projects']['attributes'][] = [ - '$id' => $method['key'] ?? '', - 'type' => Database::VAR_BOOLEAN, - 'format' => '', - 'size' => 0, - 'signed' => true, - 'required' => false, - 'default' => null, - 'array' => false, - 'filters' => [], - ]; -} - return $collections; diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index c277a9971..a9a221bb8 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -69,6 +69,12 @@ App::post('/v1/projects') if ($team->isEmpty()) { throw new Exception('Team not found', 404); } + + $auth = Config::getParam('auth', []); + $auths = []; + foreach ($auth as $index => $method) { + $auths[$method['key'] ?? ''] = true; + } $project = $dbForConsole->createDocument('projects', new Document([ '$read' => ['team:' . $teamId], @@ -90,11 +96,7 @@ App::post('/v1/projects') 'webhooks' => [], 'keys' => [], 'domains' => [], - 'usersAuthEmailPassword' => true, - 'usersAuthAnonymous' => true, - 'usersAuthInvites' => true, - 'usersAuthJWT' => true, - 'usersAuthPhone' => true, + 'auths' => $auths, ])); $collections = Config::getParam('collections2', []); /** @var array $collections */ @@ -570,9 +572,10 @@ App::patch('/v1/projects/:projectId/auth/:method') throw new Exception('Project not found', 404); } - $dbForConsole->updateDocument('projects', $project->getId(), $project - ->setAttribute($authKey, $status) - ); + $auths = $project->getAttribute('auths', []); + $auths[$authKey] = $status; + + $project = $dbForConsole->updateDocument('projects', $project->getId(), $project->setAttribute('auths', $auths)); $response->dynamic($project, Response::MODEL_PROJECT); }); diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index 654192d59..eea8a61dd 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -137,27 +137,28 @@ App::init(function ($utopia, $request, $response, $project, $user) { return; } + $auths = $project->getAttribute('auths', []); switch ($route->getLabel('auth.type', '')) { case 'emailPassword': - if($project->getAttribute('usersAuthEmailPassword', true) === false) { + if(($auths['usersAuthEmailPassword'] ?? true) === false) { throw new Exception('Email / Password authentication is disabled for this project', 501); } break; case 'anonymous': - if($project->getAttribute('usersAuthAnonymous', true) === false) { + if(($auths['usersAuthAnonymous'] ?? true) === false) { throw new Exception('Anonymous authentication is disabled for this project', 501); } break; case 'invites': - if($project->getAttribute('usersAuthInvites', true) === false) { + if(($auths['usersAuthInvites'] ?? true) === false) { throw new Exception('Invites authentication is disabled for this project', 501); } break; case 'jwt': - if($project->getAttribute('usersAuthJWT', true) === false) { + if(($auths['usersAuthJWT'] ?? 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 290df837c..417b640c0 100644 --- a/src/Appwrite/Utopia/Response/Model/Project.php +++ b/src/Appwrite/Utopia/Response/Model/Project.php @@ -225,6 +225,15 @@ class Project extends Model $document->setAttribute('serviceStatusFor'.ucfirst($key), $value); } + $authValues = $document->getAttribute('auths',[]); + $auth = Config::getParam('auth', []); + + foreach ($auth as $index => $method) { + $key = $method['key'] ?? ''; + $value = $authValues[$key] ?? true; + $document->setAttribute($key, $value); + } + return $document; } } \ No newline at end of file From 6f540fec0f2e9b586b63e26866fa6b91a4f4d399 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Fri, 6 Aug 2021 13:46:53 +0545 Subject: [PATCH 3/8] 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 11b89dd9e..6257c08c2 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 eea8a61dd..36ac0dab5 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 417b640c0..f079801f2 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 faa8cd954..709966558 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'; From ebf306f814dc53c9df070484b44483b5ba5bad51 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Fri, 6 Aug 2021 14:19:17 +0545 Subject: [PATCH 4/8] group auth limit inside auths --- app/config/collections2.php | 11 ----------- app/controllers/api/account.php | 6 +++--- app/controllers/api/projects.php | 5 ++++- app/controllers/api/teams.php | 2 +- app/init.php | 4 +++- app/views/console/users/index.phtml | 6 +++--- src/Appwrite/Utopia/Response/Model/Project.php | 6 +++++- 7 files changed, 19 insertions(+), 21 deletions(-) diff --git a/app/config/collections2.php b/app/config/collections2.php index 56136a6e1..413defe55 100644 --- a/app/config/collections2.php +++ b/app/config/collections2.php @@ -78,17 +78,6 @@ $collections = [ 'array' => false, 'filters' => [], ], - [ - '$id' => 'usersAuthLimit', - 'type' => Database::VAR_INTEGER, - 'format' => '', - 'size' => 0, - 'signed' => true, - 'required' => false, - 'default' => null, - 'array' => false, - 'filters' => [], - ], [ '$id' => 'legalName', 'type' => Database::VAR_STRING, diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 3b3d3fe5f..1eda0f7b5 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -71,7 +71,7 @@ App::post('/v1/account') } } - $limit = $project->getAttribute('usersAuthLimit', 0); + $limit = $project->getAttribute('auths', [])['limit'] ?? 0; if ($limit !== 0) { $sum = $dbForInternal->count('users', [], APP_LIMIT_USERS); @@ -450,7 +450,7 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect') $user = $dbForInternal->findOne('users', [new Query('email', Query::TYPE_EQUAL, [$email])]); // Get user by email address if ($user === false || $user->isEmpty()) { // Last option -> create the user, generate random password - $limit = $project->getAttribute('usersAuthLimit', 0); + $limit = $project->getAttribute('auths', [])['limit'] ?? 0; if ($limit !== 0) { $sum = $dbForInternal->count('users', [], APP_LIMIT_COUNT); @@ -614,7 +614,7 @@ App::post('/v1/account/sessions/anonymous') throw new Exception('Cannot create an anonymous user when logged in.', 401); } - $limit = $project->getAttribute('usersAuthLimit', 0); + $limit = $project->getAttribute('auths', [])['limit'] ?? 0; if ($limit !== 0) { $sum = $dbForInternal->count('users', [], APP_LIMIT_COUNT); diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index a9a221bb8..9185caee2 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -537,8 +537,11 @@ App::patch('/v1/projects/:projectId/auth/limit') throw new Exception('Project not found', 404); } + $auths = $project->getAttribute('auths', []); + $auths['limit'] = $limit; + $dbForConsole->updateDocument('projects', $project->getId(), $project - ->setAttribute('usersAuthLimit', $limit) + ->setAttribute('auths', $auths) ); $response->dynamic($project, Response::MODEL_PROJECT); diff --git a/app/controllers/api/teams.php b/app/controllers/api/teams.php index b9015267a..fad94fa53 100644 --- a/app/controllers/api/teams.php +++ b/app/controllers/api/teams.php @@ -277,7 +277,7 @@ App::post('/v1/teams/:teamId/memberships') if (empty($invitee)) { // Create new user if no user with same email found - $limit = $project->getAttribute('usersAuthLimit', 0); + $limit = $project->getAttribute('auths', [])['limit'] ?? 0; if ($limit !== 0 && $project->getId() !== 'console') { // check users limit, console invites are allways allowed. $sum = $dbForInternal->count('users', [], APP_LIMIT_USERS); diff --git a/app/init.php b/app/init.php index e1a777f24..83fef4d33 100644 --- a/app/init.php +++ b/app/init.php @@ -613,9 +613,11 @@ App::setResource('console', function() { 'legalCity' => '', 'legalAddress' => '', 'legalTaxId' => '', + 'auths' => [ + 'limit' => (App::getEnv('_APP_CONSOLE_WHITELIST_ROOT', 'enabled') === 'enabled') ? 1 : 0, // limit signup to 1 user + ], 'authWhitelistEmails' => (!empty(App::getEnv('_APP_CONSOLE_WHITELIST_EMAILS', null))) ? \explode(',', App::getEnv('_APP_CONSOLE_WHITELIST_EMAILS', null)) : [], 'authWhitelistIPs' => (!empty(App::getEnv('_APP_CONSOLE_WHITELIST_IPS', null))) ? \explode(',', App::getEnv('_APP_CONSOLE_WHITELIST_IPS', null)) : [], - 'usersAuthLimit' => (App::getEnv('_APP_CONSOLE_WHITELIST_ROOT', 'enabled') === 'enabled') ? 1 : 0, // limit signup to 1 user ]); }, []); diff --git a/app/views/console/users/index.phtml b/app/views/console/users/index.phtml index df02c47aa..8c7d8fc20 100644 --- a/app/views/console/users/index.phtml +++ b/app/views/console/users/index.phtml @@ -302,8 +302,8 @@ $auth = $this->getParam('auth', []);
  • -

    Unlimited Users Set Limit

    -

    Users allowed Change Limit

    +

    Unlimited Users Set Limit

    +

    Users allowed Change Limit

    Settings

    @@ -329,7 +329,7 @@ $auth = $this->getParam('auth', []); data-failure-param-alert-text="Failed to update project users limit" data-failure-param-alert-classname="error"> - +
    diff --git a/src/Appwrite/Utopia/Response/Model/Project.php b/src/Appwrite/Utopia/Response/Model/Project.php index f079801f2..cfda2e554 100644 --- a/src/Appwrite/Utopia/Response/Model/Project.php +++ b/src/Appwrite/Utopia/Response/Model/Project.php @@ -90,7 +90,7 @@ class Project extends Model 'default' => '', 'example' => '131102020', ]) - ->addRule('usersAuthLimit', [ + ->addRule('authLimit', [ 'type' => self::TYPE_INTEGER, 'description' => 'Max users allowed. 0 is unlimited.', 'default' => 0, @@ -229,6 +229,10 @@ class Project extends Model $auth = Config::getParam('auth', []); foreach ($auth as $index => $method) { + if($method == 'limit') { + $document->setAttribute('authLimit', $authValues['limit']); + continue; + } $key = $method['key']; $value = $authValues[$key] ?? true; $document->setAttribute('auth' . ucfirst($key), $value); From 9b25d65c858653a04a96d5b9f831dff682ed9c38 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Fri, 6 Aug 2021 14:34:07 +0545 Subject: [PATCH 5/8] WIP --- CHANGES.md | 6 ++++++ docker-compose.yml | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index c6e74d852..08bcd6962 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,9 @@ +# Version 0.10.0 + +## Features + +- Grouped auth related attributes in project collection. Introduced new attribute `auths` and removed all attributes related to auth methods and `usersAuthLimit` as well, all these are grouped under `auths` attribute + # Version 0.9.3 ## Bugs diff --git a/docker-compose.yml b/docker-compose.yml index 38377f99b..415078cae 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -39,7 +39,7 @@ services: build: context: . args: - - DEBUG=false + - DEBUG=true - TESTING=true - VERSION=dev ports: From 475002eef8329de314838bafef77934fa5ae4fef Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Fri, 6 Aug 2021 16:20:50 +0545 Subject: [PATCH 6/8] oauth2 providers in project grouped --- CHANGES.md | 4 +- app/config/collections2.php | 44 +++++-------------- app/controllers/api/account.php | 8 ++-- app/controllers/api/projects.php | 9 ++-- app/views/console/users/index.phtml | 16 +++---- .../Utopia/Response/Model/Project.php | 16 ++++++- .../Projects/ProjectsConsoleClientTest.php | 4 +- 7 files changed, 47 insertions(+), 54 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 08bcd6962..21fcc31b6 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,7 +2,9 @@ ## Features -- Grouped auth related attributes in project collection. Introduced new attribute `auths` and removed all attributes related to auth methods and `usersAuthLimit` as well, all these are grouped under `auths` attribute +- Grouped auth related attributes in project collection. Introduced new attribute `auths` and removed all attributes related to auth methods and `usersAuthLimit` as well, all these are grouped under `auths` attribute +- Grouped oAuth related attributes in project collection. Introduced new attribute `providers` and removed all attributes related to OAuth2 providers. All OAuth2 attributes are grouped under `providers` +- Project model changed, `userAuth` => `auth` example `userAuthEmailPassword` => `authEmailPassword`, also `userOauth2...` => `provider...` example `userOauth2GithubAppid` => `providerGithubAppid` # Version 0.9.3 diff --git a/app/config/collections2.php b/app/config/collections2.php index 413defe55..662521069 100644 --- a/app/config/collections2.php +++ b/app/config/collections2.php @@ -166,6 +166,17 @@ $collections = [ 'array' => false, 'filters' => ['json'], ], + [ + '$id' => 'providers', + 'type' => Database::VAR_STRING, + 'format' => '', + 'size' => 16384, + 'signed' => true, + 'required' => false, + 'default' => null, + 'array' => false, + 'filters' => ['json'], + ], [ '$id' => 'platforms', 'type' => Database::VAR_STRING, @@ -1394,37 +1405,4 @@ $collections = [ ], ]; -/* - * Add enabled OAuth2 providers to default data rules - */ -foreach ($providers as $index => $provider) { - if (!$provider['enabled']) { - continue; - } - - $collections['projects']['attributes'][] = [ - '$id' => 'usersOauth2' . \ucfirst($index) . 'Appid', - 'type' => Database::VAR_STRING, - 'format' => '', - 'size' => 16384, - 'signed' => true, - 'required' => false, - 'default' => null, - 'array' => false, - 'filters' => [], - ]; - - $collections['projects']['attributes'][] = [ - '$id' => 'usersOauth2' . \ucfirst($index) . 'Secret', - 'type' => Database::VAR_STRING, - 'format' => '', - 'size' => 16384, - 'signed' => true, - 'required' => false, - 'default' => null, - 'array' => false, - 'filters' => [], - ]; -} - return $collections; diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 1eda0f7b5..540f76096 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -256,8 +256,8 @@ App::get('/v1/account/sessions/oauth2/:provider') $protocol = $request->getProtocol(); $callback = $protocol.'://'.$request->getHostname().'/v1/account/sessions/oauth2/callback/'.$provider.'/'.$project->getId(); - $appId = $project->getAttribute('usersOauth2'.\ucfirst($provider).'Appid', ''); - $appSecret = $project->getAttribute('usersOauth2'.\ucfirst($provider).'Secret', '{}'); + $appId = $project->getAttribute('providers', [])[$provider.'Appid'] ?? ''; + $appSecret = $project->getAttribute('providers', [])[$provider.'Secret'] ?? '{}'; if (!empty($appSecret) && isset($appSecret['version'])) { $key = App::getEnv('_APP_OPENSSL_KEY_V'.$appSecret['version']); @@ -369,8 +369,8 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect') $defaultState = ['success' => $project->getAttribute('url', ''), 'failure' => '']; $validateURL = new URL(); - $appId = $project->getAttribute('usersOauth2'.\ucfirst($provider).'Appid', ''); - $appSecret = $project->getAttribute('usersOauth2'.\ucfirst($provider).'Secret', '{}'); + $appId = $project->getAttribute('providers', [])[$provider.'Appid'] ?? ''; + $appSecret = $project->getAttribute('providers', [])[$provider.'Secret'] ?? '{}'; if (!empty($appSecret) && isset($appSecret['version'])) { $key = App::getEnv('_APP_OPENSSL_KEY_V'.$appSecret['version']); diff --git a/app/controllers/api/projects.php b/app/controllers/api/projects.php index 9185caee2..d9af95ae8 100644 --- a/app/controllers/api/projects.php +++ b/app/controllers/api/projects.php @@ -505,10 +505,11 @@ App::patch('/v1/projects/:projectId/oauth2') throw new Exception('Project not found', 404); } - $project = $dbForConsole->updateDocument('projects', $project->getId(), $project - ->setAttribute('usersOauth2' . \ucfirst($provider) . 'Appid', $appId) - ->setAttribute('usersOauth2' . \ucfirst($provider) . 'Secret', $secret) - ); + $providers = $project->getAttribute('providers', []); + $providers[$provider . 'Appid'] = $appId; + $providers[$provider . 'Secret'] = $secret; + + $project = $dbForConsole->updateDocument('projects', $project->getId(), $project->setAttribute('providers', $providers)); $response->dynamic($project, Response::MODEL_PROJECT); }); diff --git a/app/views/console/users/index.phtml b/app/views/console/users/index.phtml index 8c7d8fc20..5a765bebf 100644 --- a/app/views/console/users/index.phtml +++ b/app/views/console/users/index.phtml @@ -439,15 +439,15 @@ $auth = $this->getParam('auth', []); - + - + - + - +
    @@ -469,14 +469,14 @@ $auth = $this->getParam('auth', []);
    + {{console-project.providerescape(ucfirst($provider)); ?>Appid}} && + {{console-project.providerescape(ucfirst($provider)); ?>Secret}}"> + !{{console-project.providerescape(ucfirst($provider)); ?>Appid}} || + !{{console-project.providerescape(ucfirst($provider)); ?>Secret}}"> diff --git a/src/Appwrite/Utopia/Response/Model/Project.php b/src/Appwrite/Utopia/Response/Model/Project.php index cfda2e554..514a06a3c 100644 --- a/src/Appwrite/Utopia/Response/Model/Project.php +++ b/src/Appwrite/Utopia/Response/Model/Project.php @@ -138,13 +138,13 @@ class Project extends Model $name = (isset($provider['name'])) ? $provider['name'] : 'Unknown'; $this - ->addRule('usersOauth2'.\ucfirst($index).'Appid', [ + ->addRule('provider'.\ucfirst($index).'Appid', [ 'type' => self::TYPE_STRING, 'description' => $name.' OAuth app ID.', 'example' => '123247283472834787438', 'default' => '', ]) - ->addRule('usersOauth2'.\ucfirst($index).'Secret', [ + ->addRule('provider'.\ucfirst($index).'Secret', [ 'type' => self::TYPE_STRING, 'description' => $name.' OAuth secret ID.', 'example' => 'djsgudsdsewe43434343dd34...', @@ -238,6 +238,18 @@ class Project extends Model $document->setAttribute('auth' . ucfirst($key), $value); } + $providers = Config::getParam('providers', []); + $providerValues = $document->getAttribute('providers', []); + + foreach ($providers as $key => $provider) { + if (!$provider['enabled']) { + continue; + } + $appId = $providerValues[$key . 'Appid'] ?? ''; + $secret = $providerValues[$key . 'Secret'] ?? ''; + $document->setAttribute($key . 'Appid', $appId)->setAttribute($key . 'Secret', $secret); + } + return $document; } } \ No newline at end of file diff --git a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php index 709966558..ae5360dd9 100644 --- a/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php +++ b/tests/e2e/Services/Projects/ProjectsConsoleClientTest.php @@ -275,8 +275,8 @@ class ProjectsConsoleClientTest extends Scope $this->assertEquals($id, $response['body']['$id']); foreach ($providers as $key => $provider) { - $this->assertEquals('AppId-'.ucfirst($key), $response['body']['usersOauth2'.ucfirst($key).'Appid']); - $this->assertEquals('Secret-'.ucfirst($key), $response['body']['usersOauth2'.ucfirst($key).'Secret']); + $this->assertEquals('AppId-'.ucfirst($key), $response['body']['provider'.ucfirst($key).'Appid']); + $this->assertEquals('Secret-'.ucfirst($key), $response['body']['provider'.ucfirst($key).'Secret']); } /** From 755943a7fc561066c1d79c3d7e51a20da3c695f3 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Fri, 6 Aug 2021 16:46:37 +0545 Subject: [PATCH 7/8] fix oauth restructure and console ui --- app/views/console/users/index.phtml | 2 +- src/Appwrite/Utopia/Response/Model/Project.php | 9 +++------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/app/views/console/users/index.phtml b/app/views/console/users/index.phtml index 5a765bebf..386404bec 100644 --- a/app/views/console/users/index.phtml +++ b/app/views/console/users/index.phtml @@ -373,7 +373,7 @@ $auth = $this->getParam('auth', []); data-failure-param-alert-classname="error"> - + diff --git a/src/Appwrite/Utopia/Response/Model/Project.php b/src/Appwrite/Utopia/Response/Model/Project.php index 514a06a3c..a5400fe80 100644 --- a/src/Appwrite/Utopia/Response/Model/Project.php +++ b/src/Appwrite/Utopia/Response/Model/Project.php @@ -228,11 +228,9 @@ class Project extends Model $authValues = $document->getAttribute('auths',[]); $auth = Config::getParam('auth', []); + $document->setAttribute('authLimit', $authValues['limit']); + foreach ($auth as $index => $method) { - if($method == 'limit') { - $document->setAttribute('authLimit', $authValues['limit']); - continue; - } $key = $method['key']; $value = $authValues[$key] ?? true; $document->setAttribute('auth' . ucfirst($key), $value); @@ -247,9 +245,8 @@ class Project extends Model } $appId = $providerValues[$key . 'Appid'] ?? ''; $secret = $providerValues[$key . 'Secret'] ?? ''; - $document->setAttribute($key . 'Appid', $appId)->setAttribute($key . 'Secret', $secret); + $document->setAttribute('provider' . ucfirst($key) . 'Appid', $appId)->setAttribute('provider' . ucfirst($key) . 'Secret', $secret); } - return $document; } } \ No newline at end of file From b1c3f2eeedf18ef0de12cbd728b1e5f6d2af501b Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Fri, 6 Aug 2021 17:11:43 +0545 Subject: [PATCH 8/8] fix debug --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 415078cae..38377f99b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -39,7 +39,7 @@ services: build: context: . args: - - DEBUG=true + - DEBUG=false - TESTING=true - VERSION=dev ports: