Today, we had an issue with a script that checks if you're part of a specific User Group before executing the script. This script checked if you're part Superusers or Reviewers group. The first group, named Superusers, will be familiar to you. This is one of the internal groups that Content Hub ships with. The second group is a custom created group specifically created for this implementation.
So which part of the code failed in the script?
var usergroupsQuery = Query.CreateQuery(entities => entities.Where(e => e.DefinitionName == UserGroupDefinitionName && (e.Identifier == SuperUsersUsergroupName || e.Identifier == ReviewerUsergroupName)));
The above line of searches for UserGroup definitions, that have the identifier of SuperUser or Reviewer (our custom group). This seems to work fine for SuperUsers, but when we tested with Reviewers, it failed. If you have some experience with Content Hub, you might spot the problem already.
If you haven't spotted the problem, no worries, we've got you covered. The problem with the code is that the assumption was made that the Identifier of custom made groups work the same way as the default groups. That's just plain wrong! Only the default groups have a specialized identifier. If we access the two user groups via the API we see the difference clearly.
var usergroupsQuery = Query.CreateQuery(entities => entities.Where(e => e.DefinitionName == UserGroupDefinitionName && (e.Identifier == SuperUsersUsergroupName || e.Property("GroupName") == ReviewerUsergroupName)));
- Only default user groups have named identifiers
- User groups across different environments don't share the same identifier. Each user group has a unique identifier for each environment.
- Use the GroupName property to select a group across multiple environments.