From b7bf44b997bd197923bf4140045a061277359a86 Mon Sep 17 00:00:00 2001 From: Carlos Alcaide Corvo Date: Tue, 9 Nov 2021 10:29:49 -0800 Subject: [PATCH 01/11] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20Add=20managed=20gr?= =?UTF-8?q?oups=20read=20CRUD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add managed groups Read CRUD operation --- addons/api/mirage/config.js | 1 + addons/core/translations/form/en-us.yaml | 2 + addons/core/translations/resources/en-us.yaml | 3 ++ .../components/form/managed-group/index.hbs | 54 +++++++++++++++++++ ui/admin/app/router.js | 8 ++- .../auth-method/managed-groups.js | 15 ++++++ .../auth-method/managed-groups/index.js | 8 ++- .../managed-groups/managed-group.js | 49 +++++++++++++++++ .../managed-groups/managed-group/index.js | 3 ++ .../auth-method/managed-groups/index.hbs | 11 +++- .../managed-groups/managed-group.hbs | 2 + .../managed-groups/managed-group/-actions.hbs | 11 ++++ .../managed-groups/managed-group/-header.hbs | 12 +++++ .../managed-group/-navigation.hbs | 7 +++ .../managed-groups/managed-group/index.hbs | 1 + ui/admin/config/environment.js | 1 + .../managed-groups/managed-group-test.js | 16 ++++++ .../managed-group/index-test.js | 16 ++++++ 18 files changed, 217 insertions(+), 3 deletions(-) create mode 100644 ui/admin/app/components/form/managed-group/index.hbs create mode 100644 ui/admin/app/routes/scopes/scope/auth-methods/auth-method/managed-groups/managed-group.js create mode 100644 ui/admin/app/routes/scopes/scope/auth-methods/auth-method/managed-groups/managed-group/index.js create mode 100644 ui/admin/app/templates/scopes/scope/auth-methods/auth-method/managed-groups/managed-group.hbs create mode 100644 ui/admin/app/templates/scopes/scope/auth-methods/auth-method/managed-groups/managed-group/-actions.hbs create mode 100644 ui/admin/app/templates/scopes/scope/auth-methods/auth-method/managed-groups/managed-group/-header.hbs create mode 100644 ui/admin/app/templates/scopes/scope/auth-methods/auth-method/managed-groups/managed-group/-navigation.hbs create mode 100644 ui/admin/app/templates/scopes/scope/auth-methods/auth-method/managed-groups/managed-group/index.hbs create mode 100644 ui/admin/tests/unit/routes/scopes/scope/auth-methods/auth-method/managed-groups/managed-group-test.js create mode 100644 ui/admin/tests/unit/routes/scopes/scope/auth-methods/auth-method/managed-groups/managed-group/index-test.js diff --git a/addons/api/mirage/config.js b/addons/api/mirage/config.js index 89e2a82b5..8c62edd5e 100644 --- a/addons/api/mirage/config.js +++ b/addons/api/mirage/config.js @@ -521,6 +521,7 @@ export default function () { return managedGroups.where({ authMethodId }); } ); + this.get('/managed-groups/:id'); /* Uncomment the following line and the Response import above * Then change the response code to simulate error responses. diff --git a/addons/core/translations/form/en-us.yaml b/addons/core/translations/form/en-us.yaml index cb7b69832..5960782e7 100644 --- a/addons/core/translations/form/en-us.yaml +++ b/addons/core/translations/form/en-us.yaml @@ -115,3 +115,5 @@ value: callback_url: label: Callback URL help: The URL to which the third-party provider sends the authentication response. Paste this into the provider configuration. +filter: + label: Filter diff --git a/addons/core/translations/resources/en-us.yaml b/addons/core/translations/resources/en-us.yaml index d7d07aee2..c52b88323 100644 --- a/addons/core/translations/resources/en-us.yaml +++ b/addons/core/translations/resources/en-us.yaml @@ -354,3 +354,6 @@ scope: managed-group: title: Managed Group title_plural: Managed Groups + description: A managed group is a resource that represents a collection of accounts. + actions: + delete: Delete Managed Group diff --git a/ui/admin/app/components/form/managed-group/index.hbs b/ui/admin/app/components/form/managed-group/index.hbs new file mode 100644 index 000000000..4f0f53c28 --- /dev/null +++ b/ui/admin/app/components/form/managed-group/index.hbs @@ -0,0 +1,54 @@ + + + + + {{#if @model.errors.name}} + + {{#each @model.errors.name as |error|}} + {{error.message}} + {{/each}} + + {{/if}} + + + + {{#if @model.errors.description}} + + {{#each @model.errors.description as |error|}} + {{error.message}} + {{/each}} + + {{/if}} + + + + \ No newline at end of file diff --git a/ui/admin/app/router.js b/ui/admin/app/router.js index 17519a2a5..49a0c0756 100644 --- a/ui/admin/app/router.js +++ b/ui/admin/app/router.js @@ -55,7 +55,13 @@ Router.map(function () { }); this.route('new'); }); - this.route('managed-groups', function () {}); + this.route('managed-groups', function () { + this.route( + 'managed-group', + { path: ':managed_group_id' }, + function () {} + ); + }); }); this.route('new'); }); 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 bde134d3f..f1c4acac5 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 @@ -1,4 +1,5 @@ import Route from '@ember/routing/route'; +import { action } from '@ember/object'; export default class ScopesScopeAuthMethodsAuthMethodManagedGroupsRoute extends Route { /** @@ -10,4 +11,18 @@ export default class ScopesScopeAuthMethodsAuthMethodManagedGroupsRoute extends const { id: auth_method_id } = authMethod; return this.store.query('managed-group', { auth_method_id }); } + + // =actions + /** + * Rollback changes on a managed group. + * @param {ManagedGroupModel} managedGroup + */ + @action + cancel(managedGroup) { + const { isNew } = managedGroup; + managedGroup.rollbackAttributes(); + if (isNew) { + this.transitionTo('scopes.scope.auth-methods.auth-method.managed-groups'); + } + } } diff --git a/ui/admin/app/routes/scopes/scope/auth-methods/auth-method/managed-groups/index.js b/ui/admin/app/routes/scopes/scope/auth-methods/auth-method/managed-groups/index.js index 24639a124..7cdc46a89 100644 --- a/ui/admin/app/routes/scopes/scope/auth-methods/auth-method/managed-groups/index.js +++ b/ui/admin/app/routes/scopes/scope/auth-methods/auth-method/managed-groups/index.js @@ -1,3 +1,9 @@ import Route from '@ember/routing/route'; -export default class ScopesScopeAuthMethodsAuthMethodManagedGroupsIndexRoute extends Route {} +export default class ScopesScopeAuthMethodsAuthMethodManagedGroupsIndexRoute extends Route { + setupController(controller) { + const authMethod = this.modelFor('scopes.scope.auth-methods.auth-method'); + super.setupController(...arguments); + controller.setProperties({ authMethod }); + } +} 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 new file mode 100644 index 000000000..816b537da --- /dev/null +++ b/ui/admin/app/routes/scopes/scope/auth-methods/auth-method/managed-groups/managed-group.js @@ -0,0 +1,49 @@ +import Route from '@ember/routing/route'; + +export default class ScopesScopeAuthMethodsAuthMethodManagedGroupsManagedGroupRoute extends Route { + // =methods + + /** + * Load managed group by ID. + * @param {object} params + * @param {string} params.managed_group_id + * @returns {ManagedGroupModel} + */ + model({ managed_group_id }) { + return this.store.findRecord('managed-group', managed_group_id, { + reload: true, + }); + } + + /** + * Render the route-set specific page sections + * @override + */ + renderTemplate() { + super.renderTemplate(...arguments); + + this.render( + 'scopes/scope/auth-methods/auth-method/managed-groups/managed-group/-header', + { + into: 'scopes/scope/auth-methods/auth-method', + outlet: 'header', + } + ); + + this.render( + 'scopes/scope/auth-methods/auth-method/managed-groups/managed-group/-actions', + { + into: 'scopes/scope/auth-methods/auth-method', + outlet: 'actions', + } + ); + + this.render( + 'scopes/scope/auth-methods/auth-method/managed-groups/managed-group/-navigation', + { + into: 'scopes/scope/auth-methods/auth-method', + outlet: 'navigation', + } + ); + } +} diff --git a/ui/admin/app/routes/scopes/scope/auth-methods/auth-method/managed-groups/managed-group/index.js b/ui/admin/app/routes/scopes/scope/auth-methods/auth-method/managed-groups/managed-group/index.js new file mode 100644 index 000000000..0dbea955a --- /dev/null +++ b/ui/admin/app/routes/scopes/scope/auth-methods/auth-method/managed-groups/managed-group/index.js @@ -0,0 +1,3 @@ +import Route from '@ember/routing/route'; + +export default class ScopesScopeAuthMethodsAuthMethodManagedGroupsManagedGroupIndexRoute extends Route {} diff --git a/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/managed-groups/index.hbs b/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/managed-groups/index.hbs index 959c50afa..7483ea871 100644 --- a/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/managed-groups/index.hbs +++ b/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/managed-groups/index.hbs @@ -12,7 +12,16 @@ {{#each @model as |managed-group|}} - {{managed-group.name}} + + {{#if (can 'read model' managed-group)}} + + {{managed-group.name}} + + {{/if}} + {{managed-group.description}} {{managed-group.type}} diff --git a/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/managed-groups/managed-group.hbs b/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/managed-groups/managed-group.hbs new file mode 100644 index 000000000..a6696c3b6 --- /dev/null +++ b/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/managed-groups/managed-group.hbs @@ -0,0 +1,2 @@ +{{page-title 'ManagedGroup'}} +{{outlet}} \ No newline at end of file diff --git a/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/managed-groups/managed-group/-actions.hbs b/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/managed-groups/managed-group/-actions.hbs new file mode 100644 index 000000000..240e83e8e --- /dev/null +++ b/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/managed-groups/managed-group/-actions.hbs @@ -0,0 +1,11 @@ +{{#if (can 'delete model' @model)}} + + + {{t 'resources.managed-group.actions.delete'}} + + +{{/if}} \ No newline at end of file diff --git a/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/managed-groups/managed-group/-header.hbs b/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/managed-groups/managed-group/-header.hbs new file mode 100644 index 000000000..1e7ef1124 --- /dev/null +++ b/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/managed-groups/managed-group/-header.hbs @@ -0,0 +1,12 @@ +

+ {{t 'resources.managed-group.title'}} + +

+

{{t 'resources.managed-group.description'}}

+ + {{@model.id}} + \ No newline at end of file diff --git a/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/managed-groups/managed-group/-navigation.hbs b/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/managed-groups/managed-group/-navigation.hbs new file mode 100644 index 000000000..3a2ce54b7 --- /dev/null +++ b/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/managed-groups/managed-group/-navigation.hbs @@ -0,0 +1,7 @@ + + + {{t 'titles.details'}} + + \ No newline at end of file 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 new file mode 100644 index 000000000..19ab29fcb --- /dev/null +++ b/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/managed-groups/managed-group/index.hbs @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/ui/admin/config/environment.js b/ui/admin/config/environment.js index 7e4c3ca78..613c6a3e8 100644 --- a/ui/admin/config/environment.js +++ b/ui/admin/config/environment.js @@ -48,6 +48,7 @@ module.exports = function (environment) { account: '/accounts', 'account.new': '/accounts/new', 'auth-method': '/auth-methods', + 'managed-groups': '/managed-groups', group: '/groups', 'group.add-members': '/groups/add-members', 'host-catalog': '/host-catalogs', diff --git a/ui/admin/tests/unit/routes/scopes/scope/auth-methods/auth-method/managed-groups/managed-group-test.js b/ui/admin/tests/unit/routes/scopes/scope/auth-methods/auth-method/managed-groups/managed-group-test.js new file mode 100644 index 000000000..f323d5e2e --- /dev/null +++ b/ui/admin/tests/unit/routes/scopes/scope/auth-methods/auth-method/managed-groups/managed-group-test.js @@ -0,0 +1,16 @@ +import { module, test } from 'qunit'; +import { setupTest } from 'ember-qunit'; + +module( + 'Unit | Route | scopes/scope/auth-methods/auth-method/managed-groups/managed-group', + function (hooks) { + setupTest(hooks); + + test('it exists', function (assert) { + let route = this.owner.lookup( + 'route:scopes/scope/auth-methods/auth-method/managed-groups/managed-group' + ); + assert.ok(route); + }); + } +); diff --git a/ui/admin/tests/unit/routes/scopes/scope/auth-methods/auth-method/managed-groups/managed-group/index-test.js b/ui/admin/tests/unit/routes/scopes/scope/auth-methods/auth-method/managed-groups/managed-group/index-test.js new file mode 100644 index 000000000..47aadd91a --- /dev/null +++ b/ui/admin/tests/unit/routes/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 | Route | scopes/scope/auth-methods/auth-method/managed-groups/managed-group/index', + function (hooks) { + setupTest(hooks); + + test('it exists', function (assert) { + let route = this.owner.lookup( + 'route:scopes/scope/auth-methods/auth-method/managed-groups/managed-group/index' + ); + assert.ok(route); + }); + } +); From f8bb37e5af82b44ea4f1c55e9e3123375c1a7f90 Mon Sep 17 00:00:00 2001 From: Carlos Alcaide Corvo Date: Tue, 9 Nov 2021 11:16:21 -0800 Subject: [PATCH 02/11] Add managed groups to auth method JUST if is type oidc. Within auth method, show the managed groups tabs JUST if type is oidc --- addons/api/mirage/factories/auth-method.js | 4 +++- addons/api/mirage/scenarios/default.js | 2 +- .../scope/auth-methods/auth-method/-navigation.hbs | 10 ++++++---- .../scopes/scope/auth-methods/auth-method/index.hbs | 3 ++- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/addons/api/mirage/factories/auth-method.js b/addons/api/mirage/factories/auth-method.js index 051ea096f..755154b09 100644 --- a/addons/api/mirage/factories/auth-method.js +++ b/addons/api/mirage/factories/auth-method.js @@ -34,7 +34,9 @@ export default factory.extend({ user.update({ accountIds: [id] }); }); - server.createList('managed-group', 2, { scope, authMethod }); + if (type === 'oidc') { + server.createList('managed-group', 2, { scope, authMethod }); + } }, }), }); diff --git a/addons/api/mirage/scenarios/default.js b/addons/api/mirage/scenarios/default.js index 9291f8a3e..965234b5d 100644 --- a/addons/api/mirage/scenarios/default.js +++ b/addons/api/mirage/scenarios/default.js @@ -22,7 +22,7 @@ export default function (server) { // Auth const globalAuthMethods = server.createList( 'auth-method', - 1, + 4, { scope: globalScope }, 'withAccountsAndUsersAndManagedGroups' ); diff --git a/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/-navigation.hbs b/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/-navigation.hbs index d13958255..40b38d901 100644 --- a/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/-navigation.hbs +++ b/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/-navigation.hbs @@ -10,8 +10,10 @@ {{/if}} {{#if (feature-flag 'managed-groups')}} - - {{t 'resources.managed-group.title_plural'}} - + {{#if @model.isOIDC}} + + {{t 'resources.managed-group.title_plural'}} + + {{/if}} {{/if}} - \ No newline at end of file + diff --git a/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/index.hbs b/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/index.hbs index e3302df0b..52639ddc0 100644 --- a/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/index.hbs +++ b/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/index.hbs @@ -1,3 +1,4 @@ +

{{@model.type}}

\ No newline at end of file +/> From 9541d2ed5c687a2e52db7802f4a7a1bc352b77fb Mon Sep 17 00:00:00 2001 From: Carlos Alcaide Corvo Date: Tue, 9 Nov 2021 11:26:19 -0800 Subject: [PATCH 03/11] Add helper text for filter field --- addons/core/translations/form/en-us.yaml | 1 + ui/admin/app/components/form/managed-group/index.hbs | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/addons/core/translations/form/en-us.yaml b/addons/core/translations/form/en-us.yaml index 5960782e7..05105fbac 100644 --- a/addons/core/translations/form/en-us.yaml +++ b/addons/core/translations/form/en-us.yaml @@ -117,3 +117,4 @@ callback_url: help: The URL to which the third-party provider sends the authentication response. Paste this into the provider configuration. filter: label: Filter + help: A boolean expression defining a filter run against the provided information. diff --git a/ui/admin/app/components/form/managed-group/index.hbs b/ui/admin/app/components/form/managed-group/index.hbs index 4f0f53c28..726e6c456 100644 --- a/ui/admin/app/components/form/managed-group/index.hbs +++ b/ui/admin/app/components/form/managed-group/index.hbs @@ -47,8 +47,9 @@ - \ No newline at end of file + From 259840808c67184b9078966a4c374c13dfc0e06d Mon Sep 17 00:00:00 2001 From: Carlos Alcaide Corvo Date: Tue, 9 Nov 2021 11:28:37 -0800 Subject: [PATCH 04/11] Fix linting errors --- ui/admin/app/components/form/managed-group/index.hbs | 2 +- .../scopes/scope/auth-methods/auth-method/-navigation.hbs | 2 +- .../templates/scopes/scope/auth-methods/auth-method/index.hbs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ui/admin/app/components/form/managed-group/index.hbs b/ui/admin/app/components/form/managed-group/index.hbs index 726e6c456..1ccd49e57 100644 --- a/ui/admin/app/components/form/managed-group/index.hbs +++ b/ui/admin/app/components/form/managed-group/index.hbs @@ -52,4 +52,4 @@ readonly={{true}} @disabled={{true}} /> - + \ No newline at end of file diff --git a/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/-navigation.hbs b/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/-navigation.hbs index 40b38d901..6c5d6bd70 100644 --- a/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/-navigation.hbs +++ b/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/-navigation.hbs @@ -16,4 +16,4 @@ {{/if}} {{/if}} - + \ No newline at end of file diff --git a/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/index.hbs b/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/index.hbs index 52639ddc0..494c7fb67 100644 --- a/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/index.hbs +++ b/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/index.hbs @@ -6,4 +6,4 @@ @removeItemByIndex={{route-action 'removeItemByIndex' @model}} @addStringItem={{route-action 'addStringItem' @model}} @addAccountClaimMapItem={{route-action 'addAccountClaimMapItem' @model}} -/> +/> \ No newline at end of file From f3d8db6aaf8614e2353e7fa68edd6f3e3e3e4c96 Mon Sep 17 00:00:00 2001 From: Carlos Alcaide Corvo Date: Wed, 10 Nov 2021 07:47:06 -0800 Subject: [PATCH 05/11] Fix typo --- .../templates/scopes/scope/auth-methods/auth-method/index.hbs | 1 - 1 file changed, 1 deletion(-) diff --git a/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/index.hbs b/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/index.hbs index 494c7fb67..e3302df0b 100644 --- a/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/index.hbs +++ b/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/index.hbs @@ -1,4 +1,3 @@ -

{{@model.type}}

Date: Tue, 9 Nov 2021 12:01:30 -0800 Subject: [PATCH 06/11] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20Add=20managed=20gr?= =?UTF-8?q?oups=20delete=20CRUD=20operation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- addons/api/mirage/config.js | 1 + .../auth-method/managed-groups.js | 24 +++++++++++++++++++ .../managed-groups/managed-group/-actions.hbs | 6 ++++- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/addons/api/mirage/config.js b/addons/api/mirage/config.js index 8c62edd5e..f71eba2cc 100644 --- a/addons/api/mirage/config.js +++ b/addons/api/mirage/config.js @@ -522,6 +522,7 @@ export default function () { } ); this.get('/managed-groups/:id'); + this.del('/managed-groups/:id'); /* Uncomment the following line and the Response import above * Then change the response code to simulate error responses. 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 f1c4acac5..e1f0d9435 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 @@ -1,7 +1,14 @@ import Route from '@ember/routing/route'; +import { inject as service } from '@ember/service'; import { action } from '@ember/object'; +import { confirm } from 'core/decorators/confirm'; +import loading from 'ember-loading/decorator'; +import { notifySuccess, notifyError } from 'core/decorators/notify'; export default class ScopesScopeAuthMethodsAuthMethodManagedGroupsRoute extends Route { + // =services + + @service notify; /** * * @returns {Promise{[ManagedGroupsModel]}} @@ -25,4 +32,21 @@ export default class ScopesScopeAuthMethodsAuthMethodManagedGroupsRoute extends this.transitionTo('scopes.scope.auth-methods.auth-method.managed-groups'); } } + + /** + * 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.replaceWith( + 'scopes.scope.auth-methods.auth-method.managed-groups' + ); + this.refresh(); + } } diff --git a/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/managed-groups/managed-group/-actions.hbs b/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/managed-groups/managed-group/-actions.hbs index 240e83e8e..98a51d476 100644 --- a/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/managed-groups/managed-group/-actions.hbs +++ b/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/managed-groups/managed-group/-actions.hbs @@ -4,7 +4,11 @@ @dropdownRight={{true}} as |dropdown| > - + {{t 'resources.managed-group.actions.delete'}} From deb9847617d53675f27b4923fc8d535488b5c76f Mon Sep 17 00:00:00 2001 From: Carlos Alcaide Corvo Date: Wed, 10 Nov 2021 07:32:40 -0800 Subject: [PATCH 07/11] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20Add=20managed=20gr?= =?UTF-8?q?oups=20create=20CRUD=20operation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- addons/api/mirage/config.js | 13 +++++++ addons/core/translations/resources/en-us.yaml | 1 + .../components/form/managed-group/index.hbs | 15 +++++++- ui/admin/app/router.js | 1 + .../auth-method/managed-groups.js | 19 ++++++++-- .../auth-method/managed-groups/new.js | 36 +++++++++++++++++++ .../auth-methods/auth-method/-actions.hbs | 12 +++++++ .../auth-method/managed-groups/new.hbs | 5 +++ .../managed-groups/new/-header.hbs | 5 +++ .../auth-method/managed-groups/new-test.js | 16 +++++++++ 10 files changed, 120 insertions(+), 3 deletions(-) create mode 100644 ui/admin/app/routes/scopes/scope/auth-methods/auth-method/managed-groups/new.js create mode 100644 ui/admin/app/templates/scopes/scope/auth-methods/auth-method/managed-groups/new.hbs create mode 100644 ui/admin/app/templates/scopes/scope/auth-methods/auth-method/managed-groups/new/-header.hbs create mode 100644 ui/admin/tests/unit/routes/scopes/scope/auth-methods/auth-method/managed-groups/new-test.js diff --git a/addons/api/mirage/config.js b/addons/api/mirage/config.js index f71eba2cc..152b68513 100644 --- a/addons/api/mirage/config.js +++ b/addons/api/mirage/config.js @@ -523,6 +523,19 @@ export default function () { ); this.get('/managed-groups/:id'); this.del('/managed-groups/:id'); + this.post( + '/managed-groups/:idMethod', + function ({ managedGroups }, { params: { idMethod } }) { + const attrs = this.normalizedRequestAttrs(); + const id = idMethod.split(':')[0]; + const managedGroup = managedGroups.find(id); + const updatedAttrs = { + version: attrs.version, + attributes: managedGroup.attributes, + }; + return managedGroup.update(updatedAttrs); + } + ); /* Uncomment the following line and the Response import above * Then change the response code to simulate error responses. diff --git a/addons/core/translations/resources/en-us.yaml b/addons/core/translations/resources/en-us.yaml index c52b88323..ba97605d8 100644 --- a/addons/core/translations/resources/en-us.yaml +++ b/addons/core/translations/resources/en-us.yaml @@ -357,3 +357,4 @@ managed-group: description: A managed group is a resource that represents a collection of accounts. actions: delete: Delete Managed Group + create: Create Managed Group diff --git a/ui/admin/app/components/form/managed-group/index.hbs b/ui/admin/app/components/form/managed-group/index.hbs index 1ccd49e57..6ebc5f284 100644 --- a/ui/admin/app/components/form/managed-group/index.hbs +++ b/ui/admin/app/components/form/managed-group/index.hbs @@ -1,4 +1,11 @@ - + + \ No newline at end of file diff --git a/ui/admin/app/router.js b/ui/admin/app/router.js index 49a0c0756..edc70b62d 100644 --- a/ui/admin/app/router.js +++ b/ui/admin/app/router.js @@ -61,6 +61,7 @@ Router.map(function () { { path: ':managed_group_id' }, function () {} ); + this.route('new'); }); }); this.route('new'); 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 e1f0d9435..e8b3e0747 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 @@ -1,8 +1,8 @@ import Route from '@ember/routing/route'; -import { inject as service } from '@ember/service'; import { action } from '@ember/object'; -import { confirm } from 'core/decorators/confirm'; +import { inject as service } from '@ember/service'; import loading from 'ember-loading/decorator'; +import { confirm } from 'core/decorators/confirm'; import { notifySuccess, notifyError } from 'core/decorators/notify'; export default class ScopesScopeAuthMethodsAuthMethodManagedGroupsRoute extends Route { @@ -33,6 +33,21 @@ export default class ScopesScopeAuthMethodsAuthMethodManagedGroupsRoute extends } } + @action + @loading + @notifyError(({ message }) => message) + @notifySuccess(({ isNew }) => + isNew ? 'notifications.create-success' : 'notifications.save-success' + ) + async save(managedGroup) { + await managedGroup.save(); + await this.transitionTo( + 'scopes.scope.auth-methods.auth-method.managed-groups.managed-group', + managedGroup + ); + this.refresh(); + } + /** * Delete a managed group in current scope and redirect to index * @param {ManagedGroupModel} managed group diff --git a/ui/admin/app/routes/scopes/scope/auth-methods/auth-method/managed-groups/new.js b/ui/admin/app/routes/scopes/scope/auth-methods/auth-method/managed-groups/new.js new file mode 100644 index 000000000..ca2b1473c --- /dev/null +++ b/ui/admin/app/routes/scopes/scope/auth-methods/auth-method/managed-groups/new.js @@ -0,0 +1,36 @@ +import Route from '@ember/routing/route'; + +export default class ScopesScopeAuthMethodsAuthMethodManagedGroupsNewRoute extends Route { + // =methods + model() { + const { id: auth_method_id, type } = this.modelFor( + 'scopes.scope.auth-methods.auth-method' + ); + return this.store.createRecord('managed-group', { + type, + auth_method_id, + }); + } + + renderTemplate() { + super.renderTemplate(...arguments); + + this.render( + 'scopes/scope/auth-methods/auth-method/managed-groups/new/-header', + { + into: 'scopes/scope/auth-methods/auth-method', + outlet: 'header', + } + ); + + this.render('_empty', { + into: 'scopes/scope/auth-methods/auth-method', + outlet: 'actions', + }); + + this.render('_empty', { + into: 'scopes/scope/auth-methods/auth-method', + outlet: 'navigation', + }); + } +} diff --git a/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/-actions.hbs b/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/-actions.hbs index a33cfdb42..865bdfeec 100644 --- a/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/-actions.hbs +++ b/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/-actions.hbs @@ -67,6 +67,18 @@ {{/if}} + {{#if (feature-flag 'managed-groups')}} + {{! TODO: Add capabilities }} + {{#if @model.isOIDC}} + + {{t 'resources.managed-group.actions.create'}} + + {{/if}} + {{/if}} + {{#if (can 'delete model' @model)}} \ No newline at end of file diff --git a/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/managed-groups/new/-header.hbs b/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/managed-groups/new/-header.hbs new file mode 100644 index 000000000..b6e89205e --- /dev/null +++ b/ui/admin/app/templates/scopes/scope/auth-methods/auth-method/managed-groups/new/-header.hbs @@ -0,0 +1,5 @@ +

+ {{t 'titles.new'}} + {{! TODO: change the icon link }} + +

\ No newline at end of file diff --git a/ui/admin/tests/unit/routes/scopes/scope/auth-methods/auth-method/managed-groups/new-test.js b/ui/admin/tests/unit/routes/scopes/scope/auth-methods/auth-method/managed-groups/new-test.js new file mode 100644 index 000000000..3ea26ad63 --- /dev/null +++ b/ui/admin/tests/unit/routes/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 | Route | scopes/scope/auth-methods/auth-method/managed-groups/new', + function (hooks) { + setupTest(hooks); + + test('it exists', function (assert) { + let route = this.owner.lookup( + 'route:scopes/scope/auth-methods/auth-method/managed-groups/new' + ); + assert.ok(route); + }); + } +); From 4e41ac531d6e17b401f2f61f03882d119724f3c5 Mon Sep 17 00:00:00 2001 From: Carlos Alcaide Corvo Date: Wed, 10 Nov 2021 09:07:17 -0800 Subject: [PATCH 08/11] WIP fixing creation mirage model error --- addons/api/mirage/config.js | 27 ++++++++++--------- addons/api/mirage/factories/managed-group.js | 14 ++++++++++ .../generated/factories/managed-group.js | 11 -------- .../auth-method/managed-groups.js | 12 ++++++++- 4 files changed, 39 insertions(+), 25 deletions(-) diff --git a/addons/api/mirage/config.js b/addons/api/mirage/config.js index 152b68513..74c6ad61e 100644 --- a/addons/api/mirage/config.js +++ b/addons/api/mirage/config.js @@ -523,19 +523,20 @@ export default function () { ); this.get('/managed-groups/:id'); this.del('/managed-groups/:id'); - this.post( - '/managed-groups/:idMethod', - function ({ managedGroups }, { params: { idMethod } }) { - const attrs = this.normalizedRequestAttrs(); - const id = idMethod.split(':')[0]; - const managedGroup = managedGroups.find(id); - const updatedAttrs = { - version: attrs.version, - attributes: managedGroup.attributes, - }; - return managedGroup.update(updatedAttrs); - } - ); + this.post('/managed-groups'); + // this.post( + // '/managed-groups/:idMethod', + // function ({ managedGroups }, { params: { idMethod } }) { + // const attrs = this.normalizedRequestAttrs(); + // const id = idMethod.split(':')[0]; + // const managedGroup = managedGroups.find(id); + // const updatedAttrs = { + // version: attrs.version, + // attributes: managedGroup.attributes, + // }; + // return managedGroup.update(updatedAttrs); + // } + // ); /* Uncomment the following line and the Response import above * Then change the response code to simulate error responses. diff --git a/addons/api/mirage/factories/managed-group.js b/addons/api/mirage/factories/managed-group.js index c65e62334..7378f84d6 100644 --- a/addons/api/mirage/factories/managed-group.js +++ b/addons/api/mirage/factories/managed-group.js @@ -1,4 +1,5 @@ import factory from '../generated/factories/managed-group'; +import { random } from 'faker'; import permissions from '../helpers/permissions'; export default factory.extend({ @@ -11,4 +12,17 @@ export default factory.extend({ 'update', 'delete', ], + + attributes() { + switch (this.type) { + case 'oidc': + return { + filter: random.word(), + }; + default: + return { + filter: '', + }; + } + }, }); diff --git a/addons/api/mirage/generated/factories/managed-group.js b/addons/api/mirage/generated/factories/managed-group.js index 17bb7d6c6..a041c0f50 100644 --- a/addons/api/mirage/generated/factories/managed-group.js +++ b/addons/api/mirage/generated/factories/managed-group.js @@ -11,15 +11,4 @@ export default Factory.extend({ created_time: () => date.recent(), updated_time: () => date.recent(), version: () => datatype.number(), - type: 'oidc', - attributes: function () { - switch (this.type) { - case 'oidc': - return { - filter: random.words(), - }; - default: - return; - } - }, }); 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 e8b3e0747..dd9b88f5b 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 @@ -8,7 +8,12 @@ import { notifySuccess, notifyError } from 'core/decorators/notify'; export default class ScopesScopeAuthMethodsAuthMethodManagedGroupsRoute extends Route { // =services + @service intl; @service notify; + @service can; + + //=methods + /** * * @returns {Promise{[ManagedGroupsModel]}} @@ -33,6 +38,10 @@ export default class ScopesScopeAuthMethodsAuthMethodManagedGroupsRoute extends } } + /** + * Save a managed group in current scope. + * @param {ManagedGroupModel} managedGroup + */ @action @loading @notifyError(({ message }) => message) @@ -40,9 +49,10 @@ export default class ScopesScopeAuthMethodsAuthMethodManagedGroupsRoute extends isNew ? 'notifications.create-success' : 'notifications.save-success' ) async save(managedGroup) { + debugger; await managedGroup.save(); await this.transitionTo( - 'scopes.scope.auth-methods.auth-method.managed-groups.managed-group', + 'scopes.scope.auth-methods.auth-method.managed-groups', managedGroup ); this.refresh(); From 7c762c1050b2fb331ea55f2729f7033ccf885c66 Mon Sep 17 00:00:00 2001 From: Susmitha Girumala Date: Wed, 10 Nov 2021 16:12:42 -0500 Subject: [PATCH 09/11] fix: Mirage post issue for managed-groups --- addons/api/addon/models/managed-group.js | 8 ++++++++ addons/api/mirage/factories/managed-group.js | 9 ++++----- .../{managed-groups.js => managed-group.js} | 0 .../components/form/managed-group/index.hbs | 19 +++++++++++++++---- .../auth-method/managed-groups.js | 4 +--- .../auth-method/managed-groups/index.hbs | 4 +++- 6 files changed, 31 insertions(+), 13 deletions(-) rename addons/api/mirage/serializers/{managed-groups.js => managed-group.js} (100%) diff --git a/addons/api/addon/models/managed-group.js b/addons/api/addon/models/managed-group.js index 426807de2..5843bb0e5 100644 --- a/addons/api/addon/models/managed-group.js +++ b/addons/api/addon/models/managed-group.js @@ -5,6 +5,14 @@ import { A } from '@ember/array'; export default class ManagedGroupModel extends GeneratedManagedGroupModel { // =attributes + + // =error attributes + // These attributes exist solely to capture errors on nested fields. + // See the application adapter's error normalization method for + // more information. + + @attr('string', { readOnly: true }) attributes_filter; + /** * Members is read-only under normal circumstances. But members can * be persisted via calls to `addMembers()` or `removeMembers()`. diff --git a/addons/api/mirage/factories/managed-group.js b/addons/api/mirage/factories/managed-group.js index 7378f84d6..9460f847f 100644 --- a/addons/api/mirage/factories/managed-group.js +++ b/addons/api/mirage/factories/managed-group.js @@ -2,8 +2,11 @@ import factory from '../generated/factories/managed-group'; import { random } from 'faker'; import permissions from '../helpers/permissions'; +const types = ['oidc']; + export default factory.extend({ id: (i) => `managed-groups-id-${i}`, + type: (i) => types[i % types.length], authorized_actions: () => permissions.authorizedActionsFor('managed-group') || [ @@ -17,11 +20,7 @@ export default factory.extend({ switch (this.type) { case 'oidc': return { - filter: random.word(), - }; - default: - return { - filter: '', + filter: random.words(), }; } }, diff --git a/addons/api/mirage/serializers/managed-groups.js b/addons/api/mirage/serializers/managed-group.js similarity index 100% rename from addons/api/mirage/serializers/managed-groups.js rename to addons/api/mirage/serializers/managed-group.js diff --git a/ui/admin/app/components/form/managed-group/index.hbs b/ui/admin/app/components/form/managed-group/index.hbs index 6ebc5f284..7918dd146 100644 --- a/ui/admin/app/components/form/managed-group/index.hbs +++ b/ui/admin/app/components/form/managed-group/index.hbs @@ -53,12 +53,23 @@ + @error={{@model.errors.attributes_filter}} + @helperText={{t 'form.filter.help'}} + as |field| + > + {{#if @model.errors.filter}} + + {{#each @model.errors.filter as |error|}} + {{error.message}} + {{/each}} + + {{/if}} + + - {{managed-group.name}} + {{managed-group.displayName}} + {{else}} + {{managed-group.displayName}} {{/if}} {{managed-group.description}} From 07aaa8fcde18bae38f3b30d5a9ff4d5a9a247cd6 Mon Sep 17 00:00:00 2001 From: Carlos Alcaide Corvo Date: Wed, 10 Nov 2021 14:40:16 -0800 Subject: [PATCH 10/11] Fix typo on description --- addons/core/translations/resources/en-us.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/core/translations/resources/en-us.yaml b/addons/core/translations/resources/en-us.yaml index c52b88323..df2366fe5 100644 --- a/addons/core/translations/resources/en-us.yaml +++ b/addons/core/translations/resources/en-us.yaml @@ -354,6 +354,6 @@ scope: managed-group: title: Managed Group title_plural: Managed Groups - description: A managed group is a resource that represents a collection of accounts. + description: A managed group represents a collection of accounts. actions: delete: Delete Managed Group From 05cf14e8b4bd1482ade7d577cf1bfa62104a1a10 Mon Sep 17 00:00:00 2001 From: Susmitha Girumala Date: Thu, 11 Nov 2021 10:05:04 -0500 Subject: [PATCH 11/11] style: Remove commented mirage config for managed groups --- addons/api/mirage/config.js | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/addons/api/mirage/config.js b/addons/api/mirage/config.js index 74c6ad61e..9036f6653 100644 --- a/addons/api/mirage/config.js +++ b/addons/api/mirage/config.js @@ -524,19 +524,6 @@ export default function () { this.get('/managed-groups/:id'); this.del('/managed-groups/:id'); this.post('/managed-groups'); - // this.post( - // '/managed-groups/:idMethod', - // function ({ managedGroups }, { params: { idMethod } }) { - // const attrs = this.normalizedRequestAttrs(); - // const id = idMethod.split(':')[0]; - // const managedGroup = managedGroups.find(id); - // const updatedAttrs = { - // version: attrs.version, - // attributes: managedGroup.attributes, - // }; - // return managedGroup.update(updatedAttrs); - // } - // ); /* Uncomment the following line and the Response import above * Then change the response code to simulate error responses.