Skip to content

Commit d3cb6b9

Browse files
authored
Merge pull request #8487 from ProcessMaker/bugfix/FOUR-23734
FOUR-23734 [44349] - Reassignment User List Not Filtering by Regular …
2 parents 97b618b + 6088e4b commit d3cb6b9

File tree

3 files changed

+73
-4
lines changed

3 files changed

+73
-4
lines changed

ProcessMaker/Http/Controllers/Api/UserController.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,14 @@ public function getUsersTaskCount(Request $request)
209209
$include_ids = explode(',', $include_ids_string);
210210
} elseif ($request->has('assignable_for_task_id')) {
211211
$task = ProcessRequestToken::findOrFail($request->input('assignable_for_task_id'));
212-
if ($task->getAssignmentRule() === 'user_group') {
212+
$assignmentRule = $task->getAssignmentRule();
213+
if ($assignmentRule === 'user_group') {
213214
// Limit the list of users to those that can be assigned to the task
214215
$include_ids = $task->process->getAssignableUsers($task->element_id);
215216
}
217+
if ($assignmentRule === 'rule_expression' && $request->has('form_data')) {
218+
$include_ids = $task->getAssigneesFromExpression($request->input('form_data'));
219+
}
216220
}
217221

218222
if (!empty($include_ids)) {

ProcessMaker/Models/ProcessRequestToken.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
use ProcessMaker\Traits\HasUuids;
3131
use ProcessMaker\Traits\HideSystemResources;
3232
use ProcessMaker\Traits\SerializeToIso8601;
33+
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
3334
use Throwable;
3435

3536
/**
@@ -968,6 +969,66 @@ public function getAssignmentRule()
968969
return $assignment;
969970
}
970971

972+
/**
973+
* Get the assignees for the token.
974+
*
975+
* @param array $assignments
976+
* @param array $variables
977+
* @return array
978+
*/
979+
public function getAssignees(array $assignments, array $variables): array
980+
{
981+
$result = [];
982+
$language = new ExpressionLanguage();
983+
984+
foreach ($assignments as $assignment) {
985+
$isTrue = false;
986+
987+
if (!empty($assignment['expression'])) {
988+
try {
989+
$isTrue = $language->evaluate($assignment['expression'], $variables);
990+
} catch (Throwable $e) {
991+
$isTrue = false;
992+
}
993+
}
994+
995+
if ($isTrue) {
996+
$result[] = $assignment['assignee'];
997+
}
998+
999+
if (isset($assignment['default']) && $assignment['default'] === true) {
1000+
$result[] = $assignment['assignee'];
1001+
}
1002+
}
1003+
1004+
return $result;
1005+
}
1006+
1007+
/**
1008+
* Get the assignees from the expression
1009+
*
1010+
* @param string $form_data
1011+
* @return array
1012+
*/
1013+
public function getAssigneesFromExpression(string $form_data): array
1014+
{
1015+
$formData = json_decode($form_data, true);
1016+
1017+
$activity = $this->getBpmnDefinition()->getBpmnElementInstance();
1018+
$assignmentRules = $activity->getProperty('assignmentRules', null);
1019+
$assignments = json_decode($assignmentRules, true);
1020+
1021+
$include_ids = $this->getAssignees($assignments, $formData);
1022+
1023+
// we add the manager to the list of assignees
1024+
$manager_id = $this->process->manager_id;
1025+
if ($manager_id) {
1026+
$include_ids[] = $manager_id;
1027+
}
1028+
1029+
return $include_ids;
1030+
}
1031+
9711032
/**
9721033
* Returns if the token has the self service option activated
9731034
*/

resources/js/common/reassignMixin.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,18 @@ export default {
2828
}
2929
if (this.task?.id) {
3030
params.assignable_for_task_id = this.task.id;
31+
// The variables are needed to calculate the rule expression.
32+
if (this?.formData) {
33+
params.form_data = this.formData;
34+
delete params.form_data._user;
35+
delete params.form_data._request;
36+
delete params.form_data._process;
37+
}
3138
}
3239

3340
ProcessMaker.apiClient.get('users_task_count', { params }).then(response => {
3441
this.reassignUsers = [];
3542
response.data.data.forEach((user) => {
36-
if (this.currentTaskUserId === user.id) {
37-
return;
38-
}
3943
this.reassignUsers.push({
4044
text: user.fullname,
4145
value: user.id,

0 commit comments

Comments
 (0)