ui: Fixup displaying a Nspace default policy when expanding the preview pane (#12316)

pull/11138/head
John Cowen 3 years ago committed by GitHub
parent 717621698d
commit 360cf89ea5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,3 @@
```release-note:bug
ui: Ensure we always display the Policy default preview in the Namespace editing form
```

@ -2,6 +2,29 @@ import Serializer from './application';
import { get } from '@ember/object'; import { get } from '@ember/object';
import { PRIMARY_KEY, SLUG_KEY } from 'consul-ui/models/nspace'; 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 { export default class NspaceSerializer extends Serializer {
primaryKey = PRIMARY_KEY; primaryKey = PRIMARY_KEY;
slugKey = SLUG_KEY; slugKey = SLUG_KEY;
@ -15,24 +38,7 @@ export default class NspaceSerializer extends Serializer {
body.map(function(item) { body.map(function(item) {
item.Namespace = '*'; item.Namespace = '*';
item.Datacenter = query.dc; item.Datacenter = query.dc;
if (get(item, 'ACLs.PolicyDefaults')) { return normalizeACLs(item);
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;
}) })
) )
), ),
@ -46,7 +52,7 @@ export default class NspaceSerializer extends Serializer {
respond((headers, body) => { respond((headers, body) => {
body.Datacenter = serialized.dc; body.Datacenter = serialized.dc;
body.Namespace = '*'; body.Namespace = '*';
return cb(headers, body); return cb(headers, normalizeACLs(body));
}), }),
serialized, serialized,
data data
@ -59,7 +65,7 @@ export default class NspaceSerializer extends Serializer {
respond((headers, body) => { respond((headers, body) => {
body.Datacenter = serialized.dc; body.Datacenter = serialized.dc;
body.Namespace = '*'; body.Namespace = '*';
return cb(headers, body); return cb(headers, normalizeACLs(body));
}), }),
serialized, serialized,
data data
@ -68,7 +74,7 @@ export default class NspaceSerializer extends Serializer {
respondForUpdateRecord(respond, serialized, data) { respondForUpdateRecord(respond, serialized, data) {
return respond((headers, body) => { return respond((headers, body) => {
return body; return normalizeACLs(body);
}); });
} }
} }

Loading…
Cancel
Save