group auth limit inside auths
This commit is contained in:
parent
6f540fec0f
commit
ebf306f814
7 changed files with 19 additions and 21 deletions
|
@ -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,
|
||||||
|
|
|
@ -71,7 +71,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);
|
||||||
|
@ -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
|
$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);
|
||||||
|
@ -614,7 +614,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);
|
||||||
|
|
|
@ -537,8 +537,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);
|
||||||
|
|
|
@ -277,7 +277,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);
|
||||||
|
|
|
@ -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
|
|
||||||
]);
|
]);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|
|
@ -302,8 +302,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>
|
||||||
|
|
||||||
|
@ -329,7 +329,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">
|
||||||
|
|
|
@ -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,
|
||||||
|
@ -229,6 +229,10 @@ class Project extends Model
|
||||||
$auth = Config::getParam('auth', []);
|
$auth = Config::getParam('auth', []);
|
||||||
|
|
||||||
foreach ($auth as $index => $method) {
|
foreach ($auth as $index => $method) {
|
||||||
|
if($method == 'limit') {
|
||||||
|
$document->setAttribute('authLimit', $authValues['limit']);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
$key = $method['key'];
|
$key = $method['key'];
|
||||||
$value = $authValues[$key] ?? true;
|
$value = $authValues[$key] ?? true;
|
||||||
$document->setAttribute('auth' . ucfirst($key), $value);
|
$document->setAttribute('auth' . ucfirst($key), $value);
|
||||||
|
|
Loading…
Reference in a new issue