refactor: 💡 remove route-action usage for auth-methods (#2178)
* refactor: 💡 remove route-action usage for auth-methods ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12603
This commit is contained in:
1 parent
f65f483611
commit
148f2db941
22 files changed
+469
-276
No files matched your search
@@ -23,7 +23,7 @@
|
||||
<form.radioGroup
|
||||
@name='theme'
|
||||
@selectedValue={{@model.state}}
|
||||
@changed={{route-action 'changeState'}}
|
||||
@changed={{fn @changeState @model}}
|
||||
as |radioGroup|
|
||||
>
|
||||
{{#each @model.options.state as |state|}}
|
||||
@@ -48,14 +48,14 @@
|
||||
{{#if @model.isPrimary}}
|
||||
<dropdown.button
|
||||
@disabled={{@model.canSave}}
|
||||
{{on 'click' (route-action 'removeAsPrimary' @model)}}
|
||||
{{on 'click' (fn @removeAsPrimary @model)}}
|
||||
>
|
||||
{{t 'resources.auth-method.actions.remove-as-primary'}}
|
||||
</dropdown.button>
|
||||
{{else}}
|
||||
<dropdown.button
|
||||
@disabled={{@model.canSave}}
|
||||
{{on 'click' (route-action 'makePrimary' @model)}}
|
||||
{{on 'click' (fn @makePrimary @model)}}
|
||||
>
|
||||
{{t 'resources.auth-method.actions.make-primary'}}
|
||||
</dropdown.button>
|
||||
@@ -86,7 +86,7 @@
|
||||
<dropdown.button
|
||||
@style='danger'
|
||||
@disabled={{@model.canSave}}
|
||||
{{on 'click' (route-action 'delete' @model)}}
|
||||
{{on 'click' (fn @delete @model)}}
|
||||
>
|
||||
{{t 'resources.auth-method.actions.delete'}}
|
||||
</dropdown.button>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* SPDX-License-Identifier: MPL-2.0
|
||||
*/
|
||||
|
||||
import Controller from '@ember/controller';
|
||||
import Controller, { inject as controller } from '@ember/controller';
|
||||
import { action } from '@ember/object';
|
||||
import { inject as service } from '@ember/service';
|
||||
import { loading } from 'ember-loading';
|
||||
@@ -11,6 +11,8 @@ import { confirm } from 'core/decorators/confirm';
|
||||
import { notifySuccess, notifyError } from 'core/decorators/notify';
|
||||
|
||||
export default class ScopesScopeAuthMethodsAuthMethodAccountsIndexController extends Controller {
|
||||
@controller('scopes/scope/auth-methods/index') authMethods;
|
||||
|
||||
// =services
|
||||
|
||||
@service can;
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
import Controller, { inject as controller } from '@ember/controller';
|
||||
|
||||
export default class ScopesScopeAuthMethodsAuthMethodIndexController extends Controller {
|
||||
@controller('scopes/scope/auth-methods/index') authMethods;
|
||||
}
|
||||
+3
-1
@@ -3,7 +3,7 @@
|
||||
* SPDX-License-Identifier: MPL-2.0
|
||||
*/
|
||||
|
||||
import Controller from '@ember/controller';
|
||||
import Controller, { inject as controller } from '@ember/controller';
|
||||
import { action } from '@ember/object';
|
||||
import { inject as service } from '@ember/service';
|
||||
import { loading } from 'ember-loading';
|
||||
@@ -11,6 +11,8 @@ import { confirm } from 'core/decorators/confirm';
|
||||
import { notifySuccess, notifyError } from 'core/decorators/notify';
|
||||
|
||||
export default class ScopesScopeAuthMethodsAuthMethodManagedGroupsIndexController extends Controller {
|
||||
@controller('scopes/scope/auth-methods/index') authMethods;
|
||||
|
||||
// =services
|
||||
|
||||
@service can;
|
||||
|
||||
@@ -5,14 +5,19 @@
|
||||
|
||||
import Controller from '@ember/controller';
|
||||
import { inject as service } from '@ember/service';
|
||||
import { tracked } from '@glimmer/tracking';
|
||||
import { action } from '@ember/object';
|
||||
import { loading } from 'ember-loading';
|
||||
import { confirm } from 'core/decorators/confirm';
|
||||
import { notifySuccess, notifyError } from 'core/decorators/notify';
|
||||
import { tracked } from '@glimmer/tracking';
|
||||
import { debounce } from 'core/decorators/debounce';
|
||||
import { TYPES_AUTH_METHOD } from 'api/models/auth-method';
|
||||
|
||||
export default class ScopesScopeAuthMethodsIndexController extends Controller {
|
||||
// =services
|
||||
|
||||
@service router;
|
||||
@service can;
|
||||
@service intl;
|
||||
|
||||
// =attributes
|
||||
@@ -92,6 +97,111 @@ export default class ScopesScopeAuthMethodsIndexController extends Controller {
|
||||
this.page = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Rollback changes to an auth-method.
|
||||
* @param {AuthMethodModel} authMethod
|
||||
*/
|
||||
@action
|
||||
cancel(authMethod) {
|
||||
const { isNew } = authMethod;
|
||||
authMethod.rollbackAttributes();
|
||||
if (isNew) this.router.transitionTo('scopes.scope.auth-methods');
|
||||
}
|
||||
|
||||
/**
|
||||
* Save an auth-method in current scope.
|
||||
* @param {AuthMethodModel} authMethod
|
||||
*/
|
||||
@action
|
||||
@loading
|
||||
@notifyError(({ message }) => message)
|
||||
@notifySuccess(({ isNew }) =>
|
||||
isNew ? 'notifications.create-success' : 'notifications.save-success',
|
||||
)
|
||||
async save(authMethod) {
|
||||
await authMethod.save();
|
||||
if (this.can.can('read model', authMethod)) {
|
||||
await this.router.transitionTo(
|
||||
'scopes.scope.auth-methods.auth-method',
|
||||
authMethod,
|
||||
);
|
||||
} else {
|
||||
await this.router.transitionTo('scopes.scope.auth-methods');
|
||||
}
|
||||
await this.router.refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an auth method in current scope and redirect to index
|
||||
* @param {AuthMethodModel} authMethod
|
||||
*/
|
||||
@action
|
||||
@loading
|
||||
@confirm('questions.delete-confirm')
|
||||
@notifyError(({ message }) => message, { catch: true })
|
||||
@notifySuccess('notifications.delete-success')
|
||||
async delete(authMethod) {
|
||||
await authMethod.destroyRecord();
|
||||
// Reload the scope, since this is where the primary_auth_method_id is
|
||||
// stored. An auth method deletion could affect this field.
|
||||
await this.scopeModel.reload();
|
||||
this.router.replaceWith('scopes.scope.auth-methods');
|
||||
await this.router.refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Elects the specified auth method to primary for the current scope.
|
||||
* @param {AuthMethodModel} authMethod
|
||||
* @param {string} authMethod.id
|
||||
*/
|
||||
@action
|
||||
@loading
|
||||
@confirm('resources.auth-method.questions.make-primary-confirm', {
|
||||
title: 'resources.auth-method.questions.make-primary',
|
||||
})
|
||||
@notifyError(({ message }) => message, { catch: true })
|
||||
@notifySuccess('resources.auth-method.notifications.make-primary-success')
|
||||
async makePrimary({ id }) {
|
||||
this.scopeModel.primary_auth_method_id = id;
|
||||
// Attempt to save the change to the scope. If this operation fails,
|
||||
// we rollback the change and rethrow the error so the user can be notified.
|
||||
try {
|
||||
await this.scopeModel.save();
|
||||
} catch (e) {
|
||||
this.scopeModel.rollbackAttributes();
|
||||
throw e;
|
||||
}
|
||||
await this.router.refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the `primary_auth_method_id` field to null for the current scope
|
||||
* and saves it if and only if the specified auth method is in fact primary
|
||||
* for the current scope.
|
||||
* @param {AuthMethodModel} authMethod
|
||||
*/
|
||||
@action
|
||||
@loading
|
||||
@confirm('resources.auth-method.questions.remove-as-primary-confirm', {
|
||||
title: 'resources.auth-method.questions.remove-as-primary',
|
||||
})
|
||||
@notifyError(({ message }) => message, { catch: true })
|
||||
@notifySuccess(
|
||||
'resources.auth-method.notifications.remove-as-primary-success',
|
||||
)
|
||||
async removeAsPrimary(authMethod) {
|
||||
this.scopeModel.primary_auth_method_id = null;
|
||||
// Attempt to save the change to the scope. If this operation fails,
|
||||
// we rollback the change and rethrow the error so the user can be notified.
|
||||
try {
|
||||
await this.scopeModel.save();
|
||||
} catch (e) {
|
||||
this.scopeModel.rollbackAttributes();
|
||||
throw e;
|
||||
}
|
||||
await authMethod.reload();
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an item from array `property` at `index` on the
|
||||
* passed `authMethod`. This is used to manage entries in fragment array
|
||||
@@ -101,7 +211,7 @@ export default class ScopesScopeAuthMethodsIndexController extends Controller {
|
||||
* @param {number} index
|
||||
*/
|
||||
@action
|
||||
async removeItemByIndex(authMethod, property, index) {
|
||||
removeItemByIndex(authMethod, property, index) {
|
||||
const array = authMethod.get(property).filter((item, i) => i !== index);
|
||||
authMethod.set(property, array);
|
||||
}
|
||||
@@ -115,9 +225,78 @@ export default class ScopesScopeAuthMethodsIndexController extends Controller {
|
||||
* @param {string} value
|
||||
*/
|
||||
@action
|
||||
async addStringItem(authMethod, property, value) {
|
||||
addStringItem(authMethod, property, value) {
|
||||
const existingArray = authMethod[property] ?? [];
|
||||
const array = [...existingArray, { value }];
|
||||
authMethod.set(property, array);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an account map fragment to the passed `authMethod`.
|
||||
* @param {AuthMethodModel} authMethod
|
||||
* @param {string} field
|
||||
* @param {string} from
|
||||
* @param {string} to
|
||||
*/
|
||||
@action
|
||||
addAccountMapItem(authMethod, field, from, to) {
|
||||
const existingArray = authMethod[field] ?? [];
|
||||
const array = [...existingArray, { from, to }];
|
||||
authMethod.set(field, array);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies the contents of string array fields in order to force the instance
|
||||
* into a dirty state. This ensures that `model.rollbackAttributes()` reverts
|
||||
* to the original expected array.
|
||||
*
|
||||
* The deep copy implemented here is required to ensure that both the
|
||||
* array itself and its members are all new.
|
||||
*
|
||||
* @param {authMethodModel} authMethod
|
||||
*/
|
||||
@action
|
||||
edit(authMethod) {
|
||||
if (authMethod.claims_scopes) {
|
||||
authMethod.claims_scopes = structuredClone(authMethod.claims_scopes);
|
||||
}
|
||||
if (authMethod.signing_algorithms) {
|
||||
authMethod.signing_algorithms = structuredClone(
|
||||
authMethod.signing_algorithms,
|
||||
);
|
||||
}
|
||||
if (authMethod.allowed_audiences) {
|
||||
authMethod.allowed_audiences = structuredClone(
|
||||
authMethod.allowed_audiences,
|
||||
);
|
||||
}
|
||||
if (authMethod.idp_ca_certs) {
|
||||
authMethod.idp_ca_certs = structuredClone(authMethod.idp_ca_certs);
|
||||
}
|
||||
if (authMethod.account_claim_maps) {
|
||||
authMethod.account_claim_maps = structuredClone(
|
||||
authMethod.account_claim_maps,
|
||||
);
|
||||
}
|
||||
if (authMethod.certificates) {
|
||||
authMethod.certificates = structuredClone(authMethod.certificates);
|
||||
}
|
||||
if (authMethod.account_attribute_maps) {
|
||||
authMethod.account_attribute_maps = structuredClone(
|
||||
authMethod.account_attribute_maps,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update state of OIDC or LDAP auth method
|
||||
* @param {string} state
|
||||
* @param {authMethodModel} authMethod
|
||||
*/
|
||||
@action
|
||||
@notifyError(({ message }) => message)
|
||||
@notifySuccess('notifications.save-success')
|
||||
async changeState(authMethod, state) {
|
||||
await authMethod.changeState(state);
|
||||
}
|
||||
}
|
||||
@@ -3,9 +3,11 @@
|
||||
* SPDX-License-Identifier: MPL-2.0
|
||||
*/
|
||||
|
||||
import Controller from '@ember/controller';
|
||||
import Controller, { inject as controller } from '@ember/controller';
|
||||
|
||||
export default class ScopesScopeAuthMethodsNewController extends Controller {
|
||||
@controller('scopes/scope/auth-methods/index') authMethods;
|
||||
|
||||
// =services
|
||||
|
||||
// =attributes
|
||||
|
||||
@@ -5,16 +5,11 @@
|
||||
|
||||
import Route from '@ember/routing/route';
|
||||
import { inject as service } from '@ember/service';
|
||||
import { action } from '@ember/object';
|
||||
import { loading } from 'ember-loading';
|
||||
import { confirm } from 'core/decorators/confirm';
|
||||
import { notifySuccess, notifyError } from 'core/decorators/notify';
|
||||
|
||||
export default class ScopesScopeAuthMethodsRoute extends Route {
|
||||
// =services
|
||||
|
||||
@service session;
|
||||
@service can;
|
||||
@service router;
|
||||
|
||||
// =methods
|
||||
@@ -25,157 +20,4 @@ export default class ScopesScopeAuthMethodsRoute extends Route {
|
||||
beforeModel() {
|
||||
if (!this.session.isAuthenticated) this.router.transitionTo('index');
|
||||
}
|
||||
|
||||
// =actions
|
||||
|
||||
/**
|
||||
* Rollback changes to an auth-method.
|
||||
* @param {AuthMethodModel} authMethod
|
||||
*/
|
||||
@action
|
||||
cancel(authMethod) {
|
||||
const { isNew } = authMethod;
|
||||
authMethod.rollbackAttributes();
|
||||
if (isNew) this.router.transitionTo('scopes.scope.auth-methods');
|
||||
}
|
||||
|
||||
/**
|
||||
* Save an auth-method in current scope.
|
||||
* @param {AuthMethodModel} authMethod
|
||||
*/
|
||||
@action
|
||||
@loading
|
||||
@notifyError(({ message }) => message)
|
||||
@notifySuccess(({ isNew }) =>
|
||||
isNew ? 'notifications.create-success' : 'notifications.save-success',
|
||||
)
|
||||
async save(authMethod) {
|
||||
await authMethod.save();
|
||||
if (this.can.can('read model', authMethod)) {
|
||||
await this.router.transitionTo(
|
||||
'scopes.scope.auth-methods.auth-method',
|
||||
authMethod,
|
||||
);
|
||||
} else {
|
||||
await this.router.transitionTo('scopes.scope.auth-methods');
|
||||
}
|
||||
this.refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an auth method in current scope and redirect to index
|
||||
* @param {AuthMethodModel} authMethod
|
||||
*/
|
||||
@action
|
||||
@loading
|
||||
@confirm('questions.delete-confirm')
|
||||
@notifyError(({ message }) => message, { catch: true })
|
||||
@notifySuccess('notifications.delete-success')
|
||||
async delete(authMethod) {
|
||||
const scopeModel = this.modelFor('scopes.scope');
|
||||
await authMethod.destroyRecord();
|
||||
// Reload the scope, since this is where the primary_auth_method_id is
|
||||
// stored. An auth method deletion could affect this field.
|
||||
await scopeModel.reload();
|
||||
this.router.replaceWith('scopes.scope.auth-methods');
|
||||
this.refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Elects the specified auth method to primary for the current scope.
|
||||
* @param {AuthMethodModel} authMethod
|
||||
* @param {string} authMethod.id
|
||||
*/
|
||||
@action
|
||||
@loading
|
||||
@confirm('resources.auth-method.questions.make-primary-confirm', {
|
||||
title: 'resources.auth-method.questions.make-primary',
|
||||
})
|
||||
@notifyError(({ message }) => message, { catch: true })
|
||||
@notifySuccess('resources.auth-method.notifications.make-primary-success')
|
||||
async makePrimary({ id }) {
|
||||
const scopeModel = this.modelFor('scopes.scope');
|
||||
scopeModel.primary_auth_method_id = id;
|
||||
// Attempt to save the change to the scope. If this operation fails,
|
||||
// we rollback the change and rethrow the error so the user can be notified.
|
||||
try {
|
||||
await scopeModel.save();
|
||||
} catch (e) {
|
||||
scopeModel.rollbackAttributes();
|
||||
throw e;
|
||||
}
|
||||
await this.refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the `primary_auth_method_id` field to null for the current scope
|
||||
* and saves it if and only if the specified auth method is in fact primary
|
||||
* for the current scope.
|
||||
* @param {AuthMethodModel} authMethod
|
||||
*/
|
||||
@action
|
||||
@loading
|
||||
@confirm('resources.auth-method.questions.remove-as-primary-confirm', {
|
||||
title: 'resources.auth-method.questions.remove-as-primary',
|
||||
})
|
||||
@notifyError(({ message }) => message, { catch: true })
|
||||
@notifySuccess(
|
||||
'resources.auth-method.notifications.remove-as-primary-success',
|
||||
)
|
||||
async removeAsPrimary(authMethod) {
|
||||
const scopeModel = this.modelFor('scopes.scope');
|
||||
scopeModel.primary_auth_method_id = null;
|
||||
// Attempt to save the change to the scope. If this operation fails,
|
||||
// we rollback the change and rethrow the error so the user can be notified.
|
||||
try {
|
||||
await scopeModel.save();
|
||||
} catch (e) {
|
||||
scopeModel.rollbackAttributes();
|
||||
throw e;
|
||||
}
|
||||
await authMethod.reload();
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an item from array `property` at `index` on the
|
||||
* passed `authMethod`. This is used to manage entries in fragment array
|
||||
* fields such as `signing_algorithms`.
|
||||
* @param {AuthMethodModel} authMethod
|
||||
* @param {string} property
|
||||
* @param {number} index
|
||||
*/
|
||||
@action
|
||||
async removeItemByIndex(authMethod, property, index) {
|
||||
const array = authMethod.get(property).filter((item, i) => i !== index);
|
||||
authMethod.set(property, array);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a string item to array `property` on the passed `authMethod`.
|
||||
* This is used to manage entries in fragment OIDC string array fields such
|
||||
* as `signing_algorithms`.
|
||||
* @param {AuthMethodModel} authMethod
|
||||
* @param {string} property
|
||||
* @param {string} value
|
||||
*/
|
||||
@action
|
||||
async addStringItem(authMethod, property, value) {
|
||||
const existingArray = authMethod[property] ?? [];
|
||||
const array = [...existingArray, { value }];
|
||||
authMethod.set(property, array);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an account map fragment to the passed `authMethod`.
|
||||
* @param {AuthMethodModel} authMethod
|
||||
* @param {string} field
|
||||
* @param {string} from
|
||||
* @param {string} to
|
||||
*/
|
||||
@action
|
||||
async addAccountMapItem(authMethod, field, from, to) {
|
||||
const existingArray = authMethod[field] ?? [];
|
||||
const array = [...existingArray, { from, to }];
|
||||
authMethod.set(field, array);
|
||||
}
|
||||
}
|
||||
@@ -4,8 +4,6 @@
|
||||
*/
|
||||
|
||||
import Route from '@ember/routing/route';
|
||||
import { action } from '@ember/object';
|
||||
import { notifySuccess, notifyError } from 'core/decorators/notify';
|
||||
import { inject as service } from '@ember/service';
|
||||
import { paramValueFinder } from 'admin/utils/param-value-finder';
|
||||
|
||||
@@ -47,61 +45,4 @@ export default class ScopesScopeAuthMethodsAuthMethodRoute extends Route {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// =actions
|
||||
|
||||
/**
|
||||
* Copies the contents of string array fields in order to force the instance
|
||||
* into a dirty state. This ensures that `model.rollbackAttributes()` reverts
|
||||
* to the original expected array.
|
||||
*
|
||||
* The deep copy implemented here is required to ensure that both the
|
||||
* array itself and its members are all new.
|
||||
*
|
||||
* @param {authMethodModel} authMethod
|
||||
*/
|
||||
@action
|
||||
edit(authMethod) {
|
||||
if (authMethod.claims_scopes) {
|
||||
authMethod.claims_scopes = structuredClone(authMethod.claims_scopes);
|
||||
}
|
||||
if (authMethod.signing_algorithms) {
|
||||
authMethod.signing_algorithms = structuredClone(
|
||||
authMethod.signing_algorithms,
|
||||
);
|
||||
}
|
||||
if (authMethod.allowed_audiences) {
|
||||
authMethod.allowed_audiences = structuredClone(
|
||||
authMethod.allowed_audiences,
|
||||
);
|
||||
}
|
||||
if (authMethod.idp_ca_certs) {
|
||||
authMethod.idp_ca_certs = structuredClone(authMethod.idp_ca_certs);
|
||||
}
|
||||
if (authMethod.account_claim_maps) {
|
||||
authMethod.account_claim_maps = structuredClone(
|
||||
authMethod.account_claim_maps,
|
||||
);
|
||||
}
|
||||
if (authMethod.certificates) {
|
||||
authMethod.certificates = structuredClone(authMethod.certificates);
|
||||
}
|
||||
if (authMethod.account_attribute_maps) {
|
||||
authMethod.account_attribute_maps = structuredClone(
|
||||
authMethod.account_attribute_maps,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update state of OIDC or LDAP auth method
|
||||
* @param {string} state
|
||||
*/
|
||||
@action
|
||||
@notifyError(({ message }) => message)
|
||||
@notifySuccess('notifications.save-success')
|
||||
async changeState(state) {
|
||||
const model = this.modelFor('scopes.scope.auth-methods.auth-method');
|
||||
await model.changeState(state);
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,13 @@
|
||||
</page.navigation>
|
||||
|
||||
<page.actions>
|
||||
<AuthMethods::AuthMethod::Actions @model={{@model.authMethod}} />
|
||||
<AuthMethods::AuthMethod::Actions
|
||||
@model={{@model.authMethod}}
|
||||
@changeState={{this.authMethods.changeState}}
|
||||
@removeAsPrimary={{this.authMethods.removeAsPrimary}}
|
||||
@makePrimary={{this.authMethods.makePrimary}}
|
||||
@delete={{this.authMethods.delete}}
|
||||
/>
|
||||
</page.actions>
|
||||
|
||||
<page.body>
|
||||
|
||||
@@ -18,18 +18,24 @@
|
||||
</page.navigation>
|
||||
|
||||
<page.actions>
|
||||
<AuthMethods::AuthMethod::Actions @model={{@model}} />
|
||||
<AuthMethods::AuthMethod::Actions
|
||||
@model={{@model}}
|
||||
@changeState={{this.authMethods.changeState}}
|
||||
@removeAsPrimary={{this.authMethods.removeAsPrimary}}
|
||||
@makePrimary={{this.authMethods.makePrimary}}
|
||||
@delete={{this.authMethods.delete}}
|
||||
/>
|
||||
</page.actions>
|
||||
|
||||
<page.body>
|
||||
<Form::AuthMethod
|
||||
@model={{@model}}
|
||||
@edit={{route-action 'edit' @model}}
|
||||
@submit={{route-action 'save' @model}}
|
||||
@cancel={{route-action 'cancel' @model}}
|
||||
@removeItemByIndex={{route-action 'removeItemByIndex' @model}}
|
||||
@addStringItem={{route-action 'addStringItem' @model}}
|
||||
@addAccountMapItem={{route-action 'addAccountMapItem' @model}}
|
||||
@edit={{fn this.authMethods.edit @model}}
|
||||
@submit={{fn this.authMethods.save @model}}
|
||||
@cancel={{fn this.authMethods.cancel @model}}
|
||||
@removeItemByIndex={{fn this.authMethods.removeItemByIndex @model}}
|
||||
@addStringItem={{fn this.authMethods.addStringItem @model}}
|
||||
@addAccountMapItem={{fn this.authMethods.addAccountMapItem @model}}
|
||||
/>
|
||||
</page.body>
|
||||
|
||||
|
||||
+7
-1
@@ -18,7 +18,13 @@
|
||||
</page.navigation>
|
||||
|
||||
<page.actions>
|
||||
<AuthMethods::AuthMethod::Actions @model={{@model.authMethod}} />
|
||||
<AuthMethods::AuthMethod::Actions
|
||||
@model={{@model.authMethod}}
|
||||
@changeState={{this.authMethods.changeState}}
|
||||
@removeAsPrimary={{this.authMethods.removeAsPrimary}}
|
||||
@makePrimary={{this.authMethods.makePrimary}}
|
||||
@delete={{this.authMethods.delete}}
|
||||
/>
|
||||
</page.actions>
|
||||
|
||||
<page.body>
|
||||
|
||||
@@ -149,7 +149,7 @@
|
||||
<dd.Interactive
|
||||
@text={{t 'resources.auth-method.actions.make-primary'}}
|
||||
data-test-make-primary-action
|
||||
{{on 'click' (route-action 'makePrimary' B.data)}}
|
||||
{{on 'click' (fn this.makePrimary B.data)}}
|
||||
/>
|
||||
{{/unless}}
|
||||
{{#if B.data.isPrimary}}
|
||||
@@ -157,7 +157,7 @@
|
||||
@text={{t
|
||||
'resources.auth-method.actions.remove-as-primary'
|
||||
}}
|
||||
{{on 'click' (route-action 'removeAsPrimary' B.data)}}
|
||||
{{on 'click' (fn this.removeAsPrimary B.data)}}
|
||||
/>
|
||||
{{/if}}
|
||||
</Hds::Dropdown>
|
||||
|
||||
@@ -25,11 +25,11 @@
|
||||
<page.body>
|
||||
<Form::AuthMethod
|
||||
@model={{@model}}
|
||||
@submit={{route-action 'save' @model}}
|
||||
@cancel={{route-action 'cancel' @model}}
|
||||
@removeItemByIndex={{route-action 'removeItemByIndex' @model}}
|
||||
@addStringItem={{route-action 'addStringItem' @model}}
|
||||
@addAccountMapItem={{route-action 'addAccountMapItem' @model}}
|
||||
@submit={{fn this.authMethods.save @model}}
|
||||
@cancel={{fn this.authMethods.cancel @model}}
|
||||
@removeItemByIndex={{fn this.authMethods.removeItemByIndex @model}}
|
||||
@addStringItem={{fn this.authMethods.addStringItem @model}}
|
||||
@addAccountMapItem={{fn this.authMethods.addAccountMapItem @model}}
|
||||
/>
|
||||
</page.body>
|
||||
</Rose::Layout::Page>
|
||||
@@ -324,8 +324,11 @@ module('Acceptance | auth-methods | create', function (hooks) {
|
||||
instances.orgScope.primaryAuthMethodId,
|
||||
'Primary auth method is not yet set.',
|
||||
);
|
||||
await visit(urls.authMethod);
|
||||
await visit(urls.authMethods);
|
||||
|
||||
await click(`[href="${urls.authMethod}"]`);
|
||||
await click(MAKE_PRIMARY_SELECTOR);
|
||||
|
||||
const scope = this.server.schema.scopes.find(instances.orgScope.id);
|
||||
assert.strictEqual(
|
||||
scope.primaryAuthMethodId,
|
||||
@@ -363,7 +366,9 @@ module('Acceptance | auth-methods | create', function (hooks) {
|
||||
instances.orgScope.primaryAuthMethodId,
|
||||
'Primary auth method is set.',
|
||||
);
|
||||
await visit(urls.authMethod);
|
||||
await visit(urls.authMethods);
|
||||
|
||||
await click(`[href="${urls.authMethod}"]`);
|
||||
await click(MAKE_PRIMARY_SELECTOR);
|
||||
const scope = this.server.schema.scopes.find(instances.orgScope.id);
|
||||
assert.notOk(scope.primaryAuthMethodId, 'Primary auth method is unset.');
|
||||
@@ -389,8 +394,9 @@ module('Acceptance | auth-methods | create', function (hooks) {
|
||||
instances.orgScope.primaryAuthMethodId,
|
||||
instances.authMethod.id,
|
||||
);
|
||||
await visit(urls.authMethods);
|
||||
|
||||
await visit(urls.authMethod);
|
||||
await click(`[href="${urls.authMethod}"]`);
|
||||
await click(MAKE_PRIMARY_SELECTOR);
|
||||
|
||||
assert.dom(ERROR_MSG_SELECTOR).hasText('Sorry!');
|
||||
|
||||
@@ -163,11 +163,12 @@ module('Acceptance | auth-methods | update', function (hooks) {
|
||||
await click(CLAIMS_SCOPES_BTN_SELECTOR, 'allowed_audiences');
|
||||
|
||||
// Remove all claim maps
|
||||
await Promise.all(
|
||||
findAll('form fieldset:nth-of-type(4) [title="Remove"]').map((element) =>
|
||||
click(element),
|
||||
),
|
||||
const claimMaps = await Promise.all(
|
||||
findAll('form fieldset:nth-of-type(4) [title="Remove"]'),
|
||||
);
|
||||
for (const element of claimMaps) {
|
||||
await click(element);
|
||||
}
|
||||
await fillIn('[name="from_claim"]', 'from_claim');
|
||||
await select('form fieldset:nth-of-type(4) select', 'email');
|
||||
await click('form fieldset:nth-of-type(4) [title="Add"]');
|
||||
@@ -235,11 +236,12 @@ module('Acceptance | auth-methods | update', function (hooks) {
|
||||
await fillIn('[name="user_attr"]', 'user attr');
|
||||
await fillIn('[name="user_filter"]', 'user filter');
|
||||
// Remove all attribute maps
|
||||
await Promise.all(
|
||||
findAll(
|
||||
'[name="account_attribute_maps"] .hds-button--color-critical',
|
||||
).map((element) => click(element)),
|
||||
const attributeMaps = await Promise.all(
|
||||
findAll('[name="account_attribute_maps"] .hds-button--color-critical'),
|
||||
);
|
||||
for (const element of attributeMaps) {
|
||||
await click(element);
|
||||
}
|
||||
await fillIn('[name="account_attribute_maps"] input', 'attribute');
|
||||
await select('[name="account_attribute_maps"] select', 'email');
|
||||
await click('[name="account_attribute_maps"] button');
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'admin/tests/helpers';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
|
||||
module(
|
||||
'Unit | Controller | scopes/scope/auth-methods/auth-method/accounts/account/index',
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'admin/tests/helpers';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
|
||||
module(
|
||||
'Unit | Controller | scopes/scope/auth-methods/auth-method/accounts/account/set-password',
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'admin/tests/helpers';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
|
||||
module(
|
||||
'Unit | Controller | scopes/scope/auth-methods/auth-method/accounts/index',
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'admin/tests/helpers';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
|
||||
module(
|
||||
'Unit | Controller | scopes/scope/auth-methods/auth-method/accounts/new',
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
|
||||
module(
|
||||
'Unit | Controller | scopes/scope/auth-methods/auth-method/index',
|
||||
function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
test('it exists', function (assert) {
|
||||
let controller = this.owner.lookup(
|
||||
'controller:scopes/scope/auth-methods/auth-method/index',
|
||||
);
|
||||
assert.ok(controller);
|
||||
});
|
||||
},
|
||||
);
|
||||
@@ -6,6 +6,10 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
import { waitUntil } from '@ember/test-helpers';
|
||||
import { visit } from '@ember/test-helpers';
|
||||
import setupMirage from 'ember-cli-mirage/test-support/setup-mirage';
|
||||
import { setupIndexedDb } from 'api/test-support/helpers/indexed-db';
|
||||
import { authenticateSession } from 'ember-simple-auth/test-support';
|
||||
import {
|
||||
TYPE_AUTH_METHOD_PASSWORD,
|
||||
TYPE_AUTH_METHOD_OIDC,
|
||||
@@ -14,18 +18,41 @@ import {
|
||||
|
||||
module('Unit | Controller | scopes/scope/auth-methods/index', function (hooks) {
|
||||
setupTest(hooks);
|
||||
setupMirage(hooks);
|
||||
setupIndexedDb(hooks);
|
||||
|
||||
test('it exists', function (assert) {
|
||||
let controller = this.owner.lookup(
|
||||
let store;
|
||||
let controller;
|
||||
let getAuthMethodCount;
|
||||
|
||||
const instances = {
|
||||
scope: {
|
||||
global: null,
|
||||
},
|
||||
authMethod: null,
|
||||
};
|
||||
|
||||
hooks.beforeEach(async function () {
|
||||
authenticateSession({});
|
||||
store = this.owner.lookup('service:store');
|
||||
controller = this.owner.lookup(
|
||||
'controller:scopes/scope/auth-methods/index',
|
||||
);
|
||||
|
||||
instances.scope.global = this.server.create('scope', { id: 'global' });
|
||||
instances.authMethod = this.server.create('auth-method', {
|
||||
scopeId: 'global',
|
||||
});
|
||||
|
||||
getAuthMethodCount = () =>
|
||||
this.server.schema.authMethods.all().models.length;
|
||||
});
|
||||
|
||||
test('controller exists', function (assert) {
|
||||
assert.ok(controller);
|
||||
});
|
||||
|
||||
test('primaryOptions returns expected object', function (assert) {
|
||||
let controller = this.owner.lookup(
|
||||
'controller:scopes/scope/auth-methods/index',
|
||||
);
|
||||
assert.deepEqual(controller.primaryOptions, [
|
||||
{ id: 'true', name: 'Yes' },
|
||||
{ id: 'false', name: 'No' },
|
||||
@@ -33,9 +60,6 @@ module('Unit | Controller | scopes/scope/auth-methods/index', function (hooks) {
|
||||
});
|
||||
|
||||
test('authMethodTypeOptions returns expected object', function (assert) {
|
||||
let controller = this.owner.lookup(
|
||||
'controller:scopes/scope/auth-methods/index',
|
||||
);
|
||||
assert.deepEqual(controller.authMethodTypeOptions, [
|
||||
{ id: TYPE_AUTH_METHOD_PASSWORD, name: 'Password' },
|
||||
{ id: TYPE_AUTH_METHOD_OIDC, name: 'OIDC' },
|
||||
@@ -44,17 +68,11 @@ module('Unit | Controller | scopes/scope/auth-methods/index', function (hooks) {
|
||||
});
|
||||
|
||||
test('filters returns expected entries', function (assert) {
|
||||
let controller = this.owner.lookup(
|
||||
'controller:scopes/scope/auth-methods/index',
|
||||
);
|
||||
assert.ok(controller.filters.allFilters);
|
||||
assert.ok(controller.filters.selectedFilters);
|
||||
});
|
||||
|
||||
test('handleSearchInput action sets expected values correctly', async function (assert) {
|
||||
let controller = this.owner.lookup(
|
||||
'controller:scopes/scope/auth-methods/index',
|
||||
);
|
||||
const searchValue = 'test';
|
||||
controller.handleSearchInput({ target: { value: searchValue } });
|
||||
await waitUntil(() => controller.search === searchValue);
|
||||
@@ -64,13 +82,173 @@ module('Unit | Controller | scopes/scope/auth-methods/index', function (hooks) {
|
||||
});
|
||||
|
||||
test('applyFilter action sets expected values correctly', async function (assert) {
|
||||
let controller = this.owner.lookup(
|
||||
'controller:scopes/scope/auth-methods/index',
|
||||
);
|
||||
const selectedItems = ['true'];
|
||||
controller.applyFilter('primary', selectedItems);
|
||||
|
||||
assert.strictEqual(controller.page, 1);
|
||||
assert.deepEqual(controller.primary, selectedItems);
|
||||
});
|
||||
|
||||
test('cancel action rolls-back changes on the specified model', async function (assert) {
|
||||
await visit('/scopes/global/auth-methods');
|
||||
const authMethodModelBefore = await store.findRecord(
|
||||
'auth-method',
|
||||
instances.authMethod.id,
|
||||
);
|
||||
authMethodModelBefore.name = 'test';
|
||||
|
||||
assert.strictEqual(authMethodModelBefore.name, 'test');
|
||||
|
||||
await controller.cancel(authMethodModelBefore);
|
||||
const authMethodModelAfter = await store.findRecord(
|
||||
'auth-method',
|
||||
instances.authMethod.id,
|
||||
);
|
||||
|
||||
assert.notEqual(authMethodModelAfter.name, 'test');
|
||||
assert.strictEqual(authMethodModelAfter.name, authMethodModelBefore.name);
|
||||
});
|
||||
|
||||
test('save action saves changes on the specified model', async function (assert) {
|
||||
await visit('/scopes/global/auth-methods');
|
||||
const authMethodModelBefore = await store.findRecord(
|
||||
'auth-method',
|
||||
instances.authMethod.id,
|
||||
);
|
||||
authMethodModelBefore.name = 'test';
|
||||
|
||||
await controller.save(authMethodModelBefore);
|
||||
const authMethodModelAfter = await store.findRecord(
|
||||
'auth-method',
|
||||
instances.authMethod.id,
|
||||
);
|
||||
|
||||
assert.strictEqual(authMethodModelAfter.name, 'test');
|
||||
});
|
||||
|
||||
test('delete action destroys specified model', async function (assert) {
|
||||
await visit('/scopes/global/scopes');
|
||||
const authMethodModel = await store.findRecord(
|
||||
'auth-method',
|
||||
instances.authMethod.id,
|
||||
);
|
||||
const authMethodCount = getAuthMethodCount();
|
||||
|
||||
await controller.delete(authMethodModel);
|
||||
|
||||
assert.strictEqual(getAuthMethodCount(), authMethodCount - 1);
|
||||
});
|
||||
|
||||
test('makePrimary action updates scope with auth-method id', async function (assert) {
|
||||
await visit('/scopes/global/auth-methods');
|
||||
const authMethodModel = await store.findRecord(
|
||||
'auth-method',
|
||||
instances.authMethod.id,
|
||||
);
|
||||
|
||||
await controller.makePrimary(authMethodModel);
|
||||
const scopeModel = await store.findRecord(
|
||||
'scope',
|
||||
instances.scope.global.id,
|
||||
);
|
||||
|
||||
assert.strictEqual(
|
||||
scopeModel.primary_auth_method_id,
|
||||
instances.authMethod.id,
|
||||
);
|
||||
});
|
||||
|
||||
test('removeAsPrimary action updates scope with null as auth-method id', async function (assert) {
|
||||
await visit('/scopes/global/auth-methods');
|
||||
const authMethodModel = await store.findRecord(
|
||||
'auth-method',
|
||||
instances.authMethod.id,
|
||||
);
|
||||
|
||||
await controller.removeAsPrimary(authMethodModel);
|
||||
const scopeModel = await store.findRecord(
|
||||
'scope',
|
||||
instances.scope.global.id,
|
||||
);
|
||||
|
||||
assert.notOk(scopeModel.primary_auth_method_id);
|
||||
});
|
||||
|
||||
test('addStringItem action adds item to field and removeItemByIndex removes correct item', async function (assert) {
|
||||
const authMethodModel = await store.findRecord(
|
||||
'auth-method',
|
||||
instances.authMethod.id,
|
||||
);
|
||||
|
||||
controller.addStringItem(authMethodModel, 'certificates', 'cert_123');
|
||||
|
||||
assert.deepEqual(authMethodModel.certificates, [{ value: 'cert_123' }]);
|
||||
|
||||
controller.addStringItem(authMethodModel, 'certificates', 'cert_456');
|
||||
controller.removeItemByIndex(authMethodModel, 'certificates', 0);
|
||||
|
||||
assert.deepEqual(authMethodModel.certificates, [{ value: 'cert_456' }]);
|
||||
});
|
||||
|
||||
test('addAccountMapItem action adds item to field and removeItemByIndex removes correct item', async function (assert) {
|
||||
const authMethodModel = await store.findRecord(
|
||||
'auth-method',
|
||||
instances.authMethod.id,
|
||||
);
|
||||
|
||||
controller.addAccountMapItem(
|
||||
authMethodModel,
|
||||
'account_attribute_maps',
|
||||
'name123',
|
||||
'fullName',
|
||||
);
|
||||
|
||||
assert.deepEqual(authMethodModel.account_attribute_maps, [
|
||||
{ from: 'name123', to: 'fullName' },
|
||||
]);
|
||||
|
||||
controller.addAccountMapItem(
|
||||
authMethodModel,
|
||||
'account_attribute_maps',
|
||||
'name456',
|
||||
'fullName',
|
||||
);
|
||||
controller.removeItemByIndex(authMethodModel, 'account_attribute_maps', 0);
|
||||
|
||||
assert.deepEqual(authMethodModel.account_attribute_maps, [
|
||||
{ from: 'name456', to: 'fullName' },
|
||||
]);
|
||||
});
|
||||
|
||||
test('edit action updates to a dirty state', async function (assert) {
|
||||
const authMethodModel = await store.findRecord(
|
||||
'auth-method',
|
||||
instances.authMethod.id,
|
||||
);
|
||||
|
||||
assert.false(authMethodModel.hasDirtyAttributes);
|
||||
|
||||
controller.edit(authMethodModel);
|
||||
|
||||
assert.true(authMethodModel.hasDirtyAttributes);
|
||||
});
|
||||
|
||||
test('changeState action updates state of auth-method', async function (assert) {
|
||||
instances.authMethod.update({ type: TYPE_AUTH_METHOD_LDAP });
|
||||
const authMethodModelBefore = await store.findRecord(
|
||||
'auth-method',
|
||||
instances.authMethod.id,
|
||||
);
|
||||
|
||||
assert.notOk(authMethodModelBefore.state);
|
||||
|
||||
await controller.changeState(authMethodModelBefore, 'public');
|
||||
|
||||
const authMethodModelAfter = await store.findRecord(
|
||||
'auth-method',
|
||||
instances.authMethod.id,
|
||||
);
|
||||
|
||||
assert.strictEqual(authMethodModelAfter.state, 'public');
|
||||
});
|
||||
});
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'admin/tests/helpers';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
|
||||
module('Unit | Controller | scopes/scope/auth-methods/new', function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
Reference in new issue
Block a user