Skip to content

Commit

Permalink
#139: catch no roles situation
Browse files Browse the repository at this point in the history
  • Loading branch information
JoernBerkefeld committed Mar 23, 2023
1 parent 1353a73 commit a4ef963
Showing 1 changed file with 39 additions and 24 deletions.
63 changes: 39 additions & 24 deletions lib/metadataTypes/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,14 +413,22 @@ class User extends MetadataType {
// delete global roles from user that were not in the c__RoleNamesGlobal array / Roles.Role
const deletedRoles = [];
const deletedRoleNames = [];
if (item.after?.Roles?.Role && !Array.isArray(item.after.Roles.Role)) {
item.after.Roles.Role = [item.after.Roles.Role];
}
if (item.before?.Roles?.Role) {
if (!Array.isArray(item.before.Roles.Role)) {
item.before.Roles.Role = [item.before.Roles.Role];
}
for (const oldRole of item.before.Roles.Role) {
// check if oldRole is missing in list of new roles --> removing role
let oldRoleFound = false;
for (const newRole of item.after.Roles.Role) {
if (newRole.ObjectID == oldRole.ObjectID) {
oldRoleFound = true;
break;
if (item.after.Roles?.Role) {
for (const newRole of item.after.Roles.Role) {
if (newRole.ObjectID == oldRole.ObjectID) {
oldRoleFound = true;
break;
}
}
}
if (!oldRoleFound && !oldRole.Name.startsWith('Individual role for ')) {
Expand All @@ -431,31 +439,33 @@ class User extends MetadataType {
}
}
const addedRoleNames = [];
for (const newRole of item.after.Roles.Role) {
// check if newRole is missing in list of old roles --> adding role
let roleAlreadyExisting = false;
if (item.before?.Roles?.Role) {
for (const oldRole of item.before.Roles.Role) {
if (newRole.ObjectID == oldRole.ObjectID) {
roleAlreadyExisting = true;
break;
if (item.after?.Roles?.Role) {
for (const newRole of item.after.Roles.Role) {
// check if newRole is missing in list of old roles --> adding role
let roleAlreadyExisting = false;
if (item.before?.Roles?.Role) {
for (const oldRole of item.before.Roles.Role) {
if (newRole.ObjectID == oldRole.ObjectID) {
roleAlreadyExisting = true;
break;
}
}
}
if (!roleAlreadyExisting) {
addedRoleNames.push(newRole.Name);
// Note: no AssignmentConfigurations property is needed to ADD global roles
}
}
if (!roleAlreadyExisting) {
addedRoleNames.push(newRole.Name);
// Note: no AssignmentConfigurations property is needed to ADD global roles
if (addedRoleNames.length) {
Util.logger.info(
Util.getGrayMsg(
` - adding role-assignment (${item.after.CustomerKey} / ${
item.after.Name
}): ${addedRoleNames.join(', ')}`
)
);
}
}
if (addedRoleNames.length) {
Util.logger.info(
Util.getGrayMsg(
` - adding role-assignment (${item.after.CustomerKey} / ${
item.after.Name
}): ${addedRoleNames.join(', ')}`
)
);
}
if (deletedRoles.length) {
Util.logger.info(
Util.getGrayMsg(
Expand All @@ -465,6 +475,11 @@ class User extends MetadataType {
)
);
// add deleted roles to payload with IsDelete=true
if (!item.after.Roles) {
item.after.Roles = { Role: [] };
} else if (!item.after.Roles.Role) {
item.after.Roles.Role = [];
}
item.after.Roles.Role.push(
...deletedRoles.map((role) =>
this._getRoleObjectForDeploy(
Expand Down

0 comments on commit a4ef963

Please sign in to comment.