Skip to content

Commit

Permalink
[SHIBUI-1031]
Browse files Browse the repository at this point in the history
Fixed an issue where Role wasn't populated/updated properly.
  • Loading branch information
Bill Smith committed Jan 7, 2019
1 parent 4fcd7eb commit 28729c7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ ResponseEntity<?> updateOne(@PathVariable(value = "username") String username, @
if (StringUtils.isNotBlank(user.getPassword())) {
persistedUser.setPassword(BCrypt.hashpw(user.getPassword(), BCrypt.gensalt()));
}
userRoleService.updateUserRole(persistedUser);
if (StringUtils.isNotBlank(user.getRole())) {
persistedUser.setRole(user.getRole());
userRoleService.updateUserRole(persistedUser);
}
User savedUser = userRepository.save(persistedUser);
return ResponseEntity.ok(savedUser);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ public class User extends AbstractAuditable {
private Set<Role> roles = new HashSet<>();

public String getRole() {
Set<Role> roles = this.getRoles();
if (roles.size() != 1) {
if (StringUtils.isNotBlank(this.role)) {
return this.role;
if (StringUtils.isBlank(this.role)) {
Set<Role> roles = this.getRoles();
if (roles.size() != 1) {
throw new RuntimeException(String.format("User with username [%s] does not have exactly one role!", this.getUsername()));
}
throw new RuntimeException(String.format("User with username [%s] does not have exactly one role!", this.getUsername()));
this.role = roles.iterator().next().getName();
}
return roles.iterator().next().getName();
return this.role;
}
}

0 comments on commit 28729c7

Please sign in to comment.