Skip to content

Commit

Permalink
feat(User): Change role to roles
Browse files Browse the repository at this point in the history
  • Loading branch information
geoffreykwan committed Feb 26, 2024
1 parent 102aa23 commit 63507e2
Showing 1 changed file with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,8 @@ HashMap<String, Object> getUserInfo(Authentication auth,
info.put("isPreviousAdmin", isPreviousAdmin(auth));
info.put("language", ud.getLanguage());
info.put("isGoogleUser", ud.isGoogleUser());

if (user.isStudent()) {
info.put("role", "student");
} else {
if (user.isAdmin()) {
info.put("role", "admin");
} else if (user.isResearcher()) {
info.put("role", "researcher");
} else if (user.isTeacher()) {
info.put("role", "teacher");
}
info.put("roles", getRoles(user));
if (user.isTeacher()) {
TeacherUserDetails tud = (TeacherUserDetails) ud;
info.put("displayName", tud.getDisplayname());
info.put("email", tud.getEmailAddress());
Expand All @@ -133,6 +124,26 @@ HashMap<String, Object> getUserInfo(Authentication auth,
return info;
}

private List<String> getRoles(User user) {
List<String> roles = new ArrayList<String>();
if (user.isAdmin()) {
roles.add("admin");
}
if (user.isResearcher()) {
roles.add("researcher");
}
if (user.isTrustedAuthor()) {
roles.add("trustedAuthor");
}
if (user.isTeacher()) {
roles.add("teacher");
}
if (user.isStudent()) {
roles.add("student");
}
return roles;
}

@Secured("ROLE_TEACHER")
@GetMapping("/info/{userId}")
HashMap<String, Object> getStudentUserInfoById(Authentication auth, @PathVariable Long userId)
Expand Down

0 comments on commit 63507e2

Please sign in to comment.