enhancements on Edit Permissions

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/widgets/workspace-sharing-widget@111512 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2015-01-28 16:41:11 +00:00
parent 91ece7a092
commit f401fc5d63
8 changed files with 201 additions and 12 deletions

View File

@ -8,14 +8,18 @@ import java.util.List;
import org.gcube.portlets.widgets.workspacesharingwidget.client.permissions.MessageBoxAlert;
import org.gcube.portlets.widgets.workspacesharingwidget.client.permissions.PanelTogglePermission;
import org.gcube.portlets.widgets.workspacesharingwidget.client.view.sharing.multisuggest.DialogMultiDragContact;
import org.gcube.portlets.widgets.workspacesharingwidget.client.view.sharing.multisuggest.MultiDragContact;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel;
import org.gcube.portlets.widgets.workspacesharingwidget.shared.WorkspaceACL;
import com.extjs.gxt.ui.client.Style.Scroll;
import com.extjs.gxt.ui.client.event.BaseEvent;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.widget.Dialog;
import com.extjs.gxt.ui.client.widget.HorizontalPanel;
import com.extjs.gxt.ui.client.widget.Html;
import com.extjs.gxt.ui.client.widget.form.TextArea;
import com.google.gwt.core.shared.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
@ -33,6 +37,7 @@ public class MultiDragContactsEditPermissions extends SimpleMultiDragWorkspaceCo
private PanelTogglePermission permission;
private HorizontalPanel hpPermission = new HorizontalPanel();
private DialogMultiDragContact dialog;
private Html htmlCurrentPermissions = new Html();
/**
* @param load
* @param workspaceItemId
@ -44,9 +49,32 @@ public class MultiDragContactsEditPermissions extends SimpleMultiDragWorkspaceCo
super(load, workspaceItemId, readGroupsFromHL, readGroupsFromPortal,hiddenMySelf);
dialog = super.getDialogMultiDragContact();
dialog.setScrollMode(Scroll.AUTOY);
// htmlCurrentPermissions.setReadOnly(true);
htmlCurrentPermissions.setWidth(MultiDragContact.WIDTH_CP);
htmlCurrentPermissions.setStyleAttribute("padding", MultiDragContact.PADDING+"px");
dialog.getLcTop().add(htmlCurrentPermissions);
// dialog.setHeight(dialog.getHeight()+100);
WorkspaceSharingController.rpcWorkspaceSharingService.getACLsDescriptionForSharedFolderId(workspaceItemId, new AsyncCallback<String>() {
@Override
public void onFailure(Throwable caught) {
// TODO Auto-generated method stub
}
@Override
public void onSuccess(String result) {
String msg = "#<b>Current Permissions:</b> <br/>";
msg+=result;
htmlCurrentPermissions.setHtml(msg);
}
});
enableSubmit(false);
// hpPermission.setStyleAttribute("margin-top", "20px");
hpPermission.setStyleAttribute("margin-left", "165px");
@ -62,7 +90,7 @@ public class MultiDragContactsEditPermissions extends SimpleMultiDragWorkspaceCo
permission = new PanelTogglePermission(result);
hpPermission.add(permission);
hpPermission.layout();
selectAclForFolder(workspaceItemId);
// selectAclForFolder(workspaceItemId);
enableSubmit(true);
// dialog.unmask();
@ -81,7 +109,7 @@ public class MultiDragContactsEditPermissions extends SimpleMultiDragWorkspaceCo
@Override
public void handleEvent(BaseEvent be) {
dialog.setHeight(dialog.getHeight()+50);
dialog.setHeight(dialog.getHeight()+100);
}
});
}

View File

@ -80,4 +80,12 @@ public interface WorkspaceSharingService extends RemoteService {
WorkspaceACL getACLForSharedItemId(String itemID) throws Exception;
/**
* @param folderId
* @return
* @throws Exception
*/
String getACLsDescriptionForSharedFolderId(String folderId)
throws Exception;
}

View File

@ -84,4 +84,8 @@ public interface WorkspaceSharingServiceAsync
AsyncCallback<WorkspaceACL> asyncCallback);
void getACLsDescriptionForSharedFolderId(String folderId,
AsyncCallback<String> callback);
}

View File

@ -14,6 +14,7 @@ import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.MessageBoxEvent;
import com.extjs.gxt.ui.client.event.SelectionListener;
import com.extjs.gxt.ui.client.widget.Dialog;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
@ -38,6 +39,9 @@ public class DialogMultiDragContact extends Dialog{
private ToolBar toolBar;
private String headTitle;
private boolean visibleTextArea;
private LayoutContainer lcTop = new LayoutContainer();
private LayoutContainer lcMiddle = new LayoutContainer();
private LayoutContainer lcBottom = new LayoutContainer();
/**
*
* @param headTitle
@ -52,7 +56,7 @@ public class DialogMultiDragContact extends Dialog{
this.visibleTextArea = visibleAlreadyShared;
init();
setHeadTitle(headTitle);
add(multiDragContact);
// add(multiDragContact);
}
/**
@ -65,7 +69,7 @@ public class DialogMultiDragContact extends Dialog{
this.hideOnPressOkButton = hideOnPressOk;
this.visibleTextArea = visibleAlreadyShared;
init();
add(multiDragContact);
// add(multiDragContact);
}
public void setHeadTitle(String headTitle){
@ -163,6 +167,11 @@ public class DialogMultiDragContact extends Dialog{
}
});
lcMiddle.add(multiDragContact);
add(lcTop);
add(lcMiddle);
add(lcBottom);
}
/**
@ -200,4 +209,16 @@ public class DialogMultiDragContact extends Dialog{
this.toolBar = toolBar;
}
public LayoutContainer getLcTop() {
return lcTop;
}
public LayoutContainer getLcMiddle() {
return lcMiddle;
}
public LayoutContainer getLcBottom() {
return lcBottom;
}
}

View File

@ -52,9 +52,11 @@ public class MultiDragContact extends ContentPanel {
private static final String ALL_CONTACTS = "All Contacts";
private static final String SHARE_WITH = "Share with...";
private static final int WIDTH_CP = 597;
public static final int WIDTH_CP = 597;
// private static final int HEIGHT_DIALOG = 542;
private static final int HEIGHT_GRID = 310;
public static final int HEIGHT_GRID = 310;
public static final int PADDING = 5;
private GridDropTarget dropSource;
private GridDropTarget dropTarget;
@ -96,7 +98,7 @@ public class MultiDragContact extends ContentPanel {
this.setBorders(false);
// setStyleAttribute("margin", "10px");
setBodyStyle("padding: 5px; background: none");
setBodyStyle("padding: "+PADDING+"px; background: none");
// SORTING STORE
setGropUserStoreSorter(storeSource);
setGropUserStoreSorter(storeTarget);

View File

@ -6,6 +6,7 @@ package org.gcube.portlets.widgets.workspacesharingwidget.server;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.gcube.common.homelibrary.home.User;
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
@ -494,5 +495,36 @@ public class GWTWorkspaceSharingBuilder {
return acls;
}
/**
* @param aclOwner
* @return
*/
public String getFormattedHtmlACLFromACLs(Map<ACLType, List<String>> aclOwner) {
String html = "<div style=\"width: 100%; text-align:left; font-size: 10px;\">";
logger.trace("Formatting "+aclOwner.size() +" ACL/s");
for (ACLType type : aclOwner.keySet()) {
List<String> listLogins = aclOwner.get(type);
html+="<span style=\"font-weight:bold; padding-top: 5px;\">"+type+": </span>";
html+="<span style=\"font-weight:normal;\">";
for (String login : listLogins) {
logger.trace("Adding login "+login);
String fullName = UserUtil.getUserFullName(login);
if(fullName!=null && !fullName.isEmpty())
html+=fullName+"; ";
else
html+=login+"; ";
}
html+="</span><br/>";
}
html+="</div>";
return html;
}
}

View File

@ -24,7 +24,6 @@ import org.gcube.common.portal.PortalContext;
import org.gcube.portlets.widgets.workspacesharingwidget.client.ConstantsSharing;
import org.gcube.portlets.widgets.workspacesharingwidget.client.rpc.WorkspaceSharingService;
import org.gcube.portlets.widgets.workspacesharingwidget.server.notifications.NotificationsProducer;
import org.gcube.portlets.widgets.workspacesharingwidget.server.notifications.NotificationsUtil;
import org.gcube.portlets.widgets.workspacesharingwidget.server.util.ScopeUtility;
import org.gcube.portlets.widgets.workspacesharingwidget.server.util.UserUtil;
import org.gcube.portlets.widgets.workspacesharingwidget.server.util.WsUtil;
@ -181,7 +180,8 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
WorkspaceItem wsItem = workspace.getItem(folderSharedId);
if(NotificationsUtil.isASharedFolder(wsItem)){
//TODO CHANGE TO READ ACL FROM SHARED SUBFOLDER
if(isASharedFolder(wsItem, true)){
WorkspaceSharedFolder wsFolder = (WorkspaceSharedFolder) wsItem;
@ -595,9 +595,10 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
Workspace workspace = getWorkspace();
WorkspaceItem item = workspace.getItem(itemID);
item.getIdSharedFolder();
if(item!=null && item.isFolder() && item.isShared()){ //IS A SHARED FOLDER
if(isASharedFolder(item, false)){ //IS A SHARED FOLDER
//TODO REMOVE PARENT SHARED FOLDER
WorkspaceSharedFolder parentSharedFolder = (WorkspaceSharedFolder) workspace.getItem(item.getIdSharedFolder());
GWTWorkspaceSharingBuilder builder = getGWTWorkspaceBuilder();
@ -621,4 +622,97 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements
throw new Exception(error);
}
}
/**
*
* @return Formatted HTML DIV containing ACLs description for folderId
* @throws Exception
*/
@Override
public String getACLsDescriptionForSharedFolderId(String folderId) throws Exception{
try {
WorkspaceSharedFolder wsFolder = getSharedFolderForId(folderId);
GWTWorkspaceSharingBuilder builder = getGWTWorkspaceBuilder();
return builder.getFormattedHtmlACLFromACLs(wsFolder.getACLOwner());
} catch (Exception e) {
logger.error("Error in server get getACLForFolderId", e);
String error = "Sorry an error occurred when getting ACL rules for selected folder. "+e.getMessage();
throw new Exception(error);
}
}
private WorkspaceSharedFolder getSharedFolderForId(String folderId) throws Exception{
if(folderId == null)
throw new Exception("Folder id is null");
logger.trace("Get ACLsDescriptionForFolderId folder id: "+folderId);
Workspace workspace = getWorkspace();
WorkspaceItem wsItem = workspace.getItem(folderId);
if(isASharedFolder(wsItem, false)){
logger.trace("Get SharedFolderForId: folder id "+folderId+" is shared");
//TODO REMOVE wsItem.getIdSharedFolder()
WorkspaceSharedFolder wsFolder = (WorkspaceSharedFolder) workspace.getItem(wsItem.getIdSharedFolder());
if(wsFolder!=null){
logger.trace("Get ACLsDescriptionForFolderId shared folder name is: "+wsFolder.getName());
return wsFolder;
//TODO USE THIS
// return (WorkspaceFolder) wsItem;
}else{
logger.trace("Source item is not a shared folder, throw exception");
throw new Exception("Source item is not a shared folder");
}
}else{
logger.trace("Source item is null or not shared, throw exception");
throw new Exception("Source item is null or not shared");
}
}
/**
*
* @param itemID
* @param asRoot true check if itemID is root, not otherwise
* @return
*/
public boolean isASharedFolder(String itemID, boolean asRoot){
try {
if(itemID==null)
throw new Exception("ItemId is null");
Workspace workspace = getWorkspace();
WorkspaceItem item = workspace.getItem(itemID);
return isASharedFolder(item, asRoot);
}catch(Exception e){
logger.error("Error in server isASharedFolder", e);
return false;
}
}
public boolean isASharedFolder(WorkspaceItem item, boolean asRoot){
try {
if(item!=null && item.isFolder() && item.isShared()){ //IS A SHARED SUB-FOLDER
if(asRoot)
return item.getType().equals(WorkspaceItemType.SHARED_FOLDER); //IS ROOT?
return true;
}
return false;
}catch(Exception e){
logger.error("Error in server isASharedFolder", e);
return false;
}
}
}

View File

@ -35,7 +35,7 @@ public class UserUtil {
return "";
logger.info("Get user full name for: "+portalLogin);
logger.info("Into portal: "+!WsUtil.isWithinPortal());
logger.info("Into portal: "+WsUtil.isWithinPortal());
if ((portalLogin.compareTo(WsUtil.TEST_USER) != 0) && (WsUtil.isWithinPortal())) { //skip test.user
UserModel curr = null;