From 4e41ac531d6e17b401f2f61f03882d119724f3c5 Mon Sep 17 00:00:00 2001 From: Carlos Alcaide Corvo Date: Wed, 10 Nov 2021 09:07:17 -0800 Subject: [PATCH] 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();