Show the user roles as real names (#867)

* Show the user roles as real names

* Add error message

* Update Role.java

* default Language without translation

* Update messages_el_GR.properties
This commit is contained in:
Ludy
2024-03-06 23:14:02 +01:00
committed by GitHub
parent ece1d071c0
commit 97472310f2
32 changed files with 166 additions and 17 deletions

View File

@@ -222,18 +222,22 @@ public class UserController {
@PreAuthorize("hasRole('ROLE_ADMIN')")
@PostMapping("/admin/deleteUser/{username}")
public String deleteUser(@PathVariable String username, Authentication authentication) {
public RedirectView deleteUser(@PathVariable String username, Authentication authentication) {
if (!userService.usernameExists(username)) {
return new RedirectView("/addUsers?messageType=deleteUsernameExists");
}
// Get the currently authenticated username
String currentUsername = authentication.getName();
// Check if the provided username matches the current session's username
if (currentUsername.equals(username)) {
throw new IllegalArgumentException("Cannot delete currently logined in user.");
return new RedirectView("/addUsers?messageType=deleteCurrentUser");
}
invalidateUserSessions(username);
userService.deleteUser(username);
return "redirect:/addUsers";
return new RedirectView("/addUsers");
}
@Autowired private SessionRegistry sessionRegistry;