feat: 🎸 add grant_scope_ids to role model (#2308)
* feat: 🎸 add grant_scope_ids to role model ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12709 * refactor: 💡 remove removeGrantScopes method ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12709 * style: 💄 add braces around if statement ✅ Closes: https://hashicorp.atlassian.net/browse/ICU-12709
This commit is contained in:
1 parent
c0cecda312
commit
f9e85aa9aa
5 files changed
+123
-6
No files matched your search
@@ -28,6 +28,12 @@ export default class GeneratedRoleModel extends BaseModel {
|
||||
})
|
||||
grant_scope_id;
|
||||
|
||||
@attr('array', {
|
||||
description:
|
||||
"The scopes to which this role applies. Defaults to the role's scope.",
|
||||
})
|
||||
grant_scope_ids;
|
||||
|
||||
@attr('date', {
|
||||
description: 'The time this resource was created\nOutput only.',
|
||||
readOnly: true,
|
||||
|
||||
@@ -74,6 +74,20 @@ export default class RoleModel extends GeneratedRoleModel {
|
||||
|
||||
// =methods
|
||||
|
||||
/**
|
||||
* Saves grant scope ids on the role via the `set-grant-scopes` method.
|
||||
* @param {[string]} grantScopeIDs
|
||||
* @return {Promise}
|
||||
*/
|
||||
setGrantScopes(grantScopeIDs) {
|
||||
return this.save({
|
||||
adapterOptions: {
|
||||
method: 'set-grant-scopes',
|
||||
grantScopeIDs,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves grant strings on the role via the `set-grants` method.
|
||||
* See serializer and adapter for more information.
|
||||
|
||||
@@ -15,23 +15,35 @@ export default class RoleSerializer extends ApplicationSerializer {
|
||||
* serialized.
|
||||
* If `adapterOptions.principalIDs` is set (to an array of user and
|
||||
* group IDs), then the payload is serialized via `serializeWithPrincipals`.
|
||||
* If `adapterOptions.grantScopeIDs` is set (to an array of scope IDs or
|
||||
* keywords), then the payload is serialized via `serializeWithGrantScopeIDs`.
|
||||
* @override
|
||||
* @param {Snapshot} snapshot
|
||||
* @return {object}
|
||||
*/
|
||||
serialize(snapshot) {
|
||||
const grantStrings = get(snapshot, 'adapterOptions.grantStrings');
|
||||
let serialized = super.serialize(...arguments);
|
||||
if (grantStrings)
|
||||
|
||||
const grantStrings = get(snapshot, 'adapterOptions.grantStrings');
|
||||
if (grantStrings) {
|
||||
serialized = this.serializeWithGrantStrings(snapshot, grantStrings);
|
||||
}
|
||||
|
||||
const principalIDs = snapshot?.adapterOptions?.principalIDs;
|
||||
if (principalIDs)
|
||||
if (principalIDs) {
|
||||
serialized = this.serializeWithPrincipals(snapshot, principalIDs);
|
||||
}
|
||||
|
||||
const grantScopeIDs = snapshot?.adapterOptions?.grantScopeIDs;
|
||||
if (grantScopeIDs) {
|
||||
serialized = this.serializeWithGrantScopeIDs(snapshot, grantScopeIDs);
|
||||
}
|
||||
|
||||
return serialized;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a payload containing only the grants array.
|
||||
* Returns a payload containing only the grants array and version.
|
||||
* @param {Snapshot} snapshot
|
||||
* @param {[string]} grantStrings
|
||||
* @return {object}
|
||||
@@ -44,8 +56,8 @@ export default class RoleSerializer extends ApplicationSerializer {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a payload containing only the principal_ids array using IDs
|
||||
* passed into the function (rather than existing principals on the model).
|
||||
* Returns a payload containing only the principal_ids array using IDs passed
|
||||
* into the function (rather than existing principals on the model) and version.
|
||||
* @param {Snapshot} snapshot
|
||||
* @param {[string]} principalIDs
|
||||
* @return {object}
|
||||
@@ -56,4 +68,17 @@ export default class RoleSerializer extends ApplicationSerializer {
|
||||
principal_ids: principalIDs,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a payload containing only the grant_scope_ids array and version.
|
||||
* @param {Snapshot} snapshot
|
||||
* @param {[string]} grantScopeIDs
|
||||
* @return {object}
|
||||
*/
|
||||
serializeWithGrantScopeIDs(snapshot, grantScopeIDs) {
|
||||
return {
|
||||
version: snapshot.attr('version'),
|
||||
grant_scope_ids: grantScopeIDs,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user