From 4e562b0f4939d248f301542e4f3e5eb44053b5db Mon Sep 17 00:00:00 2001 From: Megan Dove Date: Thu, 29 Sep 2022 13:22:55 +0100 Subject: [PATCH 1/2] Added new config to allow the target to be used for certain entities rather than the actionableBy --- .../js/std_workflow_entity_shared_role.js | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/app/plugins/std_workflow/js/std_workflow_entity_shared_role.js b/app/plugins/std_workflow/js/std_workflow_entity_shared_role.js index e6efa56e..ea45afcf 100644 --- a/app/plugins/std_workflow/js/std_workflow_entity_shared_role.js +++ b/app/plugins/std_workflow/js/std_workflow_entity_shared_role.js @@ -11,6 +11,8 @@ // pull tasks between theselves. Any change of user will be 'sticky' when the workflow // returns to that entity later on in the process. +var USE_TARGET_FOR_ENTITIES = O.application.config["std_workflow:entity_shared_roles:use_target_for_entities"]; + var sharedEntitiesForWorkflow = {}; // Database table to store the last selected entity @@ -29,6 +31,17 @@ var tableSharedRolesSelect = function(M, entityName) { return q.length ? q[0] : null; }; +var replaceActionableByMaybe = function(M, actionableBy) { + if(USE_TARGET_FOR_ENTITIES.length) { + if(-1 !== USE_TARGET_FOR_ENTITIES.indexOf(actionableBy)) { + let tt = M.target.split('.'); + if(tt.length === 2) { + return tt[1]; + } + } + } +}; + // -------------------------------------------------------------------------- P.registerWorkflowFeature("std:entities:entity_shared_roles", function(workflow, specification) { @@ -92,6 +105,9 @@ P.registerWorkflowFeature("std:entities:entity_shared_roles", function(workflow, if(M.workUnit.closed) { return; } var stateDefinition = M.$states[M.state], actionableBy = stateDefinition ? stateDefinition.actionableBy : undefined; + if(USE_TARGET_FOR_ENTITIES) { + actionableBy = replaceActionableByMaybe(M, actionableBy) || actionableBy; + } if(-1 === sharedEntitiesForWorkflow[workflow.fullName].indexOf(actionableBy)) { return; } var list = M.entities[actionableBy+"_refList"]; if(list.length > 1) { @@ -117,6 +133,9 @@ P.registerWorkflowFeature("std:entities:entity_shared_roles", function(workflow, workflow.notification({}, function(M, notify) { var stateDefinition = M.$states[M.state], actionableBy = stateDefinition ? stateDefinition.actionableBy : undefined; + if(USE_TARGET_FOR_ENTITIES) { + actionableBy = replaceActionableByMaybe(M, actionableBy) || actionableBy; + } if(-1 === sharedEntitiesForWorkflow[workflow.fullName].indexOf(actionableBy)) { return; } var row = tableSharedRolesSelect(M, actionableBy); if(row) { @@ -152,6 +171,9 @@ P.respond("GET,POST", "/do/workflow/shared-role", [ var stateDefinition = M.$states[M.state], sharedEntities = sharedEntitiesForWorkflow[workflow.fullName] || [], actionableBy = stateDefinition ? stateDefinition.actionableBy : undefined; + if(USE_TARGET_FOR_ENTITIES) { + actionableBy = replaceActionableByMaybe(M, actionableBy) || actionableBy; + } if(-1 === sharedEntities.indexOf(actionableBy)) { return; } var currentUserRef = O.currentUser.ref; From 0d90ba2a80db39606d32c1662b87cfbb63441157 Mon Sep 17 00:00:00 2001 From: Megan Dove Date: Fri, 30 Sep 2022 15:37:16 +0100 Subject: [PATCH 2/2] Add check for M.target --- app/plugins/std_workflow/js/std_workflow_entity_shared_role.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/plugins/std_workflow/js/std_workflow_entity_shared_role.js b/app/plugins/std_workflow/js/std_workflow_entity_shared_role.js index ea45afcf..d80ad5c5 100644 --- a/app/plugins/std_workflow/js/std_workflow_entity_shared_role.js +++ b/app/plugins/std_workflow/js/std_workflow_entity_shared_role.js @@ -33,7 +33,7 @@ var tableSharedRolesSelect = function(M, entityName) { var replaceActionableByMaybe = function(M, actionableBy) { if(USE_TARGET_FOR_ENTITIES.length) { - if(-1 !== USE_TARGET_FOR_ENTITIES.indexOf(actionableBy)) { + if(-1 !== USE_TARGET_FOR_ENTITIES.indexOf(actionableBy) && M.target) { let tt = M.target.split('.'); if(tt.length === 2) { return tt[1];