Merge branch 'merge/20170620_RM25' into 'master'

Merge/20170620 rm25

See merge request !360
This commit is contained in:
Tuna Aksoy
2017-06-21 10:34:57 +01:00
3 changed files with 109 additions and 6 deletions

View File

@@ -138,6 +138,7 @@
<property name="extendedSecurityService" ref="ExtendedSecurityService" /> <property name="extendedSecurityService" ref="ExtendedSecurityService" />
<property name="recordService" ref="RecordService" /> <property name="recordService" ref="RecordService" />
<property name="dispositionService" ref="DispositionService" /> <property name="dispositionService" ref="DispositionService" />
<property name="quickShareService" ref="QuickShareService"/>
</bean> </bean>
<bean id="rma.recordComponentIdentifier" class="org.alfresco.module.org_alfresco_module_rm.model.rma.aspect.RecordComponentIdentifierAspect" parent="rm.baseBehaviour"> <bean id="rma.recordComponentIdentifier" class="org.alfresco.module.org_alfresco_module_rm.model.rma.aspect.RecordComponentIdentifierAspect" parent="rm.baseBehaviour">

View File

@@ -33,6 +33,7 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import org.alfresco.model.ContentModel; 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.RecordsManagementPolicies;
import org.alfresco.module.org_alfresco_module_rm.model.behaviour.AbstractDisposableItem; import org.alfresco.module.org_alfresco_module_rm.model.behaviour.AbstractDisposableItem;
import org.alfresco.module.org_alfresco_module_rm.record.RecordService; import org.alfresco.module.org_alfresco_module_rm.record.RecordService;
@@ -48,7 +49,9 @@ import org.alfresco.repo.policy.Behaviour.NotificationFrequency;
import org.alfresco.repo.policy.annotation.Behaviour; import org.alfresco.repo.policy.annotation.Behaviour;
import org.alfresco.repo.policy.annotation.BehaviourBean; import org.alfresco.repo.policy.annotation.BehaviourBean;
import org.alfresco.repo.policy.annotation.BehaviourKind; 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.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.ChildAssociationRef;
import org.alfresco.service.cmr.repository.ContentData; import org.alfresco.service.cmr.repository.ContentData;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
@@ -68,6 +71,7 @@ import org.springframework.extensions.surf.util.I18NUtil;
) )
public class RecordAspect extends AbstractDisposableItem public class RecordAspect extends AbstractDisposableItem
implements NodeServicePolicies.OnCreateChildAssociationPolicy, implements NodeServicePolicies.OnCreateChildAssociationPolicy,
NodeServicePolicies.BeforeAddAspectPolicy,
RecordsManagementPolicies.OnCreateReference, RecordsManagementPolicies.OnCreateReference,
RecordsManagementPolicies.OnRemoveReference, RecordsManagementPolicies.OnRemoveReference,
NodeServicePolicies.OnMoveNodePolicy, NodeServicePolicies.OnMoveNodePolicy,
@@ -87,6 +91,9 @@ public class RecordAspect extends AbstractDisposableItem
/** record service */ /** record service */
protected RecordService recordService; protected RecordService recordService;
/** quickShare service */
private QuickShareService quickShareService;
/** I18N */ /** I18N */
private static final String MSG_CANNOT_UPDATE_RECORD_CONTENT = "rm.service.update-record-content"; private static final String MSG_CANNOT_UPDATE_RECORD_CONTENT = "rm.service.update-record-content";
@@ -114,6 +121,15 @@ public class RecordAspect extends AbstractDisposableItem
this.recordService = recordService; this.recordService = recordService;
} }
/**
*
* @param quickShareService
*/
public void setQuickShareService(QuickShareService quickShareService)
{
this.quickShareService = quickShareService;
}
/** /**
* Behaviour to ensure renditions have the appropriate extended security. * Behaviour to ensure renditions have the appropriate extended security.
* *
@@ -169,7 +185,7 @@ public class RecordAspect extends AbstractDisposableItem
// Deal with versioned records // Deal with versioned records
if (reference.equals(CUSTOM_REF_VERSIONS)) if (reference.equals(CUSTOM_REF_VERSIONS))
{ {
// run as system, to apply the versioned aspect to the from node // run as system, to apply the versioned aspect to the from node
// as we can't be sure if the user has add aspect rights // as we can't be sure if the user has add aspect rights
authenticationUtil.runAsSystem(new RunAsWork<Void>() authenticationUtil.runAsSystem(new RunAsWork<Void>()
{ {
@@ -318,7 +334,7 @@ public class RecordAspect extends AbstractDisposableItem
/** /**
* On copy complete behaviour for record aspect. * On copy complete behaviour for record aspect.
* *
* @param classRef * @param classRef
* @param sourceNodeRef * @param sourceNodeRef
* @param targetNodeRef * @param targetNodeRef
@@ -330,9 +346,9 @@ public class RecordAspect extends AbstractDisposableItem
( (
kind = BehaviourKind.CLASS kind = BehaviourKind.CLASS
) )
public void onCopyComplete(QName classRef, public void onCopyComplete(QName classRef,
NodeRef sourceNodeRef, NodeRef sourceNodeRef,
NodeRef targetNodeRef, NodeRef targetNodeRef,
boolean copyToNewNode, boolean copyToNewNode,
Map<NodeRef, NodeRef> copyMap) Map<NodeRef, NodeRef> copyMap)
{ {
@@ -342,7 +358,7 @@ public class RecordAspect extends AbstractDisposableItem
{ {
// then remove any extended security from the newly copied record // then remove any extended security from the newly copied record
extendedSecurityService.remove(targetNodeRef); extendedSecurityService.remove(targetNodeRef);
} }
} }
@Override @Override
@@ -359,4 +375,30 @@ public class RecordAspect extends AbstractDisposableItem
throw new IntegrityException(I18NUtil.getMessage(MSG_CANNOT_UPDATE_RECORD_CONTENT), null); throw new IntegrityException(I18NUtil.getMessage(MSG_CANNOT_UPDATE_RECORD_CONTENT), null);
} }
} }
/**
* 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<Void>()
{
@Override
public Void doWork()
{
String sharedId = (String) nodeService.getProperty(nodeRef, QuickShareModel.PROP_QSHARE_SHAREDID);
if (sharedId != null)
{
quickShareService.unshareContent(sharedId);
}
return null;
}
}, AuthenticationUtil.getSystemUserName());
}
} }

View File

@@ -27,12 +27,14 @@
package org.alfresco.module.org_alfresco_module_rm.test.integration.record; 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.capability.RMPermissionModel;
import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase; 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;
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork; import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
import org.alfresco.service.cmr.model.FileExistsException; import org.alfresco.service.cmr.model.FileExistsException;
import org.alfresco.service.cmr.model.FileNotFoundException; import org.alfresco.service.cmr.model.FileNotFoundException;
import org.alfresco.service.cmr.quickshare.QuickShareService;
import org.alfresco.service.cmr.security.AccessStatus; import org.alfresco.service.cmr.security.AccessStatus;
/** /**
@@ -42,12 +44,25 @@ import org.alfresco.service.cmr.security.AccessStatus;
*/ */
public class CreateInplaceRecordTest extends BaseRMTestCase public class CreateInplaceRecordTest extends BaseRMTestCase
{ {
private QuickShareService quickShareService;
@Override @Override
protected boolean isCollaborationSiteTest() protected boolean isCollaborationSiteTest()
{ {
return true; 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 * Given a document in a collaboration site
* When the document is declared by a site collaborator * 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<Void>()
{
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));
}
});
}
} }