Skip to content

Commit 854e16c

Browse files
committed
FOUR-28520 Added getUsersFromProcessVariable() to ProcessRequestToken to extract user IDs from form data (assignedUsers/assignedGroups variables).
Uses Process::getConsolidatedUsers() to get users from groups recursively. Validates array inputs and filters invalid IDs. Includes PHPUnit tests.
1 parent 4568f9a commit 854e16c

5 files changed

Lines changed: 440 additions & 1 deletion

File tree

ProcessMaker/Http/Controllers/Api/UserController.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,9 @@ public function getUsersTaskCount(Request $request)
260260
if ($assignmentRule === 'rule_expression' && $request->has('form_data')) {
261261
$include_ids = $processRequestToken->getAssigneesFromExpression($request->input('form_data'));
262262
}
263+
if ($assignmentRule === 'process_variable' && $request->has('form_data')) {
264+
$include_ids = $processRequestToken->getUsersFromProcessVariable($request->input('form_data'));
265+
}
263266
}
264267

265268
if (!empty($include_ids)) {

ProcessMaker/Models/ProcessRequestToken.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace ProcessMaker\Models;
44

5+
use AWS\CRT\Log as CRTLog;
56
use Carbon\Carbon;
67
use DB;
78
use DOMXPath;
@@ -991,6 +992,60 @@ public function getAssignmentRule()
991992
return $assignment;
992993
}
993994

995+
/**
996+
* Get user IDs from process variables for task assignment.
997+
*
998+
* Extracts user IDs and group IDs from form data based on the activity's
999+
* assignedUsers and assignedGroups properties. Retrieves all users from
1000+
* specified groups (including subgroups recursively) and combines them
1001+
* with directly assigned users.
1002+
*
1003+
* Used when assignment rule is 'process_variable'.
1004+
*
1005+
* @param array $form_data Form data containing process variable values.
1006+
* Keys must match activity's assignedUsers and
1007+
* assignedGroups properties. Values must be arrays.
1008+
*
1009+
* @return array Unique numeric user IDs (direct users + users from groups).
1010+
*/
1011+
public function getUsersFromProcessVariable(array $form_data)
1012+
{
1013+
$activity = $this->getBpmnDefinition()->getBpmnElementInstance();
1014+
$assignedUsers = $activity->getProperty('assignedUsers', null);
1015+
$assignedGroups = $activity->getProperty('assignedGroups', null);
1016+
1017+
$usersIds = [];
1018+
$groupsIds = [];
1019+
1020+
// Validate and get user IDs from form_data
1021+
if ($assignedUsers && isset($form_data[$assignedUsers]) && is_array($form_data[$assignedUsers])) {
1022+
$usersIds = $form_data[$assignedUsers];
1023+
}
1024+
1025+
// Validate and get group IDs from form_data
1026+
if ($assignedGroups && isset($form_data[$assignedGroups]) && is_array($form_data[$assignedGroups])) {
1027+
$groupsIds = $form_data[$assignedGroups];
1028+
}
1029+
1030+
// Get users from groups using the Process model method
1031+
$usersFromGroups = [];
1032+
if (!empty($groupsIds) && $this->process) {
1033+
// Use the getConsolidatedUsers method from the Process model
1034+
// This method gets users from groups including subgroups recursively
1035+
$this->process->getConsolidatedUsers($groupsIds, $usersFromGroups);
1036+
}
1037+
1038+
// Combine direct users with users from groups
1039+
$allUserIds = array_unique(array_merge($usersIds, $usersFromGroups));
1040+
1041+
// Convert to numeric array and filter valid values
1042+
$allUserIds = array_values(array_filter($allUserIds, function($id) {
1043+
return !empty($id) && is_numeric($id) && $id > 0;
1044+
}));
1045+
1046+
return $allUserIds;
1047+
}
1048+
9941049
/**
9951050
* Get the assignees for the token.
9961051
*

resources/js/common/reassignMixin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default {
2828
const response = await getReassignUsersApi(
2929
filter,
3030
this.task?.id,
31-
this?.formData,
31+
this.task?.request_data,
3232
this.currentTaskUserId
3333
);
3434

resources/js/tasks/components/taskPreview/TaskPreviewAssignment.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ const disabled = computed(() => !selectedUser.value || !comments.value?.trim());
9191
// Load the reassign users using the centralized function with form_data
9292
const loadReassignUsers = async (filter) => {
9393
try {
94+
console.log('reassignUsers11', JSON.stringify(props.formData));
9495
const response = await getReassignUsers(
9596
filter,
9697
props.task?.id,

0 commit comments

Comments
 (0)