updated to integrate set permissions

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@111506 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2015-01-28 11:42:48 +00:00
parent aa1cdd803f
commit 0d97e17c22
13 changed files with 266 additions and 14 deletions

View File

@ -58,7 +58,7 @@
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<scope>provided</scope>
<!-- <scope>provided</scope> -->
<version>${gwtVersion}</version>
</dependency>

View File

@ -34,6 +34,8 @@ import org.gcube.portlets.user.workspace.client.event.DeleteMessageEvent;
import org.gcube.portlets.user.workspace.client.event.DeleteMessageEventHandler;
import org.gcube.portlets.user.workspace.client.event.DeleteSmartFolderEvent;
import org.gcube.portlets.user.workspace.client.event.DeleteSmartFolderEventHandler;
import org.gcube.portlets.user.workspace.client.event.EditUserPermissionEvent;
import org.gcube.portlets.user.workspace.client.event.EditUserPermissionEventHandler;
import org.gcube.portlets.user.workspace.client.event.ExpandFolderEvent;
import org.gcube.portlets.user.workspace.client.event.ExpandFolderEventHandler;
import org.gcube.portlets.user.workspace.client.event.FileDownloadEvent;
@ -141,14 +143,17 @@ import org.gcube.portlets.user.workspace.client.workspace.folder.item.gcube.GWTI
import org.gcube.portlets.user.workspace.client.workspace.folder.item.gcube.GWTUrlDocument;
import org.gcube.portlets.user.workspace.shared.SessionExpiredException;
import org.gcube.portlets.user.workspace.shared.UserBean;
import org.gcube.portlets.user.workspace.shared.WorkspaceACL;
import org.gcube.portlets.user.workspace.shared.accounting.GxtAccountingField;
import org.gcube.portlets.widgets.fileupload.client.events.FileUploadCompleteEvent;
import org.gcube.portlets.widgets.fileupload.client.events.FileUploadCompleteEventHandler;
import org.gcube.portlets.widgets.fileupload.client.events.FileUploadSelectedEvent;
import org.gcube.portlets.widgets.fileupload.client.events.FileUploadSelectedEventHandler;
import org.gcube.portlets.widgets.workspacesharingwidget.client.MultiDragContactsEditPermissions;
import org.gcube.portlets.widgets.workspacesharingwidget.client.SimpleMultiDragConstants;
import org.gcube.portlets.widgets.workspacesharingwidget.client.SimpleMultiDragWorkspaceContact;
import org.gcube.portlets.widgets.workspacesharingwidget.client.SimpleMultiDragWorkspaceContact.LOAD_CONTACTS_AS;
import org.gcube.portlets.widgets.workspacesharingwidget.client.view.sharing.multisuggest.DialogMultiDragContact;
import com.extjs.gxt.ui.client.Registry;
import com.extjs.gxt.ui.client.event.BaseEvent;
@ -210,7 +215,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
}
private void bind() {
eventBus.addHandler(UpdateWorkspaceSizeEvent.TYPE, new UpdateWorkspaceSizeEventHandler() {
@Override
@ -331,6 +336,48 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
}
});
eventBus.addHandler(EditUserPermissionEvent.TYPE, new EditUserPermissionEventHandler() {
@Override
public void onEditUserPermission(EditUserPermissionEvent editUserPermissionEvent) {
final FileModel file = editUserPermissionEvent.getSourceFolder();
if(file==null || file.getIdentifier()==null)
return;
rpcWorkspaceService.getOwnerByItemId(file.getIdentifier(), new AsyncCallback<InfoContactModel>() {
@Override
public void onFailure(Throwable caught) {
if(caught instanceof SessionExpiredException){
GWT.log("Session expired");
eventBus.fireEvent(new SessionExpiredEvent());
return;
}
new MessageBoxAlert("Error", "Sorry, an error occurred on recovering the contacts, try again later", null);
explorerPanel.unmask();
}
@Override
public void onSuccess(InfoContactModel infoContactModel) {
//IF IS OWNER
if(AppControllerExplorer.myLogin.compareToIgnoreCase(infoContactModel.getLogin())==0)
ediPermissions(file);
else
new MessageBoxAlert("Permission denied", "You have no authority to manage user permissions. You are not manager of \""+file.getName()+"\"", null);
}
});
}
});
eventBus.addHandler(GetInfoEvent.TYPE, new GetInfoEventHandler() {
@Override
@ -2128,6 +2175,86 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
return this.explorerPanel;
}
private void ediPermissions(final FileModel file) {
GWT.log("Edit Permissions on "+file);
SimpleMultiDragConstants.HEADING_DIALOG = "Edit User/s permissions to: "+file.getName();
SimpleMultiDragConstants.ALL_CONTACTS_LEFT_LIST = "Shared User/s";
SimpleMultiDragConstants.SHARE_WITH_RIGHT_LIST = "Set permissions for User/s";
final MultiDragContactsEditPermissions multiDragContact = new MultiDragContactsEditPermissions(LOAD_CONTACTS_AS.SHARED_USER, file.getIdentifier(), false, false, true);
final DialogMultiDragContact multidrag = multiDragContact.getDialog();
multidrag.setTxtHelp("Sets the permission for the user(s) dragged in the right list");
multidrag.getButtonById(Dialog.OK).addListener(Events.Select, new Listener<BaseEvent>() {
@Override
public void handleEvent(BaseEvent be) {
final List<org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel> targets = multiDragContact.getTargetContacts();
if(targets.size()==0){
MessageBoxConfirm info = new MessageBoxConfirm("Any User/s?", "You have not selected any Users, confirm exit?");
info.getMessageBoxConfirm().addCallback(new Listener<MessageBoxEvent>() {
public void handleEvent(MessageBoxEvent be) {
//IF NOT CANCELLED
String clickedButton = be.getButtonClicked().getItemId();
if(clickedButton.equals(Dialog.YES)){
multidrag.hide();
}
}
});
}
// GWT.log(targets.toString());
if(targets.size()>1 && multiDragContact.getSelectedAcl()!=null){
final List<String> logins = new ArrayList<String>(targets.size());
String names = "";
for (org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel infoContactModel : targets) {
GWT.log(infoContactModel.toString());
logins.add(infoContactModel.getLogin());
String name = infoContactModel.getName()!=null? infoContactModel.getName():infoContactModel.getLogin();
names+="<li><i>"+name +";</i></li>";
}
// GWT.log("names "+names);
String msg = "Setting permission '"+multiDragContact.getSelectedAcl().getLabel() +"' for: <ul>"+names+"</ul>, confirm?";
MessageBoxConfirm confirm = new MessageBoxConfirm("Setting new permissions to "+file.getName() +"?", msg);
confirm.getMessageBoxConfirm().addCallback(new Listener<MessageBoxEvent>() {
public void handleEvent(MessageBoxEvent be) {
//IF NOT CANCELLED
String clickedButton = be.getButtonClicked().getItemId();
if(clickedButton.equals(Dialog.YES)){
// doAddAdministratorToFolderId(file, logins);
setACLToFolderId(file.getIdentifier(), logins, multiDragContact.getSelectedAclID());
multidrag.hide();
}
if(clickedButton.equals(Dialog.CANCEL)){
multidrag.hide();
}
}
});
}
}
});
multidrag.show();
}
/**
*
* @param file
@ -2140,7 +2267,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
SimpleMultiDragConstants.SHARE_WITH_RIGHT_LIST = "New Administrator/s";
final SimpleMultiDragWorkspaceContact multiDragContact = new SimpleMultiDragWorkspaceContact(LOAD_CONTACTS_AS.ADMINISTRATOR, file.getIdentifier(), true, false, true);
final Dialog multidrag = multiDragContact.getMultiDragContact();
final Dialog multidrag = multiDragContact.getDialogMultiDragContact();
multidrag.getButtonById(Dialog.OK).addListener(Events.Select, new Listener<BaseEvent>() {
@ -2224,6 +2351,25 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
});
}
private void setACLToFolderId(final String folderId, final List<String> logins, String aclTypeID) {
rpcWorkspaceService.setACLs(folderId, logins, aclTypeID, new AsyncCallback<Void>() {
@Override
public void onFailure(Throwable caught) {
new MessageBoxAlert("Error", caught.getMessage(), null);
}
@Override
public void onSuccess(Void result) {
String msg = "Updating permissions completed successfully";
MessageBox.info("Operation completed", msg, null);
}
});
}
private void loadMyLogin(){
rpcWorkspaceService.getMyLogin(new AsyncCallback<UserBean>() {

View File

@ -83,7 +83,7 @@ public class ConstantsExplorer {
public static final String FORWARDTO = "Forward to";
public static final String MESSAGETYPE = "Message Type";
public static final String WEBDAVURLLINKREADMORE = "https://gcube.wiki.gcube-system.org/gcube/index.php/Acces_workspace_from_Desktop_(via_WebDAV)";
public static final String EDIT_PERMISSIONS = "Edit Permissions";
public static final String TITLEACCESSWEBDAV = "Access from Desktop";
public static final String ACCESSWEBDAVMSG = "Files and folders can be managed directly from the file explorer of your desktop operating system.";
@ -217,6 +217,4 @@ public class ConstantsExplorer {
//PROPERTY
public static final String SPECIALFOLDERNAME = "SPECIALFOLDERNAME";
public static final String SPECIALFOLDERNAMEPROPERTIESFILE = "specialfoldername.properties";
}

View File

@ -35,7 +35,8 @@ public enum WorkspaceOperation {
SHARE_LINK("SLK", "SLK"), //SHARE URL LINK
PUBLIC_LINK("PLK", "PLK"), //PUBLIC LINK
// ADD_ADMINISTRATOR("AAD", "AAD"), // ADD_ADMINISTRATOR
VRE_CHANGE_PERIMISSIONS("CHP", "CHP");
VRE_CHANGE_PERIMISSIONS("CHP", "CHP"),
EDIT_PERMISSIONS("EDP", "EDP"); //EDIT PERMISSIONS
private String id; // ID CONTEXT MENU

View File

@ -0,0 +1,40 @@
package org.gcube.portlets.user.workspace.client.event;
import org.gcube.portlets.user.workspace.client.model.FileModel;
import com.google.gwt.event.shared.GwtEvent;
/**
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* @May 23, 2013
*
*/
public class EditUserPermissionEvent extends
GwtEvent<EditUserPermissionEventHandler> {
public static Type<EditUserPermissionEventHandler> TYPE = new Type<EditUserPermissionEventHandler>();
private FileModel sourceFile;
public EditUserPermissionEvent(FileModel sourceFileModel) {
this.sourceFile= sourceFileModel;
}
@Override
public Type<EditUserPermissionEventHandler> getAssociatedType() {
return TYPE;
}
@Override
protected void dispatch(EditUserPermissionEventHandler handler) {
handler.onEditUserPermission(this);
}
public FileModel getSourceFolder() {
return sourceFile;
}
public void setSourceFolder(FileModel sourceFile) {
this.sourceFile = sourceFile;
}
}

View File

@ -0,0 +1,16 @@
package org.gcube.portlets.user.workspace.client.event;
import com.google.gwt.event.shared.EventHandler;
/**
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* @Jan 27, 2015
*
*/
public interface EditUserPermissionEventHandler extends EventHandler {
/**
* @param editUserPermissionEvent
*/
void onEditUserPermission(EditUserPermissionEvent editUserPermissionEvent);
}

View File

@ -369,5 +369,11 @@ public interface Icons extends ClientBundle {
*/
@Source("icons/recycle.png")
ImageResource recycle();
/**
* @return
*/
@Source("icons/edit-permissions.png")
ImageResource permissions();
}

View File

@ -528,6 +528,11 @@ public class Resources {
return AbstractImagePrototype.create(ICONS.selectedRight());
}
public static AbstractImagePrototype getIconPermissions() {
return AbstractImagePrototype.create(ICONS.permissions());
}
/**
* @return
*/
@ -575,6 +580,7 @@ public class Resources {
return ICONS.attach();
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 899 B

View File

@ -39,7 +39,7 @@ import com.google.gwt.user.client.ui.Label;
*/
public class DialogShareFolder extends Dialog {
private int widthDialog = 530;
private int widthDialog = 535;
private int heightTextArea = 100;
private TextField<String> txtName;
private TextArea textAreaDescription = new TextArea();
@ -263,7 +263,7 @@ public class DialogShareFolder extends Dialog {
setScrollMode(Scroll.AUTOY);
setBodyStyle("padding: 9px; background: none");
setWidth(widthDialog);
setHeight(397);
setHeight(400);
setResizable(true);
setButtonAlign(HorizontalAlignment.CENTER);
setWidth(widthDialog);

View File

@ -14,6 +14,7 @@ import org.gcube.portlets.user.workspace.client.event.CopytemEvent;
import org.gcube.portlets.user.workspace.client.event.CreateSharedFolderEvent;
import org.gcube.portlets.user.workspace.client.event.CreateUrlEvent;
import org.gcube.portlets.user.workspace.client.event.DeleteItemEvent;
import org.gcube.portlets.user.workspace.client.event.EditUserPermissionEvent;
import org.gcube.portlets.user.workspace.client.event.FileDownloadEvent;
import org.gcube.portlets.user.workspace.client.event.FileDownloadEvent.DownloadType;
import org.gcube.portlets.user.workspace.client.event.FileUploadEvent;
@ -291,6 +292,25 @@ public class ContextMenuTree {
}
});
contextMenu.add(createShareFolder);
MenuItem editPermissions = new MenuItem();
editPermissions.setId(WorkspaceOperation.EDIT_PERMISSIONS.getId());
editPermissions.setText(ConstantsExplorer.EDIT_PERMISSIONS);
editPermissions.setIcon(Resources.getIconPermissions());
editPermissions.addSelectionListener(new SelectionListener<MenuEvent>() {
public void componentSelected(MenuEvent ce) {
FileModel sourceFileModel = listSelectedItems.get(0);
if (sourceFileModel != null) {
eventBus.fireEvent(new EditUserPermissionEvent(sourceFileModel));
}
}
});
contextMenu.add(editPermissions);
//Add Url
@ -728,7 +748,7 @@ public class ContextMenuTree {
contextMenu.getItemByItemId(WorkspaceOperation.REFRESH_FOLDER.getId()).setVisible(false); //refresh
contextMenu.getItemByItemId(WorkspaceOperation.PUBLIC_LINK.getId()).setVisible(false); //public link
// contextMenu.getItemByItemId(WorkspaceOperation.ADD_ADMINISTRATOR.getId()).setVisible(false); //public link
contextMenu.getItemByItemId(WorkspaceOperation.EDIT_PERMISSIONS.getId()).setVisible(false);
contextMenu.getItemByItemId(WorkspaceOperation.SHARE.getId()).setVisible(false); //SHARE
contextMenu.getItemByItemId(WorkspaceOperation.UNSHARE.getId()).setVisible(false); //UNSHARE
@ -800,6 +820,8 @@ public class ContextMenuTree {
if(selectedItem.isShareable()){ //IS SHARABLE
contextMenu.getItemByItemId(WorkspaceOperation.INSERT_SHARED_FOLDER.getId()).setVisible(false); //insert shared folder
contextMenu.getItemByItemId(WorkspaceOperation.UNSHARE.getId()).setVisible(true);
}else { //IS SUBFOLDER
contextMenu.getItemByItemId(WorkspaceOperation.EDIT_PERMISSIONS.getId()).setVisible(true);
}
}else if(selectedItem.isRoot()){ //IS ROOT

View File

@ -992,7 +992,8 @@ public class GWTWorkspaceBuilder {
if(parentFolderModel!=null && parentFolderModel.isShared()){
fileModel.setShared(true);
fileModel.setShareable(false);
fileModel.setShareable(false); //UPDATED TO CHANGE PERMISSIONS TO SHARED SUBFOLDERS
// fileModel.setShareable(true);
}
// fileModel.setOwner(new InfoContactModel(item.getOwner().getId(), item.getOwner().getPortalLogin(), "name"));
@ -1147,7 +1148,8 @@ public class GWTWorkspaceBuilder {
if(parentFileModel!=null && parentFileModel.isShared()){
fileGridModel.setShared(true);
fileGridModel.setShareable(false);
fileGridModel.setShareable(false); //UPDATED TO CHANGE PERMISSIONS TO SHARED SUBFOLDERS
// fileGridModel.setShareable(true);
}
//OWNER

View File

@ -79,6 +79,7 @@ import org.gcube.portlets.user.workspace.shared.WorkspaceUserQuote;
import org.gcube.portlets.user.workspace.shared.accounting.GxtAccountingEntryType;
import org.gcube.portlets.user.workspace.shared.accounting.GxtAccountingField;
import org.gcube.portlets.user.workspaceapplicationhandler.ApplicationReaderFromGenericResource;
import org.gcube.portlets.widgets.workspacesharingwidget.server.GWTWorkspaceSharingBuilder;
import org.gcube.vomanagement.usermanagement.GroupManager;
import org.gcube.vomanagement.usermanagement.UserManager;
import org.gcube.vomanagement.usermanagement.impl.liferay.LiferayGroupManager;
@ -2278,6 +2279,12 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
workspaceLogger.trace("get Owner By ItemId "+ itemId);
try {
//TEST MODE
if(!isWithinPortal()){
workspaceLogger.info("is without portal returning Test User");
return new InfoContactModel("francesco.mangiacrapa", "francesco.mangiacrapa", "Francesco Mangiacrapa", false);
}
Workspace workspace = getWorkspace();
WorkspaceItem wsItem = workspace.getItem(itemId);
@ -2713,8 +2720,16 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
Workspace workspace = getWorkspace();
WorkspaceItem wsItem = workspace.getItem(folderId);
if(wsItem.isShared() && (wsItem.getType().equals(WorkspaceItemType.SHARED_FOLDER))){
WorkspaceSharedFolder ite = (WorkspaceSharedFolder) workspace.getItemByPath(wsItem.getPath());
if(wsItem!= null && wsItem.isFolder() && wsItem.isShared()){
WorkspaceSharedFolder ite;
if(wsItem.getType().equals(WorkspaceItemType.SHARED_FOLDER)){
//IS ROOT SHARED FOLDER
ite = (WorkspaceSharedFolder) workspace.getItemByPath(wsItem.getPath());
}else{
// IS SUB FOLDER OF THE SHARING
ite = (WorkspaceSharedFolder) workspace.getItem(wsItem.getIdSharedFolder());
}
ite.setACL(listLogins, ACLType.valueOf(aclType));
}else
throw new Exception("Source item is not shared or shared folder");