mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
MNT-21883 - Fix unshare content from smart folder (#765)
This commit is contained in:
@@ -1,28 +1,28 @@
|
|||||||
/*
|
/*
|
||||||
* #%L
|
* #%L
|
||||||
* Alfresco Remote API
|
* Alfresco Remote API
|
||||||
* %%
|
* %%
|
||||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||||
* %%
|
* %%
|
||||||
* This file is part of the Alfresco software.
|
* This file is part of the Alfresco software.
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
* the paid license agreement will prevail. Otherwise, the software is
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
* provided under the following open source license terms:
|
* provided under the following open source license terms:
|
||||||
*
|
*
|
||||||
* Alfresco is free software: you can redistribute it and/or modify
|
* 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
|
* 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
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
* (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* Alfresco is distributed in the hope that it will be useful,
|
* Alfresco is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* GNU Lesser General Public License for more details.
|
* GNU Lesser General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
* #L%
|
* #L%
|
||||||
*/
|
*/
|
||||||
package org.alfresco.repo.web.scripts.quickshare;
|
package org.alfresco.repo.web.scripts.quickshare;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -31,10 +31,12 @@ import java.util.Map;
|
|||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import org.alfresco.model.QuickShareModel;
|
import org.alfresco.model.QuickShareModel;
|
||||||
|
import org.alfresco.repo.tenant.TenantUtil;
|
||||||
import org.alfresco.service.cmr.quickshare.InvalidSharedIdException;
|
import org.alfresco.service.cmr.quickshare.InvalidSharedIdException;
|
||||||
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
|
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
import org.alfresco.service.cmr.repository.NodeService;
|
import org.alfresco.service.cmr.repository.NodeService;
|
||||||
|
import org.alfresco.util.Pair;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.springframework.extensions.webscripts.Cache;
|
import org.springframework.extensions.webscripts.Cache;
|
||||||
@@ -82,14 +84,15 @@ public class UnshareContentDelete extends AbstractQuickShareContent
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
NodeRef nodeRef = quickShareService.getTenantNodeRefFromSharedId(sharedId).getSecond();
|
Pair<String, NodeRef> pair = quickShareService.getTenantNodeRefFromSharedId(sharedId);
|
||||||
|
String networkTenantDomain = pair.getFirst();
|
||||||
|
|
||||||
String sharedBy = (String) nodeService.getProperty(nodeRef, QuickShareModel.PROP_QSHARE_SHAREDBY);
|
TenantUtil.runAsSystemTenant(() ->
|
||||||
if (!quickShareService.canDeleteSharedLink(nodeRef, sharedBy))
|
|
||||||
{
|
{
|
||||||
throw new WebScriptException(HttpServletResponse.SC_FORBIDDEN, "Can't perform unshare action: " + sharedId);
|
checkIfCanDeleteSharedLink(sharedId);
|
||||||
}
|
quickShareService.unshareContent(sharedId);
|
||||||
quickShareService.unshareContent(sharedId);
|
return null;
|
||||||
|
}, networkTenantDomain);
|
||||||
|
|
||||||
Map<String, Object> model = new HashMap<>(1);
|
Map<String, Object> model = new HashMap<>(1);
|
||||||
model.put("success", Boolean.TRUE);
|
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);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@@ -274,15 +274,15 @@ public class QuickShareLinksImpl implements QuickShareLinks, RecognizedParamsExt
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
NodeRef nodeRef = quickShareService.getTenantNodeRefFromSharedId(sharedId).getSecond();
|
Pair<String, NodeRef> pair = quickShareService.getTenantNodeRefFromSharedId(sharedId);
|
||||||
|
String networkTenantDomain = pair.getFirst();
|
||||||
|
|
||||||
String sharedByUserId = (String)nodeService.getProperty(nodeRef, QuickShareModel.PROP_QSHARE_SHAREDBY);
|
TenantUtil.runAsSystemTenant(() ->
|
||||||
if (!quickShareService.canDeleteSharedLink(nodeRef, sharedByUserId))
|
|
||||||
{
|
{
|
||||||
throw new PermissionDeniedException("Can't perform unshare action: " + sharedId);
|
checkIfCanDeleteSharedLink(sharedId);
|
||||||
}
|
quickShareService.unshareContent(sharedId);
|
||||||
|
return null;
|
||||||
quickShareService.unshareContent(sharedId);
|
}, networkTenantDomain);
|
||||||
}
|
}
|
||||||
catch (InvalidSharedIdException ex)
|
catch (InvalidSharedIdException ex)
|
||||||
{
|
{
|
||||||
@@ -698,4 +698,14 @@ public class QuickShareLinksImpl implements QuickShareLinks, RecognizedParamsExt
|
|||||||
throw new InvalidArgumentException("A valid recipientEmail must be specified.");
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user