Files
threshold-ui/ui/admin/app/routes/scopes/scope/auth-methods/auth-method.js
T

75 lines
2.0 KiB
JavaScript
Raw Normal View History

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
2020-08-12 17:16:41 -04:00
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';
2020-08-12 17:16:41 -04:00
export default class ScopesScopeAuthMethodsAuthMethodRoute extends Route {
// =services
@service store;
2020-08-12 17:16:41 -04:00
// =methods
/**
2020-09-16 09:48:07 -04:00
* Load an auth method by ID.
2020-08-12 17:16:41 -04:00
* @param {object} params
* @param {string} params.auth_method_id
* @return {authMethodModel}
*/
2020-09-09 12:24:01 -04:00
async model({ auth_method_id }) {
return this.store.findRecord('auth-method', auth_method_id);
2020-08-12 17:16:41 -04:00
}
2020-09-14 15:58:06 -04:00
// =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
);
}
}
/**
* Update state of OIDC 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);
}
2020-08-12 17:16:41 -04:00
}