Mercurial > hg > AnnotationManagerN4J
comparison 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 |
comparison
equal
deleted
inserted
replaced
104:e953327d66bb | 105:7417f5915181 |
---|---|
129 * List of tags on this Annotation. | 129 * List of tags on this Annotation. |
130 */ | 130 */ |
131 protected Set<String> tags; | 131 protected Set<String> tags; |
132 | 132 |
133 /** | 133 /** |
134 * Enum of actions (for permissions). | |
135 */ | |
136 public static enum Action { | |
137 read, update, create, delete, admin | |
138 } | |
139 | |
140 /** | |
134 * Returns if the requested action is allowed for the given user on this annotation. | 141 * Returns if the requested action is allowed for the given user on this annotation. |
135 * | 142 * |
136 * @param action | 143 * @param action |
137 * @param user | 144 * @param user |
138 * @param store AnnotationStore to check group membership | 145 * @param store AnnotationStore to check group membership |
139 * @return | 146 * @return |
140 */ | 147 */ |
141 public boolean isActionAllowed(String action, Person user, AnnotationStore store) { | 148 public boolean isActionAllowed(Action action, Person user, AnnotationStore store) { |
142 if (action.equals("read")) { | 149 if (action == Action.read) { |
143 Actor reader = getReadPermission(); | 150 Actor reader = getReadPermission(); |
144 if (reader == null) { | 151 if (reader == null) { |
145 // if not specified then everybody is allowed | 152 // if not specified then everybody is allowed |
146 return true; | 153 return true; |
147 } else { | 154 } else { |
148 return reader.isEquivalentWith(user, store); | 155 return reader.isEquivalentWith(user, store); |
149 } | 156 } |
150 } else if (action.equals("update")) { | 157 } else if (action == Action.update) { |
151 // require at least an authenticated user | 158 // require at least an authenticated user |
152 if (user == null) return false; | 159 if (user == null) return false; |
153 Actor updater = getUpdatePermission(); | 160 Actor updater = getUpdatePermission(); |
154 if (updater == null) { | 161 if (updater == null) { |
155 // if not specified then everybody is allowed | 162 // if not specified then everybody is allowed |
156 return true; | 163 return true; |
157 } else { | 164 } else { |
158 return updater.isEquivalentWith(user, store); | 165 return updater.isEquivalentWith(user, store); |
159 } | 166 } |
160 } else if (action.equals("delete")) { | 167 } else if (action == Action.delete) { |
161 // require at least an authenticated user | 168 // require at least an authenticated user |
162 if (user == null) return false; | 169 if (user == null) return false; |
163 Actor deleter = getDeletePermission(); | 170 Actor deleter = getDeletePermission(); |
164 if (deleter == null) { | 171 if (deleter == null) { |
165 // if not specified then only creator is allowed | 172 // if not specified then only creator is allowed |
166 deleter = creator; | 173 deleter = creator; |
167 } | 174 } |
168 return deleter.isEquivalentWith(user, store); | 175 return deleter.isEquivalentWith(user, store); |
169 } else if (action.equals("admin")) { | 176 } else if (action == Action.admin) { |
170 // require at least an authenticated user | 177 // require at least an authenticated user |
171 if (user == null) return false; | 178 if (user == null) return false; |
172 Actor admin = getAdminPermission(); | 179 Actor admin = getAdminPermission(); |
173 if (admin == null) { | 180 if (admin == null) { |
174 // if not specified then only creator is allowed | 181 // if not specified then only creator is allowed |