Skip to content
Snippets Groups Projects
Commit 31a2613b authored by Julian Hochstetter's avatar Julian Hochstetter
Browse files

Task #4061: die Rolle des Benutzers muss berücksichtigt werden

parent 53942f1a
No related merge requests found
...@@ -204,10 +204,24 @@ public class CouchDBDao implements IDatabaseDao { ...@@ -204,10 +204,24 @@ public class CouchDBDao implements IDatabaseDao {
if (session == null) { if (session == null) {
throw new NotFoundException(); throw new NotFoundException();
} }
User user = this.userService.getCurrentUser();
View view = null;
try { try {
View view = new View("skill_question/by_session_sorted_by_subject_and_text"); if(session.getCreator().equals(user.getUsername())) {
view.setStartKey("[" + URLEncoder.encode("\"" + session.get_id() + "\"", "UTF-8") + "]"); view = new View("skill_question/by_session_sorted_by_subject_and_text");
view.setEndKey("[" + URLEncoder.encode("\"" + session.get_id() + "\",{}", "UTF-8") + "]"); view.setStartKey("[" + URLEncoder.encode("\"" + session.get_id() + "\"", "UTF-8") + "]");
view.setEndKey("[" + URLEncoder.encode("\"" + session.get_id() + "\",{}", "UTF-8") + "]");
} else {
if(user.getType().equals(User.THM)) {
view = new View("skill_question/by_session_for_thm");
} else {
view = new View("skill_question/by_session_for_all");
}
view.setKey(URLEncoder.encode("\"" + session.get_id() + "\"", "UTF-8"));
}
ViewResults questions = this.getDatabase().view(view); ViewResults questions = this.getDatabase().view(view);
if (questions == null || questions.isEmpty()) { if (questions == null || questions.isEmpty()) {
......
...@@ -10,38 +10,47 @@ import org.springframework.security.authentication.AnonymousAuthenticationToken; ...@@ -10,38 +10,47 @@ import org.springframework.security.authentication.AnonymousAuthenticationToken;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
public class User implements Serializable { public class User implements Serializable {
public static final String GOOGLE = "google";
public static final String TWITTER = "twitter";
public static final String FACEBOOK = "facebook";
public static final String THM = "thm";
public static final String LDAP = "ldap";
public static final String ANONYMOUS = "anonymous";
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private String username; private String username;
private String type; private String type;
public User(Google2Profile profile) { public User(Google2Profile profile) {
setUsername(profile.getEmail()); setUsername(profile.getEmail());
setType("google"); setType(User.GOOGLE);
} }
public User(TwitterProfile profile) { public User(TwitterProfile profile) {
setUsername(profile.getScreenName()); setUsername(profile.getScreenName());
setType("twitter"); setType(User.TWITTER);
} }
public User(FacebookProfile profile) { public User(FacebookProfile profile) {
setUsername(profile.getLink()); setUsername(profile.getLink());
setType("facebook"); setType(User.FACEBOOK);
} }
public User(AttributePrincipal principal) { public User(AttributePrincipal principal) {
setUsername(principal.getName()); setUsername(principal.getName());
setType("thm"); setType(User.THM);
} }
public User(AnonymousAuthenticationToken token) { public User(AnonymousAuthenticationToken token) {
setUsername("anonymous"); setUsername(User.ANONYMOUS);
setType("anonymous"); setType(User.ANONYMOUS);
} }
public User(UsernamePasswordAuthenticationToken token) { public User(UsernamePasswordAuthenticationToken token) {
setUsername(token.getName()); setUsername(token.getName());
setType("ldap"); setType(LDAP);
} }
public String getUsername() { public String getUsername() {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment