diff --git a/ui/admin/app/components/auth-methods/auth-method/managed-groups/managed-group/actions/index.hbs b/ui/admin/app/components/auth-methods/auth-method/managed-groups/managed-group/actions/index.hbs index 6f7b6d1ca..187f728d8 100644 --- a/ui/admin/app/components/auth-methods/auth-method/managed-groups/managed-group/actions/index.hbs +++ b/ui/admin/app/components/auth-methods/auth-method/managed-groups/managed-group/actions/index.hbs @@ -12,7 +12,7 @@ {{t 'resources.managed-group.actions.delete'}} diff --git a/ui/admin/app/controllers/scopes/scope/auth-methods/auth-method/managed-groups/index.js b/ui/admin/app/controllers/scopes/scope/auth-methods/auth-method/managed-groups/index.js new file mode 100644 index 000000000..b384b6114 --- /dev/null +++ b/ui/admin/app/controllers/scopes/scope/auth-methods/auth-method/managed-groups/index.js @@ -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); + } + } +} diff --git a/ui/admin/app/controllers/scopes/scope/auth-methods/auth-method/managed-groups/managed-group/index.js b/ui/admin/app/controllers/scopes/scope/auth-methods/auth-method/managed-groups/managed-group/index.js new file mode 100644 index 000000000..1c09e2919 --- /dev/null +++ b/ui/admin/app/controllers/scopes/scope/auth-methods/auth-method/managed-groups/managed-group/index.js @@ -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; +} diff --git a/ui/admin/app/controllers/scopes/scope/auth-methods/auth-method/managed-groups/managed-group/members.js b/ui/admin/app/controllers/scopes/scope/auth-methods/auth-method/managed-groups/managed-group/members.js new file mode 100644 index 000000000..bbaad9d83 --- /dev/null +++ b/ui/admin/app/controllers/scopes/scope/auth-methods/auth-method/managed-groups/managed-group/members.js @@ -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; +} diff --git a/ui/admin/app/controllers/scopes/scope/auth-methods/auth-method/managed-groups/new.js b/ui/admin/app/controllers/scopes/scope/auth-methods/auth-method/managed-groups/new.js new file mode 100644 index 000000000..aaa1503b6 --- /dev/null +++ b/ui/admin/app/controllers/scopes/scope/auth-methods/auth-method/managed-groups/new.js @@ -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; +} diff --git a/ui/admin/app/controllers/scopes/scope/auth-methods/index.js b/ui/admin/app/controllers/scopes/scope/auth-methods/index.js index 6b055f9a6..9d03c4899 100644 --- a/ui/admin/app/controllers/scopes/scope/auth-methods/index.js +++ b/ui/admin/app/controllers/scopes/scope/auth-methods/index.js @@ -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); + } } diff --git a/ui/admin/app/routes/scopes/scope/auth-methods/auth-method/managed-groups.js b/ui/admin/app/routes/scopes/scope/auth-methods/auth-method/managed-groups.js index 84c0e40cb..ee61a2baf 100644 --- a/ui/admin/app/routes/scopes/scope/auth-methods/auth-method/managed-groups.js +++ b/ui/admin/app/routes/scopes/scope/auth-methods/auth-method/managed-groups.js @@ -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(); - } } diff --git a/ui/admin/app/routes/scopes/scope/auth-methods/auth-method/managed-groups/managed-group.js b/ui/admin/app/routes/scopes/scope/auth-methods/auth-method/managed-groups/managed-group.js index 1ac4971a4..0f41cdf54 100644 --- a/ui/admin/app/routes/scopes/scope/auth-methods/auth-method/managed-groups/managed-group.js +++ b/ui/admin/app/routes/scopes/scope/auth-methods/auth-method/managed-groups/managed-group.js @@ -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); - } - } } diff --git a/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/managed-groups/managed-group/index.hbs b/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/managed-groups/managed-group/index.hbs index 99760de94..1c90bdc43 100644 --- a/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/managed-groups/managed-group/index.hbs +++ b/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/managed-groups/managed-group/index.hbs @@ -24,17 +24,18 @@ diff --git a/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/managed-groups/managed-group/members.hbs b/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/managed-groups/managed-group/members.hbs index b90a8aece..7a435911e 100644 --- a/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/managed-groups/managed-group/members.hbs +++ b/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/managed-groups/managed-group/members.hbs @@ -30,6 +30,7 @@ diff --git a/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/managed-groups/new.hbs b/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/managed-groups/new.hbs index 97cced906..b8592d96d 100644 --- a/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/managed-groups/new.hbs +++ b/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/managed-groups/new.hbs @@ -26,10 +26,10 @@ diff --git a/ui/admin/tests/unit/controllers/scopes/scope/auth-methods/auth-method/managed-groups/index-test.js b/ui/admin/tests/unit/controllers/scopes/scope/auth-methods/auth-method/managed-groups/index-test.js new file mode 100644 index 000000000..a62b1d4ae --- /dev/null +++ b/ui/admin/tests/unit/controllers/scopes/scope/auth-methods/auth-method/managed-groups/index-test.js @@ -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); + }); + }, +); diff --git a/ui/admin/tests/unit/controllers/scopes/scope/auth-methods/auth-method/managed-groups/managed-group/index-test.js b/ui/admin/tests/unit/controllers/scopes/scope/auth-methods/auth-method/managed-groups/managed-group/index-test.js new file mode 100644 index 000000000..950c52129 --- /dev/null +++ b/ui/admin/tests/unit/controllers/scopes/scope/auth-methods/auth-method/managed-groups/managed-group/index-test.js @@ -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); + }); + }, +); diff --git a/ui/admin/tests/unit/controllers/scopes/scope/auth-methods/auth-method/managed-groups/managed-group/members-test.js b/ui/admin/tests/unit/controllers/scopes/scope/auth-methods/auth-method/managed-groups/managed-group/members-test.js new file mode 100644 index 000000000..9f6fecdc2 --- /dev/null +++ b/ui/admin/tests/unit/controllers/scopes/scope/auth-methods/auth-method/managed-groups/managed-group/members-test.js @@ -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); + }); + }, +); diff --git a/ui/admin/tests/unit/controllers/scopes/scope/auth-methods/auth-method/managed-groups/new-test.js b/ui/admin/tests/unit/controllers/scopes/scope/auth-methods/auth-method/managed-groups/new-test.js new file mode 100644 index 000000000..796d71b16 --- /dev/null +++ b/ui/admin/tests/unit/controllers/scopes/scope/auth-methods/auth-method/managed-groups/new-test.js @@ -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); + }); + }, +);