root / src / gr / grnet / pithos / web / client / FolderPermissionsDialog.java @ cfdb1476
History | View | Annotate | Download (13.3 kB)
1 | 6b7d024f | Christos Stathis | /*
|
---|---|---|---|
2 | e6e9f6e6 | Christos KK Loverdos | * Copyright 2011-2013 GRNET S.A. All rights reserved.
|
3 | 6b7d024f | Christos Stathis | *
|
4 | 6b7d024f | Christos Stathis | * Redistribution and use in source and binary forms, with or
|
5 | 6b7d024f | Christos Stathis | * without modification, are permitted provided that the following
|
6 | 6b7d024f | Christos Stathis | * conditions are met:
|
7 | 6b7d024f | Christos Stathis | *
|
8 | 6b7d024f | Christos Stathis | * 1. Redistributions of source code must retain the above
|
9 | 6b7d024f | Christos Stathis | * copyright notice, this list of conditions and the following
|
10 | 6b7d024f | Christos Stathis | * disclaimer.
|
11 | 6b7d024f | Christos Stathis | *
|
12 | 6b7d024f | Christos Stathis | * 2. Redistributions in binary form must reproduce the above
|
13 | 6b7d024f | Christos Stathis | * copyright notice, this list of conditions and the following
|
14 | 6b7d024f | Christos Stathis | * disclaimer in the documentation and/or other materials
|
15 | 6b7d024f | Christos Stathis | * provided with the distribution.
|
16 | 6b7d024f | Christos Stathis | *
|
17 | 6b7d024f | Christos Stathis | * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
|
18 | 6b7d024f | Christos Stathis | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
19 | 6b7d024f | Christos Stathis | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
20 | 6b7d024f | Christos Stathis | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
|
21 | 6b7d024f | Christos Stathis | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
22 | 6b7d024f | Christos Stathis | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
23 | 6b7d024f | Christos Stathis | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
24 | 6b7d024f | Christos Stathis | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
25 | 6b7d024f | Christos Stathis | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
26 | 6b7d024f | Christos Stathis | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
27 | 6b7d024f | Christos Stathis | * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
28 | 6b7d024f | Christos Stathis | * POSSIBILITY OF SUCH DAMAGE.
|
29 | 6b7d024f | Christos Stathis | *
|
30 | 6b7d024f | Christos Stathis | * The views and conclusions contained in the software and
|
31 | 6b7d024f | Christos Stathis | * documentation are those of the authors and should not be
|
32 | 6b7d024f | Christos Stathis | * interpreted as representing official policies, either expressed
|
33 | 6b7d024f | Christos Stathis | * or implied, of GRNET S.A.
|
34 | 6b7d024f | Christos Stathis | */
|
35 | 6b7d024f | Christos Stathis | package gr.grnet.pithos.web.client; |
36 | 6b7d024f | Christos Stathis | |
37 | 6b7d024f | Christos Stathis | import com.google.gwt.core.client.GWT; |
38 | 6b7d024f | Christos Stathis | import com.google.gwt.core.client.Scheduler; |
39 | 6b7d024f | Christos Stathis | import com.google.gwt.dom.client.NativeEvent; |
40 | 6b7d024f | Christos Stathis | import com.google.gwt.event.dom.client.ClickEvent; |
41 | 6b7d024f | Christos Stathis | import com.google.gwt.event.dom.client.ClickHandler; |
42 | 6b7d024f | Christos Stathis | import com.google.gwt.event.dom.client.KeyCodes; |
43 | 6b7d024f | Christos Stathis | import com.google.gwt.event.dom.client.KeyDownEvent; |
44 | 6b7d024f | Christos Stathis | import com.google.gwt.http.client.Response; |
45 | 6b7d024f | Christos Stathis | import com.google.gwt.http.client.URL; |
46 | 6b7d024f | Christos Stathis | import com.google.gwt.user.client.Command; |
47 | 6b7d024f | Christos Stathis | import com.google.gwt.user.client.Event.NativePreviewEvent; |
48 | 87487bbf | Christos KK Loverdos | import com.google.gwt.user.client.ui.*; |
49 | 87487bbf | Christos KK Loverdos | import gr.grnet.pithos.web.client.foldertree.Folder; |
50 | 87487bbf | Christos KK Loverdos | import gr.grnet.pithos.web.client.rest.PostRequest; |
51 | 87487bbf | Christos KK Loverdos | import gr.grnet.pithos.web.client.rest.PutRequest; |
52 | 87487bbf | Christos KK Loverdos | import gr.grnet.pithos.web.client.rest.RestException; |
53 | 87487bbf | Christos KK Loverdos | |
54 | 87487bbf | Christos KK Loverdos | import java.util.Map; |
55 | 6b7d024f | Christos Stathis | |
56 | 6b7d024f | Christos Stathis | /**
|
57 | 6b7d024f | Christos Stathis | * The 'Folder properties' dialog box implementation.
|
58 | 6b7d024f | Christos Stathis | */
|
59 | 6b7d024f | Christos Stathis | public class FolderPermissionsDialog extends DialogBox { |
60 | 6b7d024f | Christos Stathis | |
61 | 6b7d024f | Christos Stathis | protected Pithos app;
|
62 | 6b7d024f | Christos Stathis | |
63 | 87487bbf | Christos KK Loverdos | /**
|
64 | 87487bbf | Christos KK Loverdos | * The widget that holds the folderName of the folder.
|
65 | 87487bbf | Christos KK Loverdos | */
|
66 | 87487bbf | Christos KK Loverdos | Label folderName = new Label(); |
67 | 87487bbf | Christos KK Loverdos | |
68 | 87487bbf | Christos KK Loverdos | protected PermissionsList permList;
|
69 | 87487bbf | Christos KK Loverdos | |
70 | 87487bbf | Christos KK Loverdos | final Folder folder;
|
71 | 6b7d024f | Christos Stathis | |
72 | 87487bbf | Christos KK Loverdos | final VerticalPanel inner;
|
73 | 6b7d024f | Christos Stathis | |
74 | 87487bbf | Christos KK Loverdos | final Button updateButton; |
75 | 6b7d024f | Christos Stathis | |
76 | 87487bbf | Christos KK Loverdos | private boolean _initialPermissionCheck = true; |
77 | 6b7d024f | Christos Stathis | |
78 | 87487bbf | Christos KK Loverdos | /**
|
79 | 87487bbf | Christos KK Loverdos | * The widget's constructor.
|
80 | 87487bbf | Christos KK Loverdos | */
|
81 | 87487bbf | Christos KK Loverdos | public FolderPermissionsDialog(final Pithos app, Folder selected) { |
82 | 6b7d024f | Christos Stathis | this.app = app;
|
83 | 87487bbf | Christos KK Loverdos | Anchor close = new Anchor("close"); |
84 | 87487bbf | Christos KK Loverdos | close.addStyleName("close");
|
85 | 87487bbf | Christos KK Loverdos | close.addClickHandler(new ClickHandler() {
|
86 | 6b7d024f | Christos Stathis | |
87 | 87487bbf | Christos KK Loverdos | @Override
|
88 | 87487bbf | Christos KK Loverdos | public void onClick(ClickEvent event) { |
89 | 87487bbf | Christos KK Loverdos | hide(); |
90 | 87487bbf | Christos KK Loverdos | } |
91 | 87487bbf | Christos KK Loverdos | }); |
92 | 6b7d024f | Christos Stathis | |
93 | 87487bbf | Christos KK Loverdos | setGlassEnabled(true);
|
94 | 87487bbf | Christos KK Loverdos | setStyleName("pithos-DialogBox");
|
95 | 6b7d024f | Christos Stathis | |
96 | 87487bbf | Christos KK Loverdos | // Enable IE selection for the dialog (must disable it upon closing it)
|
97 | 87487bbf | Christos KK Loverdos | Pithos.enableIESelection(); |
98 | 6b7d024f | Christos Stathis | |
99 | 87487bbf | Christos KK Loverdos | folder = selected; |
100 | 6b7d024f | Christos Stathis | |
101 | 87487bbf | Christos KK Loverdos | setText("Folder permissions");
|
102 | 6b7d024f | Christos Stathis | |
103 | 87487bbf | Christos KK Loverdos | // Outer contains inner and buttons
|
104 | 87487bbf | Christos KK Loverdos | VerticalPanel outer = new VerticalPanel();
|
105 | 87487bbf | Christos KK Loverdos | outer.add(close); |
106 | 87487bbf | Christos KK Loverdos | // Inner contains generalPanel and permPanel
|
107 | 87487bbf | Christos KK Loverdos | inner = new VerticalPanel();
|
108 | 87487bbf | Christos KK Loverdos | inner.addStyleName("inner");
|
109 | 6b7d024f | Christos Stathis | |
110 | 87487bbf | Christos KK Loverdos | |
111 | 87487bbf | Christos KK Loverdos | folderName.setText(folder.getName()); |
112 | 6b7d024f | Christos Stathis | |
113 | 6b7d024f | Christos Stathis | VerticalPanel permPanel = new VerticalPanel();
|
114 | 64d3b76b | Christos KK Loverdos | FileShareDialog.PrivateSharingImages images = GWT.create(FileShareDialog.PrivateSharingImages.class); |
115 | 8d09767f | Christos KK Loverdos | permList = new PermissionsList(app, images, folder.getPermissions(), folder.getOwnerID(), false, null); |
116 | 6b7d024f | Christos Stathis | permPanel.add(permList); |
117 | 6b7d024f | Christos Stathis | |
118 | b3c3954b | Christos Stathis | HorizontalPanel permButtons = new HorizontalPanel();
|
119 | 57ab6e0b | Christos Stathis | Button addUser = new Button("Add User", new ClickHandler() { |
120 | b3c3954b | Christos Stathis | @Override
|
121 | b3c3954b | Christos Stathis | public void onClick(ClickEvent event) { |
122 | 57ab6e0b | Christos Stathis | PermissionsAddDialog dlg = new PermissionsAddDialog(app, app.getAccount().getGroups(), permList, true); |
123 | b3c3954b | Christos Stathis | dlg.center(); |
124 | 87487bbf | Christos KK Loverdos | checkUpdateButtonVisibility(); |
125 | b3c3954b | Christos Stathis | } |
126 | b3c3954b | Christos Stathis | }); |
127 | 57ab6e0b | Christos Stathis | addUser.addStyleName("button");
|
128 | 57ab6e0b | Christos Stathis | permButtons.add(addUser); |
129 | 57ab6e0b | Christos Stathis | permButtons.setCellHorizontalAlignment(addUser, HasHorizontalAlignment.ALIGN_CENTER); |
130 | b3c3954b | Christos Stathis | |
131 | 57ab6e0b | Christos Stathis | Button add = new Button("Add Group", new ClickHandler() { |
132 | b3c3954b | Christos Stathis | @Override
|
133 | b3c3954b | Christos Stathis | public void onClick(ClickEvent event) { |
134 | 87487bbf | Christos KK Loverdos | if(app.getAccount().getGroups().isEmpty()) {
|
135 | 5ec7b091 | Christos Stathis | new GroupCreateDialog(app, new Command() { |
136 | 87487bbf | Christos KK Loverdos | @Override
|
137 | 87487bbf | Christos KK Loverdos | public void execute() { |
138 | 87487bbf | Christos KK Loverdos | if(app.getAccount().getGroups().isEmpty()) {
|
139 | 87487bbf | Christos KK Loverdos | return;
|
140 | 87487bbf | Christos KK Loverdos | } |
141 | 87487bbf | Christos KK Loverdos | PermissionsAddDialog dlg = new PermissionsAddDialog(app, app.getAccount().getGroups(), permList, false); |
142 | 87487bbf | Christos KK Loverdos | dlg.center(); |
143 | 87487bbf | Christos KK Loverdos | checkUpdateButtonVisibility(); |
144 | 87487bbf | Christos KK Loverdos | } |
145 | 87487bbf | Christos KK Loverdos | }).center(); |
146 | 87487bbf | Christos KK Loverdos | } |
147 | 87487bbf | Christos KK Loverdos | else {
|
148 | 87487bbf | Christos KK Loverdos | PermissionsAddDialog dlg = new PermissionsAddDialog(app, app.getAccount().getGroups(), permList, false); |
149 | 87487bbf | Christos KK Loverdos | dlg.center(); |
150 | 87487bbf | Christos KK Loverdos | checkUpdateButtonVisibility(); |
151 | 87487bbf | Christos KK Loverdos | } |
152 | b3c3954b | Christos Stathis | } |
153 | b3c3954b | Christos Stathis | }); |
154 | 57ab6e0b | Christos Stathis | add.addStyleName("button");
|
155 | 57ab6e0b | Christos Stathis | permButtons.add(add); |
156 | 57ab6e0b | Christos Stathis | permButtons.setCellHorizontalAlignment(add, HasHorizontalAlignment.ALIGN_CENTER); |
157 | 57ab6e0b | Christos Stathis | |
158 | b3c3954b | Christos Stathis | permButtons.setSpacing(8);
|
159 | b3c3954b | Christos Stathis | permPanel.add(permButtons); |
160 | 6b7d024f | Christos Stathis | |
161 | 6b7d024f | Christos Stathis | inner.add(permPanel); |
162 | 6b7d024f | Christos Stathis | |
163 | 6b7d024f | Christos Stathis | outer.add(inner); |
164 | 6b7d024f | Christos Stathis | |
165 | 87487bbf | Christos KK Loverdos | // Create the 'Create/Update' button, along with a listener that hides the dialog
|
166 | 87487bbf | Christos KK Loverdos | // when the button is clicked and quits the application.
|
167 | 87487bbf | Christos KK Loverdos | final String okLabel = "Update"; |
168 | 87487bbf | Christos KK Loverdos | updateButton = new Button(okLabel, new ClickHandler() { |
169 | 87487bbf | Christos KK Loverdos | @Override
|
170 | 87487bbf | Christos KK Loverdos | public void onClick(ClickEvent event) { |
171 | 87487bbf | Christos KK Loverdos | updateFolder(); |
172 | 87487bbf | Christos KK Loverdos | closeDialog(); |
173 | 87487bbf | Christos KK Loverdos | } |
174 | 87487bbf | Christos KK Loverdos | }); |
175 | 87487bbf | Christos KK Loverdos | updateButton.addStyleName("button");
|
176 | 87487bbf | Christos KK Loverdos | checkUpdateButtonVisibility(); |
177 | 87487bbf | Christos KK Loverdos | outer.add(updateButton); |
178 | 6b7d024f | Christos Stathis | outer.setCellHorizontalAlignment(inner, HasHorizontalAlignment.ALIGN_CENTER); |
179 | 6b7d024f | Christos Stathis | |
180 | 6b7d024f | Christos Stathis | setWidget(outer); |
181 | 87487bbf | Christos KK Loverdos | } |
182 | 87487bbf | Christos KK Loverdos | |
183 | 87487bbf | Christos KK Loverdos | private void checkUpdateButtonVisibility() { |
184 | 87487bbf | Christos KK Loverdos | if(!this._initialPermissionCheck) { |
185 | 87487bbf | Christos KK Loverdos | updateButton.setVisible(true);
|
186 | 87487bbf | Christos KK Loverdos | return;
|
187 | 87487bbf | Christos KK Loverdos | } |
188 | 87487bbf | Christos KK Loverdos | |
189 | 87487bbf | Christos KK Loverdos | updateButton.setVisible(permList.hasPermissions()); |
190 | 87487bbf | Christos KK Loverdos | |
191 | 87487bbf | Christos KK Loverdos | this._initialPermissionCheck = false; |
192 | 87487bbf | Christos KK Loverdos | } |
193 | 87487bbf | Christos KK Loverdos | |
194 | 87487bbf | Christos KK Loverdos | @Override
|
195 | 87487bbf | Christos KK Loverdos | protected void onPreviewNativeEvent(NativePreviewEvent preview) { |
196 | 87487bbf | Christos KK Loverdos | super.onPreviewNativeEvent(preview);
|
197 | 87487bbf | Christos KK Loverdos | |
198 | 87487bbf | Christos KK Loverdos | NativeEvent evt = preview.getNativeEvent(); |
199 | 87487bbf | Christos KK Loverdos | if(evt.getType().equals(KeyDownEvent.getType().getName()))
|
200 | 87487bbf | Christos KK Loverdos | // Use the popup's key preview hooks to close the dialog when either
|
201 | 87487bbf | Christos KK Loverdos | // enter or escape is pressed.
|
202 | 87487bbf | Christos KK Loverdos | { |
203 | 87487bbf | Christos KK Loverdos | switch(evt.getKeyCode()) {
|
204 | 87487bbf | Christos KK Loverdos | case KeyCodes.KEY_ENTER:
|
205 | 87487bbf | Christos KK Loverdos | updateFolder(); |
206 | 6b7d024f | Christos Stathis | closeDialog(); |
207 | 87487bbf | Christos KK Loverdos | break;
|
208 | 87487bbf | Christos KK Loverdos | case KeyCodes.KEY_ESCAPE:
|
209 | 87487bbf | Christos KK Loverdos | closeDialog(); |
210 | 87487bbf | Christos KK Loverdos | break;
|
211 | 87487bbf | Christos KK Loverdos | } |
212 | 87487bbf | Christos KK Loverdos | } |
213 | 87487bbf | Christos KK Loverdos | } |
214 | 87487bbf | Christos KK Loverdos | |
215 | 87487bbf | Christos KK Loverdos | /**
|
216 | 87487bbf | Christos KK Loverdos | * Enables IE selection prevention and hides the dialog
|
217 | 87487bbf | Christos KK Loverdos | * (we disable the prevention on creation of the dialog)
|
218 | 87487bbf | Christos KK Loverdos | */
|
219 | 87487bbf | Christos KK Loverdos | public void closeDialog() { |
220 | 87487bbf | Christos KK Loverdos | Pithos.preventIESelection(); |
221 | 87487bbf | Christos KK Loverdos | hide(); |
222 | 87487bbf | Christos KK Loverdos | } |
223 | 87487bbf | Christos KK Loverdos | |
224 | 87487bbf | Christos KK Loverdos | void updateFolder() {
|
225 | 6b7d024f | Christos Stathis | final Map<String, Boolean[]> perms = (permList.hasChanges() ? permList.getPermissions() : null); |
226 | 87487bbf | Christos KK Loverdos | updateMetadata( |
227 | 87487bbf | Christos KK Loverdos | folder.getUri() + Const.QUESTION_MARK_UPDATE_EQ, |
228 | 87487bbf | Christos KK Loverdos | perms |
229 | 87487bbf | Christos KK Loverdos | ); |
230 | 87487bbf | Christos KK Loverdos | } |
231 | 6b7d024f | Christos Stathis | |
232 | 87487bbf | Christos KK Loverdos | protected void updateMetadata(final String path, final Map<String, Boolean[]> newPermissions) { |
233 | 87487bbf | Christos KK Loverdos | if(newPermissions != null) { |
234 | dc8cc18a | Christos KK Loverdos | PostRequest updateFolder = new PostRequest(app.getApiPath(), folder.getOwnerID(), path) {
|
235 | 6b7d024f | Christos Stathis | @Override
|
236 | ebead1b5 | Christos Stathis | public void onSuccess(Resource result) { |
237 | 6b7d024f | Christos Stathis | app.updateFolder(folder.getParent(), false, new Command() { |
238 | 87487bbf | Christos KK Loverdos | @Override
|
239 | 87487bbf | Christos KK Loverdos | public void execute() { |
240 | 87487bbf | Christos KK Loverdos | app.updateMySharedRoot(); |
241 | 87487bbf | Christos KK Loverdos | } |
242 | 87487bbf | Christos KK Loverdos | }, true);
|
243 | 6b7d024f | Christos Stathis | } |
244 | 6b7d024f | Christos Stathis | |
245 | 6b7d024f | Christos Stathis | @Override
|
246 | 6b7d024f | Christos Stathis | public void onError(Throwable t) { |
247 | 87487bbf | Christos KK Loverdos | app.setError(t); |
248 | 87487bbf | Christos KK Loverdos | if(t instanceof RestException) { |
249 | 87487bbf | Christos KK Loverdos | if(((RestException) t).getHttpStatusCode() == Response.SC_NOT_FOUND) { //Probably a virtual folder |
250 | 6b7d024f | Christos Stathis | final String path1 = folder.getUri(); |
251 | dc8cc18a | Christos KK Loverdos | PutRequest newFolder = new PutRequest(app.getApiPath(), folder.getOwnerID(), path1) {
|
252 | 6b7d024f | Christos Stathis | @Override
|
253 | ebead1b5 | Christos Stathis | public void onSuccess(Resource result) { |
254 | 87487bbf | Christos KK Loverdos | updateMetadata(path, newPermissions); |
255 | 6b7d024f | Christos Stathis | } |
256 | 6b7d024f | Christos Stathis | |
257 | 6b7d024f | Christos Stathis | @Override
|
258 | 6b7d024f | Christos Stathis | public void onError(Throwable _t) { |
259 | 87487bbf | Christos KK Loverdos | app.setError(_t); |
260 | 87487bbf | Christos KK Loverdos | if(_t instanceof RestException) { |
261 | 6b7d024f | Christos Stathis | app.displayError("Unable to update folder: " + ((RestException) _t).getHttpStatusText());
|
262 | 6b7d024f | Christos Stathis | } |
263 | 87487bbf | Christos KK Loverdos | else {
|
264 | 6b7d024f | Christos Stathis | app.displayError("System error modifying folder: " + _t.getMessage());
|
265 | 87487bbf | Christos KK Loverdos | } |
266 | 6b7d024f | Christos Stathis | } |
267 | 6b7d024f | Christos Stathis | |
268 | 87487bbf | Christos KK Loverdos | @Override
|
269 | 87487bbf | Christos KK Loverdos | protected void onUnauthorized(Response response) { |
270 | 87487bbf | Christos KK Loverdos | app.sessionExpired(); |
271 | 87487bbf | Christos KK Loverdos | } |
272 | 6b7d024f | Christos Stathis | }; |
273 | cc0120ab | Christos KK Loverdos | newFolder.setHeader("X-Auth-Token", app.getUserToken());
|
274 | 6b7d024f | Christos Stathis | newFolder.setHeader("Content-Type", "application/folder"); |
275 | 6b7d024f | Christos Stathis | newFolder.setHeader("Accept", "*/*"); |
276 | 6b7d024f | Christos Stathis | newFolder.setHeader("Content-Length", "0"); |
277 | 6b7d024f | Christos Stathis | Scheduler.get().scheduleDeferred(newFolder); |
278 | 87487bbf | Christos KK Loverdos | } |
279 | 87487bbf | Christos KK Loverdos | else if(((RestException) t).getHttpStatusCode() == Response.SC_CONFLICT) { |
280 | 87487bbf | Christos KK Loverdos | app.displayError("Cannot set permissions. Probably subfolders or files already have permissions set");
|
281 | 87487bbf | Christos KK Loverdos | } |
282 | 87487bbf | Christos KK Loverdos | else {
|
283 | 87487bbf | Christos KK Loverdos | app.displayError("Εrror modifying folder: " + t.getMessage());
|
284 | 87487bbf | Christos KK Loverdos | } |
285 | 87487bbf | Christos KK Loverdos | } |
286 | 87487bbf | Christos KK Loverdos | else {
|
287 | 87487bbf | Christos KK Loverdos | app.displayError("System error modifying folder: " + t.getMessage());
|
288 | 6b7d024f | Christos Stathis | } |
289 | 6b7d024f | Christos Stathis | } |
290 | 6b7d024f | Christos Stathis | |
291 | 87487bbf | Christos KK Loverdos | @Override
|
292 | 87487bbf | Christos KK Loverdos | protected void onUnauthorized(Response response) { |
293 | 87487bbf | Christos KK Loverdos | app.sessionExpired(); |
294 | 87487bbf | Christos KK Loverdos | } |
295 | 6b7d024f | Christos Stathis | }; |
296 | cc0120ab | Christos KK Loverdos | updateFolder.setHeader("X-Auth-Token", app.getUserToken());
|
297 | 6b7d024f | Christos Stathis | String readPermHeader = "read="; |
298 | 6b7d024f | Christos Stathis | String writePermHeader = "write="; |
299 | 87487bbf | Christos KK Loverdos | for(String u : newPermissions.keySet()) { |
300 | 6b7d024f | Christos Stathis | Boolean[] p = newPermissions.get(u); |
301 | 87487bbf | Christos KK Loverdos | if(p[0] != null && p[0]) { |
302 | 6b7d024f | Christos Stathis | readPermHeader += u + ",";
|
303 | 87487bbf | Christos KK Loverdos | } |
304 | 87487bbf | Christos KK Loverdos | if(p[1] != null && p[1]) { |
305 | 6b7d024f | Christos Stathis | writePermHeader += u + ",";
|
306 | 87487bbf | Christos KK Loverdos | } |
307 | 6b7d024f | Christos Stathis | } |
308 | 87487bbf | Christos KK Loverdos | if(readPermHeader.endsWith("=")) { |
309 | 6b7d024f | Christos Stathis | readPermHeader = "";
|
310 | 87487bbf | Christos KK Loverdos | } |
311 | 87487bbf | Christos KK Loverdos | else if(readPermHeader.endsWith(",")) { |
312 | 6b7d024f | Christos Stathis | readPermHeader = readPermHeader.substring(0, readPermHeader.length() - 1); |
313 | 87487bbf | Christos KK Loverdos | } |
314 | 87487bbf | Christos KK Loverdos | if(writePermHeader.endsWith("=")) { |
315 | 6b7d024f | Christos Stathis | writePermHeader = "";
|
316 | 87487bbf | Christos KK Loverdos | } |
317 | 87487bbf | Christos KK Loverdos | else if(writePermHeader.endsWith(",")) { |
318 | 6b7d024f | Christos Stathis | writePermHeader = writePermHeader.substring(0, writePermHeader.length() - 1); |
319 | 87487bbf | Christos KK Loverdos | } |
320 | 87487bbf | Christos KK Loverdos | String permHeader = readPermHeader + ((readPermHeader.length() > 0 && writePermHeader.length() > 0) ? ";" : "") + writePermHeader; |
321 | 87487bbf | Christos KK Loverdos | if(permHeader.length() == 0) { |
322 | 6b7d024f | Christos Stathis | permHeader = "~";
|
323 | 87487bbf | Christos KK Loverdos | } |
324 | 87487bbf | Christos KK Loverdos | else {
|
325 | 87487bbf | Christos KK Loverdos | permHeader = URL.encodePathSegment(permHeader);
|
326 | 87487bbf | Christos KK Loverdos | } |
327 | 6b7d024f | Christos Stathis | updateFolder.setHeader("X-Object-Sharing", permHeader);
|
328 | 6b7d024f | Christos Stathis | Scheduler.get().scheduleDeferred(updateFolder); |
329 | 6b7d024f | Christos Stathis | } |
330 | 87487bbf | Christos KK Loverdos | else {
|
331 | 6b7d024f | Christos Stathis | app.updateFolder(folder.getParent(), false, new Command() { |
332 | 87487bbf | Christos KK Loverdos | @Override
|
333 | 87487bbf | Christos KK Loverdos | public void execute() { |
334 | 87487bbf | Christos KK Loverdos | app.updateMySharedRoot(); |
335 | 87487bbf | Christos KK Loverdos | } |
336 | 87487bbf | Christos KK Loverdos | }, true);
|
337 | 87487bbf | Christos KK Loverdos | } |
338 | 6b7d024f | Christos Stathis | } |
339 | 6b7d024f | Christos Stathis | } |