refactor: 💡 Remove route-action usage for managed-groups (#2168)
* refactor: 💡 Remove route-action usage for managed-groups ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12619
This commit is contained in:
1 parent
47a218cf8f
commit
98170ed01e
15 files changed
+217
-93
No files matched your search
+1
-1
@@ -12,7 +12,7 @@
|
||||
<dropdown.button
|
||||
@style='danger'
|
||||
@disabled={{@model.canSave}}
|
||||
{{on 'click' (route-action 'deleteManagedGroup' @model)}}
|
||||
{{on 'click' (fn @delete @model)}}
|
||||
>
|
||||
{{t 'resources.managed-group.actions.delete'}}
|
||||
</dropdown.button>
|
||||
|
||||
+89
@@ -0,0 +1,89 @@
|
||||
import Controller from '@ember/controller';
|
||||
import { action } from '@ember/object';
|
||||
import { inject as service } from '@ember/service';
|
||||
import { loading } from 'ember-loading';
|
||||
import { confirm } from 'core/decorators/confirm';
|
||||
import { notifySuccess, notifyError } from 'core/decorators/notify';
|
||||
|
||||
export default class ScopesScopeAuthMethodsAuthMethodManagedGroupsIndexController extends Controller {
|
||||
// =services
|
||||
|
||||
@service can;
|
||||
@service router;
|
||||
|
||||
// =actions
|
||||
|
||||
/**
|
||||
* Rollback changes on a managed group.
|
||||
* @param {ManagedGroupModel} managedGroup
|
||||
*/
|
||||
@action
|
||||
async cancel(managedGroup) {
|
||||
const { isNew } = managedGroup;
|
||||
managedGroup.rollbackAttributes();
|
||||
if (isNew) {
|
||||
await this.router.transitionTo(
|
||||
'scopes.scope.auth-methods.auth-method.managed-groups',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save a managed group in current scope.
|
||||
* @param {ManagedGroupModel} managedGroup
|
||||
*/
|
||||
@action
|
||||
@loading
|
||||
@notifyError(({ message }) => message)
|
||||
@notifySuccess(({ isNew }) =>
|
||||
isNew ? 'notifications.create-success' : 'notifications.save-success',
|
||||
)
|
||||
async save(managedGroup) {
|
||||
await managedGroup.save();
|
||||
if (this.can.can('read model', managedGroup)) {
|
||||
await this.router.transitionTo(
|
||||
'scopes.scope.auth-methods.auth-method.managed-groups.managed-group',
|
||||
managedGroup,
|
||||
);
|
||||
} else {
|
||||
await this.router.transitionTo(
|
||||
'scopes.scope.auth-methods.auth-method.managed-groups',
|
||||
);
|
||||
}
|
||||
await this.router.refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a managed group in current scope and redirect to index
|
||||
* @param {ManagedGroupModel} managed group
|
||||
*/
|
||||
@action
|
||||
@loading
|
||||
@confirm('questions.delete-confirm')
|
||||
@notifyError(({ message }) => message, { catch: true })
|
||||
@notifySuccess('notifications.delete-success')
|
||||
async delete(managedGroup) {
|
||||
await managedGroup.destroyRecord();
|
||||
await this.router.replaceWith(
|
||||
'scopes.scope.auth-methods.auth-method.managed-groups',
|
||||
);
|
||||
await this.router.refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 {managedGroupModel} managedGroup
|
||||
*/
|
||||
@action
|
||||
edit(managedGroup) {
|
||||
if (managedGroup.group_names) {
|
||||
managedGroup.group_names = structuredClone(managedGroup.group_names);
|
||||
}
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
import Controller, { inject as controller } from '@ember/controller';
|
||||
|
||||
export default class ScopesScopeAuthMethodsAuthMethodManagedGroupsManagedGroupIndexController extends Controller {
|
||||
@controller('scopes/scope/auth-methods/index') authMethods;
|
||||
@controller('scopes/scope/auth-methods/auth-method/managed-groups/index')
|
||||
managedGroups;
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
import Controller, { inject as controller } from '@ember/controller';
|
||||
|
||||
export default class ScopesScopeAuthMethodsAuthMethodManagedGroupsManagedGroupMembersController extends Controller {
|
||||
@controller('scopes/scope/auth-methods/auth-method/managed-groups/index')
|
||||
managedGroups;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
import Controller, { inject as controller } from '@ember/controller';
|
||||
|
||||
export default class ScopesScopeAuthMethodsAuthMethodManagedGroupsNewController extends Controller {
|
||||
@controller('scopes/scope/auth-methods/index') authMethods;
|
||||
@controller('scopes/scope/auth-methods/auth-method/managed-groups/index')
|
||||
managedGroups;
|
||||
}
|
||||
@@ -4,6 +4,7 @@
|
||||
*/
|
||||
|
||||
import Controller from '@ember/controller';
|
||||
import { action } from '@ember/object';
|
||||
|
||||
export default class ScopesScopeAuthMethodsIndexController extends Controller {
|
||||
// =attributes
|
||||
@@ -15,4 +16,35 @@ export default class ScopesScopeAuthMethodsIndexController extends Controller {
|
||||
get hasPrimaryAuthMethod() {
|
||||
return Boolean(this.scopeModel.primary_auth_method_id);
|
||||
}
|
||||
|
||||
// =actions
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
@@ -4,19 +4,13 @@
|
||||
*/
|
||||
|
||||
import Route from '@ember/routing/route';
|
||||
import { action } from '@ember/object';
|
||||
import { inject as service } from '@ember/service';
|
||||
import { loading } from 'ember-loading';
|
||||
import { confirm } from 'core/decorators/confirm';
|
||||
import { notifySuccess, notifyError } from 'core/decorators/notify';
|
||||
|
||||
export default class ScopesScopeAuthMethodsAuthMethodManagedGroupsRoute extends Route {
|
||||
// =services
|
||||
|
||||
@service store;
|
||||
@service intl;
|
||||
@service can;
|
||||
@service router;
|
||||
|
||||
//=methods
|
||||
|
||||
@@ -43,62 +37,4 @@ export default class ScopesScopeAuthMethodsAuthMethodManagedGroupsRoute extends
|
||||
managedGroups,
|
||||
};
|
||||
}
|
||||
|
||||
// =actions
|
||||
/**
|
||||
* Rollback changes on a managed group.
|
||||
* @param {ManagedGroupModel} managedGroup
|
||||
*/
|
||||
@action
|
||||
cancel(managedGroup) {
|
||||
const { isNew } = managedGroup;
|
||||
managedGroup.rollbackAttributes();
|
||||
if (isNew) {
|
||||
this.router.transitionTo(
|
||||
'scopes.scope.auth-methods.auth-method.managed-groups',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save a managed group in current scope.
|
||||
* @param {ManagedGroupModel} managedGroup
|
||||
*/
|
||||
@action
|
||||
@loading
|
||||
@notifyError(({ message }) => message)
|
||||
@notifySuccess(({ isNew }) =>
|
||||
isNew ? 'notifications.create-success' : 'notifications.save-success',
|
||||
)
|
||||
async save(managedGroup) {
|
||||
await managedGroup.save();
|
||||
if (this.can.can('read model', managedGroup)) {
|
||||
await this.router.transitionTo(
|
||||
'scopes.scope.auth-methods.auth-method.managed-groups.managed-group',
|
||||
managedGroup,
|
||||
);
|
||||
} else {
|
||||
await this.router.transitionTo(
|
||||
'scopes.scope.auth-methods.auth-method.managed-groups',
|
||||
);
|
||||
}
|
||||
this.refresh();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a managed group in current scope and redirect to index
|
||||
* @param {ManagedGroupModel} managed group
|
||||
*/
|
||||
@action
|
||||
@loading
|
||||
@confirm('questions.delete-confirm')
|
||||
@notifyError(({ message }) => message, { catch: true })
|
||||
@notifySuccess('notifications.delete-success')
|
||||
async deleteManagedGroup(managedGroup) {
|
||||
await managedGroup.destroyRecord();
|
||||
await this.router.replaceWith(
|
||||
'scopes.scope.auth-methods.auth-method.managed-groups',
|
||||
);
|
||||
this.refresh();
|
||||
}
|
||||
}
|
||||
-19
@@ -4,14 +4,12 @@
|
||||
*/
|
||||
|
||||
import Route from '@ember/routing/route';
|
||||
import { action } from '@ember/object';
|
||||
import { inject as service } from '@ember/service';
|
||||
|
||||
export default class ScopesScopeAuthMethodsAuthMethodManagedGroupsManagedGroupRoute extends Route {
|
||||
// =services
|
||||
|
||||
@service store;
|
||||
@service can;
|
||||
@service router;
|
||||
|
||||
// =methods
|
||||
@@ -44,21 +42,4 @@ export default class ScopesScopeAuthMethodsAuthMethodManagedGroupsManagedGroupRo
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 {managedGroupModel} managedGroup
|
||||
*/
|
||||
@action
|
||||
edit(managedGroup) {
|
||||
if (managedGroup.group_names) {
|
||||
managedGroup.group_names = structuredClone(managedGroup.group_names);
|
||||
}
|
||||
}
|
||||
}
|
||||
+6
-5
@@ -24,17 +24,18 @@
|
||||
<page.actions>
|
||||
<AuthMethods::AuthMethod::ManagedGroups::ManagedGroup::Actions
|
||||
@model={{@model}}
|
||||
@delete={{this.managedGroups.delete}}
|
||||
/>
|
||||
</page.actions>
|
||||
|
||||
<page.body>
|
||||
<Form::ManagedGroup
|
||||
@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}}
|
||||
@edit={{fn this.managedGroups.edit @model}}
|
||||
@submit={{fn this.managedGroups.save @model}}
|
||||
@cancel={{fn this.managedGroups.cancel @model}}
|
||||
@removeItemByIndex={{fn this.authMethods.removeItemByIndex @model}}
|
||||
@addStringItem={{fn this.authMethods.addStringItem @model}}
|
||||
/>
|
||||
</page.body>
|
||||
|
||||
|
||||
+1
@@ -30,6 +30,7 @@
|
||||
<page.actions>
|
||||
<AuthMethods::AuthMethod::ManagedGroups::ManagedGroup::Actions
|
||||
@model={{@model.managedGroup}}
|
||||
@delete={{this.managedGroups.delete}}
|
||||
/>
|
||||
</page.actions>
|
||||
|
||||
|
||||
@@ -26,10 +26,10 @@
|
||||
<page.body>
|
||||
<Form::ManagedGroup
|
||||
@model={{@model}}
|
||||
@submit={{route-action 'save' @model}}
|
||||
@cancel={{route-action 'cancel' @model}}
|
||||
@removeItemByIndex={{route-action 'removeItemByIndex' @model}}
|
||||
@addStringItem={{route-action 'addStringItem' @model}}
|
||||
@submit={{fn this.managedGroups.save @model}}
|
||||
@cancel={{fn this.managedGroups.cancel @model}}
|
||||
@removeItemByIndex={{fn this.authMethods.removeItemByIndex @model}}
|
||||
@addStringItem={{fn this.authMethods.addStringItem @model}}
|
||||
/>
|
||||
</page.body>
|
||||
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
|
||||
module(
|
||||
'Unit | Controller | scopes/scope/auth-methods/auth-method/managed-groups/index',
|
||||
function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
test('it exists', function (assert) {
|
||||
let controller = this.owner.lookup(
|
||||
'controller:scopes/scope/auth-methods/auth-method/managed-groups/index',
|
||||
);
|
||||
assert.ok(controller);
|
||||
});
|
||||
},
|
||||
);
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
|
||||
module(
|
||||
'Unit | Controller | scopes/scope/auth-methods/auth-method/managed-groups/managed-group/index',
|
||||
function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
test('it exists', function (assert) {
|
||||
let controller = this.owner.lookup(
|
||||
'controller:scopes/scope/auth-methods/auth-method/managed-groups/managed-group/index',
|
||||
);
|
||||
assert.ok(controller);
|
||||
});
|
||||
},
|
||||
);
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
|
||||
module(
|
||||
'Unit | Controller | scopes/scope/auth-methods/auth-method/managed-groups/managed-group/members',
|
||||
function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
test('it exists', function (assert) {
|
||||
let controller = this.owner.lookup(
|
||||
'controller:scopes/scope/auth-methods/auth-method/managed-groups/managed-group/members',
|
||||
);
|
||||
assert.ok(controller);
|
||||
});
|
||||
},
|
||||
);
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
import { module, test } from 'qunit';
|
||||
import { setupTest } from 'ember-qunit';
|
||||
|
||||
module(
|
||||
'Unit | Controller | scopes/scope/auth-methods/auth-method/managed-groups/new',
|
||||
function (hooks) {
|
||||
setupTest(hooks);
|
||||
|
||||
test('it exists', function (assert) {
|
||||
let controller = this.owner.lookup(
|
||||
'controller:scopes/scope/auth-methods/auth-method/managed-groups/new',
|
||||
);
|
||||
assert.ok(controller);
|
||||
});
|
||||
},
|
||||
);
|
||||
Reference in new issue
Block a user