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
4 changes: 2 additions & 2 deletions ProcessMaker/Models/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -773,8 +773,8 @@ private function getNextUserFromProcessVariable($activity, $token)
$dataManager = new DataManager();
$instanceData = $dataManager->getData($token);

$assignedUsers = $usersVariable ? Arr::get($instanceData, $usersVariable) : [];
$assignedGroups = $groupsVariable ? Arr::get($instanceData, $groupsVariable) : [];
$assignedUsers = $usersVariable ? feelExpression($usersVariable, $instanceData) : [];
$assignedGroups = $groupsVariable ? feelExpression($groupsVariable, $instanceData) : [];

if (!is_array($assignedUsers)) {
$assignedUsers = [$assignedUsers];
Expand Down
18 changes: 18 additions & 0 deletions helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use Illuminate\Support\Facades\Auth;
use Laravel\Horizon\Repositories\RedisJobRepository;
use ProcessMaker\Events\MarkArtisanCachesAsInvalid;
use ProcessMaker\Models\FormalExpression;
use ProcessMaker\Models\Setting;
use ProcessMaker\SanitizeHelper;
use ProcessMaker\Support\JsonOptimizer;
Expand Down Expand Up @@ -359,3 +360,20 @@ function json_optimize_decode(string $json, bool $assoc = false, int $depth = 51
return JsonOptimizer::decode($json, $assoc, $depth, $options);
}
}

if (!function_exists('feelExpression')) {
/**
* Evaluate a BPMN FEEL expression
*
* @param string $expression
* @param array $data
* @return mixed
*/
function feelExpression(string $expression, array $data)
{
$formalExp = new FormalExpression();
$formalExp->setLanguage('FEEL');
$formalExp->setBody($expression);
return $formalExp($data);
}
}
20 changes: 20 additions & 0 deletions tests/Feature/Api/TaskAssignmentByVariableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,26 @@ public function testProcessVariableAssignmentWithObjectVariable()
$this->assertEquals($users->first()->id, $task->user_id);
}

public function testProcessVariableAssignmentWithLiteralId()
{
// Create users of a group and a user without group
$user = User::factory()->create(['status'=>'ACTIVE']);
$group = $this->createGroup(5);
$process = $this->createProcess('process_variable', $user->id, $group->id, '', false);

// The first assignment should be to user (is the first created user)
$response = $this->startTestProcess($process, []);
$requestId = $response['id'];
$task = ProcessRequestToken::where(['process_request_id' => $requestId, 'status' => 'ACTIVE'])->firstOrFail();
$this->assertEquals($user->id, $task->user_id);

// The second assignment should be to the first user of the created group
$response = $this->startTestProcess($process, []);
$requestId = $response['id'];
$task = ProcessRequestToken::where(['process_request_id' => $requestId, 'status' => 'ACTIVE'])->firstOrFail();
$this->assertEquals($group->users->first()->id, $task->user_id);
}

/**
* Creates a process in which the assignment of the first task is configured based on the parameters of this function
*
Expand Down
Loading