diff --git a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-service-context.xml b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-service-context.xml index 4a921877a2..937a12005d 100644 --- a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-service-context.xml +++ b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-service-context.xml @@ -839,8 +839,6 @@ diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/action/dm/CreateRecordAction.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/action/dm/CreateRecordAction.java index be3d6570f9..6da56869ab 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/action/dm/CreateRecordAction.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/action/dm/CreateRecordAction.java @@ -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 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 params) diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/permission/RecordReadersDynamicAuthority.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/permission/RecordReadersDynamicAuthority.java index d8d63a64e6..0b3452e7bf 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/permission/RecordReadersDynamicAuthority.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/permission/RecordReadersDynamicAuthority.java @@ -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 readers = (Set)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 readers = (List)nodeService.getProperty(nodeRef, PROP_READERS); + for (String reader : readers) + { + if (reader.startsWith("GROUP_") == true) + { + Set 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; } diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/record/RecordService.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/record/RecordService.java index e311a3071e..90746b8511 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/record/RecordService.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/record/RecordService.java @@ -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); diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/record/RecordServiceImpl.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/record/RecordServiceImpl.java index 4f0425d8a2..839611cf91 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/record/RecordServiceImpl.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/record/RecordServiceImpl.java @@ -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() { - 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 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 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; +// } /** * diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/RecordServiceTestImpl.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/RecordServiceTestImpl.java new file mode 100644 index 0000000000..d9cd74d926 --- /dev/null +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/RecordServiceTestImpl.java @@ -0,0 +1,166 @@ +/* + * Copyright (C) 2005-2011 Alfresco Software Limited. + * + * This file is part of Alfresco + * + * 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 . + */ +package org.alfresco.module.org_alfresco_module_rm.test.service; + +import org.alfresco.model.ContentModel; +import org.alfresco.module.org_alfresco_module_rm.action.dm.CreateRecordAction; +import org.alfresco.module.org_alfresco_module_rm.capability.RMPermissionModel; +import org.alfresco.module.org_alfresco_module_rm.permission.RecordReadersDynamicAuthority; +import org.alfresco.module.org_alfresco_module_rm.test.util.BaseRMTestCase; +import org.alfresco.repo.security.authentication.AuthenticationUtil; +import org.alfresco.repo.site.SiteModel; +import org.alfresco.repo.site.SiteServiceImpl; +import org.alfresco.service.cmr.action.Action; +import org.alfresco.service.cmr.action.ActionService; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.security.AccessStatus; +import org.alfresco.service.cmr.security.PermissionService; +import org.alfresco.service.cmr.site.SiteInfo; +import org.alfresco.service.cmr.site.SiteService; +import org.alfresco.service.cmr.site.SiteVisibility; +import org.alfresco.service.cmr.tagging.TaggingService; +import org.alfresco.util.GUID; + +/** + * Record service implementation unit test. + * + * @author Roy Wetherall + */ +public class RecordServiceTestImpl extends BaseRMTestCase +{ + protected static final String COLLABORATION_SITE_ID = "collab-site-id"; + + protected ActionService dmActionService; + protected TaggingService taggingService; + protected PermissionService dmPermissionService; + + protected SiteInfo collaborationSite; + protected NodeRef documentLibrary; + protected NodeRef dmFolder; + protected NodeRef dmDocument; + + protected String dmUserName; + protected NodeRef dmUserPerson; + + @Override + protected void initServices() + { + super.initServices(); + + dmActionService = (ActionService)applicationContext.getBean("ActionService"); + taggingService = (TaggingService)applicationContext.getBean("TaggingService"); + dmPermissionService = (PermissionService)applicationContext.getBean("PermissionService"); + } + + @Override + protected boolean isUserTest() + { + return true; + } + + @Override + protected void setupTestData() + { + super.setupTestData(); + + doTestInTransaction(new Test() + { + public Void run() + { + setupCollaborationSiteTestDataImpl(); + return null; + } + }, + AuthenticationUtil.getSystemUserName()); + } + + protected void setupCollaborationSiteTestDataImpl() + { + // create collaboration site + collaborationSite = siteService.createSite("preset", COLLABORATION_SITE_ID, "title", "description", SiteVisibility.PRIVATE); + documentLibrary = SiteServiceImpl.getSiteContainer( + COLLABORATION_SITE_ID, + SiteService.DOCUMENT_LIBRARY, + true, + siteService, + transactionService, + taggingService); + + assertNotNull("Collaboration site document library component was not successfully created.", documentLibrary); + + // create a folder and documents + dmFolder = fileFolderService.create(documentLibrary, "collabFolder", ContentModel.TYPE_FOLDER).getNodeRef(); + dmDocument = fileFolderService.create(dmFolder, "collabDocument.txt", ContentModel.TYPE_CONTENT).getNodeRef(); + } + + @Override + protected void setupTestUsersImpl(NodeRef filePlan) + { + super.setupTestUsersImpl(filePlan); + + dmUserName = GUID.generate(); + dmUserPerson = createPerson(dmUserName); + siteService.setMembership(COLLABORATION_SITE_ID, dmUserName, SiteModel.SITE_COLLABORATOR); + } + + @Override + protected void tearDownImpl() + { + super.tearDownImpl(); + siteService.deleteSite(COLLABORATION_SITE_ID); + } + + public void testCreateRecordAction() + { + doTestInTransaction(new Test() + { + public Void run() + { + //assertFalse(rmService.isRecord(dmDocument)); + + assertEquals(AccessStatus.DENIED, dmPermissionService.hasPermission(dmDocument, RMPermissionModel.READ_RECORDS)); + assertEquals(AccessStatus.DENIED, dmPermissionService.hasPermission(filePlan, RMPermissionModel.VIEW_RECORDS)); + + Action action = dmActionService.createAction(CreateRecordAction.NAME); + dmActionService.executeAction(action, dmDocument); + + return null; + } + + public void test(Void result) throws Exception + { + assertEquals(AccessStatus.ALLOWED, dmPermissionService.hasPermission(dmDocument, RMPermissionModel.READ_RECORDS)); + assertEquals(AccessStatus.ALLOWED, dmPermissionService.hasPermission(filePlan, RMPermissionModel.VIEW_RECORDS)); + + assertTrue(rmService.isRecord(dmDocument)); + }; + }, + dmUserName); + + doTestInTransaction(new Test() + { + public Void run() + { + + return null; + } + }); + } + +} diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/RecordsManagementServiceImplTest.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/RecordsManagementServiceImplTest.java index fad5ec9ac2..c342b1011f 100644 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/RecordsManagementServiceImplTest.java +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/service/RecordsManagementServiceImplTest.java @@ -21,7 +21,6 @@ package org.alfresco.module.org_alfresco_module_rm.test.service; import java.util.List; import java.util.Set; -import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.module.org_alfresco_module_rm.FilePlanComponentKind; import org.alfresco.module.org_alfresco_module_rm.RecordsManagementService; import org.alfresco.module.org_alfresco_module_rm.dod5015.DOD5015Model; @@ -612,46 +611,6 @@ public class RecordsManagementServiceImplTest extends BaseRMTestCase // TODO void testGetRecordFolders(NodeRef record); - // TODO void testIsRecordDeclared(NodeRef nodeRef); - - public void testGetNewRecordsContainer() - { - doTestInTransaction(new Test() - { - @Override - public Void run() - { - NodeRef result1 = recordService.getNewRecordContainer(filePlan); - assertNotNull(result1); - assertEquals(TYPE_NEW_RECORDS_CONTAINER, nodeService.getType(result1)); - - assertNull(recordService.getNewRecordContainer(rmContainer)); - assertNull(recordService.getNewRecordContainer(rmFolder)); - - return null; - } - }); - - // Failure: File plan with no new record container - doTestInTransaction(new FailureTest - ( - "The newly created file plan shouldn't yet have a new record container.", - AlfrescoRuntimeException.class - ) - { - @Override - public void run() - { - NodeRef newFilePlan = rmService.createFilePlan(folder, GUID.generate()); - recordService.getNewRecordContainer(newFilePlan); - } - }); - } - - public void testCreateRecord() - { - - } /********** RM2 - Multi-hierarchy record taxonomy's **********/ diff --git a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/BaseRMTestCase.java b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/BaseRMTestCase.java index 78edd70461..8dc01dd7c6 100644 --- a/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/BaseRMTestCase.java +++ b/rm-server/test/java/org/alfresco/module/org_alfresco_module_rm/test/util/BaseRMTestCase.java @@ -333,9 +333,9 @@ public abstract class BaseRMTestCase extends RetryingTransactionHelperTestCase // check that the new records container has been created for the file plan public void test(Void arg0) throws Exception { - NodeRef newRecordsContainer = recordService.getNewRecordContainer(filePlan); - assertNotNull(newRecordsContainer); - assertEquals(TYPE_NEW_RECORDS_CONTAINER, nodeService.getType(newRecordsContainer)); + // NodeRef newRecordsContainer = recordService.getNewRecordContainer(filePlan); + // assertNotNull(newRecordsContainer); + // assertEquals(TYPE_NEW_RECORDS_CONTAINER, nodeService.getType(newRecordsContainer)); }; },