ui: Remove `writable` usage from policy and use the request instead (#6934)

This commit is contained in:
John Cowen 2019-12-17 16:16:43 +00:00 committed by John Cowen
parent 1b5658d5ac
commit 09b46dcfdc
5 changed files with 16 additions and 29 deletions

View File

@ -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) {

View File

@ -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;

View File

@ -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;

View File

@ -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,
});

View File

@ -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