diff --git a/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/server/WorkspaceSharingServiceImpl.java b/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/server/WorkspaceSharingServiceImpl.java index 2163b20..db445ef 100644 --- a/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/server/WorkspaceSharingServiceImpl.java +++ b/src/main/java/org/gcube/portlets/widgets/workspacesharingwidget/server/WorkspaceSharingServiceImpl.java @@ -972,16 +972,68 @@ public class WorkspaceSharingServiceImpl extends RemoteServiceServlet implements if (folderItem instanceof SharedFolder) { logger.debug("Folder type: SharedFolder"); SharedFolder sharedFolder = (SharedFolder) folderItem; - folderContainer.unshare(sharedFolder.getUsers().getMap().keySet()); - unshared = true; - ArrayList listContacts = new ArrayList<>(); - for (String key : sharedFolder.getUsers().getMap().keySet()) { - InfoContactModel contact = new InfoContactModel(key, key, key, false); - listContacts.add(contact); - } - NotificationsProducer np = getNotificationProducer(this.getThreadLocalRequest()); - np.notifyFolderUnSharing(listContacts, folderItem); + List listACL = folderContainer.getAcls(); + logger.debug("List of ACL: " + listACL); + String currentUser = getMyLogin(); + logger.debug("Current User: " + currentUser); + if (listACL != null) { + ACL userACL = null; + for (ACL acl : listACL) { + if (currentUser.compareTo(acl.getPricipal()) == 0) { + userACL = acl; + break; + } + } + if (userACL != null) { + List listOfAccessType = userACL.getAccessTypes(); + if (listOfAccessType != null && !listOfAccessType.isEmpty()) { + boolean isAdmin = false; + for (AccessType accessType : listOfAccessType) { + if (accessType.compareTo(AccessType.ADMINISTRATOR) == 0) { + isAdmin = true; + break; + } + } + + Set users; + if (isAdmin) { + users = sharedFolder.getUsers().getMap().keySet(); + folderContainer.unshare(users); + logger.info("Unshared folded for users: " + users); + ArrayList listContacts = new ArrayList<>(); + for (String key : users) { + InfoContactModel contact = new InfoContactModel(key, key, key, false); + listContacts.add(contact); + } + NotificationsProducer np = getNotificationProducer( + this.getThreadLocalRequest()); + np.notifyFolderUnSharing(listContacts, folderItem); + } else { + users = new HashSet(); + users.add(currentUser); + folderContainer.unshare(users); + logger.info("Unshared folded for users: " + users); + + } + unshared = true; + + } else { + String msg = "Invalid AccessType permission on this folder for the user."; + logger.error(msg); + throw new Exception(msg); + } + } else { + String msg = "Invalid permission on this folder for the user."; + logger.error(msg); + throw new Exception(msg); + } + } else { + String msg = "Invalid ACL list for this forlder: null."; + logger.error(msg); + throw new Exception(msg); + + } } else { String msg = "The folder requested is not a root shared folder." + "To unshare this folder you have to unshare the root shared folder!";