From 64952442ed57b58c034a1dddfca940ae1a5a426a Mon Sep 17 00:00:00 2001 From: "lucio.lelii" Date: Tue, 16 Mar 2021 15:37:18 +0100 Subject: [PATCH] unshareAll fixed --- .../storagehub/handlers/UnshareHandler.java | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/gcube/data/access/storagehub/handlers/UnshareHandler.java b/src/main/java/org/gcube/data/access/storagehub/handlers/UnshareHandler.java index ec96711..70933c6 100644 --- a/src/main/java/org/gcube/data/access/storagehub/handlers/UnshareHandler.java +++ b/src/main/java/org/gcube/data/access/storagehub/handlers/UnshareHandler.java @@ -66,20 +66,22 @@ public class UnshareHandler { public String _unshare(Session ses, Set users, Node sharedNode, String login, boolean withCopyOnUnshare) throws RepositoryException, StorageHubException{ Item item = node2Item.getItem(sharedNode, Excludes.ALL); - if (!(item instanceof FolderItem) || !((FolderItem) item).isShared() || ((SharedFolder) item).isVreFolder()) + if (!(item instanceof FolderItem) || !((FolderItem) item).isShared() || ((SharedFolder) item).isVreFolder()) { + log.warn("this item type cannot be unshared {}",item.getClass().getSimpleName()); return null; + } SharedFolder sharedItem =(SharedFolder) item; Set usersInSharedFolder = new HashSet<>(sharedItem.getUsers().getMap().keySet()); usersInSharedFolder.removeAll(users); if (users==null || users.size()==0) - return unshareAll(login, ses, sharedItem, false); + return unshareAll(login, ses, sharedItem, withCopyOnUnshare); if (usersInSharedFolder.size()<=1) { if (users.size()==1 && users.contains(login)) - return unshareAll(sharedItem.getOwner(), ses , sharedItem, false); - else return unshareAll(login, ses, sharedItem, false); + return unshareAll(sharedItem.getOwner(), ses , sharedItem, withCopyOnUnshare); + else return unshareAll(login, ses, sharedItem, withCopyOnUnshare); } try { @@ -168,25 +170,24 @@ public class UnshareHandler { accountingHandler.createUnshareFolder(sharedItemNode.getProperty(NodeProperty.TITLE.toString()).getString(), "ALL", ses, unsharedNode, false); unsharedNodeIdentifier = unsharedNode.getIdentifier(); - + log.info("[UNSHARE] unshared node id {}",unsharedNodeIdentifier); ses.save(); } - - sharedItemNode.removeSharedSet(); - ses.save(); - + log.debug("all the users have been removed, the folder is totally unshared"); - }catch(Throwable t) { log.error("erro unsharing all",t); throw t; }finally { ses.getWorkspace().getLockManager().unlock(sharedItemNode.getPath()); } + + sharedItemNode.removeSharedSet(); + ses.save(); + return unsharedNodeIdentifier; - } @@ -247,9 +248,7 @@ public class UnshareHandler { } - - - + private String unsharePartial(Set usersToUnshare, String login, Session ses, SharedFolder item) throws StorageHubException, RepositoryException { log.info("unshare partial"); authChecker.checkAdministratorControl(ses, (SharedFolder)item);