hashicorp-copywrite[bot] 5fb9df1640
[COMPLIANCE] License changes (#18443)
* Adding explicit MPL license for sub-package

This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository.

* Adding explicit MPL license for sub-package

This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository.

* Updating the license from MPL to Business Source License

Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at <Blog URL>, FAQ at www.hashicorp.com/licensing-faq, and details of the license at www.hashicorp.com/bsl.

* add missing license headers

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

* Update copyright file headers to BUSL-1.1

---------

Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
2023-08-11 09:12:13 -04:00

86 lines
2.1 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
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;
respondForQuery(respond, query, data, modelClass) {
return super.respondForQuery(
(cb) =>
respond((headers, body) =>
cb(
headers,
body.map(function (item) {
item.Namespace = '*';
item.Datacenter = query.dc;
return normalizeACLs(item);
})
)
),
query
);
}
respondForQueryRecord(respond, serialized, data) {
return super.respondForQuery(
(cb) =>
respond((headers, body) => {
body.Datacenter = serialized.dc;
body.Namespace = '*';
return cb(headers, normalizeACLs(body));
}),
serialized,
data
);
}
respondForCreateRecord(respond, serialized, data) {
return super.respondForCreateRecord(
(cb) =>
respond((headers, body) => {
body.Datacenter = serialized.dc;
body.Namespace = '*';
return cb(headers, normalizeACLs(body));
}),
serialized,
data
);
}
respondForUpdateRecord(respond, serialized, data) {
return respond((headers, body) => {
return normalizeACLs(body);
});
}
}