Files
threshold-ui/addons/api/mirage/serializers/role.js
T

46 lines
1.1 KiB
JavaScript
Raw Normal View History

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
2020-06-22 21:39:38 -04:00
import ApplicationSerializer from './application';
export default ApplicationSerializer.extend({
modelName: 'role',
_hashForModel(model) {
2021-03-04 15:47:38 -05:00
const json = ApplicationSerializer.prototype._hashForModel.apply(
this,
arguments
);
const serializedUsers = model.users.models.map((user) => ({
scope_id: model.scope.id,
id: user.id,
2021-03-04 15:47:38 -05:00
type: 'user',
}));
2021-03-04 15:47:38 -05:00
const serializedGroups = model.groups.models.map((group) => ({
scope_id: model.scope.id,
id: group.id,
2021-03-04 15:47:38 -05:00
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;
2021-03-04 15:47:38 -05:00
},
2020-06-22 21:39:38 -04:00
});