mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
RM-5309 - added behaviour bean for qshare:shared aspect and integration test
This commit is contained in:
@@ -121,6 +121,10 @@
|
||||
|
||||
<!-- rma model aspects -->
|
||||
|
||||
<bean id="rma.qShareAspect" class="org.alfresco.module.org_alfresco_module_rm.model.rma.aspect.QShareAspect" parent="rm.baseBehaviour">
|
||||
<property name="nodeService" ref="NodeService"/>
|
||||
</bean>
|
||||
|
||||
<bean id="rma.filePlanComponent" class="org.alfresco.module.org_alfresco_module_rm.model.rma.aspect.FilePlanComponentAspect" parent="rm.baseBehaviour">
|
||||
<property name="scriptService" ref="ScriptService" />
|
||||
<property name="namespaceService" ref="NamespaceService" />
|
||||
|
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Records Management Module
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2017 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* -
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
* -
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.module.org_alfresco_module_rm.model.rma.aspect;
|
||||
|
||||
import org.alfresco.module.org_alfresco_module_rm.model.BaseBehaviourBean;
|
||||
import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
|
||||
import org.alfresco.repo.node.NodeServicePolicies;
|
||||
import org.alfresco.repo.node.integrity.IntegrityException;
|
||||
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.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
/**
|
||||
* qshare:shared aspect behaviour bean
|
||||
* do not allow this aspect to be added for records
|
||||
*
|
||||
* @author Ramona Popa
|
||||
* @since 2.5
|
||||
*/
|
||||
@BehaviourBean(defaultType = "qshare:shared")
|
||||
public class QShareAspect extends BaseBehaviourBean implements NodeServicePolicies.BeforeAddAspectPolicy
|
||||
{
|
||||
private NodeService nodeService;
|
||||
|
||||
public void setNodeService(NodeService nodeService)
|
||||
{
|
||||
this.nodeService = nodeService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Behaviour to prevent sharing 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)
|
||||
{
|
||||
if (nodeService.hasAspect(nodeRef, RecordsManagementModel.ASPECT_RECORD))
|
||||
{
|
||||
throw new IntegrityException("Operation failed. Aspect " + aspectTypeQName.toString() + " cannot be added for records.", null);
|
||||
}
|
||||
}
|
||||
}
|
@@ -30,6 +30,7 @@ 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.node.integrity.IntegrityException;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
||||
import org.alfresco.service.cmr.model.FileExistsException;
|
||||
@@ -245,4 +246,45 @@ public class CreateInplaceRecordTest extends BaseRMTestCase
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a document in a collaboration site declared as record
|
||||
* When I try to share the document
|
||||
* Then it fails
|
||||
*/
|
||||
public void testRecordsFromCollabSiteCannotBeShared()
|
||||
{
|
||||
doBehaviourDrivenTest(new BehaviourDrivenTest(IntegrityException.class)
|
||||
{
|
||||
public void given()
|
||||
{
|
||||
// Check that the document is not a record
|
||||
assertFalse("The document should not be a record", recordService.isRecord(dmDocument));
|
||||
|
||||
// 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 when()
|
||||
{
|
||||
// Try to share document
|
||||
quickShareService.shareContent(dmDocument);
|
||||
}
|
||||
|
||||
public void after()
|
||||
{
|
||||
// Check that the record is not shared
|
||||
assertFalse("The document should not be shared", nodeService.hasAspect(dmDocument, QuickShareModel.ASPECT_QSHARE));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user