diff --git a/src/main/java/org/wise/portal/domain/user/User.java b/src/main/java/org/wise/portal/domain/user/User.java index 7126aebd9..016fd85d6 100644 --- a/src/main/java/org/wise/portal/domain/user/User.java +++ b/src/main/java/org/wise/portal/domain/user/User.java @@ -20,6 +20,8 @@ */ package org.wise.portal.domain.user; +import java.util.List; + import org.wise.portal.domain.Persistable; import org.wise.portal.domain.authentication.MutableUserDetails; @@ -49,4 +51,6 @@ public interface User extends Persistable, Comparable { boolean isTeacher(); boolean isTrustedAuthor(); + + List getRoles(); } diff --git a/src/main/java/org/wise/portal/domain/user/impl/UserImpl.java b/src/main/java/org/wise/portal/domain/user/impl/UserImpl.java index e2e0f47c7..83a164a63 100644 --- a/src/main/java/org/wise/portal/domain/user/impl/UserImpl.java +++ b/src/main/java/org/wise/portal/domain/user/impl/UserImpl.java @@ -20,6 +20,9 @@ */ package org.wise.portal.domain.user.impl; +import java.util.ArrayList; +import java.util.List; + import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; @@ -91,13 +94,31 @@ public boolean isTrustedAuthor() { return userDetails.hasGrantedAuthority(UserDetailsService.TRUSTED_AUTHOR_ROLE); } + public List getRoles() { + List roles = new ArrayList(); + if (this.isAdmin()) { + roles.add("admin"); + } + if (this.isResearcher()) { + roles.add("researcher"); + } + if (this.isTrustedAuthor()) { + roles.add("trustedAuthor"); + } + if (this.isTeacher()) { + roles.add("teacher"); + } + if (this.isStudent()) { + roles.add("student"); + } + return roles; + } + @Override public int hashCode() { final int PRIME = 31; int result = 1; - result = PRIME - * result - + ((userDetails == null) ? 0 : userDetails.hashCode()); + result = PRIME * result + ((userDetails == null) ? 0 : userDetails.hashCode()); return result; } @@ -108,7 +129,8 @@ public boolean equals(Object obj) { if (obj == null) return false; if (obj instanceof HibernateProxy) { - if (getClass() != (( HibernateProxy) obj).getHibernateLazyInitializer().getImplementation().getClass()) { + if (getClass() != ((HibernateProxy) obj).getHibernateLazyInitializer().getImplementation() + .getClass()) { return false; } } else if (getClass() != obj.getClass()) diff --git a/src/main/java/org/wise/portal/presentation/web/controllers/user/UserAPIController.java b/src/main/java/org/wise/portal/presentation/web/controllers/user/UserAPIController.java index 3416d6efe..f3937d222 100644 --- a/src/main/java/org/wise/portal/presentation/web/controllers/user/UserAPIController.java +++ b/src/main/java/org/wise/portal/presentation/web/controllers/user/UserAPIController.java @@ -106,17 +106,8 @@ HashMap 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", user.getRoles()); + if (user.isTeacher()) { TeacherUserDetails tud = (TeacherUserDetails) ud; info.put("displayName", tud.getDisplayname()); info.put("email", tud.getEmailAddress());