From dc45405aa9bc9c58e6aa569ef058ed60fb492b73 Mon Sep 17 00:00:00 2001 From: Erik Winlof Date: Wed, 3 Sep 2014 12:41:03 +0000 Subject: [PATCH] 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 --- .../alfresco/quickshare-services-context.xml | 1 + .../quickshare/QuickShareServiceImpl.java | 42 +++++++++++++---- .../QuickShareServiceIntegrationTest.java | 47 ++++++++++++++++++- 3 files changed, 80 insertions(+), 10 deletions(-) diff --git a/config/alfresco/quickshare-services-context.xml b/config/alfresco/quickshare-services-context.xml index 1c39150e87..13627fc395 100644 --- a/config/alfresco/quickshare-services-context.xml +++ b/config/alfresco/quickshare-services-context.xml @@ -63,6 +63,7 @@ + diff --git a/source/java/org/alfresco/repo/quickshare/QuickShareServiceImpl.java b/source/java/org/alfresco/repo/quickshare/QuickShareServiceImpl.java index 0f7e776234..8fc59b4c00 100644 --- a/source/java/org/alfresco/repo/quickshare/QuickShareServiceImpl.java +++ b/source/java/org/alfresco/repo/quickshare/QuickShareServiceImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2012 Alfresco Software Limited. + * Copyright (C) 2005-2014 Alfresco Software Limited. * * 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.EventPublisher; import org.alfresco.repo.node.NodeServicePolicies; +import org.alfresco.repo.policy.BehaviourFilter; import org.alfresco.repo.policy.JavaBehaviour; import org.alfresco.repo.policy.PolicyComponent; import org.alfresco.repo.security.authentication.AuthenticationUtil; @@ -97,6 +98,19 @@ public class QuickShareServiceImpl implements QuickShareService, NodeServicePoli private ThumbnailService thumbnailService; 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. */ @@ -221,16 +235,26 @@ public class QuickShareServiceImpl implements QuickShareService, NodeServicePoli props.put(QuickShareModel.PROP_QSHARE_SHAREDID, sharedId); props.put(QuickShareModel.PROP_QSHARE_SHAREDBY, AuthenticationUtil.getRunAsUser()); - // consumer/contributor should be able to add "shared" aspect (MNT-10366) - AuthenticationUtil.runAsSystem(new RunAsWork() + // Disable audit to preserve modifier and modified date + // see MNT-11960 + behaviourFilter.disableBehaviour(nodeRef, ContentModel.ASPECT_AUDITABLE); + try { - public Void doWork() + // consumer/contributor should be able to add "shared" aspect (MNT-10366) + AuthenticationUtil.runAsSystem(new RunAsWork() { - nodeService.addAspect(nodeRef, QuickShareModel.ASPECT_QSHARE, props); - return null; - } - }); - + public Void doWork() + { + nodeService.addAspect(nodeRef, QuickShareModel.ASPECT_QSHARE, props); + return null; + } + }); + } + finally + { + behaviourFilter.enableBehaviour(nodeRef, ContentModel.ASPECT_AUDITABLE); + } + final NodeRef tenantNodeRef = tenantService.getName(nodeRef); TenantUtil.runAsDefaultTenant(new TenantRunAsWork() diff --git a/source/test-java/org/alfresco/repo/quickshare/QuickShareServiceIntegrationTest.java b/source/test-java/org/alfresco/repo/quickshare/QuickShareServiceIntegrationTest.java index b67015bcc5..6dcb1544fc 100644 --- a/source/test-java/org/alfresco/repo/quickshare/QuickShareServiceIntegrationTest.java +++ b/source/test-java/org/alfresco/repo/quickshare/QuickShareServiceIntegrationTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2012 Alfresco Software Limited. + * Copyright (C) 2005-2014 Alfresco Software Limited. * * 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.NodeRef; 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.QName; import org.alfresco.util.test.junitrules.AlfrescoPerson; @@ -107,6 +108,7 @@ public class QuickShareServiceIntegrationTest private static DictionaryService dictionaryService; private static Repository repository; private static AttributeService attributeService; + private static PermissionService permissionService; private static AlfrescoPerson user1 = new AlfrescoPerson(testContext, "UserOne"); private static AlfrescoPerson user2 = new AlfrescoPerson(testContext, "UserTwo"); @@ -140,6 +142,7 @@ public class QuickShareServiceIntegrationTest quickShareService = ctx.getBean("QuickShareService", QuickShareService.class); repository = ctx.getBean("repositoryHelper", Repository.class); attributeService = ctx.getBean("AttributeService", AttributeService.class); + permissionService = ctx.getBean("PermissionService", PermissionService.class); } @Before public void createTestData() @@ -387,4 +390,46 @@ public class QuickShareServiceIntegrationTest AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser(); Assert.assertFalse(nodeService.exists(node)); } + + /** + * Test for MNT-11960 + *

The node is created by user1 and shared by user2. + *

The modifier should not change to user2 after sharing. + */ + @Test + public void testModifierAfterSharing() + { + AuthenticationUtil.runAs(new RunAsWork(){ + @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(){ + @Override + public Serializable doWork() throws Exception + { + return nodeService.getProperty(testNode, ContentModel.PROP_MODIFIED); + } + }); + + share(testNode, user2.getUsername()); + + AuthenticationUtil.runAsSystem(new RunAsWork(){ + @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; + } + }); + } + }