REPO-1108 / ALF-21645: Unable to delete a folder containing a checked-out document

- follow-on fix for test fallout

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@129958 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jan Vonka
2016-08-30 18:50:54 +00:00
parent 0f8c965198
commit 756bf65c24

View File

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