Skip to content

Commit

Permalink
ui: Remove writable usage from policy and use the request instead
Browse files Browse the repository at this point in the history
  • Loading branch information
John Cowen committed Dec 12, 2019
1 parent c3d2fe1 commit 4316a44
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 29 deletions.
14 changes: 12 additions & 2 deletions ui-v2/app/adapters/policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 1 addition & 5 deletions ui-v2/app/models/policy.js
Original file line number Diff line number Diff line change
@@ -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', {
Expand All @@ -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;
19 changes: 1 addition & 18 deletions ui-v2/app/models/token.js
Original file line number Diff line number Diff line change
@@ -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'),
Expand Down Expand Up @@ -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;
3 changes: 1 addition & 2 deletions ui-v2/app/serializers/policy.js
Original file line number Diff line number Diff line change
@@ -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,
});
3 changes: 1 addition & 2 deletions ui-v2/app/serializers/token.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
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';

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
Expand Down

0 comments on commit 4316a44

Please sign in to comment.