Skip to content

Commit

Permalink
Issue #79: Refactor UserController as demonstrated in PR 13
Browse files Browse the repository at this point in the history
Applied refactoring from PR #13
  • Loading branch information
ddelponte committed Oct 4, 2017
1 parent 341c1f7 commit fccf262
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,12 @@ class UserController extends AbstractS2UiDomainController {
if (!userRoleNames) {
return [:]
}
Map granted = [:]
Map notGranted = [:]
Map roleMap = [:]
for (role in sortedRoles()) {
String authority = role[authorityNameField]
if (userRoleNames.contains(authority)) {
granted[(role)] = userRoleNames.contains(authority)
} else {
notGranted[(role)] = userRoleNames.contains(authority)
}
roleMap[(role)] = userRoleNames.contains(authority)
}
return granted + notGranted
return roleMap
}

protected List sortedRoles() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class UserControllerSpec extends Specification implements ControllerUnitTest<Use

then: "the user is only granted access to roles with which they are associated"
results == expectedResults
results instanceof LinkedHashMap

where:
rolesAssignedToUser | expectedResults
Expand Down

0 comments on commit fccf262

Please sign in to comment.