comparison src/main/java/de/mpiwg/itgroup/annotations/Annotation.java @ 15:58357a4b86de

ASSIGNED - # 249: Annotations shared in groups https://it-dev.mpiwg-berlin.mpg.de/tracs/mpdl-project-software/ticket/249
author casties
date Tue, 28 Aug 2012 20:23:12 +0200
parents 629e15b345aa
children 794077e6288c
comparison
equal deleted inserted replaced
14:629e15b345aa 15:58357a4b86de
1 /** 1 /**
2 * 2 *
3 */ 3 */
4 package de.mpiwg.itgroup.annotations; 4 package de.mpiwg.itgroup.annotations;
5
6 import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore;
5 7
6 /** 8 /**
7 * @author casties 9 * @author casties
8 * 10 *
9 */ 11 */
83 85
84 /** 86 /**
85 * Returns if the requested action is allowed on this annotation. 87 * Returns if the requested action is allowed on this annotation.
86 * 88 *
87 * @param action 89 * @param action
88 * @param userId 90 * @param user
91 * @param store AnnotationStore to check group membership
89 * @return 92 * @return
90 */ 93 */
91 public boolean isActionAllowed(String action, String userId) { 94 public boolean isActionAllowed(String action, Person user, AnnotationStore store) {
92 if (action.equals("read")) { 95 if (action.equals("read")) {
93 Actor reader = getReadPermission(); 96 Actor reader = getReadPermission();
94 if (reader == null) { 97 if (reader == null) {
95 return true; 98 return true;
96 } else { 99 } else {
97 return reader.isEquivalentWith(userId); 100 return reader.isEquivalentWith(user, store);
98 } 101 }
99 } else if (action.equals("update")) { 102 } else if (action.equals("update")) {
100 // require at least an authenticated user 103 // require at least an authenticated user
101 if (userId == null) return false; 104 if (user == null) return false;
102 Actor updater = getUpdatePermission(); 105 Actor updater = getUpdatePermission();
103 if (updater == null) { 106 if (updater == null) {
104 return true; 107 return true;
105 } else { 108 } else {
106 return updater.isEquivalentWith(userId); 109 return updater.isEquivalentWith(user, store);
107 } 110 }
108 } else if (action.equals("delete")) { 111 } else if (action.equals("delete")) {
109 // require at least an authenticated user 112 // require at least an authenticated user
110 if (userId == null) return false; 113 if (user == null) return false;
111 Actor updater = getUpdatePermission(); 114 Actor updater = getUpdatePermission();
112 if (updater == null) { 115 if (updater == null) {
113 return true; 116 return true;
114 } else { 117 } else {
115 return updater.isEquivalentWith(userId); 118 return updater.isEquivalentWith(user, store);
116 } 119 }
117 } else if (action.equals("admin")) { 120 } else if (action.equals("admin")) {
118 // require at least an authenticated user 121 // require at least an authenticated user
119 if (userId == null) return false; 122 if (user == null) return false;
120 Actor admin = getAdminPermission(); 123 Actor admin = getAdminPermission();
121 if (admin == null) { 124 if (admin == null) {
122 return true; 125 return true;
123 } else { 126 } else {
124 return admin.isEquivalentWith(userId); 127 return admin.isEquivalentWith(user, store);
125 } 128 }
126 } 129 }
127 return false; 130 return false;
128 } 131 }
129 132