From 142f99b2a2b0174016d2fc24ee5170cbc83a9e30 Mon Sep 17 00:00:00 2001 From: Aleksandra Onych Date: Mon, 25 Oct 2021 10:28:36 +0200 Subject: [PATCH] MNT-21883 - Fix unshare content from smart folder (#765) --- .../quickshare/UnshareContentDelete.java | 75 +++++++++++-------- .../rest/api/impl/QuickShareLinksImpl.java | 24 ++++-- 2 files changed, 61 insertions(+), 38 deletions(-) diff --git a/remote-api/src/main/java/org/alfresco/repo/web/scripts/quickshare/UnshareContentDelete.java b/remote-api/src/main/java/org/alfresco/repo/web/scripts/quickshare/UnshareContentDelete.java index d33a411943..9b9c057a7a 100644 --- a/remote-api/src/main/java/org/alfresco/repo/web/scripts/quickshare/UnshareContentDelete.java +++ b/remote-api/src/main/java/org/alfresco/repo/web/scripts/quickshare/UnshareContentDelete.java @@ -1,28 +1,28 @@ -/* - * #%L - * Alfresco Remote API - * %% - * Copyright (C) 2005 - 2016 Alfresco Software Limited - * %% - * This file is part of the Alfresco software. - * If the software was purchased under a paid Alfresco license, the terms of - * the paid license agreement will prevail. Otherwise, the software is - * provided under the following open source license terms: - * - * Alfresco is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Alfresco is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with Alfresco. If not, see . - * #L% - */ +/* + * #%L + * Alfresco Remote API + * %% + * Copyright (C) 2005 - 2016 Alfresco Software Limited + * %% + * This file is part of the Alfresco software. + * If the software was purchased under a paid Alfresco license, the terms of + * the paid license agreement will prevail. Otherwise, the software is + * provided under the following open source license terms: + * + * Alfresco is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Alfresco is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Alfresco. If not, see . + * #L% + */ package org.alfresco.repo.web.scripts.quickshare; import java.util.HashMap; @@ -31,10 +31,12 @@ import java.util.Map; import javax.servlet.http.HttpServletResponse; import org.alfresco.model.QuickShareModel; +import org.alfresco.repo.tenant.TenantUtil; import org.alfresco.service.cmr.quickshare.InvalidSharedIdException; import org.alfresco.service.cmr.repository.InvalidNodeRefException; import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeService; +import org.alfresco.util.Pair; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.extensions.webscripts.Cache; @@ -82,14 +84,15 @@ public class UnshareContentDelete extends AbstractQuickShareContent try { - NodeRef nodeRef = quickShareService.getTenantNodeRefFromSharedId(sharedId).getSecond(); + Pair pair = quickShareService.getTenantNodeRefFromSharedId(sharedId); + String networkTenantDomain = pair.getFirst(); - String sharedBy = (String) nodeService.getProperty(nodeRef, QuickShareModel.PROP_QSHARE_SHAREDBY); - if (!quickShareService.canDeleteSharedLink(nodeRef, sharedBy)) + TenantUtil.runAsSystemTenant(() -> { - throw new WebScriptException(HttpServletResponse.SC_FORBIDDEN, "Can't perform unshare action: " + sharedId); - } - quickShareService.unshareContent(sharedId); + checkIfCanDeleteSharedLink(sharedId); + quickShareService.unshareContent(sharedId); + return null; + }, networkTenantDomain); Map model = new HashMap<>(1); model.put("success", Boolean.TRUE); @@ -106,4 +109,14 @@ public class UnshareContentDelete extends AbstractQuickShareContent throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find: " + sharedId); } } + + private void checkIfCanDeleteSharedLink(String sharedId) { + NodeRef nodeRef = quickShareService.getTenantNodeRefFromSharedId(sharedId).getSecond(); + + String sharedBy = (String) nodeService.getProperty(nodeRef, QuickShareModel.PROP_QSHARE_SHAREDBY); + if (!quickShareService.canDeleteSharedLink(nodeRef, sharedBy)) + { + throw new WebScriptException(HttpServletResponse.SC_FORBIDDEN, "Can't perform unshare action: " + sharedId); + } + } } \ No newline at end of file diff --git a/remote-api/src/main/java/org/alfresco/rest/api/impl/QuickShareLinksImpl.java b/remote-api/src/main/java/org/alfresco/rest/api/impl/QuickShareLinksImpl.java index 94ebee970d..bdb8e93c45 100644 --- a/remote-api/src/main/java/org/alfresco/rest/api/impl/QuickShareLinksImpl.java +++ b/remote-api/src/main/java/org/alfresco/rest/api/impl/QuickShareLinksImpl.java @@ -274,15 +274,15 @@ public class QuickShareLinksImpl implements QuickShareLinks, RecognizedParamsExt try { - NodeRef nodeRef = quickShareService.getTenantNodeRefFromSharedId(sharedId).getSecond(); + Pair pair = quickShareService.getTenantNodeRefFromSharedId(sharedId); + String networkTenantDomain = pair.getFirst(); - String sharedByUserId = (String)nodeService.getProperty(nodeRef, QuickShareModel.PROP_QSHARE_SHAREDBY); - if (!quickShareService.canDeleteSharedLink(nodeRef, sharedByUserId)) + TenantUtil.runAsSystemTenant(() -> { - throw new PermissionDeniedException("Can't perform unshare action: " + sharedId); - } - - quickShareService.unshareContent(sharedId); + checkIfCanDeleteSharedLink(sharedId); + quickShareService.unshareContent(sharedId); + return null; + }, networkTenantDomain); } catch (InvalidSharedIdException ex) { @@ -698,4 +698,14 @@ public class QuickShareLinksImpl implements QuickShareLinks, RecognizedParamsExt throw new InvalidArgumentException("A valid recipientEmail must be specified."); } } + + private void checkIfCanDeleteSharedLink(String sharedId) { + NodeRef nodeRef = quickShareService.getTenantNodeRefFromSharedId(sharedId).getSecond(); + + String sharedByUserId = (String)nodeService.getProperty(nodeRef, QuickShareModel.PROP_QSHARE_SHAREDBY); + if (!quickShareService.canDeleteSharedLink(nodeRef, sharedByUserId)) + { + throw new PermissionDeniedException("Can't perform unshare action: " + sharedId); + } + } } \ No newline at end of file