Ignore:
Timestamp:
Feb 10, 2017, 2:45:35 PM (7 years ago)
Author:
casties
Branch:
default
Tags:
tip
Message:

check admin permission before changing permissions.
Enum for typesafe actions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/de/mpiwg/itgroup/annotations/Annotation.java

    r95 r105  
    132132   
    133133    /**
     134     * Enum of actions (for permissions).
     135     */
     136    public static enum Action {
     137        read, update, create, delete, admin
     138    }
     139   
     140    /**
    134141     * Returns if the requested action is allowed for the given user on this annotation.
    135142     *
     
    139146     * @return
    140147     */
    141     public boolean isActionAllowed(String action, Person user, AnnotationStore store) {
    142         if (action.equals("read")) {
     148    public boolean isActionAllowed(Action action, Person user, AnnotationStore store) {
     149        if (action == Action.read) {
    143150            Actor reader = getReadPermission();
    144151            if (reader == null) {
     
    148155                return reader.isEquivalentWith(user, store);
    149156            }
    150         } else if (action.equals("update")) {
     157        } else if (action == Action.update) {
    151158            // require at least an authenticated user
    152159            if (user == null) return false;
     
    158165                return updater.isEquivalentWith(user, store);
    159166            }
    160         } else if (action.equals("delete")) {
     167        } else if (action == Action.delete) {
    161168            // require at least an authenticated user
    162169            if (user == null) return false;
     
    167174            }
    168175            return deleter.isEquivalentWith(user, store);
    169         } else if (action.equals("admin")) {
     176        } else if (action == Action.admin) {
    170177            // require at least an authenticated user
    171178            if (user == null) return false;
Note: See TracChangeset for help on using the changeset viewer.