Skip to content

Commit

Permalink
Tweak mocked directory group lookup handling
Browse files Browse the repository at this point in the history
+ Config name -> `mockDirectoryGroups`
+ Remove need for `xh:` prefix
  • Loading branch information
amcclain committed May 14, 2024
1 parent ef8fbf0 commit 91f923e
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions grails-app/services/io/xh/toolbox/user/RoleService.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,25 @@ import io.xh.hoist.role.provided.DefaultRoleService
*/
class RoleService extends DefaultRoleService {

/**
* Toolbox does not currently connect to an external directory, but supports a `mockDirectoryGroups` config
* so we can simulate directory group lookups and see all group-related controls in the Admin Console Roles UI.
*
* Config should be JSON formatted like: `{"testGroupName": ["user1@example.com", "user2@example.com"]}`.
*
* This mock code also supports use of the special group name `sim_error` to mock a lookup failure.
*/
protected Map<String, Object> doLoadUsersForDirectoryGroups(Set<String> groups, boolean strictMode) {
def config = configService.getMap('testDirectories', [:])
def config = configService.getMap('mockDirectoryGroups', [:])

return groups.collectEntries { group ->
if (!group.startsWith('xh:')) return [group, "Directory name should start with 'xh:'"];

def key = group.takeAfter('xh:')
if (config[key]) return [group, config[key] as Set]
if (key == 'sim_error') {
if (config[group]) return [group, config[group] as Set]
if (group == 'sim_error') {
def e = new RuntimeException('There was a simulated error looking up directory groups.')
if (strictMode) throw e
logError('There was an error', e)
}
return [group, [] as Set]
}
}
}
}

0 comments on commit 91f923e

Please sign in to comment.