diff --git a/source/test-java/org/alfresco/repo/site/SiteServiceImplMoreTest.java b/source/test-java/org/alfresco/repo/site/SiteServiceImplMoreTest.java index 8074d3ea55..1087f03366 100644 --- a/source/test-java/org/alfresco/repo/site/SiteServiceImplMoreTest.java +++ b/source/test-java/org/alfresco/repo/site/SiteServiceImplMoreTest.java @@ -1,4 +1,4 @@ -/* +/* * #%L * Alfresco Repository * %% @@ -9,20 +9,20 @@ * 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% - */ + * 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.site; @@ -32,14 +32,14 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; - + import java.io.Serializable; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; - + import org.alfresco.model.ContentModel; import org.alfresco.query.PagingRequest; import org.alfresco.query.PagingResults; @@ -52,11 +52,11 @@ import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork; import org.alfresco.repo.security.permissions.AccessDeniedException; import org.alfresco.repo.transaction.RetryingTransactionHelper; import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; -import org.alfresco.service.cmr.coci.CheckOutCheckInService; +import org.alfresco.service.cmr.coci.CheckOutCheckInService; import org.alfresco.service.cmr.lock.LockService; import org.alfresco.service.cmr.lock.LockStatus; import org.alfresco.service.cmr.lock.LockType; -import org.alfresco.service.cmr.lock.NodeLockedException; +import org.alfresco.service.cmr.lock.NodeLockedException; import org.alfresco.service.cmr.model.FileFolderService; import org.alfresco.service.cmr.model.FileInfo; import org.alfresco.service.cmr.repository.ChildAssociationRef; @@ -136,7 +136,7 @@ public class SiteServiceImplMoreTest private static NamespaceService NAMESPACE_SERVICE; private static NodeService NODE_SERVICE; private static NodeArchiveService NODE_ARCHIVE_SERVICE; - private static SiteService SITE_SERVICE; + private static SiteService SITE_SERVICE; private static CheckOutCheckInService COCI_SERVICE; private static RetryingTransactionHelper TRANSACTION_HELPER; private static PermissionService PERMISSION_SERVICE; @@ -155,7 +155,7 @@ public class SiteServiceImplMoreTest NAMESPACE_SERVICE = APP_CONTEXT_INIT.getApplicationContext().getBean("namespaceService", NamespaceService.class); NODE_SERVICE = APP_CONTEXT_INIT.getApplicationContext().getBean("NodeService", NodeService.class); NODE_ARCHIVE_SERVICE = APP_CONTEXT_INIT.getApplicationContext().getBean("nodeArchiveService", NodeArchiveService.class); - SITE_SERVICE = APP_CONTEXT_INIT.getApplicationContext().getBean("siteService", SiteService.class); + SITE_SERVICE = APP_CONTEXT_INIT.getApplicationContext().getBean("siteService", SiteService.class); COCI_SERVICE = APP_CONTEXT_INIT.getApplicationContext().getBean("checkOutCheckInService", CheckOutCheckInService.class); TRANSACTION_HELPER = APP_CONTEXT_INIT.getApplicationContext().getBean("retryingTransactionHelper", RetryingTransactionHelper.class); PERMISSION_SERVICE = APP_CONTEXT_INIT.getApplicationContext().getBean("permissionServiceImpl", PermissionService.class); @@ -880,169 +880,165 @@ public class SiteServiceImplMoreTest res = SiteServiceImpl.tokenizeFilterLowercase(null); assertNotNull(res); assertEquals(0, res.length); - } - - /** - * MNT-16043: Site Owner and Site Manager can delete working copy, - * Site Collaborator cannot - * - * @throws Exception - */ - @Test - public void testSiteRolesPersmissionsToDeleteWorkingCopy() throws Exception - { - final String userSiteOwner = "UserSiteOwner"; - final String userSiteManager = "UserSiteManager"; - final String userSiteCollaborator = "UserSiteCollaborator"; - final String userPrefix = "delete-locked-file"; - - // create the users - TRANSACTION_HELPER.doInTransaction(new RetryingTransactionCallback() - { - public Void execute() throws Throwable - { - createUser(userSiteOwner, userPrefix); - createUser(userSiteManager, userPrefix); - createUser(userSiteCollaborator, userPrefix); - return null; - } - }); - final String siteShortName = userPrefix + "Site" + System.currentTimeMillis(); - final String dummyContent = "Just some old content that doesn't mean anything"; - - // Create site - final TestSiteAndMemberInfo testSiteAndMemberInfo = perMethodTestSites.createTestSiteWithUserPerRole(siteShortName, "sitePreset", - SiteVisibility.PUBLIC, userSiteOwner); - - // create 1 file into the site as the owner of the site - AUTHENTICATION_COMPONENT.setCurrentUser(userSiteOwner); - - NodeRef siteContainer = SITE_SERVICE.createContainer(siteShortName, "doclib", ContentModel.TYPE_FOLDER, null); - final FileInfo fileInfo1 = FILE_FOLDER_SERVICE.create(siteContainer, "fileInfo1.txt", ContentModel.TYPE_CONTENT); - ContentWriter writer1 = FILE_FOLDER_SERVICE.getWriter(fileInfo1.getNodeRef()); - writer1.putContent(dummyContent); - - final FileInfo fileInfo2 = FILE_FOLDER_SERVICE.create(siteContainer, "fileInfo2.txt", ContentModel.TYPE_CONTENT); - ContentWriter writer2 = FILE_FOLDER_SERVICE.getWriter(fileInfo2.getNodeRef()); - writer2.putContent(dummyContent); - - final FileInfo fileInfo3 = FILE_FOLDER_SERVICE.create(siteContainer, "fileInfo3.txt", ContentModel.TYPE_CONTENT); - ContentWriter writer3 = FILE_FOLDER_SERVICE.getWriter(fileInfo2.getNodeRef()); - writer3.putContent(dummyContent); - - // Site Manager - can delete working copy but cannot delete the original - // locked file - TRANSACTION_HELPER.doInTransaction(new RetryingTransactionCallback() - { - public Void execute() throws Throwable - { - // lock a file as userOwner - NodeRef workingCopy = COCI_SERVICE.checkout(fileInfo1.getNodeRef()); - assertNotNull(workingCopy); - - // make userSiteManager a member of the site - SITE_SERVICE.setMembership(siteShortName, userSiteManager, SiteModel.SITE_MANAGER); - - // make sure we are running as userSiteManager - AUTHENTICATION_COMPONENT.setCurrentUser(userSiteManager); - - // try delete locked file by owner - try - { - NODE_SERVICE.deleteNode(fileInfo1.getNodeRef()); - fail("Cannot perform operation since the node" + fileInfo1.getNodeRef() + " is locked"); - } - catch (NodeLockedException ex) - { - // do nothing - is expected - } - - // simulate delete from Share - delete the working copy - NODE_SERVICE.deleteNode(workingCopy); - - return null; - } - }); - - // Site Owner - can delete working copy but cannot delete the original - // locked file - TRANSACTION_HELPER.doInTransaction(new RetryingTransactionCallback() - { - public Void execute() throws Throwable - { - AUTHENTICATION_COMPONENT.setCurrentUser(userSiteOwner); - // lock a file as userOwner - NodeRef workingCopy = COCI_SERVICE.checkout(fileInfo2.getNodeRef()); - assertNotNull(workingCopy); - try - { - NODE_SERVICE.deleteNode(fileInfo2.getNodeRef()); - fail("Cannot perform operation since the node" + fileInfo1.getNodeRef() + " is locked"); - } - catch (NodeLockedException ex) - { - // do nothing- expected - } - NODE_SERVICE.deleteNode(workingCopy); - return null; - } - }); - - // Site COLLABORATOR - cannot delete working copy or original file - TRANSACTION_HELPER.doInTransaction(new RetryingTransactionCallback() - { - public Void execute() throws Throwable - { - // lock a file as userOwner - AUTHENTICATION_COMPONENT.setCurrentUser(userSiteOwner); - NodeRef workingCopy = COCI_SERVICE.checkout(fileInfo3.getNodeRef()); - assertNotNull(workingCopy); - - // make userSiteCollaborator a member of the site - SITE_SERVICE.setMembership(siteShortName, userSiteCollaborator, SiteModel.SITE_COLLABORATOR); - - // make sure we are running as userSiteManager - AUTHENTICATION_COMPONENT.setCurrentUser(userSiteCollaborator); - - try - { - NODE_SERVICE.deleteNode(fileInfo3.getNodeRef()); - fail("You do not have the appropriate permissions to perform this operation"); - } - catch (AccessDeniedException ex) - { - // do nothing - is expected - } - - // try delete locked file by owner - try - { - NODE_SERVICE.deleteNode(workingCopy); - fail("You do not have the appropriate permissions to perform this operation"); - } - catch (AccessDeniedException ex) - { - // do nothing - is expected - } - - return null; - } - }); - - AUTHENTICATION_COMPONENT.setCurrentUser(userSiteOwner); - // Delete the site - TRANSACTION_HELPER.doInTransaction(new RetryingTransactionCallback() - { - public Void execute() throws Throwable - { - AUTHENTICATION_COMPONENT.getCurrentUserName(); - SITE_SERVICE.deleteSite(siteShortName); - - return null; - } - }); - - } + } + + /** + * MNT-16043: Site Owner and Site Manager can delete working copy, Site Collaborator cannot + * + * @throws Exception + */ + @Test + public void testSiteRolesPermissionsToDeleteWorkingCopy() throws Exception + { + final String userSiteOwner = "UserSiteOwner"; + final String userSiteManager = "UserSiteManager"; + final String userSiteCollaborator = "UserSiteCollaborator"; + final String userPrefix = "delete-working-copy-file"; + + // create the users + TRANSACTION_HELPER.doInTransaction(new RetryingTransactionCallback() + { + public Void execute() throws Throwable + { + createUser(userSiteOwner, userPrefix); + createUser(userSiteManager, userPrefix); + createUser(userSiteCollaborator, userPrefix); + return null; + } + }); + final String siteShortName = userPrefix + "Site" + System.currentTimeMillis(); + final String dummyContent = "Just some old content that doesn't mean anything"; + + // Create site + final TestSiteAndMemberInfo testSiteAndMemberInfo = perMethodTestSites.createTestSiteWithUserPerRole(siteShortName, "sitePreset", + SiteVisibility.PUBLIC, userSiteOwner); + + // create 1 file into the site as the owner of the site + AUTHENTICATION_COMPONENT.setCurrentUser(userSiteOwner); + + NodeRef siteContainer = SITE_SERVICE.createContainer(siteShortName, "doclib", ContentModel.TYPE_FOLDER, null); + final FileInfo fileInfo1 = FILE_FOLDER_SERVICE.create(siteContainer, "fileInfo1.txt", ContentModel.TYPE_CONTENT); + ContentWriter writer1 = FILE_FOLDER_SERVICE.getWriter(fileInfo1.getNodeRef()); + writer1.putContent(dummyContent); + + final FileInfo fileInfo2 = FILE_FOLDER_SERVICE.create(siteContainer, "fileInfo2.txt", ContentModel.TYPE_CONTENT); + ContentWriter writer2 = FILE_FOLDER_SERVICE.getWriter(fileInfo2.getNodeRef()); + writer2.putContent(dummyContent); + + final FileInfo fileInfo3 = FILE_FOLDER_SERVICE.create(siteContainer, "fileInfo3.txt", ContentModel.TYPE_CONTENT); + ContentWriter writer3 = FILE_FOLDER_SERVICE.getWriter(fileInfo2.getNodeRef()); + writer3.putContent(dummyContent); + + // Site COLLABORATOR - cannot delete working copy or original file + TRANSACTION_HELPER.doInTransaction(new RetryingTransactionCallback() + { + public Void execute() throws Throwable + { + // checkout file again as userOwner + AUTHENTICATION_COMPONENT.setCurrentUser(userSiteOwner); + NodeRef workingCopy = COCI_SERVICE.checkout(fileInfo3.getNodeRef()); + assertNotNull(workingCopy); + + // make userSiteCollaborator a member of the site + SITE_SERVICE.setMembership(siteShortName, userSiteCollaborator, SiteModel.SITE_COLLABORATOR); + + // make sure we are running as userSiteCollaborator + AUTHENTICATION_COMPONENT.setCurrentUser(userSiteCollaborator); + + // try to delete working copy file + try + { + NODE_SERVICE.deleteNode(workingCopy); + fail("You do not have the appropriate permissions to perform this operation"); + } + catch (AccessDeniedException ex) + { + // do nothing - is expected + } + + // try to delete original checked-out + try + { + NODE_SERVICE.deleteNode(fileInfo3.getNodeRef()); + fail("You do not have the appropriate permissions to perform this operation"); + } + catch (AccessDeniedException ex) + { + // do nothing - is expected + } + + return null; + } + }); + + // Site Owner - can delete working copy (or original) + TRANSACTION_HELPER.doInTransaction(new RetryingTransactionCallback() + { + public Void execute() throws Throwable + { + // checkout a file as userOwner + AUTHENTICATION_COMPONENT.setCurrentUser(userSiteOwner); + NodeRef workingCopy = COCI_SERVICE.checkout(fileInfo2.getNodeRef()); + assertNotNull(workingCopy); + + NODE_SERVICE.deleteNode(workingCopy); + + // checkout file again as userOwner + workingCopy = COCI_SERVICE.checkout(fileInfo2.getNodeRef()); + assertNotNull(workingCopy); + + NODE_SERVICE.deleteNode(fileInfo2.getNodeRef()); + + return null; + } + }); + + // Site Manager - can delete working copy (or original) + TRANSACTION_HELPER.doInTransaction(new RetryingTransactionCallback() + { + public Void execute() throws Throwable + { + // checkout a file as userOwner + AUTHENTICATION_COMPONENT.setCurrentUser(userSiteOwner); + NodeRef workingCopy = COCI_SERVICE.checkout(fileInfo1.getNodeRef()); + assertNotNull(workingCopy); + + // make userSiteManager a member of the site + SITE_SERVICE.setMembership(siteShortName, userSiteManager, SiteModel.SITE_MANAGER); + + // make sure we are running as userSiteManager + AUTHENTICATION_COMPONENT.setCurrentUser(userSiteManager); + + NODE_SERVICE.deleteNode(workingCopy); + + // checkout file again as userOwner + AUTHENTICATION_COMPONENT.setCurrentUser(userSiteOwner); + workingCopy = COCI_SERVICE.checkout(fileInfo1.getNodeRef()); + assertNotNull(workingCopy); + + // make sure we are running as userSiteManager + AUTHENTICATION_COMPONENT.setCurrentUser(userSiteManager); + + NODE_SERVICE.deleteNode(fileInfo1.getNodeRef()); + + return null; + } + }); + + AUTHENTICATION_COMPONENT.setCurrentUser(userSiteOwner); + + // Delete the site + TRANSACTION_HELPER.doInTransaction(new RetryingTransactionCallback() + { + public Void execute() throws Throwable + { + AUTHENTICATION_COMPONENT.getCurrentUserName(); + SITE_SERVICE.deleteSite(siteShortName); + + return null; + } + }); + } private void assertThatArchivedNodeExists(NodeRef originalNodeRef, String failureMsg) {