From 9f2b174a233afd6d836ca66294228ef5171bbd17 Mon Sep 17 00:00:00 2001 From: Roy Wetherall Date: Mon, 1 Dec 2014 00:48:51 +0000 Subject: [PATCH] RM-1763: Record Contributors Group * if configured, RECORD_CONTRIBUTOR group controls who can declare records within collaboration sites git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@91414 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../alfresco-global.properties | 6 + .../org_alfresco_module_rm/module-context.xml | 11 +- .../patch/rm-patch-context.xml | 3 +- .../patch/rm-patch-v23-context.xml | 17 +++ .../rm-ui-evaluators-context.xml | 8 +- .../BootstrapImporterModuleComponent.java | 14 +++ ...rdContributorsGroupBootstrapComponent.java | 73 ++++++++++++ .../capability/RMPermissionModel.java | 63 +--------- .../capability/RMSecurityCommon.java | 3 +- .../capability/policy/AssocPolicy.java | 4 +- .../capability/policy/ReadPolicy.java | 4 +- .../jscript/app/JSONConversionComponent.java | 110 +++++++++++++----- .../RMv23RecordContributorsGroupPatch.java | 53 +++++++++ .../security/FilePlanPermissionService.java | 3 +- .../util/AuthenticationUtil.java | 13 ++- ...tstrapImporterModuleComponentUnitTest.java | 94 +++++++++++++++ ...butorsGroupBootstrapComponentUnitTest.java | 83 +++++++++++++ .../test/AllUnitTestSuite.java | 8 +- 18 files changed, 469 insertions(+), 101 deletions(-) create mode 100644 rm-server/config/alfresco/module/org_alfresco_module_rm/patch/rm-patch-v23-context.xml create mode 100644 rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/bootstrap/RecordContributorsGroupBootstrapComponent.java create mode 100644 rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/patch/v23/RMv23RecordContributorsGroupPatch.java create mode 100644 rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/bootstrap/BootstrapImporterModuleComponentUnitTest.java create mode 100644 rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/bootstrap/RecordContributorsGroupBootstrapComponentUnitTest.java diff --git a/rm-server/config/alfresco/module/org_alfresco_module_rm/alfresco-global.properties b/rm-server/config/alfresco/module/org_alfresco_module_rm/alfresco-global.properties index 60f0b0e0d6..c7169d02b6 100644 --- a/rm-server/config/alfresco/module/org_alfresco_module_rm/alfresco-global.properties +++ b/rm-server/config/alfresco/module/org_alfresco_module_rm/alfresco-global.properties @@ -47,3 +47,9 @@ rm.autocompletesuggestion.nodeParameterSuggester.aspectsAndTypes=rma:record,cm:c # Global RM disposition lifecycle trigger cron job expression # rm.dispositionlifecycletrigger.cronexpression=0 0/5 * * * ? + +# +# Records contributors group +# +rm.record.contributors.group.enabled=false +rm.record.contributors.group.name=RECORD_CONTRIBUTORS diff --git a/rm-server/config/alfresco/module/org_alfresco_module_rm/module-context.xml b/rm-server/config/alfresco/module/org_alfresco_module_rm/module-context.xml index e17a8c3935..4e1ff359ae 100644 --- a/rm-server/config/alfresco/module/org_alfresco_module_rm/module-context.xml +++ b/rm-server/config/alfresco/module/org_alfresco_module_rm/module-context.xml @@ -16,6 +16,7 @@ parent="module.baseComponent"> + @@ -32,6 +33,13 @@ + + + + + + @@ -49,7 +57,8 @@ - + + diff --git a/rm-server/config/alfresco/module/org_alfresco_module_rm/patch/rm-patch-context.xml b/rm-server/config/alfresco/module/org_alfresco_module_rm/patch/rm-patch-context.xml index 8b43fd854c..b6c366bd9d 100755 --- a/rm-server/config/alfresco/module/org_alfresco_module_rm/patch/rm-patch-context.xml +++ b/rm-server/config/alfresco/module/org_alfresco_module_rm/patch/rm-patch-context.xml @@ -9,7 +9,7 @@ - + @@ -31,6 +31,7 @@ + diff --git a/rm-server/config/alfresco/module/org_alfresco_module_rm/patch/rm-patch-v23-context.xml b/rm-server/config/alfresco/module/org_alfresco_module_rm/patch/rm-patch-v23-context.xml new file mode 100644 index 0000000000..53a2078c63 --- /dev/null +++ b/rm-server/config/alfresco/module/org_alfresco_module_rm/patch/rm-patch-v23-context.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-ui-evaluators-context.xml b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-ui-evaluators-context.xml index e8d253c91f..6598830591 100644 --- a/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-ui-evaluators-context.xml +++ b/rm-server/config/alfresco/module/org_alfresco_module_rm/rm-ui-evaluators-context.xml @@ -6,8 +6,12 @@ - + + + diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/bootstrap/BootstrapImporterModuleComponent.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/bootstrap/BootstrapImporterModuleComponent.java index 1daccbddeb..f204829fe6 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/bootstrap/BootstrapImporterModuleComponent.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/bootstrap/BootstrapImporterModuleComponent.java @@ -40,6 +40,9 @@ public class BootstrapImporterModuleComponent extends ImporterModuleComponent /** module patch executer */ private ModulePatchExecuter modulePatchExecuter; + + /** record contributors group bootstrap component */ + private RecordContributorsGroupBootstrapComponent recordContributorsGroupBootstrapComponent; /** * @param nodeService node service @@ -57,6 +60,14 @@ public class BootstrapImporterModuleComponent extends ImporterModuleComponent this.modulePatchExecuter = modulePatchExecuter; } + /** + * @param recordContributorsGroupBootstrapComponent record contributors group bootstrap component + */ + public void setRecordContributorsGroupBootstrapComponent(RecordContributorsGroupBootstrapComponent recordContributorsGroupBootstrapComponent) + { + this.recordContributorsGroupBootstrapComponent = recordContributorsGroupBootstrapComponent; + } + /** * Need to check whether this module has already been executed. * @@ -69,6 +80,9 @@ public class BootstrapImporterModuleComponent extends ImporterModuleComponent if (!nodeService.exists(nodeRef)) { super.executeInternal(); + + // bootstrap the record contributors group + recordContributorsGroupBootstrapComponent.createRecordContributorsGroup(); // init module schema number modulePatchExecuter.initSchemaVersion(); diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/bootstrap/RecordContributorsGroupBootstrapComponent.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/bootstrap/RecordContributorsGroupBootstrapComponent.java new file mode 100644 index 0000000000..14482708b4 --- /dev/null +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/bootstrap/RecordContributorsGroupBootstrapComponent.java @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2005-2014 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.bootstrap; + +import org.alfresco.module.org_alfresco_module_rm.util.AuthenticationUtil; +import org.alfresco.service.cmr.security.AuthorityService; +import org.alfresco.service.cmr.security.AuthorityType; + +/** + * Record contributors group bootstrap component + * + * @author Roy Wetherall + * @since 2.3 + */ +public class RecordContributorsGroupBootstrapComponent +{ + // default record contributors group + public static final String RECORD_CONTRIBUTORS = "RECORD_CONTRIBUTORS"; + public static final String GROUP_RECORD_CONTRIBUTORS = "GROUP_" + RECORD_CONTRIBUTORS; + + /** authority service */ + private AuthorityService authorityService; + + /** authentication utils */ + private AuthenticationUtil authenticationUtil; + + /** + * @param authorityService authority service + */ + public void setAuthorityService(AuthorityService authorityService) + { + this.authorityService = authorityService; + } + + /** + * @param authenticationUtil authentication util + */ + public void setAuthenticationUtil(AuthenticationUtil authenticationUtil) + { + this.authenticationUtil = authenticationUtil; + } + + /** + * Create record contributor group + */ + public void createRecordContributorsGroup() + { + if (!authorityService.authorityExists(GROUP_RECORD_CONTRIBUTORS)) + { + // create record contributors group + authorityService.createAuthority(AuthorityType.GROUP, RECORD_CONTRIBUTORS); + + // add the admin user + authorityService.addAuthority(GROUP_RECORD_CONTRIBUTORS, authenticationUtil.getAdminUserName()); + } + } +} diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/capability/RMPermissionModel.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/capability/RMPermissionModel.java index b229e2fa35..f002c507d5 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/capability/RMPermissionModel.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/capability/RMPermissionModel.java @@ -63,124 +63,65 @@ public interface RMPermissionModel String ROLE_ADMINISTRATOR = SimplePermissionReference.getPermissionReference(RecordsManagementModel.ASPECT_FILE_PLAN_COMPONENT, FilePlanRoleService.ROLE_ADMIN).toString(); // Capability permissions - String DECLARE_RECORDS = "DeclareRecords"; - - String VIEW_RECORDS = "ViewRecords"; - + String VIEW_RECORDS = "ViewRecords"; String CREATE_MODIFY_DESTROY_FOLDERS = "CreateModifyDestroyFolders"; - String EDIT_RECORD_METADATA = "EditRecordMetadata"; - String EDIT_NON_RECORD_METADATA = "EditNonRecordMetadata"; - String ADD_MODIFY_EVENT_DATES = "AddModifyEventDates"; - String CLOSE_FOLDERS = "CloseFolders"; - String DECLARE_RECORDS_IN_CLOSED_FOLDERS = "DeclareRecordsInClosedFolders"; - String RE_OPEN_FOLDERS = "ReOpenFolders"; - String CYCLE_VITAL_RECORDS = "CycleVitalRecords"; - String PLANNING_REVIEW_CYCLES = "PlanningReviewCycles"; - String UPDATE_TRIGGER_DATES = "UpdateTriggerDates"; - String CREATE_MODIFY_DESTROY_EVENTS = "CreateModifyDestroyEvents"; - String MANAGE_ACCESS_RIGHTS = "ManageAccessRights"; - String MOVE_RECORDS = "MoveRecords"; - String CHANGE_OR_DELETE_REFERENCES = "ChangeOrDeleteReferences"; - String DELETE_LINKS = "DeleteLinks"; - String EDIT_DECLARED_RECORD_METADATA = "EditDeclaredRecordMetadata"; - String MANUALLY_CHANGE_DISPOSITION_DATES = "ManuallyChangeDispositionDates"; - String APPROVE_RECORDS_SCHEDULED_FOR_CUTOFF = "ApproveRecordsScheduledForCutoff"; - String CREATE_MODIFY_RECORDS_IN_CUTOFF_FOLDERS = "CreateModifyRecordsInCutoffFolders"; - String EXTEND_RETENTION_PERIOD_OR_FREEZE = "ExtendRetentionPeriodOrFreeze"; - String UNFREEZE = "Unfreeze"; - String VIEW_UPDATE_REASONS_FOR_FREEZE = "ViewUpdateReasonsForFreeze"; - String DESTROY_RECORDS_SCHEDULED_FOR_DESTRUCTION = "DestroyRecordsScheduledForDestruction"; - String DESTROY_RECORDS = "DestroyRecords"; - String UPDATE_VITAL_RECORD_CYCLE_INFORMATION = "UpdateVitalRecordCycleInformation"; - String UNDECLARE_RECORDS = "UndeclareRecords"; - String DECLARE_AUDIT_AS_RECORD = "DeclareAuditAsRecord"; - String DELETE_AUDIT = "DeleteAudit"; - String CREATE_MODIFY_DESTROY_TIMEFRAMES = "CreateModifyDestroyTimeframes"; - String AUTHORIZE_NOMINATED_TRANSFERS = "AuthorizeNominatedTransfers"; - String EDIT_SELECTION_LISTS = "EditSelectionLists"; - String AUTHORIZE_ALL_TRANSFERS = "AuthorizeAllTransfers"; - String CREATE_MODIFY_DESTROY_FILEPLAN_METADATA = "CreateModifyDestroyFileplanMetadata"; - String CREATE_AND_ASSOCIATE_SELECTION_LISTS = "CreateAndAssociateSelectionLists"; - String ATTACH_RULES_TO_METADATA_PROPERTIES = "AttachRulesToMetadataProperties"; - String CREATE_MODIFY_DESTROY_FILEPLAN_TYPES = "CreateModifyDestroyFileplanTypes"; - String CREATE_MODIFY_DESTROY_RECORD_TYPES = "CreateModifyDestroyRecordTypes"; - String MAKE_OPTIONAL_PARAMETERS_MANDATORY = "MakeOptionalParametersMandatory"; - String MAP_EMAIL_METADATA = "MapEmailMetadata"; - String DELETE_RECORDS = "DeleteRecords"; - String TRIGGER_AN_EVENT = "TriggerAnEvent"; - String CREATE_MODIFY_DESTROY_ROLES = "CreateModifyDestroyRoles"; - String CREATE_MODIFY_DESTROY_USERS_AND_GROUPS = "CreateModifyDestroyUsersAndGroups"; - String PASSWORD_CONTROL = "PasswordControl"; - String ENABLE_DISABLE_AUDIT_BY_TYPES = "EnableDisableAuditByTypes"; - String SELECT_AUDIT_METADATA = "SelectAuditMetadata"; - String DISPLAY_RIGHTS_REPORT = "DisplayRightsReport"; - String ACCESS_AUDIT = "AccessAudit"; - String EXPORT_AUDIT = "ExportAudit"; - String CREATE_MODIFY_DESTROY_REFERENCE_TYPES = "CreateModifyDestroyReferenceTypes"; - String UPDATE_CLASSIFICATION_DATES = "UpdateClassificationDates"; - String CREATE_MODIFY_DESTROY_CLASSIFICATION_GUIDES = "CreateModifyDestroyClassificationGuides"; - String UPGRADE_DOWNGRADE_AND_DECLASSIFY_RECORDS = "UpgradeDowngradeAndDeclassifyRecords"; - String UPDATE_EXEMPTION_CATEGORIES = "UpdateExemptionCategories"; - String MAP_CLASSIFICATION_GUIDE_METADATA = "MapClassificationGuideMetadata"; - String MANAGE_ACCESS_CONTROLS = "ManageAccessControls"; - String CREATE_HOLD = "CreateHold"; String ADD_TO_HOLD = "AddToHold"; String REMOVE_FROM_HOLD = "RemoveFromHold"; -} +} \ No newline at end of file diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/capability/RMSecurityCommon.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/capability/RMSecurityCommon.java index 0ed1312e43..c97016896c 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/capability/RMSecurityCommon.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/capability/RMSecurityCommon.java @@ -22,6 +22,7 @@ import java.util.Map; import net.sf.acegisecurity.vote.AccessDecisionVoter; +import org.alfresco.module.org_alfresco_module_rm.capability.impl.ViewRecordsCapability; import org.alfresco.module.org_alfresco_module_rm.caveat.RMCaveatConfigComponent; import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService; import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel; @@ -276,7 +277,7 @@ public class RMSecurityCommon implements ApplicationContextAware } else { - AccessStatus result = permissionService.hasPermission(filePlan, RMPermissionModel.VIEW_RECORDS); + AccessStatus result = permissionService.hasPermission(filePlan, ViewRecordsCapability.NAME); transactionCache.put(key, result); return result; } diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/capability/policy/AssocPolicy.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/capability/policy/AssocPolicy.java index 657831e395..0db6c2f053 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/capability/policy/AssocPolicy.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/capability/policy/AssocPolicy.java @@ -18,7 +18,7 @@ */ package org.alfresco.module.org_alfresco_module_rm.capability.policy; -import org.alfresco.module.org_alfresco_module_rm.capability.RMPermissionModel; +import org.alfresco.module.org_alfresco_module_rm.capability.impl.ViewRecordsCapability; import org.alfresco.service.cmr.repository.NodeRef; import org.aopalliance.intercept.MethodInvocation; @@ -32,7 +32,7 @@ public class AssocPolicy extends AbstractBasePolicy ConfigAttributeDefinition cad) { NodeRef testNodeRef = getTestNode(invocation, params, cad.getParameters().get(0), cad.isParent()); - return getCapabilityService().getCapability(RMPermissionModel.VIEW_RECORDS).evaluate(testNodeRef); + return getCapabilityService().getCapability(ViewRecordsCapability.NAME).evaluate(testNodeRef); } } \ No newline at end of file diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/capability/policy/ReadPolicy.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/capability/policy/ReadPolicy.java index decc5e51e2..d86971029e 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/capability/policy/ReadPolicy.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/capability/policy/ReadPolicy.java @@ -18,7 +18,7 @@ */ package org.alfresco.module.org_alfresco_module_rm.capability.policy; -import org.alfresco.module.org_alfresco_module_rm.capability.RMPermissionModel; +import org.alfresco.module.org_alfresco_module_rm.capability.impl.ViewRecordsCapability; import org.alfresco.service.cmr.repository.NodeRef; import org.aopalliance.intercept.MethodInvocation; @@ -38,6 +38,6 @@ public class ReadPolicy extends AbstractBasePolicy ConfigAttributeDefinition cad) { NodeRef testNodeRef = getTestNode(invocation, params, cad.getParameters().get(0), cad.isParent()); - return getCapabilityService().getCapability(RMPermissionModel.VIEW_RECORDS).evaluate(testNodeRef); + return getCapabilityService().getCapability(ViewRecordsCapability.NAME).evaluate(testNodeRef); } } \ No newline at end of file diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/jscript/app/JSONConversionComponent.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/jscript/app/JSONConversionComponent.java index 82b94f8fd0..474a6137fe 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/jscript/app/JSONConversionComponent.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/jscript/app/JSONConversionComponent.java @@ -19,11 +19,13 @@ package org.alfresco.module.org_alfresco_module_rm.jscript.app; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import org.alfresco.model.ContentModel; import org.alfresco.module.org_alfresco_module_rm.capability.CapabilityService; -import org.alfresco.module.org_alfresco_module_rm.capability.RMPermissionModel; +import org.alfresco.module.org_alfresco_module_rm.capability.impl.ViewRecordsCapability; import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanComponentKind; import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService; import org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel; @@ -53,9 +55,23 @@ import org.json.simple.JSONObject; * * @author Roy Wetherall */ -public class JSONConversionComponent extends org.alfresco.repo.jscript.app.JSONConversionComponent implements NodeServicePolicies.OnDeleteNodePolicy, - NodeServicePolicies.OnCreateNodePolicy +public class JSONConversionComponent extends org.alfresco.repo.jscript.app.JSONConversionComponent + implements NodeServicePolicies.OnDeleteNodePolicy, + NodeServicePolicies.OnCreateNodePolicy { + /** JSON values */ + private static final String IS_RM_NODE = "isRmNode"; + private static final String RM_NODE = "rmNode"; + private static final String IS_RM_SITE_CREATED = "isRmSiteCreated"; + private static final String IS_RECORD_CONTRIBUTOR_GROUP_ENABLED = "isRecordContributorGroupEnabled"; + private static final String RECORD_CONTRIBUTOR_GROUP_NAME = "recordContributorGroupName"; + + /** true if record contributor group is enabled, false otherwise */ + private boolean isRecordContributorsGroupEnabled = false; + + /** record contributors group */ + private String recordContributorsGroupName = "RECORD_CONTRIBUTORS"; + /** Record service */ private RecordService recordService; @@ -86,6 +102,22 @@ public class JSONConversionComponent extends org.alfresco.repo.jscript.app.JSONC /** Constant for checking the cache */ private static final String RM_SITE_EXISTS = "rmSiteExists"; + /** + * @param enabled true if enabled, false otherwise + */ + public void setRecordContributorsGroupEnabled(boolean enabled) + { + isRecordContributorsGroupEnabled = enabled; + } + + /** + * @param recordContributorsGroupName record contributors group name + */ + public void setRecordContributorsGroupName(String recordContributorsGroupName) + { + this.recordContributorsGroupName = recordContributorsGroupName; + } + /** * @param recordService record service */ @@ -199,21 +231,25 @@ public class JSONConversionComponent extends org.alfresco.repo.jscript.app.JSONC // Set the base root values super.setRootValues(nodeInfo, rootJSONObject, useShortQNames); + // check the exisitance of the RM site checkRmSiteExistence(rootJSONObject); + + // get the record contributor information + rootJSONObject.put(IS_RECORD_CONTRIBUTOR_GROUP_ENABLED, isRecordContributorsGroupEnabled); + rootJSONObject.put(RECORD_CONTRIBUTOR_GROUP_NAME, recordContributorsGroupName); // Get the node reference for convenience NodeRef nodeRef = nodeInfo.getNodeRef(); - if (AccessStatus.ALLOWED.equals(capabilityService.getCapabilityAccessState(nodeRef, - RMPermissionModel.VIEW_RECORDS))) + if (AccessStatus.ALLOWED.equals(capabilityService.getCapabilityAccessState(nodeRef, ViewRecordsCapability.NAME))) { // Indicate whether the node is a RM object or not boolean isFilePlanComponent = filePlanService.isFilePlanComponent(nodeInfo.getNodeRef()); - rootJSONObject.put("isRmNode", isFilePlanComponent); + rootJSONObject.put(IS_RM_NODE, isFilePlanComponent); if (isFilePlanComponent) { - rootJSONObject.put("rmNode", setRmNodeValues(nodeRef, useShortQNames)); + rootJSONObject.put(RM_NODE, setRmNodeValues(nodeRef, useShortQNames)); // FIXME: Is this the right place to add the information? addInfo(nodeInfo, rootJSONObject); @@ -222,6 +258,11 @@ public class JSONConversionComponent extends org.alfresco.repo.jscript.app.JSONC } } + /** + * Checks for the existance of the RM site + * + * @param rootJSONObject the root JSON object + */ @SuppressWarnings("unchecked") private void checkRmSiteExistence(JSONObject rootJSONObject) { @@ -231,17 +272,17 @@ public class JSONConversionComponent extends org.alfresco.repo.jscript.app.JSONC if (site != null) { getJsonConversionComponentCache().put(RM_SITE_EXISTS, true); - rootJSONObject.put("isRmSiteCreated", true); + rootJSONObject.put(IS_RM_SITE_CREATED, true); } else { getJsonConversionComponentCache().put(RM_SITE_EXISTS, false); - rootJSONObject.put("isRmSiteCreated", false); + rootJSONObject.put(IS_RM_SITE_CREATED, false); } } else { - rootJSONObject.put("isRmSiteCreated", getJsonConversionComponentCache().get(RM_SITE_EXISTS)); + rootJSONObject.put(IS_RM_SITE_CREATED, getJsonConversionComponentCache().get(RM_SITE_EXISTS)); } } @@ -293,6 +334,7 @@ public class JSONConversionComponent extends org.alfresco.repo.jscript.app.JSONC if (originatingLocation != null) { + // add the originating location (if there is one) String pathSeparator = "/"; String displayPath = getDisplayPath(originatingLocation); String[] displayPathElements = displayPath.split(pathSeparator); @@ -324,12 +366,14 @@ public class JSONConversionComponent extends org.alfresco.repo.jscript.app.JSONC } /** - * @param nodeRef - * @param useShortQName - * @return + * Helper method to set the RM node values + * + * @param nodeRef node reference + * @param useShortQName indicates whether the short QName are used or not + * @return {@link JSONObject} JSON object containing values */ @SuppressWarnings("unchecked") - private JSONObject setRmNodeValues(NodeRef nodeRef, boolean useShortQName) + private JSONObject setRmNodeValues(final NodeRef nodeRef, final boolean useShortQName) { JSONObject rmNodeValues = new JSONObject(); @@ -339,20 +383,32 @@ public class JSONConversionComponent extends org.alfresco.repo.jscript.app.JSONC // Get the 'kind' of the file plan component FilePlanComponentKind kind = filePlanService.getFilePlanComponentKind(nodeRef); rmNodeValues.put("kind", kind.toString()); - - // File plan node reference - NodeRef filePlan = filePlanService.getFilePlan(nodeRef); - rmNodeValues.put("filePlan", filePlan.toString()); - - // Unfiled container node reference - NodeRef unfiledRecordContainer = filePlanService.getUnfiledContainer(filePlan); - if (unfiledRecordContainer != null) + + Map values = AuthenticationUtil.runAsSystem(new RunAsWork>() { - rmNodeValues.put("unfiledRecordContainer", unfiledRecordContainer.toString()); - rmNodeValues.put("properties", propertiesToJSON(unfiledRecordContainer, nodeService.getProperties(unfiledRecordContainer), useShortQName)); - QName type = fileFolderService.getFileInfo(unfiledRecordContainer).getType(); - rmNodeValues.put("type", useShortQName ? type.toPrefixString(namespaceService) : type.toString()); - } + public Map doWork() throws Exception + { + Map result = new HashMap(); + + // File plan node reference + NodeRef filePlan = filePlanService.getFilePlan(nodeRef); + result.put("filePlan", filePlan.toString()); + + // Unfiled container node reference + NodeRef unfiledRecordContainer = filePlanService.getUnfiledContainer(filePlan); + if (unfiledRecordContainer != null) + { + result.put("unfiledRecordContainer", unfiledRecordContainer.toString()); + result.put("properties", propertiesToJSON(unfiledRecordContainer, nodeService.getProperties(unfiledRecordContainer), useShortQName)); + QName type = fileFolderService.getFileInfo(unfiledRecordContainer).getType(); + result.put("type", useShortQName ? type.toPrefixString(namespaceService) : type.toString()); + } + + return result; + } + }); + + rmNodeValues.putAll(values); // Set the indicators array setIndicators(rmNodeValues, nodeRef); diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/patch/v23/RMv23RecordContributorsGroupPatch.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/patch/v23/RMv23RecordContributorsGroupPatch.java new file mode 100644 index 0000000000..ab9d387b53 --- /dev/null +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/patch/v23/RMv23RecordContributorsGroupPatch.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2005-2014 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.patch.v23; + +import org.alfresco.module.org_alfresco_module_rm.bootstrap.RecordContributorsGroupBootstrapComponent; +import org.alfresco.module.org_alfresco_module_rm.patch.AbstractModulePatch; + +/** + * RM v2.3 patch that creates the record contributors group. + * + * @author Roy Wetherall + * @since 2.3 + */ +public class RMv23RecordContributorsGroupPatch extends AbstractModulePatch +{ + /** record contributors group bootstrap component */ + private RecordContributorsGroupBootstrapComponent recordContributorsGroupBootstrapComponent; + + /** + * @param recordContributorsGroupBootstrapComponent record contributors group bootstrap component + */ + public void setRecordContributorsGroupBootstrapComponent(RecordContributorsGroupBootstrapComponent recordContributorsGroupBootstrapComponent) + { + this.recordContributorsGroupBootstrapComponent = recordContributorsGroupBootstrapComponent; + } + + /** + * @see org.alfresco.module.org_alfresco_module_rm.patch.AbstractModulePatch#applyInternal() + */ + @Override + public void applyInternal() + { + // create record contributors group + recordContributorsGroupBootstrapComponent.createRecordContributorsGroup(); + } + +} diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/security/FilePlanPermissionService.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/security/FilePlanPermissionService.java index 18ff94f3e4..a34b4b7da5 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/security/FilePlanPermissionService.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/security/FilePlanPermissionService.java @@ -29,8 +29,9 @@ import org.alfresco.service.cmr.repository.NodeRef; public interface FilePlanPermissionService { /** + * Setup permissions for a record category * - * @param nodeRef + * @param nodeRef record category node reference */ void setupRecordCategoryPermissions(NodeRef recordCategory); diff --git a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/util/AuthenticationUtil.java b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/util/AuthenticationUtil.java index d40dd28420..ab38e037fc 100644 --- a/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/util/AuthenticationUtil.java +++ b/rm-server/source/java/org/alfresco/module/org_alfresco_module_rm/util/AuthenticationUtil.java @@ -69,7 +69,7 @@ public class AuthenticationUtil /** * Helper method that gets the admin user name. *

- * Usefule when testing using mocks. + * Useful when testing using mocks. * * @see org.alfresco.repo.security.authentication.AuthenticationUtil#getAdminUserName() */ @@ -77,5 +77,14 @@ public class AuthenticationUtil { return org.alfresco.repo.security.authentication.AuthenticationUtil.getAdminUserName(); } - + + /** + * Helper method that gets the system user name. + * + * @see org.alfresco.repo.security.authentication.AuthenticationUtil#getSystemUserName() + */ + public String getSystemUserName() + { + return org.alfresco.repo.security.authentication.AuthenticationUtil.getSystemUserName(); + } } diff --git a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/bootstrap/BootstrapImporterModuleComponentUnitTest.java b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/bootstrap/BootstrapImporterModuleComponentUnitTest.java new file mode 100644 index 0000000000..102304dd1e --- /dev/null +++ b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/bootstrap/BootstrapImporterModuleComponentUnitTest.java @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2005-2014 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.bootstrap; + +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import org.alfresco.module.org_alfresco_module_rm.patch.ModulePatchExecuter; +import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest; +import org.alfresco.repo.importer.ImporterBootstrap; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.StoreRef; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; + +/** + * Bootstrap importer module component unit test + * + * @author Roy Wetherall + * @since 2.3 + */ +public class BootstrapImporterModuleComponentUnitTest extends BaseUnitTest +{ + /** RM config node */ + private static final NodeRef configNodeRef = new NodeRef(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, "rm_config_folder"); + + /** mocks */ + @Mock(name="importer") private ImporterBootstrap mockedImporter; + @Mock(name="modulePatchExecuter") private ModulePatchExecuter mockedModulePatchExecuter; + @Mock(name="recordContributorsGroupBootstrapComponent") private RecordContributorsGroupBootstrapComponent mockedRecordContributorsGroupBootstrapComponent; + + /** importer */ + @InjectMocks + private BootstrapImporterModuleComponent importer; + + /** + * Given that the system has already been bootstraped + * When I try and boostrap the system + * Then the system is not bootstraped again + */ + @Test + public void alreadyBootstraped() throws Throwable + { + // config node exists + doReturn(true).when(mockedNodeService).exists(configNodeRef); + + // boostrap + importer.executeInternal(); + + // not bootstraped + verify(mockedImporter, never()).bootstrap(); + verify(mockedModulePatchExecuter, never()).initSchemaVersion(); + verify(mockedRecordContributorsGroupBootstrapComponent, never()).createRecordContributorsGroup(); + } + + /** + * Given that the system has not been bootstraped + * When I try and bootstrap the system + * Then the system is bootstraped + */ + @Test + public void boostrap() throws Throwable + { + // config node does not exist + doReturn(false).when(mockedNodeService).exists(configNodeRef); + + // boostrap + importer.executeInternal(); + + // not bootstraped + verify(mockedImporter, times(1)).bootstrap(); + verify(mockedModulePatchExecuter, times(1)).initSchemaVersion(); + verify(mockedRecordContributorsGroupBootstrapComponent, times(1)).createRecordContributorsGroup(); + } +} diff --git a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/bootstrap/RecordContributorsGroupBootstrapComponentUnitTest.java b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/bootstrap/RecordContributorsGroupBootstrapComponentUnitTest.java new file mode 100644 index 0000000000..48f1d3315c --- /dev/null +++ b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/bootstrap/RecordContributorsGroupBootstrapComponentUnitTest.java @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2005-2014 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.bootstrap; + +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; + +import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest; +import org.alfresco.service.cmr.security.AuthorityType; +import org.junit.Test; +import org.mockito.InjectMocks; + +/** + * Record contributors group bootstrap component unit test + * + * @author Roy Wetherall + * @since 2.3 + */ +public class RecordContributorsGroupBootstrapComponentUnitTest extends BaseUnitTest +{ + @InjectMocks + private RecordContributorsGroupBootstrapComponent component; + + /** + * Given that the record contributors group already exists + * When I try and create the group + * Then nothing happens + */ + @Test + public void groupAlreadyExists() + { + // group already exists + doReturn(true).when(mockedAuthorityService).authorityExists(RecordContributorsGroupBootstrapComponent.GROUP_RECORD_CONTRIBUTORS); + + // create group + component.createRecordContributorsGroup(); + + // group not created + verify(mockedAuthorityService, times(1)).authorityExists(RecordContributorsGroupBootstrapComponent.GROUP_RECORD_CONTRIBUTORS); + verifyNoMoreInteractions(mockedAuthorityService); + } + + /** + * Given that the record contributors group does not exist + * When I try and create the group + * Then the group is successfully created + * And 'everyone' is added to the new group + */ + @Test + public void createGroup() + { + // group does not exists + doReturn(false).when(mockedAuthorityService).authorityExists(RecordContributorsGroupBootstrapComponent.GROUP_RECORD_CONTRIBUTORS); + + // create group + component.createRecordContributorsGroup(); + + // group not created + verify(mockedAuthorityService, times(1)).createAuthority(AuthorityType.GROUP, RecordContributorsGroupBootstrapComponent.RECORD_CONTRIBUTORS); + verify(mockedAuthorityService, times(1)).addAuthority(RecordContributorsGroupBootstrapComponent.GROUP_RECORD_CONTRIBUTORS, "admin"); + verify(mockedAuthorityService, times(1)).authorityExists(RecordContributorsGroupBootstrapComponent.GROUP_RECORD_CONTRIBUTORS); + verifyNoMoreInteractions(mockedAuthorityService); + } + +} diff --git a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/test/AllUnitTestSuite.java b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/test/AllUnitTestSuite.java index b71c8ee56e..7bdde55429 100644 --- a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/test/AllUnitTestSuite.java +++ b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/test/AllUnitTestSuite.java @@ -19,6 +19,8 @@ package org.alfresco.module.org_alfresco_module_rm.test; import org.alfresco.module.org_alfresco_module_rm.action.impl.FileReportActionUnitTest; +import org.alfresco.module.org_alfresco_module_rm.bootstrap.BootstrapImporterModuleComponentUnitTest; +import org.alfresco.module.org_alfresco_module_rm.bootstrap.RecordContributorsGroupBootstrapComponentUnitTest; import org.alfresco.module.org_alfresco_module_rm.capability.declarative.condition.HoldCapabilityConditionUnitTest; import org.alfresco.module.org_alfresco_module_rm.forms.RecordsManagementTypeFormFilterUnitTest; import org.alfresco.module.org_alfresco_module_rm.hold.HoldServiceImplUnitTest; @@ -81,7 +83,11 @@ import org.junit.runners.Suite.SuiteClasses; // recorded version config RecordedVersionConfigGetTest.class, - RecordedVersionConfigPostTest.class + RecordedVersionConfigPostTest.class, + + // bootstrap + BootstrapImporterModuleComponentUnitTest.class, + RecordContributorsGroupBootstrapComponentUnitTest.class }) public class AllUnitTestSuite {