From ab461f6603c74f82191776bbdad2f575ca3177f5 Mon Sep 17 00:00:00 2001 From: John Cowen Date: Tue, 17 Dec 2019 16:16:43 +0000 Subject: [PATCH] ui: Remove `writable` usage from policy and use the request instead (#6934) --- ui-v2/app/adapters/policy.js | 14 ++++++++++++-- ui-v2/app/models/policy.js | 6 +----- ui-v2/app/models/token.js | 19 +------------------ ui-v2/app/serializers/policy.js | 3 +-- ui-v2/app/serializers/token.js | 3 +-- 5 files changed, 16 insertions(+), 29 deletions(-) diff --git a/ui-v2/app/adapters/policy.js b/ui-v2/app/adapters/policy.js index ed5772878dc5..f24ae80265ed 100644 --- a/ui-v2/app/adapters/policy.js +++ b/ui-v2/app/adapters/policy.js @@ -25,14 +25,24 @@ export default Adapter.extend({ return request` PUT /v1/acl/policy?${{ [API_DATACENTER_KEY]: data[DATACENTER_KEY] }} - ${serialized} + ${{ + Name: serialized.Name, + Description: serialized.Description, + Rules: serialized.Rules, + Datacenters: serialized.Datacenters, + }} `; }, requestForUpdateRecord: function(request, serialized, data) { return request` PUT /v1/acl/policy/${data[SLUG_KEY]}?${{ [API_DATACENTER_KEY]: data[DATACENTER_KEY] }} - ${serialized} + ${{ + Name: serialized.Name, + Description: serialized.Description, + Rules: serialized.Rules, + Datacenters: serialized.Datacenters, + }} `; }, requestForDeleteRecord: function(request, serialized, data) { diff --git a/ui-v2/app/models/policy.js b/ui-v2/app/models/policy.js index 9dfa92ed2889..4c5bd2e25e08 100644 --- a/ui-v2/app/models/policy.js +++ b/ui-v2/app/models/policy.js @@ -1,11 +1,10 @@ import Model from 'ember-data/model'; import attr from 'ember-data/attr'; -import writable from 'consul-ui/utils/model/writable'; export const PRIMARY_KEY = 'uid'; export const SLUG_KEY = 'ID'; -const model = Model.extend({ +export default Model.extend({ [PRIMARY_KEY]: attr('string'), [SLUG_KEY]: attr('string'), Name: attr('string', { @@ -29,6 +28,3 @@ const model = Model.extend({ defaultValue: '', }), }); -// TODO: Remove this in favour of just specifying it in the Adapter -export const ATTRS = writable(model, ['Name', 'Description', 'Rules', 'Datacenters']); -export default model; diff --git a/ui-v2/app/models/token.js b/ui-v2/app/models/token.js index 32625eab26bc..e1de817358f0 100644 --- a/ui-v2/app/models/token.js +++ b/ui-v2/app/models/token.js @@ -1,11 +1,10 @@ import Model from 'ember-data/model'; import attr from 'ember-data/attr'; -import writable from 'consul-ui/utils/model/writable'; export const PRIMARY_KEY = 'uid'; export const SLUG_KEY = 'AccessorID'; -const model = Model.extend({ +export default Model.extend({ [PRIMARY_KEY]: attr('string'), [SLUG_KEY]: attr('string'), IDPName: attr('string'), @@ -43,19 +42,3 @@ const model = Model.extend({ CreateIndex: attr('number'), ModifyIndex: attr('number'), }); -// TODO: Remove this in favour of just specifying it in the Adapter -// Name and Rules is only for legacy tokens -export const ATTRS = writable(model, [ - 'Name', - 'Rules', - 'Type', - 'Local', - 'Description', - 'Policies', - 'Roles', - // SecretID isn't writable but we need it to identify an - // update via the old API, see TokenAdapter dataForRequest - 'SecretID', - 'AccessorID', -]); -export default model; diff --git a/ui-v2/app/serializers/policy.js b/ui-v2/app/serializers/policy.js index 3f07501161e8..aac641b8148c 100644 --- a/ui-v2/app/serializers/policy.js +++ b/ui-v2/app/serializers/policy.js @@ -1,8 +1,7 @@ import Serializer from './application'; -import { PRIMARY_KEY, SLUG_KEY, ATTRS } from 'consul-ui/models/policy'; +import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/policy'; export default Serializer.extend({ primaryKey: PRIMARY_KEY, slugKey: SLUG_KEY, - attrs: ATTRS, }); diff --git a/ui-v2/app/serializers/token.js b/ui-v2/app/serializers/token.js index cbd4785de573..c12824efa928 100644 --- a/ui-v2/app/serializers/token.js +++ b/ui-v2/app/serializers/token.js @@ -1,6 +1,6 @@ import Serializer from './application'; import { get } from '@ember/object'; -import { PRIMARY_KEY, SLUG_KEY, ATTRS } from 'consul-ui/models/token'; +import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/token'; import WithPolicies from 'consul-ui/mixins/policy/as-many'; import WithRoles from 'consul-ui/mixins/role/as-many'; @@ -8,7 +8,6 @@ import WithRoles from 'consul-ui/mixins/role/as-many'; export default Serializer.extend(WithPolicies, WithRoles, { primaryKey: PRIMARY_KEY, slugKey: SLUG_KEY, - attrs: ATTRS, serialize: function(snapshot, options) { let data = this._super(...arguments); // If a token has Rules, use the old API shape