Revision 8d09767f
b/src/gr/grnet/pithos/web/client/FilePermissionsDialog.java | ||
---|---|---|
144 | 144 |
private VerticalPanel createSharingPanel() { |
145 | 145 |
VerticalPanel permPanel = new VerticalPanel(); |
146 | 146 |
|
147 |
permList = new PermissionsList(images, file.getPermissions(), file.getOwnerID(), false, new Command() { |
|
147 |
permList = new PermissionsList(app, images, file.getPermissions(), file.getOwnerID(), false, new Command() {
|
|
148 | 148 |
|
149 | 149 |
@Override |
150 | 150 |
public void execute() { |
b/src/gr/grnet/pithos/web/client/FolderPermissionsDialog.java | ||
---|---|---|
115 | 115 |
|
116 | 116 |
VerticalPanel permPanel = new VerticalPanel(); |
117 | 117 |
FilePermissionsDialog.Images images = GWT.create(FilePermissionsDialog.Images.class); |
118 |
permList = new PermissionsList(images, folder.getPermissions(), folder.getOwnerID(), false, null); |
|
118 |
permList = new PermissionsList(app, images, folder.getPermissions(), folder.getOwnerID(), false, null);
|
|
119 | 119 |
permPanel.add(permList); |
120 | 120 |
|
121 | 121 |
HorizontalPanel permButtons = new HorizontalPanel(); |
b/src/gr/grnet/pithos/web/client/PermissionsAddDialog.java | ||
---|---|---|
34 | 34 |
*/ |
35 | 35 |
package gr.grnet.pithos.web.client; |
36 | 36 |
|
37 |
import com.google.gwt.http.client.Request; |
|
38 |
import com.google.gwt.http.client.Response; |
|
39 |
import com.google.gwt.json.client.JSONObject; |
|
40 |
import gr.grnet.pithos.web.client.catalog.GetUserCatalogs; |
|
41 |
import gr.grnet.pithos.web.client.catalog.UserCatalogs; |
|
37 | 42 |
import gr.grnet.pithos.web.client.grouptree.Group; |
38 | 43 |
|
39 | 44 |
import java.util.List; |
... | ... | |
55 | 60 |
import com.google.gwt.user.client.ui.VerticalPanel; |
56 | 61 |
|
57 | 62 |
public class PermissionsAddDialog extends DialogBox { |
63 |
final static RegExp EmailValidator = RegExp.compile("^[A-Z0-9._%+-]+@[A-Z0-9.-]+[.][A-Z]{2,4}$", "i"); |
|
58 | 64 |
|
59 | 65 |
private TextBox userBox = new TextBox(); |
60 | 66 |
|
... | ... | |
105 | 111 |
permTable.setWidget(1, 0, userBox); |
106 | 112 |
} |
107 | 113 |
else { |
108 |
for (Group group : _groups) |
|
114 |
for (Group group : _groups) {
|
|
109 | 115 |
groupBox.addItem(group.getName(), group.getName()); |
116 |
} |
|
110 | 117 |
permTable.setWidget(1, 0, groupBox); |
111 | 118 |
} |
112 | 119 |
|
... | ... | |
137 | 144 |
} |
138 | 145 |
|
139 | 146 |
protected void addPermission() { |
147 |
final boolean readValue = read.getValue(); |
|
148 |
final boolean writeValue = write.getValue(); |
|
149 |
|
|
140 | 150 |
String selected = null; |
141 | 151 |
if (userAdd) { |
142 |
selected = userBox.getText().trim(); |
|
143 |
RegExp emailValidator = RegExp.compile("^[A-Z0-9._%+-]+@[A-Z0-9.-]+[.][A-Z]{2,4}$", "i"); |
|
144 |
if (!emailValidator.test(selected)) { |
|
145 |
app.displayWarning("Username must be a valid email address"); |
|
146 |
return; |
|
147 |
} |
|
152 |
final String userDisplayName = userBox.getText().trim(); |
|
153 |
addUserPermission(userDisplayName, readValue, writeValue); |
|
154 |
return; |
|
148 | 155 |
} else if (groupBox.getSelectedIndex() > -1) { |
149 | 156 |
String groupName = groupBox.getValue(groupBox.getSelectedIndex()); |
150 | 157 |
selected = app.getUserID() + ":" + groupName; |
... | ... | |
157 | 164 |
return; |
158 | 165 |
} |
159 | 166 |
|
160 |
boolean readValue = read.getValue(); |
|
161 |
boolean writeValue = write.getValue(); |
|
162 |
|
|
163 | 167 |
permList.addPermission(selected, readValue, writeValue); |
164 | 168 |
} |
165 | 169 |
|
170 |
private boolean alreadyHasPermission(String selected) { |
|
171 |
return permList.getPermissions().get(selected) != null; |
|
172 |
} |
|
173 |
|
|
174 |
private void addUserPermission(final String userDisplayName, final boolean readValue, final boolean writeValue) { |
|
175 |
if (!EmailValidator.test(userDisplayName)) { |
|
176 |
app.displayWarning("Username must be a valid email address"); |
|
177 |
return; |
|
178 |
} |
|
179 |
|
|
180 |
// Now get the userID |
|
181 |
final String userID = app.getUserIDForDisplayName(userDisplayName); |
|
182 |
if(userID != null) { |
|
183 |
// Check if already have the permission |
|
184 |
if(!alreadyHasPermission(userID)) { |
|
185 |
permList.addPermission(userID, readValue, writeValue); |
|
186 |
} |
|
187 |
} |
|
188 |
else { |
|
189 |
// Must call server to obtain userID |
|
190 |
new GetUserCatalogs(app, null, Helpers.toList(userDisplayName)) { |
|
191 |
@Override |
|
192 |
public void onSuccess(Request request, Response response, JSONObject result, UserCatalogs userCatalogs) { |
|
193 |
app.getUserCatalogs().updateFrom(userCatalogs); |
|
194 |
final String userID = app.getUserIDForDisplayName(userDisplayName); |
|
195 |
if(userID == null) { |
|
196 |
app.displayWarning("Unknown user " + userDisplayName); |
|
197 |
} |
|
198 |
else if(!alreadyHasPermission(userID)) { |
|
199 |
permList.addPermission(userID, readValue, writeValue); |
|
200 |
} |
|
201 |
} |
|
202 |
}.scheduleDeferred(); |
|
203 |
} |
|
204 |
} |
|
205 |
|
|
166 | 206 |
@Override |
167 | 207 |
protected void onPreviewNativeEvent(NativePreviewEvent preview) { |
168 | 208 |
super.onPreviewNativeEvent(preview); |
b/src/gr/grnet/pithos/web/client/PermissionsList.java | ||
---|---|---|
34 | 34 |
*/ |
35 | 35 |
package gr.grnet.pithos.web.client; |
36 | 36 |
|
37 |
import com.google.gwt.http.client.Request; |
|
38 |
import com.google.gwt.http.client.Response; |
|
39 |
import com.google.gwt.json.client.JSONObject; |
|
37 | 40 |
import gr.grnet.pithos.web.client.FilePermissionsDialog.Images; |
38 | 41 |
|
39 | 42 |
import java.util.HashMap; |
... | ... | |
53 | 56 |
import com.google.gwt.user.client.ui.PushButton; |
54 | 57 |
import com.google.gwt.user.client.ui.RadioButton; |
55 | 58 |
import com.google.gwt.user.client.ui.VerticalPanel; |
59 |
import gr.grnet.pithos.web.client.catalog.GetUserCatalogs; |
|
60 |
import gr.grnet.pithos.web.client.catalog.UserCatalogs; |
|
56 | 61 |
|
57 | 62 |
|
58 | 63 |
public class PermissionsList extends Composite { |
... | ... | |
72 | 77 |
private boolean readonly = false; |
73 | 78 |
|
74 | 79 |
Command changePermissionsCallback; |
80 |
|
|
81 |
private final Pithos app; |
|
75 | 82 |
|
76 |
public PermissionsList(final Images theImages, Map<String, Boolean[]> thePermissions, String theOwner, boolean inheritsPermissions, Command _changePermissionsCallback){ |
|
83 |
public PermissionsList(Pithos app, final Images theImages, Map<String, Boolean[]> thePermissions, String theOwner, boolean inheritsPermissions, Command _changePermissionsCallback){ |
|
84 |
this.app = app; |
|
77 | 85 |
changePermissionsCallback = _changePermissionsCallback; |
78 | 86 |
images = theImages; |
79 | 87 |
owner = theOwner; |
... | ... | |
105 | 113 |
return permissions; |
106 | 114 |
} |
107 | 115 |
|
108 |
public void addPermission(String user, boolean read, boolean write){ |
|
109 |
permissions.put(user, new Boolean[] {Boolean.valueOf(read), Boolean.valueOf(write)}); |
|
116 |
public void addPermission(String userID, boolean read, boolean write){
|
|
117 |
permissions.put(userID, new Boolean[] {Boolean.valueOf(read), Boolean.valueOf(write)});
|
|
110 | 118 |
hasChanges = true; |
111 | 119 |
updatePermissionTable(); |
112 | 120 |
if (changePermissionsCallback != null) |
... | ... | |
119 | 127 |
*/ |
120 | 128 |
void updatePermissionTable(){ |
121 | 129 |
int i = 1; |
130 |
final int ii = i; |
|
122 | 131 |
for (int j=1; j<permTable.getRowCount(); j++) |
123 | 132 |
permTable.removeRow(j); |
124 |
for(final String user : permissions.keySet()) { |
|
125 |
if (!user.contains(":")) //not a group |
|
126 |
permTable.setHTML(i, 0, "<span>" + AbstractImagePrototype.create(images.permUser()).getHTML() + " " + user + "</span>"); |
|
127 |
else |
|
128 |
permTable.setHTML(i, 0, "<span>" + AbstractImagePrototype.create(images.permGroup()).getHTML() + " " + user.split(":")[1].trim() + "</span>"); |
|
133 |
for(final String userID : permissions.keySet()) { |
|
134 |
if (!userID.contains(":")) { |
|
135 |
//not a group |
|
136 |
final String displayName = app.getUserDisplayNameForID(userID); |
|
137 |
if(displayName != null) { |
|
138 |
permTable.setHTML( |
|
139 |
i, |
|
140 |
0, |
|
141 |
"<span>" + AbstractImagePrototype.create(images.permUser()).getHTML() + " " + displayName + "</span>" |
|
142 |
); |
|
143 |
} |
|
144 |
else { |
|
145 |
new GetUserCatalogs(app, userID) { |
|
146 |
@Override |
|
147 |
public void onSuccess(Request request, Response response, JSONObject result, UserCatalogs userCatalogs) { |
|
148 |
app.getUserCatalogs().updateFrom(userCatalogs); |
|
149 |
final String displayName = app.getUserDisplayNameForID(userID); |
|
150 |
permTable.setHTML( |
|
151 |
ii, |
|
152 |
0, |
|
153 |
"<span>" + AbstractImagePrototype.create(images.permUser()).getHTML() + " " + displayName + "</span>" |
|
154 |
); |
|
155 |
} |
|
156 |
}.scheduleDeferred(); |
|
157 |
} |
|
158 |
} |
|
159 |
else { |
|
160 |
permTable.setHTML(i, 0, "<span>" + AbstractImagePrototype.create(images.permGroup()).getHTML() + " " + userID.split(":")[1].trim() + "</span>"); |
|
161 |
} |
|
129 | 162 |
permTable.getFlexCellFormatter().setStyleName(i, 0, "props-values"); |
130 | 163 |
|
131 |
Boolean[] userPerms = permissions.get(user); |
|
164 |
Boolean[] userPerms = permissions.get(userID);
|
|
132 | 165 |
Boolean readP = userPerms[0]; |
133 | 166 |
Boolean writeP = userPerms[1]; |
134 | 167 |
|
... | ... | |
146 | 179 |
read.addValueChangeHandler(new ValueChangeHandler<Boolean>() { |
147 | 180 |
@Override |
148 | 181 |
public void onValueChange(ValueChangeEvent<Boolean> booleanValueChangeEvent) { |
149 |
Boolean[] ps = permissions.get(user); |
|
182 |
Boolean[] ps = permissions.get(userID);
|
|
150 | 183 |
ps[0] = booleanValueChangeEvent.getValue(); |
151 | 184 |
ps[1] = !booleanValueChangeEvent.getValue(); |
152 | 185 |
hasChanges = true; |
... | ... | |
157 | 190 |
write.addValueChangeHandler(new ValueChangeHandler<Boolean>() { |
158 | 191 |
@Override |
159 | 192 |
public void onValueChange(ValueChangeEvent<Boolean> booleanValueChangeEvent) { |
160 |
Boolean[] ps = permissions.get(user); |
|
193 |
Boolean[] ps = permissions.get(userID);
|
|
161 | 194 |
ps[0] = !booleanValueChangeEvent.getValue(); |
162 | 195 |
ps[1] = booleanValueChangeEvent.getValue(); |
163 | 196 |
hasChanges = true; |
... | ... | |
170 | 203 |
removeButton.addClickHandler(new ClickHandler() { |
171 | 204 |
@Override |
172 | 205 |
public void onClick(ClickEvent event) { |
173 |
permissions.remove(user); |
|
206 |
permissions.remove(userID);
|
|
174 | 207 |
updatePermissionTable(); |
175 | 208 |
hasChanges = true; |
176 | 209 |
if (changePermissionsCallback != null) |
Also available in: Unified diff