RM: In-place filing prototype WIP

* dynamic authority set ReadRecord permission on new record and ViewRecord capability on containing file plan
 * dynamic 'Record Readers' authority working correctly (checking whether current user is contained in the users/groups snap shoted as readers when the document was made a record)
 * unit test showing document in collab site being made a record and the existing collab user having record read permissions without being added to the RM site or given an RM role.
 * this check-in is sufficient to demonstrate that collaboration users can create records and view them without having to introduce any form of noticable mapping between the RM and Collab sites.  (relates to RM-485)



git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/DEV/INPLACE@41708 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Roy Wetherall
2012-09-18 08:16:53 +00:00
parent 7b9912626c
commit 58bb845f42
8 changed files with 284 additions and 111 deletions

View File

@@ -41,6 +41,7 @@ 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.QName;
import org.alfresco.service.namespace.RegexQNamePattern;
/**
* Creates a new record from an existing content object.
@@ -52,6 +53,8 @@ import org.alfresco.service.namespace.QName;
public class CreateRecordAction extends ActionExecuterAbstractBase
implements RecordsManagementModel
{
public static final String NAME = "create-record";
private RecordsManagementService recordsManagementService;
private RecordService recordService;
@@ -103,7 +106,7 @@ public class CreateRecordAction extends ActionExecuterAbstractBase
ChildAssociationRef parentAssoc = nodeService.getPrimaryParent(actionedUponNodeRef);
/// get the new record container for the file plan
NodeRef newRecordContainer = recordService.getNewRecordContainer(filePlan);
NodeRef newRecordContainer = getNewRecordContainer(filePlan);
if (newRecordContainer == null)
{
throw new AlfrescoRuntimeException("Unable to create record, because new record container could not be found.");
@@ -127,6 +130,10 @@ public class CreateRecordAction extends ActionExecuterAbstractBase
RecordReadersDynamicAuthority.RECORD_READERS,
RMPermissionModel.READ_RECORDS,
true);
permissionService.setPermission(filePlan,
RecordReadersDynamicAuthority.RECORD_READERS,
RMPermissionModel.VIEW_RECORDS,
true);
return null;
}
@@ -137,6 +144,16 @@ public class CreateRecordAction extends ActionExecuterAbstractBase
throw new AlfrescoRuntimeException("Unable to file file plan.");
}
}
private NodeRef getNewRecordContainer(NodeRef filePlan)
{
List<ChildAssociationRef> assocs = nodeService.getChildAssocs(filePlan, ASSOC_NEW_RECORDS, RegexQNamePattern.MATCH_ALL);
if (assocs.size() != 1)
{
throw new AlfrescoRuntimeException("Error getting the new record container, because the container cannot be indentified.");
}
return assocs.get(0).getChildRef();
}
@Override
protected void addParameterDefinitions(List<ParameterDefinition> params)

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2005-2012 Alfresco Software Limited.
` * Copyright (C) 2005-2012 Alfresco Software Limited.
*
* This file is part of Alfresco
*
@@ -18,6 +18,7 @@
*/
package org.alfresco.module.org_alfresco_module_rm.permission;
import java.util.List;
import java.util.Set;
import org.alfresco.module.org_alfresco_module_rm.FilePlanComponentKind;
@@ -28,6 +29,7 @@ import org.alfresco.repo.security.permissions.PermissionReference;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.security.AuthorityService;
import org.alfresco.service.cmr.security.AuthorityType;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
@@ -104,17 +106,39 @@ public class RecordReadersDynamicAuthority implements DynamicAuthority, RecordsM
{
if (getNodeService().hasAspect(nodeRef, ASPECT_EXTENDED_RECORD_SECURITY) == true)
{
result = true;
System.out.println("Setting hasAuthority to true! - " + userName + " - " + nodeRef.toString());
// Set<String> readers = (Set<String>)nodeService.getProperty(nodeRef, PROP_READERS);
// for (String reader : readers)
// {
// // check to see if the user is one of the readers or is contained there within
// }
List<String> readers = (List<String>)nodeService.getProperty(nodeRef, PROP_READERS);
for (String reader : readers)
{
if (reader.startsWith("GROUP_") == true)
{
Set<String> contained = getAuthorityService().getContainedAuthorities(AuthorityType.USER, reader, false);
if (contained.isEmpty() == false &&
contained.contains(userName) == true)
{
System.out.println("User " + userName + " is contained in the read group " + reader);
result = true;
break;
}
}
else
{
// presume we have a user
if (reader.equals(userName) == true)
{
System.out.println("User " + userName + " matches read user " + reader);
result = true;
break;
}
}
}
}
}
else if (FilePlanComponentKind.FILE_PLAN.equals(kind) == true)
{
result = true;
}
return result;
}

View File

@@ -49,9 +49,9 @@ public interface RecordService
// TODO boolean isRecordFiled(NodeRef record);
// TODO boolean isRecordClassified(NodeRef record);
NodeRef getNewRecordContainer(NodeRef filePlan);
// NodeRef getNewRecordContainer(NodeRef filePlan);
NodeRef createRecord(NodeRef filePlan, NodeRef document);
//NodeRef createRecord(NodeRef filePlan, NodeRef document);
// TODO NodeRef createAndFileRecord(NodeRef recordFolder, NodeRef document);

View File

@@ -20,7 +20,6 @@ package org.alfresco.module.org_alfresco_module_rm.record;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.alfresco.error.AlfrescoRuntimeException;
@@ -31,6 +30,8 @@ import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel;
import org.alfresco.repo.policy.JavaBehaviour;
import org.alfresco.repo.policy.PolicyComponent;
import org.alfresco.repo.policy.Behaviour.NotificationFrequency;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
import org.alfresco.service.cmr.dictionary.AspectDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
@@ -38,7 +39,6 @@ import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.namespace.RegexQNamePattern;
/**
* @author Roy Wetherall
@@ -93,22 +93,31 @@ public class RecordServiceImpl implements RecordService, RecordsManagementModel
new JavaBehaviour(this, "onCreateNewRecord", NotificationFrequency.TRANSACTION_COMMIT));
}
public void onCreateNewRecord(ChildAssociationRef childAssocRef, boolean bNew)
public void onCreateNewRecord(final ChildAssociationRef childAssocRef, boolean bNew)
{
NodeRef nodeRef = childAssocRef.getChildRef();
if (nodeService.exists(nodeRef) == true)
AuthenticationUtil.runAsSystem(new RunAsWork<Void>()
{
QName type = nodeService.getType(nodeRef);
if (ContentModel.TYPE_CONTENT.equals(type) == true ||
dictionaryService.isSubClass(type, ContentModel.TYPE_CONTENT) == true)
@Override
public Void doWork() throws Exception
{
makeRecord(nodeRef);
}
else
{
throw new AlfrescoRuntimeException("Only content can be created as a record.");
}
}
NodeRef nodeRef = childAssocRef.getChildRef();
if (nodeService.exists(nodeRef) == true)
{
QName type = nodeService.getType(nodeRef);
if (ContentModel.TYPE_CONTENT.equals(type) == true ||
dictionaryService.isSubClass(type, ContentModel.TYPE_CONTENT) == true)
{
makeRecord(nodeRef);
}
else
{
throw new AlfrescoRuntimeException("Only content can be created as a record.");
}
}
return null;
}
});
}
/**
@@ -147,44 +156,44 @@ public class RecordServiceImpl implements RecordService, RecordsManagementModel
/**
* @see org.alfresco.module.org_alfresco_module_rm.record.RecordService#getNewRecordContainer(org.alfresco.service.cmr.repository.NodeRef)
*/
public NodeRef getNewRecordContainer(NodeRef filePlan)
{
NodeRef result = null;
if (recordsManagementService.isFilePlan(filePlan) == true)
{
List<ChildAssociationRef> assocs = nodeService.getChildAssocs(filePlan, ASSOC_NEW_RECORDS, RegexQNamePattern.MATCH_ALL);
if (assocs.size() != 1)
{
throw new AlfrescoRuntimeException("Error getting the new record container, because the container cannot be indentified.");
}
result = assocs.get(0).getChildRef();
}
return result;
}
// public NodeRef getNewRecordContainer(NodeRef filePlan)
// {
// NodeRef result = null;
//
// if (recordsManagementService.isFilePlan(filePlan) == true)
// {
// List<ChildAssociationRef> assocs = nodeService.getChildAssocs(filePlan, ASSOC_NEW_RECORDS, RegexQNamePattern.MATCH_ALL);
// if (assocs.size() != 1)
// {
// throw new AlfrescoRuntimeException("Error getting the new record container, because the container cannot be indentified.");
// }
// result = assocs.get(0).getChildRef();
// }
//
// return result;
// }
@Override
public NodeRef createRecord(NodeRef filePlan, NodeRef document)
{
// get the documents primary parent assoc
ChildAssociationRef parentAssoc = nodeService.getPrimaryParent(document);
/// get the new record container for the file plan
NodeRef newRecordContainer = getNewRecordContainer(filePlan);
if (newRecordContainer == null)
{
throw new AlfrescoRuntimeException("Unable to create record, because new record container could not be found.");
}
// move the document into the file plan
nodeService.moveNode(document, newRecordContainer, ContentModel.ASSOC_CONTAINS, parentAssoc.getQName());
// maintain the original primary location
nodeService.addChild(parentAssoc.getParentRef(), document, parentAssoc.getTypeQName(), parentAssoc.getQName());
return document;
}
// @Override
// public NodeRef createRecord(NodeRef filePlan, NodeRef document)
// {
// // get the documents primary parent assoc
// ChildAssociationRef parentAssoc = nodeService.getPrimaryParent(document);
//
// /// get the new record container for the file plan
// NodeRef newRecordContainer = getNewRecordContainer(filePlan);
// if (newRecordContainer == null)
// {
// throw new AlfrescoRuntimeException("Unable to create record, because new record container could not be found.");
// }
//
// // move the document into the file plan
// nodeService.moveNode(document, newRecordContainer, ContentModel.ASSOC_CONTAINS, parentAssoc.getQName());
//
// // maintain the original primary location
// nodeService.addChild(parentAssoc.getParentRef(), document, parentAssoc.getTypeQName(), parentAssoc.getQName());
//
// return document;
// }
/**
*