From cf4d9ae04b814b11f470549ced8d0de474760d69 Mon Sep 17 00:00:00 2001 From: Tuna Aksoy Date: Tue, 17 Feb 2015 17:20:18 +0000 Subject: [PATCH] RM-1942 (Hold creator can't view the hold he has created) git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/BRANCHES/V2.3@97278 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../FilePlanPermissionServiceImpl.java | 29 +++- .../test/integration/hold/CreateHoldTest.java | 126 ++++++++++++++++++ .../test/integration/hold/HoldTestSuite.java | 3 +- 3 files changed, 151 insertions(+), 7 deletions(-) create mode 100644 rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/hold/CreateHoldTest.java diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/security/FilePlanPermissionServiceImpl.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/security/FilePlanPermissionServiceImpl.java index 2822e6d124..030fa5cd05 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/security/FilePlanPermissionServiceImpl.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/security/FilePlanPermissionServiceImpl.java @@ -289,8 +289,7 @@ public class FilePlanPermissionServiceImpl extends ServiceBaseImpl ) public void onCreateHold(final ChildAssociationRef childAssocRef) { - mandatory("childAssocRef", childAssocRef); - setupPermissions(childAssocRef.getParentRef(), childAssocRef.getChildRef()); + createContainerElement(childAssocRef); } /** @@ -306,19 +305,37 @@ public class FilePlanPermissionServiceImpl extends ServiceBaseImpl notificationFrequency = TRANSACTION_COMMIT ) public void onCreateTransfer(final ChildAssociationRef childAssocRef) + { + createContainerElement(childAssocRef); + } + + /** + * Helper method to create a container element, e.g. transfer folder or hold + * + * @param childAssocRef + */ + private void createContainerElement(final ChildAssociationRef childAssocRef) { mandatory("childAssocRef", childAssocRef); - - final NodeRef childRef = childAssocRef.getChildRef(); + NodeRef childRef = childAssocRef.getChildRef(); setupPermissions(childAssocRef.getParentRef(), childRef); + grantFilingPermissionToCreator(childRef); + } + /** + * Helper method to give filing permissions to the currently logged in user who creates the node (transfer folder, hold, etc.) + * + * @param nodeRef The node reference of the created object + */ + private void grantFilingPermissionToCreator(final NodeRef nodeRef) + { final String user = AuthenticationUtil.getFullyAuthenticatedUser(); final boolean hasUserPermission = authenticationUtil.runAs(new AuthenticationUtil.RunAsWork() { public Boolean doWork() { - return getPermissionService().hasPermission(childRef, RMPermissionModel.FILING) == AccessStatus.ALLOWED; + return getPermissionService().hasPermission(nodeRef, RMPermissionModel.FILING) == AccessStatus.ALLOWED; } }, user); @@ -328,7 +345,7 @@ public class FilePlanPermissionServiceImpl extends ServiceBaseImpl { public Void doWork() { - getPermissionService().setPermission(childRef, user, RMPermissionModel.FILING, true); + getPermissionService().setPermission(nodeRef, user, RMPermissionModel.FILING, true); return null; } }); diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/hold/CreateHoldTest.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/hold/CreateHoldTest.java new file mode 100644 index 0000000000..f5a7b93ec9 --- /dev/null +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/hold/CreateHoldTest.java @@ -0,0 +1,126 @@ +/* + * Copyright (C) 2005-2015 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * 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 . + */ +package org.alfresco.module.org_alfresco_module_rm.test.integration.hold; + +import static org.alfresco.repo.security.authentication.AuthenticationUtil.getAdminUserName; +import static org.alfresco.repo.security.authentication.AuthenticationUtil.runAs; +import static org.alfresco.repo.site.SiteModel.SITE_CONSUMER; +import static org.alfresco.service.cmr.security.AccessStatus.ALLOWED; +import static org.alfresco.util.GUID.generate; + +import java.util.HashSet; +import java.util.Set; + +import org.alfresco.module.org_alfresco_module_rm.capability.Capability; +import org.alfresco.module.org_alfresco_module_rm.role.Role; +import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase; +import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork; +import org.alfresco.service.cmr.repository.NodeRef; + +/** + * Tests that the user who created the hold has filing permissions on the created hold. + * + * @author Tuna Aksoy + * @since 2.3 + */ +public class CreateHoldTest extends BaseRMTestCase +{ + // Test user + private String testUser = null; + + /** + * @see org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase#isUserTest() + */ + @Override + protected boolean isUserTest() + { + return true; + } + + /** + * @see org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase#setupTestUsersImpl(org.alfresco.service.cmr.repository.NodeRef) + */ + @Override + protected void setupTestUsersImpl(NodeRef filePlan) + { + super.setupTestUsersImpl(filePlan); + + // Create test user + testUser = generate(); + createPerson(testUser); + + // Join the RM site + siteService.setMembership(siteId, testUser, SITE_CONSUMER); + + // Create role + Set capabilities = new HashSet(2); + capabilities.add(capabilityService.getCapability(VIEW_RECORDS)); + capabilities.add(capabilityService.getCapability(CREATE_HOLD)); + Role role = filePlanRoleService.createRole(filePlan, generate(), generate(), capabilities); + + // Add the test user to RM Records Manager role + filePlanRoleService.assignRoleToAuthority(filePlan, role.getName(), testUser); + } + + public void testFilingPermissionOnCreatedHold() + { + doBehaviourDrivenTest(new BehaviourDrivenTest(testUser) + { + // Hold + private NodeRef hold; + + /** + * @see org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase.BehaviourDrivenTest#given() + */ + @Override + public void given() throws Exception + { + // Give test user filing permissions on hold container + runAs(new RunAsWork() + { + public Void doWork() throws Exception + { + filePlanPermissionService.setPermission(holdsContainer, testUser, FILING); + return null; + } + }, getAdminUserName()); + } + + /** + * @see org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase.BehaviourDrivenTest#when() + */ + @Override + public void when() throws Exception + { + // Create a hold + hold = holdService.createHold(filePlan, generate(), generate(), generate()); + } + + /** + * @see org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase.BehaviourDrivenTest#then() + */ + @Override + public void then() throws Exception + { + // Check the permission on the hold + assertEquals(ALLOWED, permissionService.hasPermission(hold, FILING)); + } + }); + } +} diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/hold/HoldTestSuite.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/hold/HoldTestSuite.java index fb488c95eb..fc81361be2 100644 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/hold/HoldTestSuite.java +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/hold/HoldTestSuite.java @@ -32,7 +32,8 @@ import org.junit.runners.Suite.SuiteClasses; @SuiteClasses( { DeleteHoldTest.class, - AddRemoveFromHoldTest.class + AddRemoveFromHoldTest.class, + CreateHoldTest.class }) public class HoldTestSuite {