2020-06-22 21:39:38 -04:00
|
|
|
import ApplicationSerializer from './application';
|
|
|
|
|
|
|
|
|
|
export default ApplicationSerializer.extend({
|
2020-08-28 17:34:14 -04:00
|
|
|
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'
|
|
|
|
|
}));
|
|
|
|
|
json.principals = [ ...serializedUsers, ...serializedGroups ];
|
2020-09-12 11:40:21 -04:00
|
|
|
if (!json.principals.length) delete json.principals;
|
2020-11-05 09:38:37 -05:00
|
|
|
|
|
|
|
|
// default grant scope
|
|
|
|
|
if (!json.grant_scope_id) json.grant_scope_id = json.scope.id;
|
|
|
|
|
|
2020-08-28 17:34:14 -04:00
|
|
|
return json;
|
|
|
|
|
}
|
2020-06-22 21:39:38 -04:00
|
|
|
});
|