Skip to content

Commit

Permalink
#139: block deployments of users with "Marketing Cloud" roles
Browse files Browse the repository at this point in the history
because they are not added and, if already existing, removed even if kept in the payload
  • Loading branch information
JoernBerkefeld committed Mar 22, 2023
1 parent 315b553 commit 235482a
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions lib/metadataTypes/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,23 +86,28 @@ class User extends MetadataType {
(roleName) => !roleName.startsWith('Individual role for ')
)
.map((roleName) => {
let roleCache;
try {
const roleKey = cache.searchForField(
'role',
roleName,
'Name',
'CustomerKey'
);
const roleCache = cache.getByKey('role', roleKey);
return {
ObjectID: roleCache.ObjectID,
Name: roleName,
notAssignable: roleCache.c__notAssignable || false,
};
roleCache = cache.getByKey('role', roleKey);
} catch {
// skip this role in case of errors
return;
}
if (roleCache?.c__notAssignable) {
throw new Error(
`Default roles starting on 'Marketing Cloud' are not assignable via API and get removed upon update. Please create/update the user manually in the GUI or remove that role.`
);
}
return {
ObjectID: roleCache.ObjectID,
Name: roleName,
};
})
.filter(Boolean),
};
Expand Down Expand Up @@ -433,17 +438,9 @@ class User extends MetadataType {
}
}
if (!roleAlreadyExisting) {
if (newRole.notAssignable) {
Util.logger.warn(
` ☇ skipping new role ${newRole.Name}: default roles starting on 'Marketing Cloud' are not assignable via API. Please assign them manually in the GUI`
);
} else {
addedRoleNames.push(newRole.Name);
}
addedRoleNames.push(newRole.Name);
// Note: no AssignmentConfigurations property is needed to ADD global roles
}
// remove custom field that we added merely to easily identify not-addable roles
delete newRole.notAssignable;
}
if (addedRoleNames.length) {
Util.logger.info(
Expand Down

0 comments on commit 235482a

Please sign in to comment.