From deb9847617d53675f27b4923fc8d535488b5c76f Mon Sep 17 00:00:00 2001 From: Carlos Alcaide Corvo Date: Wed, 10 Nov 2021 07:32:40 -0800 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20Add=20managed=20groups?= =?UTF-8?q?=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); + }); + } +);