Skip to content

Commit

Permalink
SHIBUI-1999
Browse files Browse the repository at this point in the history
fixed issue when assigning user to admin role (should also put them in
the admin user group regardless of previous group(s))
  • Loading branch information
chasegawa committed Jul 23, 2021
1 parent 9bece3f commit 7e250c6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public void updateUserGroupsWithGroup(Group assignedGroup) {
// 1) If a UG doesn't match the incoming assignment, move it out of the list and into the old for deletion
// 2) If it DOES match, update the group object so hibernate doesn't have a cow
userGroups.forEach(ug -> {
if (ug.getGroup().getResourceId().equals(groupId)) {
if (ug.getGroup().getResourceId().equals(assignedGroup.getResourceId())) {
ug.setGroup(assignedGroup);
setWithNewGroup.add(ug);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,21 @@ class UsersControllerIntegrationTests extends Specification {

def List<UserGroup> groups = ugRepo.findAllByUser(user)
groups.size() == 1

when: 'Updating user role to admin puts the user in the admin group'
user.setRole("ROLE_ADMIN")
user.setGroupId("AAA") // Dont care that this is different, ROLE_ADMIN should take precedence
def resultUserNewRole = mockMvc.perform(patch("$RESOURCE_URI/$user.username").contentType(MediaType.APPLICATION_JSON)
.content(mapper.writeValueAsString(user)).accept(MediaType.APPLICATION_JSON))

then:
resultUserNewRole.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("\$.groupId").value("admingroup"))

def groupsCheck = ugRepo.findAllByUser(user)
groupsCheck.size() == 1

}

@WithMockUser(value = "admin", roles = ["ADMIN"])
Expand Down

0 comments on commit 7e250c6

Please sign in to comment.