2020-08-12 15:43:34 -04:00
|
|
|
import Route from '@ember/routing/route';
|
2020-08-12 17:16:41 -04:00
|
|
|
import { inject as service } from '@ember/service';
|
|
|
|
|
import { action } from '@ember/object';
|
2022-01-03 09:28:24 -05:00
|
|
|
import { loading } from 'ember-loading';
|
2020-11-18 13:19:46 -05:00
|
|
|
import { confirm } from 'core/decorators/confirm';
|
2020-11-18 13:59:11 -05:00
|
|
|
import { notifySuccess, notifyError } from 'core/decorators/notify';
|
2021-12-06 17:26:36 -05:00
|
|
|
import { resourceFilter } from 'core/decorators/resource-filter';
|
2020-08-12 15:43:34 -04:00
|
|
|
|
|
|
|
|
export default class ScopesScopeAuthMethodsRoute extends Route {
|
2020-08-12 17:16:41 -04:00
|
|
|
// =services
|
|
|
|
|
|
|
|
|
|
@service intl;
|
|
|
|
|
@service notify;
|
2020-08-18 16:49:45 -04:00
|
|
|
@service session;
|
2021-08-30 19:16:58 -07:00
|
|
|
@service can;
|
2021-11-10 12:40:07 -05:00
|
|
|
@service resourceFilterStore;
|
2022-01-03 12:12:53 -05:00
|
|
|
@service router;
|
2021-11-10 12:40:07 -05:00
|
|
|
|
|
|
|
|
// =attributes
|
|
|
|
|
|
2021-12-06 17:26:36 -05:00
|
|
|
@resourceFilter({ allowed: ['password', 'oidc'] }) type;
|
2020-08-12 17:16:41 -04:00
|
|
|
|
2020-08-12 15:43:34 -04:00
|
|
|
// =methods
|
|
|
|
|
|
2020-08-18 16:49:45 -04:00
|
|
|
/**
|
|
|
|
|
* If arriving here unauthenticated, redirect to index for further processing.
|
|
|
|
|
*/
|
|
|
|
|
beforeModel() {
|
2022-01-03 12:35:48 -05:00
|
|
|
if (!this.session.isAuthenticated) this.router.transitionTo('index');
|
2020-08-18 16:49:45 -04:00
|
|
|
}
|
|
|
|
|
|
2020-08-12 15:43:34 -04:00
|
|
|
/**
|
|
|
|
|
* Load all auth-methods under current scope
|
|
|
|
|
* @return {Promise[AuthMethodModel]}
|
|
|
|
|
*/
|
|
|
|
|
async model() {
|
2021-08-30 19:16:58 -07:00
|
|
|
const scope = this.modelFor('scopes.scope');
|
|
|
|
|
const { id: scope_id } = scope;
|
|
|
|
|
if (
|
|
|
|
|
this.can.can('list collection', scope, { collection: 'auth-methods' })
|
|
|
|
|
) {
|
2021-11-10 12:40:07 -05:00
|
|
|
const { type } = this;
|
|
|
|
|
return this.resourceFilterStore.queryBy(
|
|
|
|
|
'auth-method',
|
|
|
|
|
{ type },
|
|
|
|
|
{ scope_id }
|
|
|
|
|
);
|
2021-08-30 19:16:58 -07:00
|
|
|
}
|
2020-08-12 15:43:34 -04:00
|
|
|
}
|
2020-08-12 17:16:41 -04:00
|
|
|
|
|
|
|
|
// =actions
|
|
|
|
|
/**
|
|
|
|
|
* Rollback changes to an auth-method.
|
|
|
|
|
* @param {AuthMethodModel} authMethod
|
|
|
|
|
*/
|
|
|
|
|
@action
|
|
|
|
|
cancel(authMethod) {
|
|
|
|
|
const { isNew } = authMethod;
|
|
|
|
|
authMethod.rollbackAttributes();
|
2022-01-03 12:35:48 -05:00
|
|
|
if (isNew) this.router.transitionTo('scopes.scope.auth-methods');
|
2020-08-12 17:16:41 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Save an auth-method in current scope.
|
|
|
|
|
* @param {AuthMethodModel} authMethod
|
|
|
|
|
*/
|
|
|
|
|
@action
|
2020-09-25 18:09:56 -04:00
|
|
|
@loading
|
2020-10-08 18:11:48 -04:00
|
|
|
@notifyError(({ message }) => message)
|
2020-11-16 15:08:59 -05:00
|
|
|
@notifySuccess(({ isNew }) =>
|
|
|
|
|
isNew ? 'notifications.create-success' : 'notifications.save-success'
|
|
|
|
|
)
|
2020-08-12 17:16:41 -04:00
|
|
|
async save(authMethod) {
|
2020-10-08 18:11:48 -04:00
|
|
|
await authMethod.save();
|
2021-09-08 11:29:13 -07:00
|
|
|
if (this.can.can('read model', authMethod)) {
|
2022-01-03 12:35:48 -05:00
|
|
|
await this.router.transitionTo(
|
2021-09-08 11:29:13 -07:00
|
|
|
'scopes.scope.auth-methods.auth-method',
|
|
|
|
|
authMethod
|
|
|
|
|
);
|
|
|
|
|
} else {
|
2022-01-03 12:35:48 -05:00
|
|
|
await this.router.transitionTo('scopes.scope.auth-methods');
|
2021-09-08 11:29:13 -07:00
|
|
|
}
|
2020-10-08 18:11:48 -04:00
|
|
|
this.refresh();
|
2020-08-12 17:16:41 -04:00
|
|
|
}
|
2020-08-19 17:10:48 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Delete an auth method in current scope and redirect to index
|
|
|
|
|
* @param {AuthMethodModel} authMethod
|
|
|
|
|
*/
|
|
|
|
|
@action
|
2020-09-25 18:09:56 -04:00
|
|
|
@loading
|
2020-09-30 18:41:55 -04:00
|
|
|
@confirm('questions.delete-confirm')
|
2020-10-08 18:11:48 -04:00
|
|
|
@notifyError(({ message }) => message, { catch: true })
|
|
|
|
|
@notifySuccess('notifications.delete-success')
|
2020-08-19 17:10:48 -04:00
|
|
|
async delete(authMethod) {
|
2021-03-26 11:33:43 -04:00
|
|
|
const scopeModel = this.modelFor('scopes.scope');
|
2020-10-08 18:11:48 -04:00
|
|
|
await authMethod.destroyRecord();
|
2021-03-26 11:33:43 -04:00
|
|
|
// 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();
|
2022-01-03 12:12:53 -05:00
|
|
|
await this.router.replaceWith('scopes.scope.auth-methods');
|
2020-10-08 18:11:48 -04:00
|
|
|
this.refresh();
|
2020-08-19 17:10:48 -04:00
|
|
|
}
|
2021-03-26 12:47:49 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Elects the specified auth method to primary for the current scope.
|
|
|
|
|
* @param {AuthMethodModel} authMethod
|
|
|
|
|
* @param {string} authMethod.id
|
|
|
|
|
*/
|
|
|
|
|
@action
|
|
|
|
|
@loading
|
2021-03-29 19:24:21 -04:00
|
|
|
@confirm('resources.auth-method.questions.make-primary-confirm', {
|
|
|
|
|
title: 'resources.auth-method.questions.make-primary',
|
|
|
|
|
})
|
2021-03-26 12:47:49 -04:00
|
|
|
@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
|
2021-03-29 19:24:21 -04:00
|
|
|
@confirm('resources.auth-method.questions.remove-as-primary-confirm', {
|
|
|
|
|
title: 'resources.auth-method.questions.remove-as-primary',
|
|
|
|
|
})
|
2021-03-26 12:47:49 -04:00
|
|
|
@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();
|
|
|
|
|
}
|
2021-05-26 15:28:41 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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);
|
|
|
|
|
array.removeAt(index);
|
|
|
|
|
}
|
2021-05-26 17:12:51 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Adds a string item to array `property` on the passed `authMethod`.
|
2021-05-26 18:09:28 -04:00
|
|
|
* This is used to manage entries in fragment OIDC string array fields such
|
2021-05-26 17:12:51 -04:00
|
|
|
* as `signing_algorithms`.
|
|
|
|
|
* @param {AuthMethodModel} authMethod
|
|
|
|
|
* @param {string} property
|
|
|
|
|
* @param {string} value
|
|
|
|
|
*/
|
|
|
|
|
@action
|
|
|
|
|
async addStringItem(authMethod, property, value) {
|
|
|
|
|
const array = authMethod.get(property);
|
|
|
|
|
array.addObject({ value });
|
|
|
|
|
}
|
2021-05-26 18:09:28 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Adds an account claim map fragment to the passed OIDC `authMethod`.
|
|
|
|
|
* @param {AuthMethodModel} authMethod
|
|
|
|
|
* @param {string} property
|
|
|
|
|
* @param {string} value
|
|
|
|
|
*/
|
|
|
|
|
@action
|
|
|
|
|
async addAccountClaimMapItem(authMethod, from, to) {
|
|
|
|
|
const array = authMethod.attributes.account_claim_maps;
|
|
|
|
|
const value = { from, to };
|
|
|
|
|
array.addObject(value);
|
|
|
|
|
}
|
2021-11-10 12:40:07 -05:00
|
|
|
|
2021-11-12 16:11:45 -05:00
|
|
|
/**
|
|
|
|
|
* Sets the specified resource filter field to the specified value.
|
|
|
|
|
* @param {string} field
|
|
|
|
|
* @param value
|
|
|
|
|
*/
|
2021-11-10 12:40:07 -05:00
|
|
|
@action
|
|
|
|
|
filterBy(field, value) {
|
|
|
|
|
this[field] = value;
|
|
|
|
|
}
|
2021-11-12 16:11:45 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Clears and filter selections.
|
|
|
|
|
*/
|
|
|
|
|
@action
|
|
|
|
|
clearAllFilters() {
|
|
|
|
|
this.type = [];
|
|
|
|
|
}
|
2020-08-12 15:43:34 -04:00
|
|
|
}
|