Changed logic to get Folder Link (as Public folder)
The access is granted for owner or admin git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@135039 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
7c1bfb252c
commit
9a82befd32
|
@ -16,6 +16,7 @@ import org.gcube.portlets.user.workspace.client.model.ScopeModel;
|
|||
import org.gcube.portlets.user.workspace.client.model.SmartFolderModel;
|
||||
import org.gcube.portlets.user.workspace.client.model.SubTree;
|
||||
import org.gcube.portlets.user.workspace.client.workspace.GWTWorkspaceItem;
|
||||
import org.gcube.portlets.user.workspace.shared.AllowAccess;
|
||||
import org.gcube.portlets.user.workspace.shared.ExtendedWorkspaceACL;
|
||||
import org.gcube.portlets.user.workspace.shared.GarbageItem;
|
||||
import org.gcube.portlets.user.workspace.shared.PublicLink;
|
||||
|
@ -728,4 +729,13 @@ public interface GWTWorkspaceService extends RemoteService{
|
|||
* @throws Exception the exception
|
||||
*/
|
||||
PublicLink markFolderAsPublicForFolderItemId(String itemId, boolean b) throws SessionExpiredException, Exception;
|
||||
|
||||
|
||||
/**
|
||||
* Access to folder link.
|
||||
*
|
||||
* @param itemId the item id
|
||||
* @return the allow access
|
||||
*/
|
||||
AllowAccess accessToFolderLink(String itemId) throws SessionExpiredException, Exception;
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ import org.gcube.portlets.user.workspace.client.model.ScopeModel;
|
|||
import org.gcube.portlets.user.workspace.client.model.SmartFolderModel;
|
||||
import org.gcube.portlets.user.workspace.client.model.SubTree;
|
||||
import org.gcube.portlets.user.workspace.client.workspace.GWTWorkspaceItem;
|
||||
import org.gcube.portlets.user.workspace.shared.AllowAccess;
|
||||
import org.gcube.portlets.user.workspace.shared.ExtendedWorkspaceACL;
|
||||
import org.gcube.portlets.user.workspace.shared.GarbageItem;
|
||||
import org.gcube.portlets.user.workspace.shared.PublicLink;
|
||||
|
@ -355,6 +356,16 @@ public interface GWTWorkspaceServiceAsync {
|
|||
void getOwnerByItemId(String itemId,
|
||||
AsyncCallback<InfoContactModel> callback);
|
||||
|
||||
|
||||
/**
|
||||
* Access to folder link.
|
||||
*
|
||||
* @param itemId the item id
|
||||
* @param callback the callback
|
||||
*/
|
||||
void accessToFolderLink(String itemId,
|
||||
AsyncCallback<AllowAccess> callback);
|
||||
|
||||
/**
|
||||
* Item exists in workpace folder.
|
||||
*
|
||||
|
|
|
@ -4,8 +4,8 @@ import org.gcube.portlets.user.workspace.client.AppControllerExplorer;
|
|||
import org.gcube.portlets.user.workspace.client.event.RefreshFolderEvent;
|
||||
import org.gcube.portlets.user.workspace.client.event.SessionExpiredEvent;
|
||||
import org.gcube.portlets.user.workspace.client.model.FileModel;
|
||||
import org.gcube.portlets.user.workspace.client.model.InfoContactModel;
|
||||
import org.gcube.portlets.user.workspace.client.resources.Resources;
|
||||
import org.gcube.portlets.user.workspace.shared.AllowAccess;
|
||||
import org.gcube.portlets.user.workspace.shared.PublicLink;
|
||||
import org.gcube.portlets.user.workspace.shared.SessionExpiredException;
|
||||
|
||||
|
@ -139,10 +139,11 @@ public class DialogGetLink extends Dialog {
|
|||
setIcon(Resources.getIconFolderPublic());
|
||||
|
||||
if(item.getIdentifier()!=null && !item.getIdentifier().isEmpty()){
|
||||
AppControllerExplorer.rpcWorkspaceService.getOwnerByItemId(item.getIdentifier(), new AsyncCallback<InfoContactModel>() {
|
||||
AppControllerExplorer.rpcWorkspaceService.accessToFolderLink(item.getIdentifier(), new AsyncCallback<AllowAccess>() {
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable caught) {
|
||||
|
||||
vp.unmask();
|
||||
if(caught instanceof SessionExpiredException){
|
||||
GWT.log("Session expired");
|
||||
|
@ -154,15 +155,16 @@ public class DialogGetLink extends Dialog {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(InfoContactModel result) {
|
||||
public void onSuccess(AllowAccess result) {
|
||||
GWT.log("AllowAccess? "+result);
|
||||
vp.unmask();
|
||||
if(result.getLogin().compareToIgnoreCase(AppControllerExplorer.myLogin)==0){
|
||||
if(result.getAccessGranted()){
|
||||
String msg = DialogGetLink.this.setAsPublic?"Getting":"Removing";
|
||||
msg=msg+" Folder Link... permissions granted";
|
||||
vp.mask(msg);
|
||||
allowAccessToFolderLink(item.getIdentifier(), DialogGetLink.this.setAsPublic);
|
||||
}else
|
||||
new MessageBoxAlert("Permission Denied", "You have not permission to get Folder Link, you must be owner or administrator to the folder", null);
|
||||
new MessageBoxAlert("Permission Denied", result.getAccessAllowDenyMotivation(), null);
|
||||
|
||||
}
|
||||
});
|
||||
|
|
|
@ -74,6 +74,7 @@ import org.gcube.portlets.user.workspace.server.util.UserUtil;
|
|||
import org.gcube.portlets.user.workspace.server.util.WsUtil;
|
||||
import org.gcube.portlets.user.workspace.server.util.resource.PropertySpecialFolderReader;
|
||||
import org.gcube.portlets.user.workspace.server.util.scope.ScopeUtilFilter;
|
||||
import org.gcube.portlets.user.workspace.shared.AllowAccess;
|
||||
import org.gcube.portlets.user.workspace.shared.ExtendedWorkspaceACL;
|
||||
import org.gcube.portlets.user.workspace.shared.GarbageItem;
|
||||
import org.gcube.portlets.user.workspace.shared.PublicLink;
|
||||
|
@ -1995,10 +1996,10 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
|
|||
try {
|
||||
|
||||
//TEST MODE
|
||||
if(!isWithinPortal()){
|
||||
/*if(!isWithinPortal()){
|
||||
workspaceLogger.info("getOwnerByItemId is in test mode returning owner francesco.mangiacrapa");
|
||||
return new InfoContactModel("francesco.mangiacrapa", "francesco.mangiacrapa", "Francesco Mangiacrapa", false);
|
||||
}
|
||||
}*/
|
||||
|
||||
Workspace workspace = getWorkspace();
|
||||
WorkspaceItem wsItem = workspace.getItem(itemId);
|
||||
|
@ -3595,4 +3596,48 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
|
|||
workspaceLogger.debug("getServletContextPath=" + url.toString());
|
||||
return url.toString();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.gcube.portlets.user.workspace.client.rpc.GWTWorkspaceService#accessToFolderLink(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public AllowAccess accessToFolderLink(String itemId) throws SessionExpiredException, Exception {
|
||||
workspaceLogger.info("Access to Folder Link "+itemId+" working... ");
|
||||
try {
|
||||
Workspace workspace = getWorkspace();
|
||||
WorkspaceItem item = workspace.getItem(itemId);
|
||||
if(item instanceof WorkspaceFolder){
|
||||
WorkspaceFolder folder = (WorkspaceFolder) item;
|
||||
InfoContactModel owner = getOwnerByItemId(itemId);
|
||||
PortalContextInfo context = WsUtil.getPortalContext(this.getThreadLocalRequest());
|
||||
workspaceLogger.info("owner of: "+folder.getName() +" is: "+owner);
|
||||
workspaceLogger.info("current context user: "+context.getUsername());
|
||||
if(owner.getLogin().compareToIgnoreCase(context.getUsername())==0){
|
||||
workspaceLogger.info("Access to Folder Link "+folder.getName()+" granted, "+context.getUsername() +" is the owner of: "+itemId);
|
||||
return new AllowAccess(itemId, true, context.getUserFullName() +" is the owner of: "+folder.getName(),null);
|
||||
}
|
||||
|
||||
try{
|
||||
List<InfoContactModel> admins = getAdministratorsByFolderId(itemId);
|
||||
for (InfoContactModel infoContactModel : admins) {
|
||||
if(infoContactModel.getLogin().compareToIgnoreCase(context.getUsername())==0){
|
||||
workspaceLogger.info("Access to Folder Link "+folder.getName()+" granted, "+context.getUsername() +" is the admin of: "+itemId);
|
||||
return new AllowAccess(itemId, true, context.getUserFullName() +" is the admin of: "+folder.getName(),null);
|
||||
}
|
||||
}
|
||||
}catch (Exception e){
|
||||
return new AllowAccess(itemId, false, "You have not permission to get Folder Link, you must be owner or administrator to the folder", e.getMessage());
|
||||
}
|
||||
|
||||
return new AllowAccess(itemId, false, "You have not permission to get Folder Link, you must be owner or administrator to the folder", null);
|
||||
}
|
||||
|
||||
return new AllowAccess(itemId, false, "The item is not a folder", null);
|
||||
|
||||
} catch (Exception e) {
|
||||
workspaceLogger.error("Error in server FormattedGcubeItemProperties: ", e);
|
||||
String error = ConstantsExplorer.SERVER_ERROR +" when reading access policy to Folder Link: "+itemId+", Refresh and try again";
|
||||
throw new Exception(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,147 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.portlets.user.workspace.shared;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||
* Nov 29, 2016
|
||||
*/
|
||||
public class AllowAccess implements Serializable{
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -2180345568585856822L;
|
||||
|
||||
private String itemId;
|
||||
private Boolean accessGranted = false;
|
||||
private String accessAllowDenyMotivation;
|
||||
private String error;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public AllowAccess() {
|
||||
}
|
||||
|
||||
public AllowAccess(String itemId){
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param itemId
|
||||
* @param accessGranted
|
||||
* @param accessAllowDenyMotivation
|
||||
* @param error
|
||||
*/
|
||||
public AllowAccess(
|
||||
String itemId, Boolean accessGranted, String accessAllowDenyMotivation,
|
||||
String error) {
|
||||
|
||||
super();
|
||||
this.itemId = itemId;
|
||||
this.accessGranted = accessGranted;
|
||||
this.accessAllowDenyMotivation = accessAllowDenyMotivation;
|
||||
this.error = error;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the itemId
|
||||
*/
|
||||
public String getItemId() {
|
||||
|
||||
return itemId;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the accessGranted
|
||||
*/
|
||||
public Boolean getAccessGranted() {
|
||||
|
||||
return accessGranted;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the accessAllowDenyMotivation
|
||||
*/
|
||||
public String getAccessAllowDenyMotivation() {
|
||||
|
||||
return accessAllowDenyMotivation;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the error
|
||||
*/
|
||||
public String getError() {
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param itemId the itemId to set
|
||||
*/
|
||||
public void setItemId(String itemId) {
|
||||
|
||||
this.itemId = itemId;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param accessGranted the accessGranted to set
|
||||
*/
|
||||
public void setAccessGranted(Boolean accessGranted) {
|
||||
|
||||
this.accessGranted = accessGranted;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param accessAllowDenyMotivation the accessAllowDenyMotivation to set
|
||||
*/
|
||||
public void setAccessAllowDenyMotivation(String accessAllowDenyMotivation) {
|
||||
|
||||
this.accessAllowDenyMotivation = accessAllowDenyMotivation;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param error the error to set
|
||||
*/
|
||||
public void setError(String error) {
|
||||
|
||||
this.error = error;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("AllowAccess [itemId=");
|
||||
builder.append(itemId);
|
||||
builder.append(", accessGranted=");
|
||||
builder.append(accessGranted);
|
||||
builder.append(", accessAllowDenyMotivation=");
|
||||
builder.append(accessAllowDenyMotivation);
|
||||
builder.append(", error=");
|
||||
builder.append(error);
|
||||
builder.append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue