Data modeling for tokens and policies

This commit is contained in:
Michael Lange 2017-10-13 15:17:51 -07:00
parent c04d9020c2
commit 040e3fec10
7 changed files with 67 additions and 1 deletions

View file

@ -0,0 +1,5 @@
import { default as ApplicationAdapter, namespace } from './application';
export default ApplicationAdapter.extend({
namespace: namespace + '/acl',
});

5
ui/app/adapters/token.js Normal file
View file

@ -0,0 +1,5 @@
import { default as ApplicationAdapter, namespace } from './application';
export default ApplicationAdapter.extend({
namespace: namespace + '/acl',
});

8
ui/app/models/policy.js Normal file
View file

@ -0,0 +1,8 @@
import Model from 'ember-data/model';
import attr from 'ember-data/attr';
export default Model.extend({
name: attr('string'),
description: attr('string'),
rules: attr('string'),
});

18
ui/app/models/token.js Normal file
View file

@ -0,0 +1,18 @@
import Ember from 'ember';
import Model from 'ember-data/model';
import attr from 'ember-data/attr';
import { hasMany } from 'ember-data/relationships';
const { computed } = Ember;
export default Model.extend({
secret: attr('string'),
name: attr('string'),
global: attr('boolean'),
createTime: attr('date'),
type: attr('string'),
policies: hasMany('policy'),
policyNames: attr(),
accessor: computed.alias('id'),
});

View file

@ -11,7 +11,10 @@ export default JSONSerializer.extend({
},
keyForRelationship(attr, relationshipType) {
const key = `${attr.camelize().capitalize()}ID`;
const key = `${attr
.singularize()
.camelize()
.capitalize()}ID`;
return relationshipType === 'hasMany' ? key.pluralize() : key;
},

View file

@ -0,0 +1,8 @@
import ApplicationSerializer from './application';
export default ApplicationSerializer.extend({
normalize(typeHash, hash) {
hash.ID = hash.Name;
return this._super(typeHash, hash);
},
});

View file

@ -0,0 +1,19 @@
import Ember from 'ember';
import ApplicationSerializer from './application';
const { copy } = Ember;
export default ApplicationSerializer.extend({
primaryKey: 'AccessorID',
attrs: {
taskGroupName: 'TaskGroup',
secret: 'SecretID',
},
normalize(typeHash, hash) {
hash.PolicyIDs = hash.Policies;
hash.PolicyNames = copy(hash.Policies);
return this._super(typeHash, hash);
},
});