Files
threshold-ui/addons/api/mirage/serializers/role.js
T
hashicorp-copywrite[bot]andCameron Perera 3d610427d0 [COMPLIANCE] Add Copyright and License Headers (#1617)
* [COMPLIANCE] Add Copyright and License Headers

* chore: 🤖 update Copyright headers to satisfy our lint rules

---------

Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
Co-authored-by: Cameron Perera <cameron.perera@hashicorp.com>
2023-03-01 09:39:41 -06:00

47 lines
1.1 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import ApplicationSerializer from './application';
export default ApplicationSerializer.extend({
modelName: 'role',
_hashForModel(model) {
const json = ApplicationSerializer.prototype._hashForModel.apply(
this,
arguments
);
const serializedUsers = model.users.models.map((user) => ({
scope_id: model.scope.id,
id: user.id,
type: 'user',
}));
const serializedGroups = model.groups.models.map((group) => ({
scope_id: model.scope.id,
id: group.id,
type: 'group',
}));
const serializedManagedGroups = model.managedGroups.models.map(
(managedGroup) => ({
scope_id: model.scope.id,
id: managedGroup.id,
type: 'managed group',
})
);
json.principals = [
...serializedUsers,
...serializedGroups,
...serializedManagedGroups,
];
if (!json.principals.length) delete json.principals;
// default grant scope
if (!json.grant_scope_id) json.grant_scope_id = json.scope.id;
return json;
},
});