From ecf95c9e5031029245f92ec63b4c1f6c7077e362 Mon Sep 17 00:00:00 2001 From: Christos Stathis Date: Tue, 9 Aug 2011 19:45:56 +0300 Subject: [PATCH] Finished file permissions. Started folder permissions (displayed but not updated yet) --- .../web/client/AbstractPropertiesDialog.java | 5 +- .../pithos/web/client/FilePropertiesDialog.java | 226 +++++++------------- .../grnet/pithos/web/client/FolderContextMenu.java | 5 +- .../pithos/web/client/FolderPropertiesDialog.java | 129 ++++++----- .../pithos/web/client/PermissionsAddDialog.java | 3 +- .../grnet/pithos/web/client/PermissionsList.java | 104 +++++---- .../grnet/pithos/web/client/foldertree/File.java | 4 + .../grnet/pithos/web/client/foldertree/Folder.java | 23 ++ 8 files changed, 234 insertions(+), 265 deletions(-) diff --git a/src/gr/grnet/pithos/web/client/AbstractPropertiesDialog.java b/src/gr/grnet/pithos/web/client/AbstractPropertiesDialog.java index 2fbda4c..be45732 100644 --- a/src/gr/grnet/pithos/web/client/AbstractPropertiesDialog.java +++ b/src/gr/grnet/pithos/web/client/AbstractPropertiesDialog.java @@ -144,7 +144,6 @@ public abstract class AbstractPropertiesDialog extends DialogBox { protected abstract void accept(); @Override - @SuppressWarnings("fallthrough") protected void onPreviewNativeEvent(NativePreviewEvent preview) { super.onPreviewNativeEvent(preview); @@ -156,8 +155,8 @@ public abstract class AbstractPropertiesDialog extends DialogBox { case KeyCodes.KEY_ENTER: accept(); case KeyCodes.KEY_ESCAPE: - closeDialog(); - break; + closeDialog(); + break; } } diff --git a/src/gr/grnet/pithos/web/client/FilePropertiesDialog.java b/src/gr/grnet/pithos/web/client/FilePropertiesDialog.java index a1ae971..f3c3194 100644 --- a/src/gr/grnet/pithos/web/client/FilePropertiesDialog.java +++ b/src/gr/grnet/pithos/web/client/FilePropertiesDialog.java @@ -35,8 +35,6 @@ package gr.grnet.pithos.web.client; import com.google.gwt.core.client.Scheduler; -import com.google.gwt.json.client.JSONArray; -import com.google.gwt.json.client.JSONString; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.Anchor; import com.google.gwt.user.client.ui.Label; @@ -55,7 +53,6 @@ import com.google.gwt.json.client.JSONBoolean; import com.google.gwt.json.client.JSONObject; import com.google.gwt.resources.client.ClientBundle; import com.google.gwt.resources.client.ImageResource; -import com.google.gwt.user.client.Command; import com.google.gwt.user.client.DeferredCommand; import com.google.gwt.user.client.ui.Button; import com.google.gwt.user.client.ui.CheckBox; @@ -69,7 +66,7 @@ import com.google.gwt.user.client.ui.HorizontalPanel; import com.google.gwt.user.client.ui.TextBox; import com.google.gwt.user.client.ui.VerticalPanel; import gr.grnet.pithos.web.client.tagtree.Tag; -import java.util.Iterator; +import java.util.Map; /** * The 'File properties' dialog box implementation. @@ -107,12 +104,8 @@ public class FilePropertiesDialog extends AbstractPropertiesDialog { */ private TextBox name = new TextBox(); - private final CheckBox versioned = new CheckBox(); - final File file; - private String userFullName; - Images images = GWT.create(Images.class); /** @@ -256,35 +249,37 @@ public class FilePropertiesDialog extends AbstractPropertiesDialog { private VerticalPanel createSharingPanel() { VerticalPanel permPanel = new VerticalPanel(); - permList = new PermissionsList(app, images, file.getPermissions(), file.getOwner()); + permList = new PermissionsList(images, file.getPermissions(), file.getOwner(), file.getInheritedPermissionsFrom() != null); permPanel.add(permList); - HorizontalPanel permButtons = new HorizontalPanel(); - Button add = new Button("Add Group", new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - PermissionsAddDialog dlg = new PermissionsAddDialog(app, app.getAccount().getGroups(), permList, false); - dlg.center(); - permList.updatePermissionTable(); - } - }); - permButtons.add(add); - permButtons.setCellHorizontalAlignment(add, HasHorizontalAlignment.ALIGN_CENTER); + if (file.getInheritedPermissionsFrom() == null) { + HorizontalPanel permButtons = new HorizontalPanel(); + Button add = new Button("Add Group", new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + PermissionsAddDialog dlg = new PermissionsAddDialog(app, app.getAccount().getGroups(), permList, false); + dlg.center(); + permList.updatePermissionTable(); + } + }); + permButtons.add(add); + permButtons.setCellHorizontalAlignment(add, HasHorizontalAlignment.ALIGN_CENTER); - final Button addUser = new Button("Add User", new ClickHandler() { - @Override - public void onClick(ClickEvent event) { - PermissionsAddDialog dlg = new PermissionsAddDialog(app, app.getAccount().getGroups(), permList, true); - dlg.center(); - permList.updatePermissionTable(); - } - }); - permButtons.add(addUser); - permButtons.setCellHorizontalAlignment(addUser, HasHorizontalAlignment.ALIGN_CENTER); + final Button addUser = new Button("Add User", new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + PermissionsAddDialog dlg = new PermissionsAddDialog(app, app.getAccount().getGroups(), permList, true); + dlg.center(); + permList.updatePermissionTable(); + } + }); + permButtons.add(addUser); + permButtons.setCellHorizontalAlignment(addUser, HasHorizontalAlignment.ALIGN_CENTER); - permButtons.setSpacing(8); - permButtons.addStyleName("pithos-TabPanelBottom"); - permPanel.add(permButtons); + permButtons.setSpacing(8); + permButtons.addStyleName("pithos-TabPanelBottom"); + permPanel.add(permButtons); + } final Label readForAllNote = new Label("When this option is enabled, the file will be readable" + " by everyone. By checking this option, you are certifying that you have the right to " + @@ -401,49 +396,22 @@ public class FilePropertiesDialog extends AbstractPropertiesDialog { @Override protected void accept() { String newFilename = null; -// permList.updatePermissionsAccordingToInput(); -// Set perms = permList.getPermissions(); -// JSONObject json = new JSONObject(); + + final Map perms = (permList.hasChanges() ? permList.getPermissions() : null); if (!name.getText().trim().equals(file.getName())) { newFilename = name.getText().trim(); -// json.put("name", new JSONString(newFilename)); } -// if (versioned.getValue() != file.isVersioned()) -// json.put("versioned", JSONBoolean.getInstance(versioned.getValue())); + //only update the read for all perm if the user is the owner Boolean published = null; if (readForAll.getValue() != file.isPublished()) if (file.getOwner().equals(app.getUsername())) published = readForAll.getValue(); final Boolean finalPublished = published; -// json.put("readForAll", JSONBoolean.getInstance(readForAll.getValue())); -// int i = 0; -// if (permList.hasChanges()) { -// GWT.log("Permissions change", null); -// JSONArray perma = new JSONArray(); -// -// for (PermissionHolder p : perms) { -// JSONObject po = new JSONObject(); -// if (p.getUser() != null) -// po.put("user", new JSONString(p.getUser())); -// if (p.getGroup() != null) -// po.put("group", new JSONString(p.getGroup())); -// po.put("read", JSONBoolean.getInstance(p.isRead())); -// po.put("write", JSONBoolean.getInstance(p.isWrite())); -// po.put("modifyACL", JSONBoolean.getInstance(p.isModifyACL())); -// perma.set(i, po); -// i++; -// } -// json.put("permissions", perma); -// } + String[] tagset = null; if (!tags.getText().equals(initialTagText)) tagset = tags.getText().split(","); -// String jsonString = json.toString(); -// if(jsonString.equals("{}")){ -// GWT.log("NO CHANGES", null); -// return; -// } final String[] newTags = tagset; if (newFilename != null) { @@ -451,10 +419,7 @@ public class FilePropertiesDialog extends AbstractPropertiesDialog { PutRequest updateFile = new PutRequest(app.getApiPath(), app.getUsername(), path) { @Override public void onSuccess(Resource result) { - if (newTags != null || finalPublished != null) - updateMetaData(app.getApiPath(), app.getUsername(), path + "?update=", newTags, finalPublished); - else - app.updateFolder(file.getParent()); + updateMetaData(app.getApiPath(), app.getUsername(), path + "?update=", newTags, finalPublished, perms); } @Override @@ -468,96 +433,53 @@ public class FilePropertiesDialog extends AbstractPropertiesDialog { updateFile.setHeader("Content-Type", file.getContentType()); Scheduler.get().scheduleDeferred(updateFile); } - else if (newTags != null || finalPublished != null) - updateMetaData(app.getApiPath(), app.getUsername(), file.getUri() + "?update=", newTags, finalPublished); + else + updateMetaData(app.getApiPath(), app.getUsername(), file.getUri() + "?update=", newTags, finalPublished, perms); } - private void updateMetaData(String api, String owner, String path, String[] newTags, Boolean published) { - PostRequest updateFile = new PostRequest(api, owner, path) { - @Override - public void onSuccess(Resource result) { - app.updateFolder(file.getParent()); - } + private void updateMetaData(String api, String owner, String path, String[] newTags, Boolean published, Map newPermissions) { + if (newTags != null || published != null || newPermissions != null) { + PostRequest updateFile = new PostRequest(api, owner, path) { + @Override + public void onSuccess(Resource result) { + app.updateFolder(file.getParent()); + } - @Override - public void onError(Throwable t) { - GWT.log("", t); - app.displayError("System error modifying file:" + t.getMessage()); + @Override + public void onError(Throwable t) { + GWT.log("", t); + app.displayError("System error modifying file:" + t.getMessage()); + } + }; + updateFile.setHeader("X-Auth-Token", app.getToken()); + if (newTags != null) + for (String t : newTags) + updateFile.setHeader("X-Object-Meta-" + t.trim(), "true"); + if (published != null) + updateFile.setHeader("X-Object-Public", published.toString()); + if (newPermissions != null) { + String readPermHeader = "read=" + app.getUsername() + ","; + String writePermHeader = "write=" + app.getUsername() + ","; + for (String u : newPermissions.keySet()) { + Boolean[] p = newPermissions.get(u); + if (p[0] != null && p[0]) + readPermHeader += u + ","; + if (p[1] != null && p[1]) + writePermHeader += u + ","; + } + if (readPermHeader.endsWith(",")) + readPermHeader = readPermHeader.substring(0, readPermHeader.length() - 1); + if (writePermHeader.endsWith(",")) + writePermHeader = writePermHeader.substring(0, writePermHeader.length() - 1); + String permHeader = readPermHeader + ";" + writePermHeader; + updateFile.setHeader("X-Object-Sharing", permHeader); } - }; - updateFile.setHeader("X-Auth-Token", app.getToken()); - if (newTags != null) - for (String t : newTags) - updateFile.setHeader("X-Object-Meta-" + t.trim(), "true"); - if (published != null) - updateFile.setHeader("X-Object-Public", published.toString()); - Scheduler.get().scheduleDeferred(updateFile); + Scheduler.get().scheduleDeferred(updateFile); + } + else + app.updateFolder(file.getParent()); } private void removeAllOldVersions() { - JSONObject json = new JSONObject(); - json.put("versioned", JSONBoolean.getInstance(false)); - GWT.log(json.toString(), null); - PostCommand cf = new PostCommand(app, file.getUri() + "?update=", json.toString(), 200) { - - @Override - public void onComplete() { - toggleVersioned(true); - } - - @Override - public void onError(Throwable t) { - GWT.log("", t); - if (t instanceof RestException) { - int statusCode = ((RestException) t).getHttpStatusCode(); - if (statusCode == 405) - app.displayError("You don't have the necessary permissions"); - else if (statusCode == 404) - app.displayError("User in permissions does not exist"); - else if (statusCode == 409) - app.displayError("A folder with the same name already exists"); - else if (statusCode == 413) - app.displayError("Your quota has been exceeded"); - else - app.displayError("Unable to modify file:" + ((RestException) t).getHttpStatusText()); - } else - app.displayError("System error moifying file:" + t.getMessage()); - } - }; - DeferredCommand.addCommand(cf); - } - - private void toggleVersioned(boolean versionedValue) { - JSONObject json = new JSONObject(); - json.put("versioned", JSONBoolean.getInstance(versionedValue)); - GWT.log(json.toString(), null); - PostCommand cf = new PostCommand(app, file.getUri() + "?update=", json.toString(), 200) { - - @Override - public void onComplete() { - app.getTreeView().refreshCurrentNode(false); - } - - @Override - public void onError(Throwable t) { - GWT.log("", t); - if (t instanceof RestException) { - int statusCode = ((RestException) t).getHttpStatusCode(); - if (statusCode == 405) - app.displayError("You don't have the necessary permissions"); - else if (statusCode == 404) - app.displayError("User in permissions does not exist"); - else if (statusCode == 409) - app.displayError("A folder with the same name already exists"); - else if (statusCode == 413) - app.displayError("Your quota has been exceeded"); - else - app.displayError("Unable to modify file:" + ((RestException) t).getHttpStatusText()); - } else - app.displayError("System error moifying file:" + t.getMessage()); - } - }; - DeferredCommand.addCommand(cf); } - } diff --git a/src/gr/grnet/pithos/web/client/FolderContextMenu.java b/src/gr/grnet/pithos/web/client/FolderContextMenu.java index ea8553f..e6eb7e5 100644 --- a/src/gr/grnet/pithos/web/client/FolderContextMenu.java +++ b/src/gr/grnet/pithos/web/client/FolderContextMenu.java @@ -103,6 +103,9 @@ public class FolderContextMenu extends PopupPanel { MenuItem delete = new MenuItem("" + AbstractImagePrototype.create(newImages.delete()).getHTML() + " Delete", true, new DeleteCommand(app, this, folder, newImages)); contextMenu.addItem(delete); + + MenuItem properties = new MenuItem("" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + " Properties", true, new PropertiesCommand(app, this, folder, newImages, 0)); + contextMenu.addItem(properties); } // MenuItem refresh = new MenuItem("" + AbstractImagePrototype.create(images.refresh()).getHTML() + " Refresh", true, new RefreshCommand(this, images)); @@ -111,8 +114,6 @@ public class FolderContextMenu extends PopupPanel { // MenuItem sharing = new MenuItem("" + AbstractImagePrototype.create(newImages.sharing()).getHTML() + " Sharing", true, new PropertiesCommand(this, newImages, 1)); // contextMenu.addItem(sharing); - MenuItem properties = new MenuItem("" + AbstractImagePrototype.create(newImages.viewText()).getHTML() + " Properties", true, new PropertiesCommand(app, this, folder, newImages, 0)); - contextMenu.addItem(properties); add(contextMenu); } diff --git a/src/gr/grnet/pithos/web/client/FolderPropertiesDialog.java b/src/gr/grnet/pithos/web/client/FolderPropertiesDialog.java index 57f3291..19193fd 100644 --- a/src/gr/grnet/pithos/web/client/FolderPropertiesDialog.java +++ b/src/gr/grnet/pithos/web/client/FolderPropertiesDialog.java @@ -37,6 +37,7 @@ package gr.grnet.pithos.web.client; import com.google.gwt.core.client.Scheduler; import com.google.gwt.event.dom.client.KeyDownEvent; import com.google.gwt.user.client.Command; +import gr.grnet.pithos.web.client.FilePropertiesDialog.Images; import gr.grnet.pithos.web.client.foldertree.File; import gr.grnet.pithos.web.client.foldertree.Folder; import gr.grnet.pithos.web.client.foldertree.Resource; @@ -82,6 +83,8 @@ public class FolderPropertiesDialog extends DialogBox { */ private final boolean create; + private PermissionsList permList; + final Folder folder; final TabPanel inner; @@ -89,7 +92,7 @@ public class FolderPropertiesDialog extends DialogBox { /** * The widget's constructor. */ - public FolderPropertiesDialog(Pithos app, boolean _create, Folder selected) { + public FolderPropertiesDialog(final Pithos app, boolean _create, Folder selected) { this.app = app; setAnimationEnabled(true); @@ -111,45 +114,79 @@ public class FolderPropertiesDialog extends DialogBox { // Inner contains generalPanel and permPanel inner = new DecoratedTabPanel(); inner.setAnimationEnabled(true); + VerticalPanel generalPanel = new VerticalPanel(); - VerticalPanel permPanel = new VerticalPanel(); - final HorizontalPanel permForAll = new HorizontalPanel(); - final HorizontalPanel pathPanel = new HorizontalPanel(); - HorizontalPanel buttons = new HorizontalPanel(); - HorizontalPanel permButtons = new HorizontalPanel(); - - inner.add(generalPanel, "General"); - if (!create) - inner.add(permPanel, "Sharing"); - inner.selectTab(0); - - FlexTable generalTable = new FlexTable(); - generalTable.setText(0, 0, "Name"); - generalTable.setText(1, 0, "Parent"); - generalTable.setText(2, 0, "Creator"); - generalTable.setText(3, 0, "Last modified"); - folderName.setText(create ? "" : folder.getName()); + FlexTable generalTable = new FlexTable(); + generalTable.setText(0, 0, "Name"); + generalTable.setText(1, 0, "Parent"); + generalTable.setText(2, 0, "Creator"); + generalTable.setText(3, 0, "Last modified"); + folderName.setText(create ? "" : folder.getName()); folderName.setReadOnly(folder.isContainer() && !create); - generalTable.setWidget(0, 1, folderName); + generalTable.setWidget(0, 1, folderName); + + if (create) + generalTable.setText(1, 1, folder.getName()); + else + generalTable.setText(1, 1, folder.getPrefix()); + generalTable.setText(2, 1, ""); + DateTimeFormat formatter = DateTimeFormat.getFormat("d/M/yyyy h:mm a"); + if(folder.getLastModified() != null) + generalTable.setText(3, 1, formatter.format(folder.getLastModified())); + generalTable.getFlexCellFormatter().setStyleName(0, 0, "props-labels"); + generalTable.getFlexCellFormatter().setStyleName(1, 0, "props-labels"); + generalTable.getFlexCellFormatter().setStyleName(2, 0, "props-labels"); + generalTable.getFlexCellFormatter().setStyleName(3, 0, "props-labels"); + generalTable.getFlexCellFormatter().setStyleName(0, 1, "props-values"); + generalTable.getFlexCellFormatter().setStyleName(1, 1, "props-values"); + generalTable.getFlexCellFormatter().setStyleName(2, 1, "props-values"); + generalTable.getFlexCellFormatter().setStyleName(3, 1, "props-values"); + generalTable.setCellSpacing(4); + generalPanel.add(generalTable); + inner.add(generalPanel, "General"); + + VerticalPanel permPanel = new VerticalPanel(); + FilePropertiesDialog.Images images = GWT.create(FilePropertiesDialog.Images.class); + boolean permsReadonly = folder.getInheritedPermissionsFrom() != null || folder.existChildrenPermissions(); + permList = new PermissionsList(images, folder.getPermissions(), folder.getOwner(), permsReadonly); + permPanel.add(permList); + final HorizontalPanel permForAll = new HorizontalPanel(); + final HorizontalPanel pathPanel = new HorizontalPanel(); + + if (!permsReadonly) { + HorizontalPanel permButtons = new HorizontalPanel(); + Button add = new Button("Add Group", new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + PermissionsAddDialog dlg = new PermissionsAddDialog(app, app.getAccount().getGroups(), permList, false); + dlg.center(); + } + }); + permButtons.add(add); + permButtons.setCellHorizontalAlignment(add, HasHorizontalAlignment.ALIGN_CENTER); - if (create) - generalTable.setText(1, 1, folder.getName()); - else - generalTable.setText(1, 1, folder.getPrefix()); - generalTable.setText(2, 1, ""); - DateTimeFormat formatter = DateTimeFormat.getFormat("d/M/yyyy h:mm a"); - if(folder.getLastModified() != null) - generalTable.setText(3, 1, formatter.format(folder.getLastModified())); - generalTable.getFlexCellFormatter().setStyleName(0, 0, "props-labels"); - generalTable.getFlexCellFormatter().setStyleName(1, 0, "props-labels"); - generalTable.getFlexCellFormatter().setStyleName(2, 0, "props-labels"); - generalTable.getFlexCellFormatter().setStyleName(3, 0, "props-labels"); - generalTable.getFlexCellFormatter().setStyleName(0, 1, "props-values"); - generalTable.getFlexCellFormatter().setStyleName(1, 1, "props-values"); - generalTable.getFlexCellFormatter().setStyleName(2, 1, "props-values"); - generalTable.getFlexCellFormatter().setStyleName(3, 1, "props-values"); - generalTable.setCellSpacing(4); + Button addUser = new Button("Add User", new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + PermissionsAddDialog dlg = new PermissionsAddDialog(app, app.getAccount().getGroups(), permList, true); + dlg.center(); + } + }); + addUser.getElement().setId("folderPropertiesDialog.button.addUser"); + permButtons.add(addUser); + permButtons.setCellHorizontalAlignment(addUser, HasHorizontalAlignment.ALIGN_CENTER); + permButtons.setSpacing(8); + permButtons.addStyleName("gss-TabPanelBottom"); + permPanel.add(permButtons); + } + if (!create) + inner.add(permPanel, "Sharing"); + inner.selectTab(0); + + outer.add(inner); + + HorizontalPanel buttons = new HorizontalPanel(); // Create the 'Create/Update' button, along with a listener that hides the dialog // when the button is clicked and quits the application. String okLabel; @@ -179,21 +216,11 @@ public class FolderPropertiesDialog extends DialogBox { buttons.setCellHorizontalAlignment(cancel, HasHorizontalAlignment.ALIGN_CENTER); buttons.setSpacing(8); buttons.addStyleName("pithos-TabPanelBottom"); + outer.add(buttons); + outer.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER); + outer.addStyleName("pithos-TabPanelBottom"); - generalPanel.add(generalTable); - - - outer.add(inner); - outer.add(buttons); - outer.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_CENTER); - outer.addStyleName("pithos-TabPanelBottom"); - - setWidget(outer); - - /*if (create) - folderName.setFocus(true); - else - ok.setFocus(true);*/ + setWidget(outer); } @Override @@ -212,8 +239,8 @@ public class FolderPropertiesDialog extends DialogBox { // enter or escape is pressed. switch (evt.getKeyCode()) { case KeyCodes.KEY_ENTER: - closeDialog(); createOrUpdateFolder(); + closeDialog(); break; case KeyCodes.KEY_ESCAPE: closeDialog(); diff --git a/src/gr/grnet/pithos/web/client/PermissionsAddDialog.java b/src/gr/grnet/pithos/web/client/PermissionsAddDialog.java index 8b28f62..ab58cd1 100644 --- a/src/gr/grnet/pithos/web/client/PermissionsAddDialog.java +++ b/src/gr/grnet/pithos/web/client/PermissionsAddDialog.java @@ -140,8 +140,7 @@ public class PermissionsAddDialog extends DialogBox { selected = app.getUsername() + ":" + groupName; } if (permList.getPermissions().get(selected) != null) { - app.displayError((userAdd ? "User " : "Group ") + "already has access to the resource"); - return; + return; } boolean readValue = read.getValue(); boolean writeValue = write.getValue(); diff --git a/src/gr/grnet/pithos/web/client/PermissionsList.java b/src/gr/grnet/pithos/web/client/PermissionsList.java index 4b5faf2..d8b7bb4 100644 --- a/src/gr/grnet/pithos/web/client/PermissionsList.java +++ b/src/gr/grnet/pithos/web/client/PermissionsList.java @@ -34,7 +34,10 @@ */ package gr.grnet.pithos.web.client; +import com.google.gwt.event.logical.shared.ValueChangeEvent; +import com.google.gwt.event.logical.shared.ValueChangeHandler; import gr.grnet.pithos.web.client.FilePropertiesDialog.Images; +import gr.grnet.pithos.web.client.foldertree.File; import gr.grnet.pithos.web.client.rest.GetCommand; import gr.grnet.pithos.web.client.rest.resource.PermissionHolder; import gr.grnet.pithos.web.client.rest.resource.UserResource; @@ -59,10 +62,6 @@ import com.google.gwt.user.client.ui.VerticalPanel; public class PermissionsList extends Composite { - int selectedRow = -1; - - int permissionCount = -1; - Map permissions = null; final Images images; @@ -74,16 +73,14 @@ public class PermissionsList extends Composite { final String owner; private boolean hasChanges = false; - - private boolean hasAddition = false; - private Pithos app; + private boolean readonly = false; - public PermissionsList(Pithos _app, final Images theImages, Map thePermissions, String anOwner){ - app = _app; + public PermissionsList(final Images theImages, Map thePermissions, String theOwner, boolean inheritsPermissions){ images = theImages; - owner = anOwner; + owner = theOwner; permissions = new HashMap(thePermissions); + readonly = inheritsPermissions; permTable.setText(0, 0, "Users/Groups"); permTable.setText(0, 1, "Read"); permTable.setText(0, 2, "Write"); @@ -99,25 +96,7 @@ public class PermissionsList extends Composite { } public boolean hasChanges(){ - return hasChanges || hasAddition; - } - - public void updatePermissionsAccordingToInput(){ -// int i=1; -// for(PermissionHolder dto : permissions){ -// /*if(dto.getId() == null) -// hasChanges =true;*/ -// CheckBox r = (CheckBox) permTable.getWidget(i, 1); -// CheckBox w = (CheckBox) permTable.getWidget(i, 2); -// -// -// if(dto.isRead() != r.getValue() || dto.isWrite() != w.getValue() || dto.isModifyACL() != m.getValue()) -// hasChanges = true; -// dto.setRead(r.getValue()); -// dto.setWrite(w.getValue()); -// dto.setModifyACL(m.getValue()); -// i++; -// } + return hasChanges; } /** @@ -131,7 +110,7 @@ public class PermissionsList extends Composite { public void addPermission(String user, boolean read, boolean write){ permissions.put(user, new Boolean[] {Boolean.valueOf(read), Boolean.valueOf(write)}); - hasAddition = true; + hasChanges = true; updatePermissionTable(); } @@ -144,22 +123,11 @@ public class PermissionsList extends Composite { for (int j=1; j" + AbstractImagePrototype.create(images.permUser()).getHTML() + " Owner"); - removeButton.setVisible(false); - } - else if (!user.contains(":")) //not a group + if (!user.contains(":")) //not a group permTable.setHTML(i, 0, "" + AbstractImagePrototype.create(images.permUser()).getHTML() + " " + user + ""); else permTable.setHTML(i, 0, "" + AbstractImagePrototype.create(images.permGroup()).getHTML() + " " + user.split(":")[1].trim() + ""); + permTable.getFlexCellFormatter().setStyleName(i, 0, "props-labels"); Boolean[] userPerms = permissions.get(user); Boolean readP = userPerms[0]; @@ -167,19 +135,45 @@ public class PermissionsList extends Composite { CheckBox read = new CheckBox(); read.setValue(readP != null ? readP : false); - - CheckBox write = new CheckBox(); - write.setValue(writeP != null ? writeP : false); - - permTable.setWidget(i, 1, read); - permTable.setWidget(i, 2, write); - permTable.setWidget(i, 3, removeButton); - permTable.getFlexCellFormatter().setStyleName(i, 0, "props-labels"); - permTable.getFlexCellFormatter().setHorizontalAlignment(i, 1, HasHorizontalAlignment.ALIGN_CENTER); - permTable.getFlexCellFormatter().setHorizontalAlignment(i, 2, HasHorizontalAlignment.ALIGN_CENTER); - permTable.getFlexCellFormatter().setHorizontalAlignment(i, 3, HasHorizontalAlignment.ALIGN_CENTER); + permTable.setWidget(i, 1, read); + permTable.getFlexCellFormatter().setHorizontalAlignment(i, 1, HasHorizontalAlignment.ALIGN_CENTER); + + CheckBox write = new CheckBox(); + write.setValue(writeP != null ? writeP : false); + permTable.setWidget(i, 2, write); + permTable.getFlexCellFormatter().setHorizontalAlignment(i, 2, HasHorizontalAlignment.ALIGN_CENTER); + + if (!readonly) { + read.addValueChangeHandler(new ValueChangeHandler() { + @Override + public void onValueChange(ValueChangeEvent booleanValueChangeEvent) { + Boolean[] ps = permissions.get(user); + ps[0] = booleanValueChangeEvent.getValue(); + } + }); + write.addValueChangeHandler(new ValueChangeHandler() { + @Override + public void onValueChange(ValueChangeEvent booleanValueChangeEvent) { + Boolean[] ps = permissions.get(user); + ps[1] = booleanValueChangeEvent.getValue(); + } + }); + PushButton removeButton = new PushButton(AbstractImagePrototype.create(images.delete()).createImage(), new ClickHandler() { + @Override + public void onClick(ClickEvent event) { + permissions.remove(user); + updatePermissionTable(); + hasChanges = true; + } + }); + permTable.setWidget(i, 3, removeButton); + permTable.getFlexCellFormatter().setHorizontalAlignment(i, 3, HasHorizontalAlignment.ALIGN_CENTER); + } + else { + read.setEnabled(false); + write.setEnabled(false); + } i++; } - hasChanges = false; } } diff --git a/src/gr/grnet/pithos/web/client/foldertree/File.java b/src/gr/grnet/pithos/web/client/foldertree/File.java index cd970f8..9c1f79c 100644 --- a/src/gr/grnet/pithos/web/client/foldertree/File.java +++ b/src/gr/grnet/pithos/web/client/foldertree/File.java @@ -260,4 +260,8 @@ public class File extends Resource { public Map getPermissions() { return permissions; } + + public String getInheritedPermissionsFrom() { + return inheritedPermissionsFrom; + } } diff --git a/src/gr/grnet/pithos/web/client/foldertree/Folder.java b/src/gr/grnet/pithos/web/client/foldertree/Folder.java index 46aaf84..960c852 100644 --- a/src/gr/grnet/pithos/web/client/foldertree/Folder.java +++ b/src/gr/grnet/pithos/web/client/foldertree/Folder.java @@ -311,4 +311,27 @@ public class Folder extends Resource { public Set getTags() { return tags; } + + public String getInheritedPermissionsFrom() { + return inheritedPermissionsFrom; + } + + public Map getPermissions() { + return permissions; + } + + public String getOwner() { + return owner; + } + + public boolean existChildrenPermissions() { + for (File f : files) + if (!f.getPermissions().isEmpty() && f.getInheritedPermissionsFrom() == null) + return true; + + for (Folder fo : subfolders) + if ((!fo.getPermissions().isEmpty() && fo.getInheritedPermissionsFrom() == null) || fo.existChildrenPermissions()) + return true; + return false; + } } -- 1.7.10.4