Merge pull request #1472 from appwrite/feat-project-object-restructuring
feat-project-object-restructuring
This commit is contained in:
commit
a04096ec4a
11 changed files with 145 additions and 151 deletions
|
@ -1,3 +1,11 @@
|
||||||
|
# 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
|
||||||
|
- 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<AuthMethod>` => `auth<AuthMethod>` example `userAuthEmailPassword` => `authEmailPassword`, also `userOauth2<Provider>...` => `provider<Provider>...` example `userOauth2GithubAppid` => `providerGithubAppid`
|
||||||
|
|
||||||
# Version 0.9.3
|
# Version 0.9.3
|
||||||
|
|
||||||
## Bugs
|
## Bugs
|
||||||
|
|
|
@ -5,35 +5,35 @@
|
||||||
return [
|
return [
|
||||||
'email-password' => [
|
'email-password' => [
|
||||||
'name' => 'Email/Password',
|
'name' => 'Email/Password',
|
||||||
'key' => 'usersAuthEmailPassword',
|
'key' => 'emailPassword',
|
||||||
'icon' => '/images/users/email.png',
|
'icon' => '/images/users/email.png',
|
||||||
'docs' => 'https://appwrite.io/docs/client/account?sdk=web#accountCreateSession',
|
'docs' => 'https://appwrite.io/docs/client/account?sdk=web#accountCreateSession',
|
||||||
'enabled' => true,
|
'enabled' => true,
|
||||||
],
|
],
|
||||||
'anonymous' => [
|
'anonymous' => [
|
||||||
'name' => 'Anonymous',
|
'name' => 'Anonymous',
|
||||||
'key' => 'usersAuthAnonymous',
|
'key' => 'anonymous',
|
||||||
'icon' => '/images/users/anonymous.png',
|
'icon' => '/images/users/anonymous.png',
|
||||||
'docs' => 'https://appwrite.io/docs/client/account?sdk=web#accountCreateAnonymousSession',
|
'docs' => 'https://appwrite.io/docs/client/account?sdk=web#accountCreateAnonymousSession',
|
||||||
'enabled' => true,
|
'enabled' => true,
|
||||||
],
|
],
|
||||||
'invites' => [
|
'invites' => [
|
||||||
'name' => 'Invites',
|
'name' => 'Invites',
|
||||||
'key' => 'usersAuthInvites',
|
'key' => 'invites',
|
||||||
'icon' => '/images/users/invites.png',
|
'icon' => '/images/users/invites.png',
|
||||||
'docs' => 'https://appwrite.io/docs/client/teams?sdk=web#teamsCreateMembership',
|
'docs' => 'https://appwrite.io/docs/client/teams?sdk=web#teamsCreateMembership',
|
||||||
'enabled' => true,
|
'enabled' => true,
|
||||||
],
|
],
|
||||||
'jwt' => [
|
'jwt' => [
|
||||||
'name' => 'JWT',
|
'name' => 'JWT',
|
||||||
'key' => 'usersAuthJWT',
|
'key' => 'JWT',
|
||||||
'icon' => '/images/users/jwt.png',
|
'icon' => '/images/users/jwt.png',
|
||||||
'docs' => 'https://appwrite.io/docs/client/account?sdk=web#accountCreateJWT',
|
'docs' => 'https://appwrite.io/docs/client/account?sdk=web#accountCreateJWT',
|
||||||
'enabled' => true,
|
'enabled' => true,
|
||||||
],
|
],
|
||||||
'phone' => [
|
'phone' => [
|
||||||
'name' => 'Phone',
|
'name' => 'Phone',
|
||||||
'key' => 'usersAuthPhone',
|
'key' => 'phone',
|
||||||
'icon' => '/images/users/phone.png',
|
'icon' => '/images/users/phone.png',
|
||||||
'docs' => 'https://appwrite.io/docs/client/account?sdk=web#accountCreatePhoneSession',
|
'docs' => 'https://appwrite.io/docs/client/account?sdk=web#accountCreatePhoneSession',
|
||||||
'docs' => '',
|
'docs' => '',
|
||||||
|
|
|
@ -78,17 +78,6 @@ $collections = [
|
||||||
'array' => false,
|
'array' => false,
|
||||||
'filters' => [],
|
'filters' => [],
|
||||||
],
|
],
|
||||||
[
|
|
||||||
'$id' => 'usersAuthLimit',
|
|
||||||
'type' => Database::VAR_INTEGER,
|
|
||||||
'format' => '',
|
|
||||||
'size' => 0,
|
|
||||||
'signed' => true,
|
|
||||||
'required' => false,
|
|
||||||
'default' => null,
|
|
||||||
'array' => false,
|
|
||||||
'filters' => [],
|
|
||||||
],
|
|
||||||
[
|
[
|
||||||
'$id' => 'legalName',
|
'$id' => 'legalName',
|
||||||
'type' => Database::VAR_STRING,
|
'type' => Database::VAR_STRING,
|
||||||
|
@ -166,6 +155,28 @@ $collections = [
|
||||||
'array' => false,
|
'array' => false,
|
||||||
'filters' => ['json'],
|
'filters' => ['json'],
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
'$id' => 'auths',
|
||||||
|
'type' => Database::VAR_STRING,
|
||||||
|
'format' => '',
|
||||||
|
'size' => 16384,
|
||||||
|
'signed' => true,
|
||||||
|
'required' => false,
|
||||||
|
'default' => null,
|
||||||
|
'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',
|
'$id' => 'platforms',
|
||||||
'type' => Database::VAR_STRING,
|
'type' => Database::VAR_STRING,
|
||||||
|
@ -1394,51 +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' => [],
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
return $collections;
|
||||||
|
|
|
@ -73,7 +73,7 @@ App::post('/v1/account')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$limit = $project->getAttribute('usersAuthLimit', 0);
|
$limit = $project->getAttribute('auths', [])['limit'] ?? 0;
|
||||||
|
|
||||||
if ($limit !== 0) {
|
if ($limit !== 0) {
|
||||||
$sum = $dbForInternal->count('users', [], APP_LIMIT_USERS);
|
$sum = $dbForInternal->count('users', [], APP_LIMIT_USERS);
|
||||||
|
@ -258,8 +258,8 @@ App::get('/v1/account/sessions/oauth2/:provider')
|
||||||
|
|
||||||
$protocol = $request->getProtocol();
|
$protocol = $request->getProtocol();
|
||||||
$callback = $protocol.'://'.$request->getHostname().'/v1/account/sessions/oauth2/callback/'.$provider.'/'.$project->getId();
|
$callback = $protocol.'://'.$request->getHostname().'/v1/account/sessions/oauth2/callback/'.$provider.'/'.$project->getId();
|
||||||
$appId = $project->getAttribute('usersOauth2' . \ucfirst($provider) . 'Appid', '');
|
$appId = $project->getAttribute('providers', [])[$provider.'Appid'] ?? '';
|
||||||
$appSecret = $project->getAttribute('usersOauth2' . \ucfirst($provider) . 'Secret', '{}');
|
$appSecret = $project->getAttribute('providers', [])[$provider.'Secret'] ?? '{}';
|
||||||
|
|
||||||
if (!empty($appSecret) && isset($appSecret['version'])) {
|
if (!empty($appSecret) && isset($appSecret['version'])) {
|
||||||
$key = App::getEnv('_APP_OPENSSL_KEY_V' . $appSecret['version']);
|
$key = App::getEnv('_APP_OPENSSL_KEY_V' . $appSecret['version']);
|
||||||
|
@ -370,9 +370,8 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect')
|
||||||
$callback = $protocol . '://' . $request->getHostname() . '/v1/account/sessions/oauth2/callback/' . $provider . '/' . $project->getId();
|
$callback = $protocol . '://' . $request->getHostname() . '/v1/account/sessions/oauth2/callback/' . $provider . '/' . $project->getId();
|
||||||
$defaultState = ['success' => $project->getAttribute('url', ''), 'failure' => ''];
|
$defaultState = ['success' => $project->getAttribute('url', ''), 'failure' => ''];
|
||||||
$validateURL = new URL();
|
$validateURL = new URL();
|
||||||
|
$appId = $project->getAttribute('providers', [])[$provider.'Appid'] ?? '';
|
||||||
$appId = $project->getAttribute('usersOauth2' . \ucfirst($provider) . 'Appid', '');
|
$appSecret = $project->getAttribute('providers', [])[$provider.'Secret'] ?? '{}';
|
||||||
$appSecret = $project->getAttribute('usersOauth2' . \ucfirst($provider) . 'Secret', '{}');
|
|
||||||
|
|
||||||
if (!empty($appSecret) && isset($appSecret['version'])) {
|
if (!empty($appSecret) && isset($appSecret['version'])) {
|
||||||
$key = App::getEnv('_APP_OPENSSL_KEY_V' . $appSecret['version']);
|
$key = App::getEnv('_APP_OPENSSL_KEY_V' . $appSecret['version']);
|
||||||
|
@ -452,7 +451,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
|
$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
|
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) {
|
if ($limit !== 0) {
|
||||||
$sum = $dbForInternal->count('users', [], APP_LIMIT_COUNT);
|
$sum = $dbForInternal->count('users', [], APP_LIMIT_COUNT);
|
||||||
|
@ -616,7 +615,7 @@ App::post('/v1/account/sessions/anonymous')
|
||||||
throw new Exception('Cannot create an anonymous user when logged in.', 401);
|
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) {
|
if ($limit !== 0) {
|
||||||
$sum = $dbForInternal->count('users', [], APP_LIMIT_COUNT);
|
$sum = $dbForInternal->count('users', [], APP_LIMIT_COUNT);
|
||||||
|
|
|
@ -32,14 +32,6 @@ App::init(function ($project) {
|
||||||
}
|
}
|
||||||
}, ['project'], 'projects');
|
}, ['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')
|
App::post('/v1/projects')
|
||||||
->desc('Create Project')
|
->desc('Create Project')
|
||||||
->groups(['api', 'projects'])
|
->groups(['api', 'projects'])
|
||||||
|
@ -80,6 +72,12 @@ App::post('/v1/projects')
|
||||||
throw new Exception('Team not found', 404);
|
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([
|
$project = $dbForConsole->createDocument('projects', new Document([
|
||||||
'$id' => $projectId == 'unique()' ? $dbForConsole->getId() : $projectId,
|
'$id' => $projectId == 'unique()' ? $dbForConsole->getId() : $projectId,
|
||||||
'$collection' => 'projects',
|
'$collection' => 'projects',
|
||||||
|
@ -102,11 +100,7 @@ App::post('/v1/projects')
|
||||||
'webhooks' => [],
|
'webhooks' => [],
|
||||||
'keys' => [],
|
'keys' => [],
|
||||||
'domains' => [],
|
'domains' => [],
|
||||||
'usersAuthEmailPassword' => true,
|
'auths' => $auths,
|
||||||
'usersAuthAnonymous' => true,
|
|
||||||
'usersAuthInvites' => true,
|
|
||||||
'usersAuthJWT' => true,
|
|
||||||
'usersAuthPhone' => true,
|
|
||||||
]));
|
]));
|
||||||
|
|
||||||
$collections = Config::getParam('collections2', []); /** @var array $collections */
|
$collections = Config::getParam('collections2', []); /** @var array $collections */
|
||||||
|
@ -515,10 +509,11 @@ App::patch('/v1/projects/:projectId/oauth2')
|
||||||
throw new Exception('Project not found', 404);
|
throw new Exception('Project not found', 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
$project = $dbForConsole->updateDocument('projects', $project->getId(), $project
|
$providers = $project->getAttribute('providers', []);
|
||||||
->setAttribute('usersOauth2' . \ucfirst($provider) . 'Appid', $appId)
|
$providers[$provider . 'Appid'] = $appId;
|
||||||
->setAttribute('usersOauth2' . \ucfirst($provider) . 'Secret', $secret)
|
$providers[$provider . 'Secret'] = $secret;
|
||||||
);
|
|
||||||
|
$project = $dbForConsole->updateDocument('projects', $project->getId(), $project->setAttribute('providers', $providers));
|
||||||
|
|
||||||
$response->dynamic($project, Response::MODEL_PROJECT);
|
$response->dynamic($project, Response::MODEL_PROJECT);
|
||||||
});
|
});
|
||||||
|
@ -547,8 +542,11 @@ App::patch('/v1/projects/:projectId/auth/limit')
|
||||||
throw new Exception('Project not found', 404);
|
throw new Exception('Project not found', 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$auths = $project->getAttribute('auths', []);
|
||||||
|
$auths['limit'] = $limit;
|
||||||
|
|
||||||
$dbForConsole->updateDocument('projects', $project->getId(), $project
|
$dbForConsole->updateDocument('projects', $project->getId(), $project
|
||||||
->setAttribute('usersAuthLimit', $limit)
|
->setAttribute('auths', $auths)
|
||||||
);
|
);
|
||||||
|
|
||||||
$response->dynamic($project, Response::MODEL_PROJECT);
|
$response->dynamic($project, Response::MODEL_PROJECT);
|
||||||
|
@ -582,9 +580,10 @@ App::patch('/v1/projects/:projectId/auth/:method')
|
||||||
throw new Exception('Project not found', 404);
|
throw new Exception('Project not found', 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
$dbForConsole->updateDocument('projects', $project->getId(), $project
|
$auths = $project->getAttribute('auths', []);
|
||||||
->setAttribute($authKey, $status)
|
$auths[$authKey] = $status;
|
||||||
);
|
|
||||||
|
$project = $dbForConsole->updateDocument('projects', $project->getId(), $project->setAttribute('auths', $auths));
|
||||||
|
|
||||||
$response->dynamic($project, Response::MODEL_PROJECT);
|
$response->dynamic($project, Response::MODEL_PROJECT);
|
||||||
});
|
});
|
||||||
|
|
|
@ -279,7 +279,7 @@ App::post('/v1/teams/:teamId/memberships')
|
||||||
|
|
||||||
if (empty($invitee)) { // Create new user if no user with same email found
|
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.
|
if ($limit !== 0 && $project->getId() !== 'console') { // check users limit, console invites are allways allowed.
|
||||||
$sum = $dbForInternal->count('users', [], APP_LIMIT_USERS);
|
$sum = $dbForInternal->count('users', [], APP_LIMIT_USERS);
|
||||||
|
|
|
@ -129,27 +129,28 @@ App::init(function ($utopia, $request, $project) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$auths = $project->getAttribute('auths', []);
|
||||||
switch ($route->getLabel('auth.type', '')) {
|
switch ($route->getLabel('auth.type', '')) {
|
||||||
case 'emailPassword':
|
case 'emailPassword':
|
||||||
if($project->getAttribute('usersAuthEmailPassword', true) === false) {
|
if(($auths['emailPassword'] ?? true) === false) {
|
||||||
throw new Exception('Email / Password authentication is disabled for this project', 501);
|
throw new Exception('Email / Password authentication is disabled for this project', 501);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'anonymous':
|
case 'anonymous':
|
||||||
if($project->getAttribute('usersAuthAnonymous', true) === false) {
|
if(($auths['anonymous'] ?? true) === false) {
|
||||||
throw new Exception('Anonymous authentication is disabled for this project', 501);
|
throw new Exception('Anonymous authentication is disabled for this project', 501);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'invites':
|
case 'invites':
|
||||||
if($project->getAttribute('usersAuthInvites', true) === false) {
|
if(($auths['invites'] ?? true) === false) {
|
||||||
throw new Exception('Invites authentication is disabled for this project', 501);
|
throw new Exception('Invites authentication is disabled for this project', 501);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'jwt':
|
case 'jwt':
|
||||||
if($project->getAttribute('usersAuthJWT', true) === false) {
|
if(($auths['JWT'] ?? true) === false) {
|
||||||
throw new Exception('JWT authentication is disabled for this project', 501);
|
throw new Exception('JWT authentication is disabled for this project', 501);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -613,9 +613,11 @@ App::setResource('console', function() {
|
||||||
'legalCity' => '',
|
'legalCity' => '',
|
||||||
'legalAddress' => '',
|
'legalAddress' => '',
|
||||||
'legalTaxId' => '',
|
'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)) : [],
|
'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)) : [],
|
'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
|
|
||||||
]);
|
]);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|
|
@ -324,8 +324,8 @@ $auth = $this->getParam('auth', []);
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li data-state="/console/users/providers?project={{router.params.project}}">
|
<li data-state="/console/users/providers?project={{router.params.project}}">
|
||||||
<p data-ls-if="{{console-project.usersAuthLimit}} == 0" class="text-fade text-size-small margin-bottom pull-end">Unlimited Users <span class="link" data-ls-ui-trigger="project-update-auth-users-limit">Set Limit</a></p>
|
<p data-ls-if="{{console-project.authLimit}} == 0" class="text-fade text-size-small margin-bottom pull-end">Unlimited Users <span class="link" data-ls-ui-trigger="project-update-auth-users-limit">Set Limit</a></p>
|
||||||
<p data-ls-if="{{console-project.usersAuthLimit}} != 0" class="text-fade text-size-small margin-bottom pull-end"><span data-ls-bind="{{console-project.usersAuthLimit|statsTotal}}"></span> Users allowed <span class="link" data-ls-ui-trigger="project-update-auth-users-limit">Change Limit</a></p>
|
<p data-ls-if="{{console-project.authLimit}} != 0" class="text-fade text-size-small margin-bottom pull-end"><span data-ls-bind="{{console-project.authLimit|statsTotal}}"></span> Users allowed <span class="link" data-ls-ui-trigger="project-update-auth-users-limit">Change Limit</a></p>
|
||||||
|
|
||||||
<h2>Settings</h2>
|
<h2>Settings</h2>
|
||||||
|
|
||||||
|
@ -351,7 +351,7 @@ $auth = $this->getParam('auth', []);
|
||||||
data-failure-param-alert-text="Failed to update project users limit"
|
data-failure-param-alert-text="Failed to update project users limit"
|
||||||
data-failure-param-alert-classname="error">
|
data-failure-param-alert-classname="error">
|
||||||
|
|
||||||
<input name="limit" id="users-limit" type="number" data-ls-bind="{{console-project.usersAuthLimit}}" data-cast-to="numeric" min="0" />
|
<input name="limit" id="users-limit" type="number" data-ls-bind="{{console-project.authLimit}}" data-cast-to="numeric" min="0" />
|
||||||
|
|
||||||
<div class="info row thin margin-bottom margin-top">
|
<div class="info row thin margin-bottom margin-top">
|
||||||
<div class="col span-1">
|
<div class="col span-1">
|
||||||
|
@ -395,7 +395,7 @@ $auth = $this->getParam('auth', []);
|
||||||
data-failure-param-alert-classname="error">
|
data-failure-param-alert-classname="error">
|
||||||
<input name="method" id="<?php echo $this->escape($key); ?>" type="hidden" autocomplete="off" value="<?php echo $this->escape($index); ?>">
|
<input name="method" id="<?php echo $this->escape($key); ?>" type="hidden" autocomplete="off" value="<?php echo $this->escape($index); ?>">
|
||||||
|
|
||||||
<input name="status" type="hidden" data-forms-switch data-ls-bind="{{console-project.<?php echo $this->escape($key); ?>}}" data-cast-to="boolean" class="pull-end" />
|
<input name="status" type="hidden" data-forms-switch data-ls-bind="{{console-project.auth<?php echo $this->escape(ucfirst($key)); ?>}}" data-cast-to="boolean" class="pull-end" />
|
||||||
</form>
|
</form>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
|
@ -461,15 +461,14 @@ $auth = $this->getParam('auth', []);
|
||||||
|
|
||||||
<?php if (!$form): ?>
|
<?php if (!$form): ?>
|
||||||
<label for="oauth2<?php echo $this->escape(ucfirst($provider)); ?>Appid">App ID</label>
|
<label for="oauth2<?php echo $this->escape(ucfirst($provider)); ?>Appid">App ID</label>
|
||||||
<input name="appId" id="oauth2<?php echo $this->escape(ucfirst($provider)); ?>Appid" type="text" autocomplete="off" data-ls-bind="{{console-project.usersOauth2<?php echo $this->escape(ucfirst($provider)); ?>Appid}}">
|
<input name="appId" id="oauth2<?php echo $this->escape(ucfirst($provider)); ?>Appid" type="text" autocomplete="off" data-ls-bind="{{console-project.provider<?php echo $this->escape(ucfirst($provider)); ?>Appid}}">
|
||||||
|
|
||||||
<label for="oauth2<?php echo $this->escape(ucfirst($provider)); ?>Secret">App Secret</label>
|
<label for="oauth2<?php echo $this->escape(ucfirst($provider)); ?>Secret">App Secret</label>
|
||||||
<input name="secret" data-forms-show-secret id="oauth2<?php echo $this->escape(ucfirst($provider)); ?>Secret" type="password" autocomplete="off" data-ls-bind="{{console-project.usersOauth2<?php echo $this->escape(ucfirst($provider)); ?>Secret}}">
|
<input name="secret" data-forms-show-secret id="oauth2<?php echo $this->escape(ucfirst($provider)); ?>Secret" type="password" autocomplete="off" data-ls-bind="{{console-project.provider<?php echo $this->escape(ucfirst($provider)); ?>Secret}}">
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
<label for="oauth2<?php echo $this->escape(ucfirst($provider)); ?>Appid">Bundle ID <span class="tooltip" data-tooltip="Attribute internal display name"><i class="icon-info-circled"></i></span></label>
|
<label for="oauth2<?php echo $this->escape(ucfirst($provider)); ?>Appid">Bundle ID <span class="tooltip" data-tooltip="Attribute internal display name"><i class="icon-info-circled"></i></span></label>
|
||||||
<input name="appId" id="oauth2<?php echo $this->escape(ucfirst($provider)); ?>Appid" type="text" autocomplete="off" data-ls-bind="{{console-project.usersOauth2<?php echo $this->escape(ucfirst($provider)); ?>Appid}}" placeholder="com.company.appname" />
|
<input name="appId" id="oauth2<?php echo $this->escape(ucfirst($provider)); ?>Appid" type="text" autocomplete="off" data-ls-bind="{{console-project.provider<?php echo $this->escape(ucfirst($provider)); ?>Appid}}" placeholder="com.company.appname" />
|
||||||
|
<input name="secret" data-forms-oauth-apple id="oauth2<?php echo $this->escape(ucfirst($provider)); ?>Secret" type="hidden" autocomplete="off" data-ls-bind="{{console-project.provider<?php echo $this->escape(ucfirst($provider)); ?>Secret}}" />
|
||||||
<input name="secret" data-forms-oauth-apple id="oauth2<?php echo $this->escape(ucfirst($provider)); ?>Secret" type="hidden" autocomplete="off" data-ls-bind="{{console-project.usersOauth2<?php echo $this->escape(ucfirst($provider)); ?>Secret}}" />
|
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
<div class="info row thin margin-bottom margin-top">
|
<div class="info row thin margin-bottom margin-top">
|
||||||
|
@ -491,14 +490,14 @@ $auth = $this->getParam('auth', []);
|
||||||
|
|
||||||
<div class="box padding-small margin-bottom">
|
<div class="box padding-small margin-bottom">
|
||||||
<span data-ls-if="
|
<span data-ls-if="
|
||||||
{{console-project.usersOauth2<?php echo $this->escape(ucfirst($provider)); ?>Appid}} &&
|
{{console-project.provider<?php echo $this->escape(ucfirst($provider)); ?>Appid}} &&
|
||||||
{{console-project.usersOauth2<?php echo $this->escape(ucfirst($provider)); ?>Secret}}">
|
{{console-project.provider<?php echo $this->escape(ucfirst($provider)); ?>Secret}}">
|
||||||
<button class="switch on pull-end" data-ls-ui-trigger="provider-update-<?php echo $provider; ?>"></button>
|
<button class="switch on pull-end" data-ls-ui-trigger="provider-update-<?php echo $provider; ?>"></button>
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
<span data-ls-if="
|
<span data-ls-if="
|
||||||
!{{console-project.usersOauth2<?php echo $this->escape(ucfirst($provider)); ?>Appid}} ||
|
!{{console-project.provider<?php echo $this->escape(ucfirst($provider)); ?>Appid}} ||
|
||||||
!{{console-project.usersOauth2<?php echo $this->escape(ucfirst($provider)); ?>Secret}}">
|
!{{console-project.provider<?php echo $this->escape(ucfirst($provider)); ?>Secret}}">
|
||||||
<button class="switch pull-end" data-ls-ui-trigger="provider-update-<?php echo $this->escape($provider); ?>"></button>
|
<button class="switch pull-end" data-ls-ui-trigger="provider-update-<?php echo $this->escape($provider); ?>"></button>
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
|
|
|
@ -90,7 +90,7 @@ class Project extends Model
|
||||||
'default' => '',
|
'default' => '',
|
||||||
'example' => '131102020',
|
'example' => '131102020',
|
||||||
])
|
])
|
||||||
->addRule('usersAuthLimit', [
|
->addRule('authLimit', [
|
||||||
'type' => self::TYPE_INTEGER,
|
'type' => self::TYPE_INTEGER,
|
||||||
'description' => 'Max users allowed. 0 is unlimited.',
|
'description' => 'Max users allowed. 0 is unlimited.',
|
||||||
'default' => 0,
|
'default' => 0,
|
||||||
|
@ -138,13 +138,13 @@ class Project extends Model
|
||||||
$name = (isset($provider['name'])) ? $provider['name'] : 'Unknown';
|
$name = (isset($provider['name'])) ? $provider['name'] : 'Unknown';
|
||||||
|
|
||||||
$this
|
$this
|
||||||
->addRule('usersOauth2'.\ucfirst($index).'Appid', [
|
->addRule('provider'.\ucfirst($index).'Appid', [
|
||||||
'type' => self::TYPE_STRING,
|
'type' => self::TYPE_STRING,
|
||||||
'description' => $name.' OAuth app ID.',
|
'description' => $name.' OAuth app ID.',
|
||||||
'example' => '123247283472834787438',
|
'example' => '123247283472834787438',
|
||||||
'default' => '',
|
'default' => '',
|
||||||
])
|
])
|
||||||
->addRule('usersOauth2'.\ucfirst($index).'Secret', [
|
->addRule('provider'.\ucfirst($index).'Secret', [
|
||||||
'type' => self::TYPE_STRING,
|
'type' => self::TYPE_STRING,
|
||||||
'description' => $name.' OAuth secret ID.',
|
'description' => $name.' OAuth secret ID.',
|
||||||
'example' => 'djsgudsdsewe43434343dd34...',
|
'example' => 'djsgudsdsewe43434343dd34...',
|
||||||
|
@ -158,7 +158,7 @@ class Project extends Model
|
||||||
$key = $method['key'] ?? '';
|
$key = $method['key'] ?? '';
|
||||||
|
|
||||||
$this
|
$this
|
||||||
->addRule($key, [
|
->addRule('auth' . ucfirst($key), [
|
||||||
'type' => self::TYPE_BOOLEAN,
|
'type' => self::TYPE_BOOLEAN,
|
||||||
'description' => $name.' auth method status',
|
'description' => $name.' auth method status',
|
||||||
'example' => true,
|
'example' => true,
|
||||||
|
@ -225,6 +225,28 @@ class Project extends Model
|
||||||
$document->setAttribute('serviceStatusFor'.ucfirst($key), $value);
|
$document->setAttribute('serviceStatusFor'.ucfirst($key), $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$authValues = $document->getAttribute('auths',[]);
|
||||||
|
$auth = Config::getParam('auth', []);
|
||||||
|
|
||||||
|
$document->setAttribute('authLimit', $authValues['limit']);
|
||||||
|
|
||||||
|
foreach ($auth as $index => $method) {
|
||||||
|
$key = $method['key'];
|
||||||
|
$value = $authValues[$key] ?? true;
|
||||||
|
$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('provider' . ucfirst($key) . 'Appid', $appId)->setAttribute('provider' . ucfirst($key) . 'Secret', $secret);
|
||||||
|
}
|
||||||
return $document;
|
return $document;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -281,8 +281,8 @@ class ProjectsConsoleClientTest extends Scope
|
||||||
$this->assertEquals($id, $response['body']['$id']);
|
$this->assertEquals($id, $response['body']['$id']);
|
||||||
|
|
||||||
foreach ($providers as $key => $provider) {
|
foreach ($providers as $key => $provider) {
|
||||||
$this->assertEquals('AppId-'.ucfirst($key), $response['body']['usersOauth2'.ucfirst($key).'Appid']);
|
$this->assertEquals('AppId-'.ucfirst($key), $response['body']['provider'.ucfirst($key).'Appid']);
|
||||||
$this->assertEquals('Secret-'.ucfirst($key), $response['body']['usersOauth2'.ucfirst($key).'Secret']);
|
$this->assertEquals('Secret-'.ucfirst($key), $response['body']['provider'.ucfirst($key).'Secret']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -358,7 +358,7 @@ class ProjectsConsoleClientTest extends Scope
|
||||||
|
|
||||||
$this->assertEquals(200, $response['headers']['status-code']);
|
$this->assertEquals(200, $response['headers']['status-code']);
|
||||||
$this->assertNotEmpty($response['body']['$id']);
|
$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';
|
$email = uniqid().'user@localhost.test';
|
||||||
|
|
Loading…
Reference in a new issue