* refactor: 💡 auth-method, account, & managed abilities & routes * refactor: 💡 credential store resources abilities & routes * refactor: 💡 group abilities & routes * refactor: 💡 host-catalog resources abilities & routes * refactor: 💡 role abilities & routes * test: 💍 fix route-info-test * test: 💍 fix host serializer tests * test: 💍 fix create-test for host-sets * refactor: 💡 session recording resources abilities & routes * refactor: 💡 storage bucket abilities & routes * refactor: 💡 target abilities & routes * refactor: 💡 user abilities & routes * refactor: 💡 worker abilities & routes * refactor: 💡 remove ability changes and add comments * Update ui/admin/app/utils/route-info.js Co-authored-by: Zhihe Li <zhihe.li@hashicorp.com> * test: 💍 add test cases and rename util file * refactor: 💡 remove dup file and update imports ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-11282 * docs: ✏️ update comments & remove console.log ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-11282 * Update ui/admin/app/routes/scopes/scope/auth-methods/auth-method.js Co-authored-by: Dharini Jeeva <dharini@hashicorp.com> --------- Co-authored-by: Zhihe Li <zhihe.li@hashicorp.com> Co-authored-by: Dharini Jeeva <dharini@hashicorp.com>
108 lines
2.9 KiB
JavaScript
108 lines
2.9 KiB
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
*/
|
|
|
|
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';
|
|
|
|
export default class ScopesScopeAuthMethodsAuthMethodRoute extends Route {
|
|
// =services
|
|
|
|
@service store;
|
|
@service can;
|
|
@service router;
|
|
|
|
// =methods
|
|
|
|
/**
|
|
* Load an auth method by ID.
|
|
* @param {object} params
|
|
* @param {string} params.auth_method_id
|
|
* @return {Promise{AuthMethodModel}}
|
|
*/
|
|
async model({ auth_method_id }) {
|
|
return this.store.findRecord('auth-method', auth_method_id, {
|
|
reload: true,
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Redirects to route with correct scope id if incorrect.
|
|
* @param {AuthMethodModel} authMethod
|
|
* @param {object} transition
|
|
*/
|
|
redirect(authMethod, transition) {
|
|
const scope = this.modelFor('scopes.scope');
|
|
if (authMethod.scopeID !== scope.id) {
|
|
let paramValues = paramValueFinder('auth-method', transition.to.parent);
|
|
this.router.replaceWith(
|
|
transition.to.name,
|
|
authMethod.scopeID,
|
|
authMethod.id,
|
|
...paramValues
|
|
);
|
|
}
|
|
}
|
|
|
|
// =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);
|
|
}
|
|
}
|