diff --git a/addons/api/addon/models/account.js b/addons/api/addon/models/account.js index 0e61e3aa5..76321d86d 100644 --- a/addons/api/addon/models/account.js +++ b/addons/api/addon/models/account.js @@ -1,3 +1,12 @@ import GeneratedAccountModel from '../generated/models/account'; +import { fragment } from 'ember-data-model-fragments/attributes'; -export default class AccountModel extends GeneratedAccountModel {} +export default class AccountModel extends GeneratedAccountModel { + + /** + * Attributes of this resource, if any, represented as a JSON fragment. + * @type {FragmentAccountAttributesModel} + */ + @fragment('fragment-account-attributes', { defaultValue: {} }) attributes; + +} diff --git a/addons/api/addon/models/fragment-account-attributes.js b/addons/api/addon/models/fragment-account-attributes.js new file mode 100644 index 000000000..ee2281f18 --- /dev/null +++ b/addons/api/addon/models/fragment-account-attributes.js @@ -0,0 +1,13 @@ +import Fragment from 'ember-data-model-fragments/fragment'; +import { attr } from '@ember-data/model'; + +export default class FragmentAccountAttributesModel extends Fragment { + + @attr('string', { + description: 'The account login name' + }) login_name; + + @attr('string', { + description: 'The account password' + }) password; +} diff --git a/addons/api/addon/models/fragment-host-attributes.js b/addons/api/addon/models/fragment-host-attributes.js index 114da4bca..851b404b2 100644 --- a/addons/api/addon/models/fragment-host-attributes.js +++ b/addons/api/addon/models/fragment-host-attributes.js @@ -6,4 +6,5 @@ export default class FragmentHostAttributesModel extends Fragment { @attr('string', { description: 'The address (DNS or IP name) used to reach the host' }) address; + } diff --git a/addons/api/app/models/fragment-account-attributes.js b/addons/api/app/models/fragment-account-attributes.js new file mode 100644 index 000000000..8d0d8f53f --- /dev/null +++ b/addons/api/app/models/fragment-account-attributes.js @@ -0,0 +1 @@ +export { default } from 'api/models/fragment-account-attributes'; diff --git a/addons/api/tests/unit/models/account-test.js b/addons/api/tests/unit/models/account-test.js index 8dcfecdde..4237ae6b6 100644 --- a/addons/api/tests/unit/models/account-test.js +++ b/addons/api/tests/unit/models/account-test.js @@ -10,4 +10,15 @@ module('Unit | Model | account', function(hooks) { let model = store.createRecord('account', {}); assert.ok(model); }); + + test('it contains attributes', function(assert) { + let store = this.owner.lookup('service:store'); + let model = store.createRecord('account', { + type: 'password', + attributes: { + login_name: 'loginname' + } + }); + assert.equal(model.attributes.login_name, 'loginname'); + }); }); diff --git a/ui/core/mirage/config.js b/ui/core/mirage/config.js index 3b9e24cce..225a896ba 100644 --- a/ui/core/mirage/config.js +++ b/ui/core/mirage/config.js @@ -49,6 +49,29 @@ export default function() { this.patch('/auth-methods/:id'); this.del('/auth-methods/:id'); + // Auth Method Accounts + this.get('/accounts', ({ accounts }, { queryParams: { scope_id: scopeId } }) => { + return accounts.where({ scopeId }); + }); + this.post('/accounts'); + this.get('/accounts/:id'); + this.patch('/accounts/:id'); + this.del('/accounts/:id'); + this.post('/accounts/:idMethod', function ({ accounts }, { params: { idMethod } }) { + const attrs = this.normalizedRequestAttrs(); + const id = idMethod.split(':')[0]; + const method = idMethod.split(':')[1]; + const account = accounts.find(id); + const updatedAttrs = { + version: attrs.version + }; + // Set new password + if (method === 'set-password') { + updatedAttrs.password = accounts.attributes.password; + } + return account.update(updatedAttrs); + }); + // Authenticate/deauthenticate routes this.post('/auth-methods/:id_method', authHandler); this.post('/scopes/:id_method', deauthHandler);