Merged HEAD-BUG-FIX (5.0/Cloud) to HEAD (5.0/Cloud)

78573: Merged V4.2-BUG-FIX (4.2.4) to HEAD-BUG-FIX (5.0/Cloud)
      78005: Merged DEV to V4.2-BUG-FIX (4.2.4)
         77740: MNT-11960 : Public Share Link action changes modified by and modifier values on content
         Disabled audit for sharing.
         Added JUnit test.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@82609 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Erik Winlof
2014-09-03 12:41:03 +00:00
parent f7c9eb6db8
commit dc45405aa9
3 changed files with 80 additions and 10 deletions

View File

@@ -63,6 +63,7 @@
<property name="tenantService" ref="tenantService"/> <property name="tenantService" ref="tenantService"/>
<property name="thumbnailService" ref="ThumbnailService"/> <property name="thumbnailService" ref="ThumbnailService"/>
<property name="eventPublisher" ref="eventPublisher" /> <property name="eventPublisher" ref="eventPublisher" />
<property name="behaviourFilter" ref="policyBehaviourFilter" />
</bean> </bean>
</beans> </beans>

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2005-2012 Alfresco Software Limited. * Copyright (C) 2005-2014 Alfresco Software Limited.
* *
* This file is part of Alfresco * This file is part of Alfresco
* *
@@ -35,6 +35,7 @@ import org.alfresco.repo.copy.DoNothingCopyBehaviourCallback;
import org.alfresco.repo.events.EventPreparator; import org.alfresco.repo.events.EventPreparator;
import org.alfresco.repo.events.EventPublisher; import org.alfresco.repo.events.EventPublisher;
import org.alfresco.repo.node.NodeServicePolicies; import org.alfresco.repo.node.NodeServicePolicies;
import org.alfresco.repo.policy.BehaviourFilter;
import org.alfresco.repo.policy.JavaBehaviour; import org.alfresco.repo.policy.JavaBehaviour;
import org.alfresco.repo.policy.PolicyComponent; import org.alfresco.repo.policy.PolicyComponent;
import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.authentication.AuthenticationUtil;
@@ -97,6 +98,19 @@ public class QuickShareServiceImpl implements QuickShareService, NodeServicePoli
private ThumbnailService thumbnailService; private ThumbnailService thumbnailService;
private EventPublisher eventPublisher; private EventPublisher eventPublisher;
/** Component to determine which behaviours are active and which not */
private BehaviourFilter behaviourFilter;
/**
* Spring configuration
*
* @param behaviourFilter the behaviourFilter to set
*/
public void setBehaviourFilter(BehaviourFilter behaviourFilter)
{
this.behaviourFilter = behaviourFilter;
}
/** /**
* Enable or disable this service. * Enable or disable this service.
*/ */
@@ -221,6 +235,11 @@ public class QuickShareServiceImpl implements QuickShareService, NodeServicePoli
props.put(QuickShareModel.PROP_QSHARE_SHAREDID, sharedId); props.put(QuickShareModel.PROP_QSHARE_SHAREDID, sharedId);
props.put(QuickShareModel.PROP_QSHARE_SHAREDBY, AuthenticationUtil.getRunAsUser()); props.put(QuickShareModel.PROP_QSHARE_SHAREDBY, AuthenticationUtil.getRunAsUser());
// Disable audit to preserve modifier and modified date
// see MNT-11960
behaviourFilter.disableBehaviour(nodeRef, ContentModel.ASPECT_AUDITABLE);
try
{
// consumer/contributor should be able to add "shared" aspect (MNT-10366) // consumer/contributor should be able to add "shared" aspect (MNT-10366)
AuthenticationUtil.runAsSystem(new RunAsWork<Void>() AuthenticationUtil.runAsSystem(new RunAsWork<Void>()
{ {
@@ -230,6 +249,11 @@ public class QuickShareServiceImpl implements QuickShareService, NodeServicePoli
return null; return null;
} }
}); });
}
finally
{
behaviourFilter.enableBehaviour(nodeRef, ContentModel.ASPECT_AUDITABLE);
}
final NodeRef tenantNodeRef = tenantService.getName(nodeRef); final NodeRef tenantNodeRef = tenantService.getName(nodeRef);

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2005-2012 Alfresco Software Limited. * Copyright (C) 2005-2014 Alfresco Software Limited.
* *
* This file is part of Alfresco * This file is part of Alfresco
* *
@@ -43,6 +43,7 @@ import org.alfresco.service.cmr.repository.CopyService;
import org.alfresco.service.cmr.repository.InvalidNodeRefException; import org.alfresco.service.cmr.repository.InvalidNodeRefException;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.QName;
import org.alfresco.util.test.junitrules.AlfrescoPerson; import org.alfresco.util.test.junitrules.AlfrescoPerson;
@@ -107,6 +108,7 @@ public class QuickShareServiceIntegrationTest
private static DictionaryService dictionaryService; private static DictionaryService dictionaryService;
private static Repository repository; private static Repository repository;
private static AttributeService attributeService; private static AttributeService attributeService;
private static PermissionService permissionService;
private static AlfrescoPerson user1 = new AlfrescoPerson(testContext, "UserOne"); private static AlfrescoPerson user1 = new AlfrescoPerson(testContext, "UserOne");
private static AlfrescoPerson user2 = new AlfrescoPerson(testContext, "UserTwo"); private static AlfrescoPerson user2 = new AlfrescoPerson(testContext, "UserTwo");
@@ -140,6 +142,7 @@ public class QuickShareServiceIntegrationTest
quickShareService = ctx.getBean("QuickShareService", QuickShareService.class); quickShareService = ctx.getBean("QuickShareService", QuickShareService.class);
repository = ctx.getBean("repositoryHelper", Repository.class); repository = ctx.getBean("repositoryHelper", Repository.class);
attributeService = ctx.getBean("AttributeService", AttributeService.class); attributeService = ctx.getBean("AttributeService", AttributeService.class);
permissionService = ctx.getBean("PermissionService", PermissionService.class);
} }
@Before public void createTestData() @Before public void createTestData()
@@ -387,4 +390,46 @@ public class QuickShareServiceIntegrationTest
AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser(); AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
Assert.assertFalse(nodeService.exists(node)); Assert.assertFalse(nodeService.exists(node));
} }
/**
* Test for MNT-11960
* <p> The node is created by user1 and shared by user2.
* <p> The modifier should not change to user2 after sharing.
*/
@Test
public void testModifierAfterSharing()
{
AuthenticationUtil.runAs(new RunAsWork<Void>(){
@Override
public Void doWork() throws Exception
{
permissionService.setPermission(testNode, user2.getUsername(), PermissionService.CONSUMER, true);
return null;
}
}, user1.getUsername());
final Serializable modifiedDate = AuthenticationUtil.runAsSystem(new RunAsWork<Serializable>(){
@Override
public Serializable doWork() throws Exception
{
return nodeService.getProperty(testNode, ContentModel.PROP_MODIFIED);
}
});
share(testNode, user2.getUsername());
AuthenticationUtil.runAsSystem(new RunAsWork<Void>(){
@Override
public Void doWork() throws Exception
{
assertTrue(nodeService.getAspects(testNode).contains(ContentModel.ASPECT_AUDITABLE));
assertNotNull(nodeService.getProperty(testNode, ContentModel.PROP_MODIFIER));
assertEquals("The modifier has changed after sharing.", user1.getUsername(), nodeService.getProperty(testNode, ContentModel.PROP_MODIFIER));
assertNotNull(nodeService.getProperty(testNode, ContentModel.PROP_MODIFIED));
assertEquals("The modified date has changed after sharing.", modifiedDate, nodeService.getProperty(testNode, ContentModel.PROP_MODIFIED));
return null;
}
});
}
} }