Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Dec 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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