diff --git a/addons/api/mirage/config.js b/addons/api/mirage/config.js index 007950f69..40a582e2c 100644 --- a/addons/api/mirage/config.js +++ b/addons/api/mirage/config.js @@ -1,6 +1,6 @@ import Ember from 'ember'; import config from '../config/environment'; -import { authHandler, deauthHandler } from './route-handlers/auth'; +import { deauthHandler } from './route-handlers/auth'; import { pickRandomStatusString } from './factories/session'; import { Response } from 'miragejs'; import initializeMockIPC from './scenarios/ipc'; @@ -71,6 +71,31 @@ export default function () { } return new Response(202); }); + this.post('/auth-methods/:idMethod', function (schema, request) { + const idMethod = request.params.idMethod; + const id = idMethod.split(':')[0]; + const method = idMethod.split(':')[1]; + + if (method === 'authenticate') { + schema.authHandler.call(this, schema, request); + return; + } + + const attrs = this.normalizedRequestAttrs(); + const authMethods = schema.authMethods; + const authMethod = authMethods.find(id); + let updatedAttrs = {}; + + if (method === 'change-state') { + updatedAttrs = { + attributes: { + state: attrs.attributes.state, + }, + }; + } + + return authMethod.update(updatedAttrs); + }); // Auth Method Accounts this.get( diff --git a/addons/api/mirage/scenarios/default.js b/addons/api/mirage/scenarios/default.js index 62018788c..1f2595bb8 100644 --- a/addons/api/mirage/scenarios/default.js +++ b/addons/api/mirage/scenarios/default.js @@ -1,3 +1,5 @@ +import { authHandler } from '../route-handlers/auth'; + export default function (server) { // Scope resources @@ -50,4 +52,8 @@ export default function (server) { server.createList('target', 2, { scope }, 'withRandomHostSets'); server.createList('session', 4, { scope }, 'withAssociations'); }); + + // Authenticate route handler + // TODO: Better way to pass-in auth handler + server.schema.authHandler = authHandler; } 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 5ff803bfb..397823a8e 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,4 +67,4 @@ > {{t 'resources.auth-method.actions.delete'}} - \ No newline at end of file +