Statistics
| Branch: | Tag: | Revision:

root / src / gr / grnet / pithos / web / client / FolderPermissionsDialog.java @ 39f6d7b0

History | View | Annotate | Download (13.8 kB)

1 6b7d024f Christos Stathis
/*
2 cae2a8db Christos Stathis
 * Copyright 2011-2012 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 gr.grnet.pithos.web.client.foldertree.File;
38 6b7d024f Christos Stathis
import gr.grnet.pithos.web.client.foldertree.Folder;
39 6b7d024f Christos Stathis
import gr.grnet.pithos.web.client.foldertree.Resource;
40 6b7d024f Christos Stathis
import gr.grnet.pithos.web.client.rest.PostRequest;
41 6b7d024f Christos Stathis
import gr.grnet.pithos.web.client.rest.PutRequest;
42 6b7d024f Christos Stathis
import gr.grnet.pithos.web.client.rest.RestException;
43 6b7d024f Christos Stathis
44 6b7d024f Christos Stathis
import java.util.Iterator;
45 6b7d024f Christos Stathis
import java.util.Map;
46 6b7d024f Christos Stathis
47 6b7d024f Christos Stathis
import com.google.gwt.core.client.GWT;
48 6b7d024f Christos Stathis
import com.google.gwt.core.client.Scheduler;
49 6b7d024f Christos Stathis
import com.google.gwt.dom.client.NativeEvent;
50 6b7d024f Christos Stathis
import com.google.gwt.event.dom.client.ClickEvent;
51 6b7d024f Christos Stathis
import com.google.gwt.event.dom.client.ClickHandler;
52 6b7d024f Christos Stathis
import com.google.gwt.event.dom.client.KeyCodes;
53 6b7d024f Christos Stathis
import com.google.gwt.event.dom.client.KeyDownEvent;
54 6b7d024f Christos Stathis
import com.google.gwt.http.client.Response;
55 6b7d024f Christos Stathis
import com.google.gwt.http.client.URL;
56 6b7d024f Christos Stathis
import com.google.gwt.user.client.Command;
57 6b7d024f Christos Stathis
import com.google.gwt.user.client.Event.NativePreviewEvent;
58 6b7d024f Christos Stathis
import com.google.gwt.user.client.ui.Anchor;
59 6b7d024f Christos Stathis
import com.google.gwt.user.client.ui.Button;
60 6b7d024f Christos Stathis
import com.google.gwt.user.client.ui.DialogBox;
61 6b7d024f Christos Stathis
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
62 6b7d024f Christos Stathis
import com.google.gwt.user.client.ui.HorizontalPanel;
63 6b7d024f Christos Stathis
import com.google.gwt.user.client.ui.Label;
64 6b7d024f Christos Stathis
import com.google.gwt.user.client.ui.VerticalPanel;
65 6b7d024f Christos Stathis
66 6b7d024f Christos Stathis
/**
67 6b7d024f Christos Stathis
 * The 'Folder properties' dialog box implementation.
68 6b7d024f Christos Stathis
 */
69 6b7d024f Christos Stathis
public class FolderPermissionsDialog extends DialogBox {
70 6b7d024f Christos Stathis
71 6b7d024f Christos Stathis
    protected Pithos app;
72 6b7d024f Christos Stathis
73 6b7d024f Christos Stathis
        /**
74 6b7d024f Christos Stathis
         * The widget that holds the folderName of the folder.
75 6b7d024f Christos Stathis
         */
76 6b7d024f Christos Stathis
        Label folderName = new Label();
77 6b7d024f Christos Stathis
78 6b7d024f Christos Stathis
        protected PermissionsList permList;
79 6b7d024f Christos Stathis
80 6b7d024f Christos Stathis
        final Folder folder;
81 6b7d024f Christos Stathis
82 6b7d024f Christos Stathis
        final VerticalPanel inner;
83 6b7d024f Christos Stathis
84 6b7d024f Christos Stathis
        /**
85 6b7d024f Christos Stathis
         * The widget's constructor.
86 6b7d024f Christos Stathis
         */
87 6b7d024f Christos Stathis
        public FolderPermissionsDialog(final Pithos app, Folder selected) {
88 6b7d024f Christos Stathis
        this.app = app;
89 6b7d024f Christos Stathis
                Anchor close = new Anchor();
90 6b7d024f Christos Stathis
                close.addStyleName("close");
91 6b7d024f Christos Stathis
                close.addClickHandler(new ClickHandler() {
92 6b7d024f Christos Stathis
                        
93 6b7d024f Christos Stathis
                        @Override
94 ebead1b5 Christos Stathis
                        public void onClick(ClickEvent event) {
95 6b7d024f Christos Stathis
                                hide();
96 6b7d024f Christos Stathis
                        }
97 6b7d024f Christos Stathis
                });
98 6b7d024f Christos Stathis
99 6b7d024f Christos Stathis
                setAnimationEnabled(true);
100 6b7d024f Christos Stathis
                setGlassEnabled(true);
101 6b7d024f Christos Stathis
                setStyleName("pithos-DialogBox");
102 6b7d024f Christos Stathis
103 6b7d024f Christos Stathis
                // Enable IE selection for the dialog (must disable it upon closing it)
104 6b7d024f Christos Stathis
                Pithos.enableIESelection();
105 6b7d024f Christos Stathis
106 6b7d024f Christos Stathis
                folder = selected;
107 6b7d024f Christos Stathis
108 6b7d024f Christos Stathis
                setText("Folder permissions");
109 6b7d024f Christos Stathis
110 6b7d024f Christos Stathis
                // Outer contains inner and buttons
111 6b7d024f Christos Stathis
                VerticalPanel outer = new VerticalPanel();
112 6b7d024f Christos Stathis
                outer.add(close);
113 6b7d024f Christos Stathis
                // Inner contains generalPanel and permPanel
114 6b7d024f Christos Stathis
                inner = new VerticalPanel();
115 6b7d024f Christos Stathis
                inner.addStyleName("inner");
116 6b7d024f Christos Stathis
117 6b7d024f Christos Stathis
118 6b7d024f Christos Stathis
                folderName.setText(folder.getName());
119 6b7d024f Christos Stathis
120 6b7d024f Christos Stathis
        VerticalPanel permPanel = new VerticalPanel();
121 6b7d024f Christos Stathis
        FilePermissionsDialog.Images images = GWT.create(FilePermissionsDialog.Images.class);
122 4d869bf1 Christos Stathis
        permList = new PermissionsList(images, folder.getPermissions(), folder.getOwner(), false, null);
123 6b7d024f Christos Stathis
        permPanel.add(permList);
124 6b7d024f Christos Stathis
125 b3c3954b Christos Stathis
        HorizontalPanel permButtons = new HorizontalPanel();
126 57ab6e0b Christos Stathis
        Button addUser = new Button("Add User", new ClickHandler() {
127 b3c3954b Christos Stathis
            @Override
128 b3c3954b Christos Stathis
            public void onClick(ClickEvent event) {
129 57ab6e0b Christos Stathis
                PermissionsAddDialog dlg = new PermissionsAddDialog(app, app.getAccount().getGroups(), permList, true);
130 b3c3954b Christos Stathis
                dlg.center();
131 b3c3954b Christos Stathis
            }
132 b3c3954b Christos Stathis
        });
133 57ab6e0b Christos Stathis
        addUser.addStyleName("button");
134 57ab6e0b Christos Stathis
        permButtons.add(addUser);
135 57ab6e0b Christos Stathis
        permButtons.setCellHorizontalAlignment(addUser, HasHorizontalAlignment.ALIGN_CENTER);
136 b3c3954b Christos Stathis
137 57ab6e0b Christos Stathis
        Button add = new Button("Add Group", new ClickHandler() {
138 b3c3954b Christos Stathis
            @Override
139 b3c3954b Christos Stathis
            public void onClick(ClickEvent event) {
140 57ab6e0b Christos Stathis
                PermissionsAddDialog dlg = new PermissionsAddDialog(app, app.getAccount().getGroups(), permList, false);
141 b3c3954b Christos Stathis
                dlg.center();
142 b3c3954b Christos Stathis
            }
143 b3c3954b Christos Stathis
        });
144 57ab6e0b Christos Stathis
        add.addStyleName("button");
145 57ab6e0b Christos Stathis
        permButtons.add(add);
146 57ab6e0b Christos Stathis
        permButtons.setCellHorizontalAlignment(add, HasHorizontalAlignment.ALIGN_CENTER);
147 57ab6e0b Christos Stathis
148 b3c3954b Christos Stathis
        permButtons.setSpacing(8);
149 b3c3954b Christos Stathis
        permPanel.add(permButtons);
150 6b7d024f Christos Stathis
151 6b7d024f Christos Stathis
        inner.add(permPanel);
152 6b7d024f Christos Stathis
153 6b7d024f Christos Stathis
        outer.add(inner);
154 6b7d024f Christos Stathis
155 6b7d024f Christos Stathis
                // Create the 'Create/Update' button, along with a listener that hides the dialog
156 6b7d024f Christos Stathis
                // when the button is clicked and quits the application.
157 6b7d024f Christos Stathis
                String okLabel = "Update";
158 6b7d024f Christos Stathis
                final Button ok = new Button(okLabel, new ClickHandler() {
159 6b7d024f Christos Stathis
                        @Override
160 ebead1b5 Christos Stathis
                        public void onClick(ClickEvent event) {
161 6b7d024f Christos Stathis
                                updateFolder();
162 6b7d024f Christos Stathis
                                closeDialog();
163 6b7d024f Christos Stathis
                        }
164 6b7d024f Christos Stathis
                });
165 6b7d024f Christos Stathis
                ok.addStyleName("button");
166 6b7d024f Christos Stathis
                outer.add(ok);
167 6b7d024f Christos Stathis
        outer.setCellHorizontalAlignment(inner, HasHorizontalAlignment.ALIGN_CENTER);
168 6b7d024f Christos Stathis
169 6b7d024f Christos Stathis
        setWidget(outer);
170 6b7d024f Christos Stathis
        }
171 6b7d024f Christos Stathis
172 6b7d024f Christos Stathis
        @Override
173 6b7d024f Christos Stathis
        protected void onPreviewNativeEvent(NativePreviewEvent preview) {
174 6b7d024f Christos Stathis
                super.onPreviewNativeEvent(preview);
175 6b7d024f Christos Stathis
176 6b7d024f Christos Stathis
                NativeEvent evt = preview.getNativeEvent();
177 6b7d024f Christos Stathis
                if (evt.getType().equals(KeyDownEvent.getType().getName()))
178 6b7d024f Christos Stathis
                        // Use the popup's key preview hooks to close the dialog when either
179 6b7d024f Christos Stathis
                        // enter or escape is pressed.
180 6b7d024f Christos Stathis
                        switch (evt.getKeyCode()) {
181 6b7d024f Christos Stathis
                                case KeyCodes.KEY_ENTER:
182 6b7d024f Christos Stathis
                                        updateFolder();
183 6b7d024f Christos Stathis
                    closeDialog();
184 6b7d024f Christos Stathis
                                        break;
185 6b7d024f Christos Stathis
                                case KeyCodes.KEY_ESCAPE:
186 6b7d024f Christos Stathis
                                        closeDialog();
187 6b7d024f Christos Stathis
                                        break;
188 6b7d024f Christos Stathis
                        }
189 6b7d024f Christos Stathis
        }
190 6b7d024f Christos Stathis
191 6b7d024f Christos Stathis
192 6b7d024f Christos Stathis
        /**
193 6b7d024f Christos Stathis
         * Enables IE selection prevention and hides the dialog
194 6b7d024f Christos Stathis
         * (we disable the prevention on creation of the dialog)
195 6b7d024f Christos Stathis
         */
196 6b7d024f Christos Stathis
        public void closeDialog() {
197 6b7d024f Christos Stathis
                Pithos.preventIESelection();
198 6b7d024f Christos Stathis
                hide();
199 6b7d024f Christos Stathis
        }
200 6b7d024f Christos Stathis
201 6b7d024f Christos Stathis
        void updateFolder() {
202 6b7d024f Christos Stathis
        final Map<String, Boolean[]> perms = (permList.hasChanges() ? permList.getPermissions() : null);
203 6b7d024f Christos Stathis
        final String newName = folderName.getText().trim();
204 6b7d024f Christos Stathis
        if (!folder.isContainer() && !folder.getName().equals(newName)) {
205 6b7d024f Christos Stathis
            final String path = folder.getParent().getUri() + "/" + newName;
206 6b7d024f Christos Stathis
            PutRequest newFolder = new PutRequest(app.getApiPath(), folder.getParent().getOwner(), path) {
207 6b7d024f Christos Stathis
                @Override
208 ebead1b5 Christos Stathis
                public void onSuccess(Resource result) {
209 6b7d024f Christos Stathis
                    Iterator<File> iter = folder.getFiles().iterator();
210 6b7d024f Christos Stathis
                    app.copyFiles(iter, folder.getParent().getOwner(), folder.getParent().getUri() + "/" + newName, new Command() {
211 6b7d024f Christos Stathis
                        @Override
212 6b7d024f Christos Stathis
                        public void execute() {
213 6b7d024f Christos Stathis
                            Iterator<Folder> iterf = folder.getSubfolders().iterator();
214 6b7d024f Christos Stathis
                            app.copySubfolders(iterf, folder.getParent().getOwner(), folder.getParent().getUri() + "/" + newName, new Command() {
215 6b7d024f Christos Stathis
                                @Override
216 6b7d024f Christos Stathis
                                public void execute() {
217 2c801ad7 Christos Stathis
                                    app.deleteFolder(folder, null);
218 6b7d024f Christos Stathis
                                    updateMetadata(path + "?update=", perms);
219 6b7d024f Christos Stathis
                                }
220 6b7d024f Christos Stathis
                            });
221 6b7d024f Christos Stathis
                        }
222 6b7d024f Christos Stathis
                    });
223 6b7d024f Christos Stathis
                }
224 6b7d024f Christos Stathis
225 6b7d024f Christos Stathis
                @Override
226 6b7d024f Christos Stathis
                public void onError(Throwable t) {
227 6b7d024f Christos Stathis
                    GWT.log("", t);
228 6b7d024f Christos Stathis
                                        app.setError(t);
229 6b7d024f Christos Stathis
                    if(t instanceof RestException){
230 6b7d024f Christos Stathis
                        app.displayError("Unable to update folder: " + ((RestException) t).getHttpStatusText());
231 6b7d024f Christos Stathis
                    }
232 6b7d024f Christos Stathis
                    else
233 6b7d024f Christos Stathis
                        app.displayError("System error modifying folder: " + t.getMessage());
234 6b7d024f Christos Stathis
                }
235 6b7d024f Christos Stathis
236 6b7d024f Christos Stathis
                                @Override
237 ebead1b5 Christos Stathis
                                protected void onUnauthorized(Response response) {
238 6b7d024f Christos Stathis
                                        app.sessionExpired();
239 6b7d024f Christos Stathis
                                }
240 6b7d024f Christos Stathis
            };
241 6b7d024f Christos Stathis
            newFolder.setHeader("X-Auth-Token", app.getToken());
242 6b7d024f Christos Stathis
            newFolder.setHeader("Content-Type", "application/folder");
243 6b7d024f Christos Stathis
            newFolder.setHeader("Accept", "*/*");
244 6b7d024f Christos Stathis
            newFolder.setHeader("Content-Length", "0");
245 6b7d024f Christos Stathis
            Scheduler.get().scheduleDeferred(newFolder);
246 6b7d024f Christos Stathis
        }
247 6b7d024f Christos Stathis
        else
248 6b7d024f Christos Stathis
            updateMetadata(folder.getUri() + "?update=", perms);
249 6b7d024f Christos Stathis
        }
250 6b7d024f Christos Stathis
251 6b7d024f Christos Stathis
        protected void updateMetadata(final String path, final Map<String, Boolean[]> newPermissions) {
252 6b7d024f Christos Stathis
        if (newPermissions != null) {
253 6b7d024f Christos Stathis
            PostRequest updateFolder = new PostRequest(app.getApiPath(), folder.getOwner(), path) {
254 6b7d024f Christos Stathis
                @Override
255 ebead1b5 Christos Stathis
                public void onSuccess(Resource result) {
256 6b7d024f Christos Stathis
                    app.updateFolder(folder.getParent(), false, new Command() {
257 6b7d024f Christos Stathis
                                                
258 6b7d024f Christos Stathis
                                                @Override
259 6b7d024f Christos Stathis
                                                public void execute() {
260 6b7d024f Christos Stathis
                                                        app.updateMySharedRoot();
261 6b7d024f Christos Stathis
                                                }
262 6acd4df3 Christos Stathis
                                        }, true);
263 6b7d024f Christos Stathis
                }
264 6b7d024f Christos Stathis
265 6b7d024f Christos Stathis
                @Override
266 6b7d024f Christos Stathis
                public void onError(Throwable t) {
267 6b7d024f Christos Stathis
                    GWT.log("", t);
268 6b7d024f Christos Stathis
                                        app.setError(t);
269 6b7d024f Christos Stathis
                    if (t instanceof RestException) {
270 6b7d024f Christos Stathis
                            if (((RestException) t).getHttpStatusCode() == Response.SC_NOT_FOUND) { //Probably a virtual folder
271 6b7d024f Christos Stathis
                            final String path1 = folder.getUri();
272 6b7d024f Christos Stathis
                            PutRequest newFolder = new PutRequest(app.getApiPath(), folder.getOwner(), path1) {
273 6b7d024f Christos Stathis
                                @Override
274 ebead1b5 Christos Stathis
                                public void onSuccess(Resource result) {
275 6b7d024f Christos Stathis
                                        updateMetadata(path, newPermissions);
276 6b7d024f Christos Stathis
                                }
277 6b7d024f Christos Stathis
278 6b7d024f Christos Stathis
                                @Override
279 6b7d024f Christos Stathis
                                public void onError(Throwable _t) {
280 6b7d024f Christos Stathis
                                    GWT.log("", _t);
281 6b7d024f Christos Stathis
                                                            app.setError(_t);
282 6b7d024f Christos Stathis
                                    if(_t instanceof RestException){
283 6b7d024f Christos Stathis
                                        app.displayError("Unable to update folder: " + ((RestException) _t).getHttpStatusText());
284 6b7d024f Christos Stathis
                                    }
285 6b7d024f Christos Stathis
                                    else
286 6b7d024f Christos Stathis
                                        app.displayError("System error modifying folder: " + _t.getMessage());
287 6b7d024f Christos Stathis
                                }
288 6b7d024f Christos Stathis
289 6b7d024f Christos Stathis
                                                @Override
290 ebead1b5 Christos Stathis
                                                protected void onUnauthorized(Response response) {
291 6b7d024f Christos Stathis
                                                        app.sessionExpired();
292 6b7d024f Christos Stathis
                                                }
293 6b7d024f Christos Stathis
                            };
294 6b7d024f Christos Stathis
                            newFolder.setHeader("X-Auth-Token", app.getToken());
295 6b7d024f Christos Stathis
                            newFolder.setHeader("Content-Type", "application/folder");
296 6b7d024f Christos Stathis
                            newFolder.setHeader("Accept", "*/*");
297 6b7d024f Christos Stathis
                            newFolder.setHeader("Content-Length", "0");
298 6b7d024f Christos Stathis
                            Scheduler.get().scheduleDeferred(newFolder);
299 6b7d024f Christos Stathis
                            }
300 6b7d024f Christos Stathis
                            else if (((RestException) t).getHttpStatusCode() == Response.SC_CONFLICT) {
301 6b7d024f Christos Stathis
                                    app.displayError("Cannot set permissions. Probably subfolders or files already have permissions set");
302 6b7d024f Christos Stathis
                            }
303 6b7d024f Christos Stathis
                            else
304 15dce1cd Christos Stathis
                                    app.displayError("Εrror modifying folder: " + t.getMessage());
305 6b7d024f Christos Stathis
                    }
306 6b7d024f Christos Stathis
                    else
307 6b7d024f Christos Stathis
                            app.displayError("System error modifying folder: " + t.getMessage());
308 6b7d024f Christos Stathis
                }
309 6b7d024f Christos Stathis
310 6b7d024f Christos Stathis
                                @Override
311 ebead1b5 Christos Stathis
                                protected void onUnauthorized(Response response) {
312 6b7d024f Christos Stathis
                                        app.sessionExpired();
313 6b7d024f Christos Stathis
                                }
314 6b7d024f Christos Stathis
            };
315 6b7d024f Christos Stathis
            updateFolder.setHeader("X-Auth-Token", app.getToken());
316 6b7d024f Christos Stathis
            String readPermHeader = "read=";
317 6b7d024f Christos Stathis
            String writePermHeader = "write=";
318 6b7d024f Christos Stathis
            for (String u : newPermissions.keySet()) {
319 6b7d024f Christos Stathis
                Boolean[] p = newPermissions.get(u);
320 6b7d024f Christos Stathis
                if (p[0] != null && p[0])
321 6b7d024f Christos Stathis
                    readPermHeader += u + ",";
322 6b7d024f Christos Stathis
                if (p[1] != null && p[1])
323 6b7d024f Christos Stathis
                    writePermHeader += u + ",";
324 6b7d024f Christos Stathis
            }
325 6b7d024f Christos Stathis
            if (readPermHeader.endsWith("="))
326 6b7d024f Christos Stathis
                readPermHeader = "";
327 6b7d024f Christos Stathis
            else if (readPermHeader.endsWith(","))
328 6b7d024f Christos Stathis
                readPermHeader = readPermHeader.substring(0, readPermHeader.length() - 1);
329 6b7d024f Christos Stathis
            if (writePermHeader.endsWith("="))
330 6b7d024f Christos Stathis
                writePermHeader = "";
331 6b7d024f Christos Stathis
            else if (writePermHeader.endsWith(","))
332 6b7d024f Christos Stathis
                writePermHeader = writePermHeader.substring(0, writePermHeader.length() - 1);
333 6b7d024f Christos Stathis
            String permHeader = readPermHeader +  ((readPermHeader.length()  > 0 && writePermHeader.length() > 0) ?  ";" : "") + writePermHeader;
334 6b7d024f Christos Stathis
            if (permHeader.length() == 0)
335 6b7d024f Christos Stathis
                permHeader = "~";
336 6b7d024f Christos Stathis
            else
337 6b7d024f Christos Stathis
                    permHeader = URL.encodePathSegment(permHeader);
338 6b7d024f Christos Stathis
            updateFolder.setHeader("X-Object-Sharing", permHeader);
339 6b7d024f Christos Stathis
            Scheduler.get().scheduleDeferred(updateFolder);
340 6b7d024f Christos Stathis
        }
341 6b7d024f Christos Stathis
        else
342 6b7d024f Christos Stathis
            app.updateFolder(folder.getParent(), false, new Command() {
343 6b7d024f Christos Stathis
                                
344 6b7d024f Christos Stathis
                                @Override
345 6b7d024f Christos Stathis
                                public void execute() {
346 6b7d024f Christos Stathis
                                        app.updateMySharedRoot();
347 6b7d024f Christos Stathis
                                }
348 6acd4df3 Christos Stathis
                        }, true);
349 6b7d024f Christos Stathis
    }
350 6b7d024f Christos Stathis
}