Mercurial > hg > AnnotationManagerN4J
diff src/main/java/de/mpiwg/itgroup/annotations/Annotation.java @ 105:7417f5915181 default tip
check admin permission before changing permissions.
Enum for typesafe actions.
author | casties |
---|---|
date | Fri, 10 Feb 2017 15:45:35 +0100 |
parents | acd44dfec9c8 |
children |
line wrap: on
line diff
--- a/src/main/java/de/mpiwg/itgroup/annotations/Annotation.java Fri Feb 10 15:02:32 2017 +0100 +++ b/src/main/java/de/mpiwg/itgroup/annotations/Annotation.java Fri Feb 10 15:45:35 2017 +0100 @@ -131,6 +131,13 @@ protected Set<String> tags; /** + * Enum of actions (for permissions). + */ + public static enum Action { + read, update, create, delete, admin + } + + /** * Returns if the requested action is allowed for the given user on this annotation. * * @param action @@ -138,8 +145,8 @@ * @param store AnnotationStore to check group membership * @return */ - public boolean isActionAllowed(String action, Person user, AnnotationStore store) { - if (action.equals("read")) { + public boolean isActionAllowed(Action action, Person user, AnnotationStore store) { + if (action == Action.read) { Actor reader = getReadPermission(); if (reader == null) { // if not specified then everybody is allowed @@ -147,7 +154,7 @@ } else { return reader.isEquivalentWith(user, store); } - } else if (action.equals("update")) { + } else if (action == Action.update) { // require at least an authenticated user if (user == null) return false; Actor updater = getUpdatePermission(); @@ -157,7 +164,7 @@ } else { return updater.isEquivalentWith(user, store); } - } else if (action.equals("delete")) { + } else if (action == Action.delete) { // require at least an authenticated user if (user == null) return false; Actor deleter = getDeletePermission(); @@ -166,7 +173,7 @@ deleter = creator; } return deleter.isEquivalentWith(user, store); - } else if (action.equals("admin")) { + } else if (action == Action.admin) { // require at least an authenticated user if (user == null) return false; Actor admin = getAdminPermission();