Merge pull request #1472 from appwrite/feat-project-object-restructuring
feat-project-object-restructuring
This commit is contained in:
commit
a04096ec4a
|
@ -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
|
||||
|
||||
## Bugs
|
||||
|
|
|
@ -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' => '',
|
||||
|
|
|
@ -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,
|
||||
|
@ -166,6 +155,28 @@ $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' => '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,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;
|
||||
|
|
|
@ -73,7 +73,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);
|
||||
|
@ -257,9 +257,9 @@ App::get('/v1/account/sessions/oauth2/:provider')
|
|||
/** @var Utopia\Database\Document $project */
|
||||
|
||||
$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', '{}');
|
||||
$callback = $protocol.'://'.$request->getHostname().'/v1/account/sessions/oauth2/callback/'.$provider.'/'.$project->getId();
|
||||
$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']);
|
||||
|
@ -370,9 +370,8 @@ App::get('/v1/account/sessions/oauth2/:provider/redirect')
|
|||
$callback = $protocol . '://' . $request->getHostname() . '/v1/account/sessions/oauth2/callback/' . $provider . '/' . $project->getId();
|
||||
$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']);
|
||||
|
@ -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
|
||||
|
||||
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);
|
||||
|
@ -616,7 +615,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);
|
||||
|
|
|
@ -32,14 +32,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'])
|
||||
|
@ -79,6 +71,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([
|
||||
'$id' => $projectId == 'unique()' ? $dbForConsole->getId() : $projectId,
|
||||
|
@ -102,11 +100,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 */
|
||||
|
@ -515,10 +509,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);
|
||||
});
|
||||
|
@ -547,8 +542,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);
|
||||
|
@ -582,9 +580,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);
|
||||
});
|
||||
|
|
|
@ -279,7 +279,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);
|
||||
|
|
|
@ -129,27 +129,28 @@ App::init(function ($utopia, $request, $project) {
|
|||
return;
|
||||
}
|
||||
|
||||
$auths = $project->getAttribute('auths', []);
|
||||
switch ($route->getLabel('auth.type', '')) {
|
||||
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);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'anonymous':
|
||||
if($project->getAttribute('usersAuthAnonymous', true) === false) {
|
||||
if(($auths['anonymous'] ?? true) === false) {
|
||||
throw new Exception('Anonymous authentication is disabled for this project', 501);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'invites':
|
||||
if($project->getAttribute('usersAuthInvites', true) === false) {
|
||||
if(($auths['invites'] ?? true) === false) {
|
||||
throw new Exception('Invites authentication is disabled for this project', 501);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'jwt':
|
||||
if($project->getAttribute('usersAuthJWT', true) === false) {
|
||||
if(($auths['JWT'] ?? true) === false) {
|
||||
throw new Exception('JWT authentication is disabled for this project', 501);
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -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
|
||||
]);
|
||||
}, []);
|
||||
|
||||
|
|
|
@ -324,9 +324,9 @@ $auth = $this->getParam('auth', []);
|
|||
</li>
|
||||
|
||||
<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.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">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"><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>
|
||||
|
||||
<div data-ui-modal class="modal close" data-button-alias="none" data-open-event="project-update-auth-users-limit">
|
||||
|
@ -351,7 +351,7 @@ $auth = $this->getParam('auth', []);
|
|||
data-failure-param-alert-text="Failed to update project users limit"
|
||||
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="col span-1">
|
||||
|
@ -367,37 +367,37 @@ $auth = $this->getParam('auth', []);
|
|||
<p class="text-fade margin-bottom">Choose auth methods you wish to use.</p>
|
||||
|
||||
<ul class="tiles cell-3 margin-bottom-small">
|
||||
<?php foreach ($auth as $index => $method):
|
||||
$key = $method['key'] ?? '';
|
||||
$name = $method['name'] ?? '';
|
||||
$icon = $method['icon'] ?? '';
|
||||
$docs = $method['docs'] ?? '';
|
||||
$enabled = $method['enabled'] ?? false;
|
||||
?>
|
||||
<li class="">
|
||||
<div class="box padding-small margin-bottom clear">
|
||||
<?php if ($enabled): ?>
|
||||
<form
|
||||
data-analytics
|
||||
data-analytics-activity
|
||||
data-analytics-event="submit"
|
||||
data-analytics-category="console"
|
||||
data-analytics-label="Update Project Auth Status (<?php echo $this->escape($name); ?>)"
|
||||
data-service="projects.updateAuthStatus"
|
||||
data-scope="console"
|
||||
data-event="change"
|
||||
data-param-project-id="{{router.params.project}}"
|
||||
data-success="alert,trigger"
|
||||
data-success-param-alert-text="Updated project auth status successfully"
|
||||
data-success-param-trigger-events="projects.update"
|
||||
data-failure="alert"
|
||||
data-failure-param-alert-text="Failed to update project auth status settings"
|
||||
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); ?>">
|
||||
<?php foreach($auth as $index => $method):
|
||||
$key = $method['key'] ?? '';
|
||||
$name = $method['name'] ?? '';
|
||||
$icon = $method['icon'] ?? '';
|
||||
$docs = $method['docs'] ?? '';
|
||||
$enabled = $method['enabled'] ?? false;
|
||||
?>
|
||||
<li class="">
|
||||
<div class="box padding-small margin-bottom clear">
|
||||
<?php if($enabled): ?>
|
||||
<form
|
||||
data-analytics
|
||||
data-analytics-activity
|
||||
data-analytics-event="submit"
|
||||
data-analytics-category="console"
|
||||
data-analytics-label="Update Project Auth Status (<?php echo $this->escape($name); ?>)"
|
||||
data-service="projects.updateAuthStatus"
|
||||
data-scope="console"
|
||||
data-event="change"
|
||||
data-param-project-id="{{router.params.project}}"
|
||||
data-success="alert,trigger"
|
||||
data-success-param-alert-text="Updated project auth status successfully"
|
||||
data-success-param-trigger-events="projects.update"
|
||||
data-failure="alert"
|
||||
data-failure-param-alert-text="Failed to update project auth status settings"
|
||||
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="status" type="hidden" data-forms-switch data-ls-bind="{{console-project.<?php echo $this->escape($key); ?>}}" data-cast-to="boolean" class="pull-end" />
|
||||
</form>
|
||||
<?php endif;?>
|
||||
<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>
|
||||
<?php endif; ?>
|
||||
|
||||
<img src="<?php echo $this->escape($icon); ?>?buster=<?php echo APP_CACHE_BUSTER; ?>" alt="<?php echo $this->escape($name); ?> Logo" class="pull-start provider margin-end" />
|
||||
|
||||
|
@ -461,16 +461,15 @@ $auth = $this->getParam('auth', []);
|
|||
|
||||
<?php if (!$form): ?>
|
||||
<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>
|
||||
<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: ?>
|
||||
<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="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;?>
|
||||
<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}}" />
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="info row thin margin-bottom margin-top">
|
||||
<div class="col span-1">
|
||||
|
@ -491,14 +490,14 @@ $auth = $this->getParam('auth', []);
|
|||
|
||||
<div class="box padding-small margin-bottom">
|
||||
<span data-ls-if="
|
||||
{{console-project.usersOauth2<?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)); ?>Appid}} &&
|
||||
{{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>
|
||||
</span>
|
||||
|
||||
<span data-ls-if="
|
||||
!{{console-project.usersOauth2<?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)); ?>Appid}} ||
|
||||
!{{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>
|
||||
</span>
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
@ -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...',
|
||||
|
@ -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,
|
||||
|
@ -225,6 +225,28 @@ class Project extends Model
|
|||
$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;
|
||||
}
|
||||
}
|
|
@ -281,8 +281,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']);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -358,7 +358,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';
|
||||
|
|
Loading…
Reference in a new issue