feat: Add account attributes to account model

This commit is contained in:
Susmitha Girumala committed 2020-09-14 11:45:48 -04:00
1 parent 879989a127
commit a3060e089d
6 files changed
+59 -1

No files matched your search

+10 -1
View File
@@ -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;
}
@@ -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;
}
@@ -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;
}
@@ -0,0 +1 @@
export { default } from 'api/models/fragment-account-attributes';
@@ -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');
});
});
+23
View File
@@ -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);