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: [Backport 1.9.x] Fixup displaying a Nspace default policy when expanding the preview pane #12411

Merged
merged 1 commit into from
Feb 28, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/12316.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
ui: Ensure we always display the Policy default preview in the Namespace editing form
```
46 changes: 26 additions & 20 deletions ui/packages/consul-ui/app/serializers/nspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,29 @@ import Serializer from './application';
import { get } from '@ember/object';
import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/nspace';

const normalizeACLs = item => {
if (get(item, 'ACLs.PolicyDefaults')) {
item.ACLs.PolicyDefaults = item.ACLs.PolicyDefaults.map(function(item) {
if (typeof item.template === 'undefined') {
item.template = '';
}
return item;
});
}
// Both of these might come though unset so we make sure we at least
// have an empty array here so we can add children to them if we
// need to whilst saving nspaces
['PolicyDefaults', 'RoleDefaults'].forEach(function(prop) {
if (typeof item.ACLs === 'undefined') {
item.ACLs = [];
}
if (typeof item.ACLs[prop] === 'undefined') {
item.ACLs[prop] = [];
}
});
return item;
};

export default class NspaceSerializer extends Serializer {
primaryKey = PRIMARY_KEY;
slugKey = SLUG_KEY;
Expand All @@ -11,24 +34,7 @@ export default class NspaceSerializer extends Serializer {
return this.attachHeaders(
headers,
body.map(function(item) {
if (get(item, 'ACLs.PolicyDefaults')) {
item.ACLs.PolicyDefaults = item.ACLs.PolicyDefaults.map(function(item) {
item.template = '';
return item;
});
}
// Both of these might come though unset so we make sure we at least
// have an empty array here so we can add children to them if we
// need to whilst saving nspaces
['PolicyDefaults', 'RoleDefaults'].forEach(function(prop) {
if (typeof item.ACLs === 'undefined') {
item.ACLs = [];
}
if (typeof item.ACLs[prop] === 'undefined') {
item.ACLs[prop] = [];
}
});
return item;
return normalizeACLs(item);
})
);
});
Expand All @@ -39,7 +45,7 @@ export default class NspaceSerializer extends Serializer {
// queries on form views yet, and by the time we do Serializers should
// have been refactored to not use attachHeaders
return respond((headers, body) => {
return body;
return normalizeACLs(body);
});
}

Expand All @@ -54,7 +60,7 @@ export default class NspaceSerializer extends Serializer {

respondForUpdateRecord(respond, serialized, data) {
return respond((headers, body) => {
return body;
return normalizeACLs(body);
});
}

Expand Down