diff --git a/source/java/org/alfresco/rest/api/impl/QuickShareLinksImpl.java b/source/java/org/alfresco/rest/api/impl/QuickShareLinksImpl.java index ceeca7ace6..e9ba62c055 100644 --- a/source/java/org/alfresco/rest/api/impl/QuickShareLinksImpl.java +++ b/source/java/org/alfresco/rest/api/impl/QuickShareLinksImpl.java @@ -33,7 +33,6 @@ import org.alfresco.repo.quickshare.QuickShareServiceImpl.QuickShareEmailRequest import org.alfresco.repo.search.QueryParameterDefImpl; import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.permissions.AccessDeniedException; -import org.alfresco.repo.site.SiteModel; import org.alfresco.repo.tenant.TenantUtil; import org.alfresco.rest.antlr.WhereClauseParser; import org.alfresco.rest.api.Nodes; @@ -77,9 +76,7 @@ import org.alfresco.service.cmr.search.ResultSet; import org.alfresco.service.cmr.search.ResultSetRow; import org.alfresco.service.cmr.search.SearchParameters; import org.alfresco.service.cmr.search.SearchService; -import org.alfresco.service.cmr.security.AuthorityService; import org.alfresco.service.cmr.security.PersonService; -import org.alfresco.service.cmr.site.SiteService; import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.QName; import org.alfresco.util.Pair; @@ -107,7 +104,7 @@ import java.util.Set; * * @author janv * @author Jamal Kaabi-Mofrad - * + * * @since publicapi1.0 */ public class QuickShareLinksImpl implements QuickShareLinks, InitializingBean @@ -124,12 +121,10 @@ public class QuickShareLinksImpl implements QuickShareLinks, InitializingBean private NodeService nodeService; private PersonService personService; - private AuthorityService authorityService; private MimetypeService mimeTypeService; private SearchService searchService; private DictionaryService dictionaryService; private NamespaceService namespaceService; - private SiteService siteService; public void setServiceRegistry(ServiceRegistry sr) { @@ -166,12 +161,10 @@ public class QuickShareLinksImpl implements QuickShareLinks, InitializingBean this.nodeService = sr.getNodeService(); this.personService = sr.getPersonService(); - this.authorityService = sr.getAuthorityService(); this.mimeTypeService = sr.getMimetypeService(); this.searchService = sr.getSearchService(); this.dictionaryService = sr.getDictionaryService(); this.namespaceService = sr.getNamespaceService(); - this.siteService = sr.getSiteService(); } /** @@ -280,7 +273,7 @@ public class QuickShareLinksImpl implements QuickShareLinks, InitializingBean NodeRef nodeRef = quickShareService.getTenantNodeRefFromSharedId(sharedId).getSecond(); String sharedByUserId = (String)nodeService.getProperty(nodeRef, QuickShareModel.PROP_QSHARE_SHAREDBY); - if (! canDeleteSharedLink(nodeRef, sharedByUserId)) + if (!quickShareService.canDeleteSharedLink(nodeRef, sharedByUserId)) { throw new PermissionDeniedException("Can't perform unshare action: " + sharedId); } @@ -558,7 +551,7 @@ public class QuickShareLinksImpl implements QuickShareLinks, InitializingBean // note: if noAuth mode then do not return allowable operations (eg. but can be optionally returned when finding shared links) if ((! noAuth) && includeParam.contains(PARAM_INCLUDE_ALLOWABLEOPERATIONS)) { - if (canDeleteSharedLink(nodeRef, sharedByUserId)) + if (quickShareService.canDeleteSharedLink(nodeRef, sharedByUserId)) { qs.setAllowableOperations(Collections.singletonList(Nodes.OP_DELETE)); } @@ -578,54 +571,6 @@ public class QuickShareLinksImpl implements QuickShareLinks, InitializingBean } } - // TODO push down to QuickShareService and also update v0 webscript (UnshareContentDelete) - private boolean canDeleteSharedLink(NodeRef nodeRef, String sharedByUserId) - { - boolean canDeleteSharedLink = false; - - String currentUser = AuthenticationUtil.getFullyAuthenticatedUser(); - String siteName = getSiteName(nodeRef); - - if (siteName != null) - { - // node belongs to a site - current user must be a manager or collaborator (irrespective of whether they shared the link or not) - String role = siteService.getMembersRole(siteName, currentUser); - if (role.equals(SiteModel.SITE_MANAGER) || role.equals(SiteModel.SITE_COLLABORATOR)) - { - canDeleteSharedLink = true; - } - } - else if ((currentUser.equals(sharedByUserId)) || (authorityService.isAdminAuthority(currentUser))) - { - // node does not belongs to a site - current user must be the person who shared the link or an admin - canDeleteSharedLink = true; - } - - return canDeleteSharedLink; - } - - private String getSiteName(NodeRef nodeRef) - { - NodeRef parent = nodeService.getPrimaryParent(nodeRef).getParentRef(); - while (parent != null && !nodeService.getType(parent).equals(SiteModel.TYPE_SITE)) - { - // check that we can read parent name - String parentName = (String) nodeService.getProperty(parent, ContentModel.PROP_NAME); - - if (nodeService.getPrimaryParent(nodeRef) != null) - { - parent = nodeService.getPrimaryParent(parent).getParentRef(); - } - } - - if (parent == null) - { - return null; - } - - return nodeService.getProperty(parent, ContentModel.PROP_NAME).toString(); - } - private void checkEnabled() { if (!enabled)