* 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>
56 lines
1.2 KiB
JavaScript
56 lines
1.2 KiB
JavaScript
/**
|
|
* Copyright (c) HashiCorp, Inc.
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
*/
|
|
|
|
import Route from '@ember/routing/route';
|
|
import { action } from '@ember/object';
|
|
import { inject as service } from '@ember/service';
|
|
|
|
export default class ScopesScopeRolesRoleRoute extends Route {
|
|
// =services
|
|
|
|
@service store;
|
|
@service can;
|
|
@service router;
|
|
|
|
// =methods
|
|
|
|
/**
|
|
* Load a role in current scope.
|
|
* @param {object} params
|
|
* @param {string} params.role_id
|
|
* @return {Promise{RoleModel}}
|
|
*/
|
|
async model({ role_id }) {
|
|
const { id: scopeID } = this.modelFor('scopes.scope');
|
|
return this.store.findRecord('role', role_id, {
|
|
reload: true,
|
|
adapterOptions: { scopeID },
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Redirects to route with correct scope id if incorrect.
|
|
* @param {RoleModel} role
|
|
* @param {object} transition
|
|
*/
|
|
redirect(role, transition) {
|
|
const scope = this.modelFor('scopes.scope');
|
|
if (role.scopeID !== scope.id) {
|
|
this.router.replaceWith(transition.to.name, role.scopeID, role.id);
|
|
}
|
|
}
|
|
|
|
// =actions
|
|
/**
|
|
* Rollback changes on a role.
|
|
* @param {RoleModel} role
|
|
*/
|
|
@action
|
|
cancel(role) {
|
|
role.rollbackAttributes();
|
|
this.refresh();
|
|
}
|
|
}
|