From 24576cd30f0d180755ff496416de8a1379ed47af Mon Sep 17 00:00:00 2001 From: "lucio.lelii" Date: Fri, 10 Sep 2021 10:59:07 +0200 Subject: [PATCH] solved bug on messages attachments --- CHANGELOG.md | 4 ++++ pom.xml | 2 +- .../data/access/storagehub/AuthorizationChecker.java | 9 ++++++++- .../access/storagehub/services/MessageManager.java | 12 ++++++------ .../storage/backend/impl/GCubeStorageBackend.java | 3 ++- src/main/webapp/WEB-INF/README | 2 +- src/main/webapp/WEB-INF/gcube-app.xml | 2 +- 7 files changed, 23 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e25b7cf..1d8b74a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [v1.3.1] - [2021-09-08] + +- solved bug on attachment rights + ## [v1.3.0] - [2021-03-31] - possibility to impersonate people added diff --git a/pom.xml b/pom.xml index 8546ba6..bd0fb1f 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ 4.0.0 org.gcube.data.access storagehub - 1.3.0 + 1.3.1 storagehub diff --git a/src/main/java/org/gcube/data/access/storagehub/AuthorizationChecker.java b/src/main/java/org/gcube/data/access/storagehub/AuthorizationChecker.java index abb690e..bf95023 100644 --- a/src/main/java/org/gcube/data/access/storagehub/AuthorizationChecker.java +++ b/src/main/java/org/gcube/data/access/storagehub/AuthorizationChecker.java @@ -64,6 +64,12 @@ public class AuthorizationChecker { if (hasParentPublicFolder(session, item)) return; + //TODO: remove when messages will be passed to a new system + String parentPath = item.getParentPath(); + if (parentPath.endsWith("hl:attachments") && (parentPath.contains("/OutBox/") || parentPath.contains("/InBox/"))) { + return ; + } + if (item.isShared()) { //SharedFolder parentShared = node2Item.getItem(retrieveSharedFolderParent(node, session), Excludes.EXCLUDE_ACCOUNTING); //if (parentShared.getUsers().getMap().keySet().contains(userToCheck)) return; @@ -88,13 +94,14 @@ public class AuthorizationChecker { } } } - + throw new UserNotAuthorizedException("Insufficent Privileges for user "+userToCheck+" to read node with id "+id); } private boolean hasParentPublicFolder(Session session, Item item) { + if(item==null || item.getParentPath()==null) return false; if (item.getParentPath().replaceAll("/Home/[^/]*/"+Constants.WORKSPACE_ROOT_FOLDER_NAME,"").isEmpty() || item.getParentPath().replaceAll(Constants.SHARED_FOLDER_PATH, "").isEmpty()) { if (item instanceof FolderItem) return ((FolderItem) item).isPublicItem(); diff --git a/src/main/java/org/gcube/data/access/storagehub/services/MessageManager.java b/src/main/java/org/gcube/data/access/storagehub/services/MessageManager.java index a8614e1..b101740 100644 --- a/src/main/java/org/gcube/data/access/storagehub/services/MessageManager.java +++ b/src/main/java/org/gcube/data/access/storagehub/services/MessageManager.java @@ -10,7 +10,6 @@ import javax.inject.Inject; import javax.jcr.ItemNotFoundException; import javax.jcr.Node; import javax.jcr.NodeIterator; -import javax.jcr.PathNotFoundException; import javax.jcr.RepositoryException; import javax.jcr.Session; import javax.servlet.ServletContext; @@ -392,12 +391,13 @@ public class MessageManager extends Impersonable{ String newPath= String.format("%s/%s", destination.getPath(), uniqueName); session.getWorkspace().copy(nodeToCopy.getPath(), newPath); Node newNode = session.getNode(newPath); - + if (itemToCopy instanceof AbstractFileItem) { - ((AbstractFileItem) itemToCopy).getContent().setRemotePath(newPath); - String newStorageID = folderPluginHandler.getDefault().getStorageBackend().onCopy((AbstractFileItem) itemToCopy); - ((AbstractFileItem) itemToCopy).getContent().setStorageId(newStorageID); - item2Node.replaceContent(newNode, (AbstractFileItem) itemToCopy, ItemAction.CLONED); + AbstractFileItem newNodeItem = node2Item.getItem(newNode, Excludes.EXCLUDE_ACCOUNTING); + newNodeItem.getContent().setRemotePath(newPath); + String newStorageID = folderPluginHandler.getDefault().getStorageBackend().onCopy(newNodeItem); + newNodeItem.getContent().setStorageId(newStorageID); + item2Node.replaceContent(newNode, newNodeItem, ItemAction.CLONED); } Utils.setPropertyOnChangeNode(newNode, currentUser, ItemAction.CLONED); diff --git a/src/main/java/org/gcube/data/access/storagehub/storage/backend/impl/GCubeStorageBackend.java b/src/main/java/org/gcube/data/access/storagehub/storage/backend/impl/GCubeStorageBackend.java index 7764309..e50148e 100644 --- a/src/main/java/org/gcube/data/access/storagehub/storage/backend/impl/GCubeStorageBackend.java +++ b/src/main/java/org/gcube/data/access/storagehub/storage/backend/impl/GCubeStorageBackend.java @@ -38,8 +38,9 @@ public class GCubeStorageBackend implements StorageBackend { @Override public String onCopy(AbstractFileItem item) { + log.info("copying storage Id {} to newPath {}", item.getContent().getStorageId(), item.getPath()); String newStorageID = getStorageClient(AuthorizationProvider.instance.get().getClient().getId()).getClient().copyFile(true).from(item.getContent().getStorageId()).to(item.getPath()); - log.info("copying storage Id {} to newPath {} and the id returned by storage is {}", item.getContent().getStorageId(), item.getPath(), newStorageID); + log.info("The id returned by storage is {}", newStorageID); return newStorageID; } diff --git a/src/main/webapp/WEB-INF/README b/src/main/webapp/WEB-INF/README index 67dfd58..15122bb 100644 --- a/src/main/webapp/WEB-INF/README +++ b/src/main/webapp/WEB-INF/README @@ -25,7 +25,7 @@ The projects leading to this software have received funding from a series of Version -------------------------------------------------- -1.3.0-SNAPSHOT (20210504-102919) +1.3.1 (20210910-085653) Please see the file named "changelog.xml" in this directory for the release notes. diff --git a/src/main/webapp/WEB-INF/gcube-app.xml b/src/main/webapp/WEB-INF/gcube-app.xml index 52098e5..04f2d74 100644 --- a/src/main/webapp/WEB-INF/gcube-app.xml +++ b/src/main/webapp/WEB-INF/gcube-app.xml @@ -1,7 +1,7 @@ StorageHub DataAccess - 1.3.0-SNAPSHOT + 1.3.1 Storage Hub webapp \ No newline at end of file