Skip to content

Commit

Permalink
[#33] Add updateUserInstitution method
Browse files Browse the repository at this point in the history
- method updateUserInstitution is conditional if security provider is "oidc"
- method updateUser is conditional if security provider is "internal"
  • Loading branch information
kostobog committed Dec 12, 2023
1 parent 4ae185f commit 3c6ac92
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/main/java/cz/cvut/kbss/study/rest/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,25 @@ public void removeUser(@PathVariable("username") String username) {
}
}

@ConditionalOnProperty(prefix = "security", name = "provider", havingValue = "oidc")
@PreAuthorize("hasRole('" + SecurityConstants.ROLE_ADMIN + "') or #username == authentication.name")
@PutMapping(value = "/{username}", consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void updateUserInstitution(@PathVariable("username") String username, @RequestBody User user,
@RequestParam(value = "email", defaultValue = "true") boolean sendEmail) {
if (!username.equals(user.getUsername())) {
throw new BadRequestException("The passed user's username is different from the specified one.");
}
final User original = getByUsername(username);
original.setInstitution(user.getInstitution());
assert original != null;
userService.update(original, sendEmail, "profileUpdate");
if (LOG.isTraceEnabled()) {
LOG.trace("Added user {} to institution {} successfully.", user, user.getInstitution());
}
}

@ConditionalOnProperty(prefix = "security", name = "provider", havingValue = "internal")
@PreAuthorize("hasRole('" + SecurityConstants.ROLE_ADMIN + "') or #username == authentication.name")
@PutMapping(value = "/{username}", consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.NO_CONTENT)
Expand Down

0 comments on commit 3c6ac92

Please sign in to comment.