diff --git a/src/main/java/org/gcube/portlets/widgets/wsexplorer/server/stohub/StorageHubServiceUtil.java b/src/main/java/org/gcube/portlets/widgets/wsexplorer/server/stohub/StorageHubServiceUtil.java index f744dd7..de46c97 100644 --- a/src/main/java/org/gcube/portlets/widgets/wsexplorer/server/stohub/StorageHubServiceUtil.java +++ b/src/main/java/org/gcube/portlets/widgets/wsexplorer/server/stohub/StorageHubServiceUtil.java @@ -12,6 +12,8 @@ import org.gcube.common.storagehub.client.proxies.ItemManagerClient; import org.gcube.common.storagehub.client.proxies.WorkspaceManagerClient; import org.gcube.common.storagehub.model.acls.ACL; import org.gcube.common.storagehub.model.items.Item; +import org.gcube.common.storagehub.model.items.SharedFolder; +import org.gcube.common.storagehub.model.items.VreFolder; import com.liferay.portal.kernel.log.Log; import com.liferay.portal.kernel.log.LogFactoryUtil; @@ -32,7 +34,7 @@ public class StorageHubServiceUtil { Item itemRoot = client.getWorkspace(ACCOUNTING_HL_NODE_NAME); return itemRoot; } - + public static Item getItem(HttpServletRequest request, String itemId) { PortalContext pContext = PortalContext.getConfiguration(); String userName = pContext.getCurrentUser(request).getUsername(); @@ -44,7 +46,7 @@ public class StorageHubServiceUtil { Item toReturn = client.get(itemId, ACCOUNTING_HL_NODE_NAME); return toReturn; } - + public static List getParents(HttpServletRequest request, String itemId) { PortalContext pContext = PortalContext.getConfiguration(); String userName = pContext.getCurrentUser(request).getUsername(); @@ -56,7 +58,7 @@ public class StorageHubServiceUtil { List toReturn = client.getAnchestors(itemId, ACCOUNTING_HL_NODE_NAME); return toReturn; } - + /** * * @param request @@ -84,8 +86,8 @@ public class StorageHubServiceUtil { } return toReturn; } - - + + public static String getUserACLForFolderId(HttpServletRequest request, String folderId) { PortalContext pContext = PortalContext.getConfiguration(); String userName = pContext.getCurrentUser(request).getUsername(); @@ -93,22 +95,34 @@ public class StorageHubServiceUtil { String authorizationToken = pContext.getCurrentUserToken(scope, userName); ScopeProvider.instance.set(scope); SecurityTokenProvider.instance.set(authorizationToken); - + Item theFolder = getItem(request, folderId); if (!theFolder.isShared()) { return "OWNER"; } else { ItemManagerClient client = AbstractPlugin.item().build(); List acls = client.getACL(folderId); + SharedFolder sharedFolder = (SharedFolder) theFolder; + + boolean found = false; //this is needed because in case o VRE Foder the permission is assigned ot the group and not to the user. for (ACL acl : acls) { - if (acl.getPricipal().compareTo(userName) == 0) - return acl.getAccessTypes().toString(); + System.out.println("ACL: "+acl.getPricipal().toString() + " types: "+ acl.getAccessTypes().toString()); + if (acl.getPricipal().compareTo(userName) == 0) { + found = true; + return acl.getAccessTypes().get(0).toString(); + } + } + if (!found && sharedFolder.isVreFolder()) { + for (ACL acl : acls) { + if (acl.getPricipal().startsWith(pContext.getInfrastructureName())) + return acl.getAccessTypes().get(0).toString(); + } } } - return "NO PERMISSIONS"; + return "UNDEFINED"; } - + /** * */