Skip to content

Commit

Permalink
allow admins to do member-only actions on collections
Browse files Browse the repository at this point in the history
  • Loading branch information
smeets committed Nov 22, 2017
1 parent 7969be2 commit 25921c8
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/main/java/se/lth/cs/connect/routes/Collection.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ protected void setup(PippoSettings conf) {
});

if (res.resultOf(new JcBoolean("ok")).size() == 0)
throw new RequestException("id does not exist in database");

throw new RequestException("id does not exist in database");
rc.next();
});

Expand Down Expand Up @@ -289,7 +289,7 @@ public RetVal(int mem, int ent) {
throw new RequestException("Not invited to that collection.");
});

// Must be logged in AND member of collection to proceed
// Must be logged in AND member of collection to proceed (or ADMIN)
ALL("/{id}/.*", (rc) -> {
final String email = rc.getSession("email");
final int id = rc.getParameter("id").toInt();
Expand All @@ -304,9 +304,19 @@ public RetVal(int mem, int ent) {
NATIVE.cypher("RETURN TRUE AS ok")
});

if (res.resultOf(new JcBoolean("ok")).size() == 0)
throw new RequestException(403, "You are not a member of that collection");

/* allow admins to do whatever they want */
boolean isAdmin = false;
if (email != null) {
AccountSystem.Account user = AccountSystem.findByEmail(email);
if (TrustLevel.authorize(user.trust, TrustLevel.ADMIN)) {
isAdmin = true;
}
}

if (res.resultOf(new JcBoolean("ok")).size() == 0 && !isAdmin)
throw new RequestException(403, "You are not a member of that collection");

rc.setLocal("admin", isAdmin);
rc.next();
});

Expand Down

0 comments on commit 25921c8

Please sign in to comment.