diff --git a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-model-context.xml b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-model-context.xml
index dde414270d..033da4a348 100644
--- a/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-model-context.xml
+++ b/rm-community/rm-community-repo/config/alfresco/module/org_alfresco_module_rm/rm-model-context.xml
@@ -133,6 +133,7 @@
+
diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/aspect/RecordAspect.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/aspect/RecordAspect.java
index a2ece30962..fb5fc43d10 100644
--- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/aspect/RecordAspect.java
+++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/model/rma/aspect/RecordAspect.java
@@ -33,6 +33,7 @@ import java.util.Map;
import java.util.Set;
import org.alfresco.model.ContentModel;
+import org.alfresco.model.QuickShareModel;
import org.alfresco.module.org_alfresco_module_rm.RecordsManagementPolicies;
import org.alfresco.module.org_alfresco_module_rm.model.behaviour.AbstractDisposableItem;
import org.alfresco.module.org_alfresco_module_rm.record.RecordService;
@@ -46,7 +47,9 @@ import org.alfresco.repo.policy.Behaviour.NotificationFrequency;
import org.alfresco.repo.policy.annotation.Behaviour;
import org.alfresco.repo.policy.annotation.BehaviourBean;
import org.alfresco.repo.policy.annotation.BehaviourKind;
+import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
+import org.alfresco.service.cmr.quickshare.QuickShareService;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.ScriptService;
@@ -64,6 +67,7 @@ import org.alfresco.service.namespace.QName;
)
public class RecordAspect extends AbstractDisposableItem
implements NodeServicePolicies.OnCreateChildAssociationPolicy,
+ NodeServicePolicies.BeforeAddAspectPolicy,
RecordsManagementPolicies.OnCreateReference,
RecordsManagementPolicies.OnRemoveReference,
NodeServicePolicies.OnMoveNodePolicy,
@@ -81,6 +85,9 @@ public class RecordAspect extends AbstractDisposableItem
/** record service */
protected RecordService recordService;
+
+ /** quickShare service */
+ private QuickShareService quickShareService;
/**
* @param extendedSecurityService extended security service
@@ -106,6 +113,15 @@ public class RecordAspect extends AbstractDisposableItem
this.recordService = recordService;
}
+ /**
+ *
+ * @param quickShareService
+ */
+ public void setQuickShareService(QuickShareService quickShareService)
+ {
+ this.quickShareService = quickShareService;
+ }
+
/**
* Behaviour to ensure renditions have the appropriate extended security.
*
@@ -336,4 +352,30 @@ public class RecordAspect extends AbstractDisposableItem
extendedSecurityService.remove(targetNodeRef);
}
}
+
+ /**
+ * Behaviour to remove the shared link before declare a record
+ *
+ * @see org.alfresco.repo.node.NodeServicePolicies.BeforeAddAspectPolicy#beforeAddAspect(org.alfresco.service.cmr.repository.NodeRef,
+ * org.alfresco.service.namespace.QName)
+ */
+ @Override
+ @Behaviour(kind = BehaviourKind.CLASS, notificationFrequency = NotificationFrequency.FIRST_EVENT)
+ public void beforeAddAspect(final NodeRef nodeRef, final QName aspectTypeQName)
+ {
+ AuthenticationUtil.runAs(new RunAsWork()
+ {
+ @Override
+ public Void doWork()
+ {
+ String sharedId = (String) nodeService.getProperty(nodeRef, QuickShareModel.PROP_QSHARE_SHAREDID);
+ if (sharedId != null)
+ {
+ quickShareService.unshareContent(sharedId);
+ }
+
+ return null;
+ }
+ }, AuthenticationUtil.getSystemUserName());
+ }
}
diff --git a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/record/CreateInplaceRecordTest.java b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/record/CreateInplaceRecordTest.java
index e5f5137695..d8b3a918ba 100644
--- a/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/record/CreateInplaceRecordTest.java
+++ b/rm-community/rm-community-repo/test/java/org/alfresco/module/org_alfresco_module_rm/test/integration/record/CreateInplaceRecordTest.java
@@ -27,12 +27,14 @@
package org.alfresco.module.org_alfresco_module_rm.test.integration.record;
+import org.alfresco.model.QuickShareModel;
import org.alfresco.module.org_alfresco_module_rm.capability.RMPermissionModel;
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
import org.alfresco.service.cmr.model.FileExistsException;
import org.alfresco.service.cmr.model.FileNotFoundException;
+import org.alfresco.service.cmr.quickshare.QuickShareService;
import org.alfresco.service.cmr.security.AccessStatus;
/**
@@ -42,12 +44,25 @@ import org.alfresco.service.cmr.security.AccessStatus;
*/
public class CreateInplaceRecordTest extends BaseRMTestCase
{
+ private QuickShareService quickShareService;
+
@Override
protected boolean isCollaborationSiteTest()
{
return true;
}
+ /**
+ * @see org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase#initServices()
+ */
+ @Override
+ protected void initServices()
+ {
+ super.initServices();
+
+ quickShareService = (QuickShareService) applicationContext.getBean("quickShareService");
+ }
+
/**
* Given a document in a collaboration site
* When the document is declared by a site collaborator
@@ -185,4 +200,49 @@ public class CreateInplaceRecordTest extends BaseRMTestCase
}
});
}
+
+ /**
+ * Given a shared document in a collaboration site
+ * When the document is declared as record by a site collaborator
+ * Then the document becomes a record and is not shared anymore
+ */
+ public void testCreateInplaceRecordFromCollabSiteRemovesSharedLink()
+ {
+ doBehaviourDrivenTest(new BehaviourDrivenTest()
+ {
+ public void given()
+ {
+ // Check that the document is not a record
+ assertFalse("The document should not be a record", recordService.isRecord(dmDocument));
+
+ quickShareService.shareContent(dmDocument);
+ // Check the document is shared
+ assertTrue("The document is shared", nodeService.hasAspect(dmDocument, QuickShareModel.ASPECT_QSHARE));
+ }
+
+ public void when()
+ {
+ // Declare the document as a record
+ AuthenticationUtil.runAs(new RunAsWork()
+ {
+ public Void doWork() throws Exception
+ {
+ // Declare record
+ recordService.createRecord(filePlan, dmDocument);
+
+ return null;
+ }
+ }, dmCollaborator);
+ }
+
+ public void then()
+ {
+ // Check that the document is a record now
+ assertTrue("The document should now be a record", recordService.isRecord(dmDocument));
+
+ // Check that the record is not shared anymore
+ assertFalse("The document should not be shared anymore", nodeService.hasAspect(dmDocument, QuickShareModel.ASPECT_QSHARE));
+ }
+ });
+ }
}