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
This commit is contained in:
Tuna Aksoy
2015-02-17 17:20:18 +00:00
parent 283c2464ec
commit cf4d9ae04b
3 changed files with 151 additions and 7 deletions

View File

@@ -289,8 +289,7 @@ public class FilePlanPermissionServiceImpl extends ServiceBaseImpl
) )
public void onCreateHold(final ChildAssociationRef childAssocRef) public void onCreateHold(final ChildAssociationRef childAssocRef)
{ {
mandatory("childAssocRef", childAssocRef); createContainerElement(childAssocRef);
setupPermissions(childAssocRef.getParentRef(), childAssocRef.getChildRef());
} }
/** /**
@@ -306,19 +305,37 @@ public class FilePlanPermissionServiceImpl extends ServiceBaseImpl
notificationFrequency = TRANSACTION_COMMIT notificationFrequency = TRANSACTION_COMMIT
) )
public void onCreateTransfer(final ChildAssociationRef childAssocRef) 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); mandatory("childAssocRef", childAssocRef);
NodeRef childRef = childAssocRef.getChildRef();
final NodeRef childRef = childAssocRef.getChildRef();
setupPermissions(childAssocRef.getParentRef(), childRef); 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 String user = AuthenticationUtil.getFullyAuthenticatedUser();
final boolean hasUserPermission = authenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Boolean>() final boolean hasUserPermission = authenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Boolean>()
{ {
public Boolean doWork() public Boolean doWork()
{ {
return getPermissionService().hasPermission(childRef, RMPermissionModel.FILING) == AccessStatus.ALLOWED; return getPermissionService().hasPermission(nodeRef, RMPermissionModel.FILING) == AccessStatus.ALLOWED;
} }
}, user); }, user);
@@ -328,7 +345,7 @@ public class FilePlanPermissionServiceImpl extends ServiceBaseImpl
{ {
public Void doWork() public Void doWork()
{ {
getPermissionService().setPermission(childRef, user, RMPermissionModel.FILING, true); getPermissionService().setPermission(nodeRef, user, RMPermissionModel.FILING, true);
return null; return null;
} }
}); });

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
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<Capability> capabilities = new HashSet<Capability>(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<Void>()
{
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));
}
});
}
}

View File

@@ -32,7 +32,8 @@ import org.junit.runners.Suite.SuiteClasses;
@SuiteClasses( @SuiteClasses(
{ {
DeleteHoldTest.class, DeleteHoldTest.class,
AddRemoveFromHoldTest.class AddRemoveFromHoldTest.class,
CreateHoldTest.class
}) })
public class HoldTestSuite public class HoldTestSuite
{ {