From 040e3fec108b476760e140415013b1f28b94e6f0 Mon Sep 17 00:00:00 2001 From: Michael Lange Date: Fri, 13 Oct 2017 15:17:51 -0700 Subject: [PATCH] Data modeling for tokens and policies --- ui/app/adapters/policy.js | 5 +++++ ui/app/adapters/token.js | 5 +++++ ui/app/models/policy.js | 8 ++++++++ ui/app/models/token.js | 18 ++++++++++++++++++ ui/app/serializers/application.js | 5 ++++- ui/app/serializers/policy.js | 8 ++++++++ ui/app/serializers/token.js | 19 +++++++++++++++++++ 7 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 ui/app/adapters/policy.js create mode 100644 ui/app/adapters/token.js create mode 100644 ui/app/models/policy.js create mode 100644 ui/app/models/token.js create mode 100644 ui/app/serializers/policy.js create mode 100644 ui/app/serializers/token.js diff --git a/ui/app/adapters/policy.js b/ui/app/adapters/policy.js new file mode 100644 index 000000000..66f6c0b30 --- /dev/null +++ b/ui/app/adapters/policy.js @@ -0,0 +1,5 @@ +import { default as ApplicationAdapter, namespace } from './application'; + +export default ApplicationAdapter.extend({ + namespace: namespace + '/acl', +}); diff --git a/ui/app/adapters/token.js b/ui/app/adapters/token.js new file mode 100644 index 000000000..66f6c0b30 --- /dev/null +++ b/ui/app/adapters/token.js @@ -0,0 +1,5 @@ +import { default as ApplicationAdapter, namespace } from './application'; + +export default ApplicationAdapter.extend({ + namespace: namespace + '/acl', +}); diff --git a/ui/app/models/policy.js b/ui/app/models/policy.js new file mode 100644 index 000000000..47193a6b7 --- /dev/null +++ b/ui/app/models/policy.js @@ -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'), +}); diff --git a/ui/app/models/token.js b/ui/app/models/token.js new file mode 100644 index 000000000..07243dd8a --- /dev/null +++ b/ui/app/models/token.js @@ -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'), +}); diff --git a/ui/app/serializers/application.js b/ui/app/serializers/application.js index 339995e2a..bdec30fc1 100644 --- a/ui/app/serializers/application.js +++ b/ui/app/serializers/application.js @@ -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; }, diff --git a/ui/app/serializers/policy.js b/ui/app/serializers/policy.js new file mode 100644 index 000000000..b9cfa02ed --- /dev/null +++ b/ui/app/serializers/policy.js @@ -0,0 +1,8 @@ +import ApplicationSerializer from './application'; + +export default ApplicationSerializer.extend({ + normalize(typeHash, hash) { + hash.ID = hash.Name; + return this._super(typeHash, hash); + }, +}); diff --git a/ui/app/serializers/token.js b/ui/app/serializers/token.js new file mode 100644 index 000000000..93675cfe8 --- /dev/null +++ b/ui/app/serializers/token.js @@ -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); + }, +});