Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion ProcessMaker/Http/Controllers/Api/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,14 @@ public function getUsersTaskCount(Request $request)
$include_ids = explode(',', $include_ids_string);
} elseif ($request->has('assignable_for_task_id')) {
$task = ProcessRequestToken::findOrFail($request->input('assignable_for_task_id'));
if ($task->getAssignmentRule() === 'user_group') {
$assignmentRule = $task->getAssignmentRule();
if ($assignmentRule === 'user_group') {
// Limit the list of users to those that can be assigned to the task
$include_ids = $task->process->getAssignableUsers($task->element_id);
}
if ($assignmentRule === 'rule_expression' && $request->has('form_data')) {
$include_ids = $task->getAssigneesFromExpression($request->input('form_data'));
}
}

if (!empty($include_ids)) {
Expand Down
61 changes: 61 additions & 0 deletions ProcessMaker/Models/ProcessRequestToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
use ProcessMaker\Traits\HasUuids;
use ProcessMaker\Traits\HideSystemResources;
use ProcessMaker\Traits\SerializeToIso8601;
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
use Throwable;

/**
Expand Down Expand Up @@ -968,6 +969,66 @@ public function getAssignmentRule()
return $assignment;
}

/**
* Get the assignees for the token.
*
* @param array $assignments
* @param array $variables
* @return array
*/
public function getAssignees(array $assignments, array $variables): array
{
$result = [];
$language = new ExpressionLanguage();

foreach ($assignments as $assignment) {
$isTrue = false;

if (!empty($assignment['expression'])) {
try {
$isTrue = $language->evaluate($assignment['expression'], $variables);
} catch (Throwable $e) {
$isTrue = false;
}
}

if ($isTrue) {
$result[] = $assignment['assignee'];
}

if (isset($assignment['default']) && $assignment['default'] === true) {
$result[] = $assignment['assignee'];
}
}

return $result;
}

/**
* Get the assignees from the expression
*
* @param string $form_data
* @return array
*/
public function getAssigneesFromExpression(string $form_data): array
{
$formData = json_decode($form_data, true);

$activity = $this->getBpmnDefinition()->getBpmnElementInstance();
$assignmentRules = $activity->getProperty('assignmentRules', null);
$assignments = json_decode($assignmentRules, true);

$include_ids = $this->getAssignees($assignments, $formData);

// we add the manager to the list of assignees
$manager_id = $this->process->manager_id;
if ($manager_id) {
$include_ids[] = $manager_id;
}

return $include_ids;
}

/**
* Returns if the token has the self service option activated
*/
Expand Down
10 changes: 7 additions & 3 deletions resources/js/common/reassignMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,18 @@ export default {
}
if (this.task?.id) {
params.assignable_for_task_id = this.task.id;
// The variables are needed to calculate the rule expression.
if (this?.formData) {
params.form_data = this.formData;
delete params.form_data._user;
delete params.form_data._request;
delete params.form_data._process;
}
}

ProcessMaker.apiClient.get('users_task_count', { params }).then(response => {
this.reassignUsers = [];
response.data.data.forEach((user) => {
if (this.currentTaskUserId === user.id) {
return;
}
this.reassignUsers.push({
text: user.fullname,
value: user.id,
Expand Down