Skip to content

Commit 70369ba

Browse files
committed
FOUR-27904 Web entry Authenticated, is not working, when the start event is with anonymous
## Description When the second task is set to authenticated and the start event to anonymous, we get an error message on the screen. ## Related tickets https://processmaker.atlassian.net/browse/FOUR-27904
1 parent 17355e1 commit 70369ba

2 files changed

Lines changed: 67 additions & 10 deletions

File tree

ProcessMaker/AssignmentRules/ProcessManagerAssigned.php

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,39 +20,78 @@ class ProcessManagerAssigned implements AssignmentRuleInterface
2020
* The task is assigned to the Manager of the Process.
2121
*
2222
* It takes in count the process version of the request.
23-
* If the process does not have assigned a Manager, it throws an exception.
23+
* If the process does not have assigned a Manager, it returns null instead of throwing an exception.
2424
*
2525
* @param ActivityInterface $task
2626
* @param TokenInterface $token
2727
* @param Process $process
2828
* @param ProcessRequest $request
2929
* @return int|null
30-
* @throws ThereIsNoProcessManagerAssignedException
3130
*/
3231
public function getNextUser(ActivityInterface $task, TokenInterface $token, Process $process, ProcessRequest $request)
3332
{
3433
// review for multiple managers
3534
$managers = $request->processVersion->manager_id;
36-
$user_id = $this->getNextManagerAssigned($managers, $task, $request);
37-
if (!$user_id) {
38-
throw new ThereIsNoProcessManagerAssignedException($task);
35+
36+
// Normalize: treat empty array as null
37+
if (is_array($managers) && empty($managers)) {
38+
$managers = null;
3939
}
4040

41+
$user_id = $this->getNextManagerAssigned($managers, $task, $request);
42+
43+
// Return null instead of throwing exception when no manager is found
44+
// This allows the process to continue without crashing
4145
return $user_id;
4246
}
4347

4448
/**
4549
* Get the round robin manager using a true round robin algorithm
4650
*
47-
* @param array $managers
51+
* @param array|int|null $managers Manager ID(s) - can be array, single int, or null
4852
* @param ActivityInterface $task
4953
* @param ProcessRequest $request
5054
* @return int|null
5155
*/
5256
private function getNextManagerAssigned($managers, $task, $request)
5357
{
54-
// Validate input
55-
if (empty($managers) || !is_array($managers)) {
58+
// Handle null case
59+
if (is_null($managers)) {
60+
return null;
61+
}
62+
63+
// Convert single value to array for backward compatibility
64+
if (!is_array($managers)) {
65+
// If it's a valid integer, convert to array
66+
if (is_numeric($managers) && $managers > 0) {
67+
$managers = [(int) $managers];
68+
} else {
69+
// Invalid single value (0, empty string, 'undefined', etc.)
70+
return null;
71+
}
72+
}
73+
74+
// Validate array is not empty
75+
if (empty($managers)) {
76+
return null;
77+
}
78+
79+
// Filter out invalid values (null, 0, empty strings, 'undefined', false, etc.)
80+
$managers = array_filter($managers, function ($id) {
81+
// Only accept positive integers
82+
if (!is_numeric($id)) {
83+
return false;
84+
}
85+
$id = (int) $id;
86+
87+
return $id > 0;
88+
});
89+
90+
// Re-index array after filtering
91+
$managers = array_values($managers);
92+
93+
// Check if we have any valid managers after filtering
94+
if (empty($managers)) {
5695
return null;
5796
}
5897

ProcessMaker/Models/Process.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -694,13 +694,25 @@ private function checkAssignment(ProcessRequest $request, ActivityInterface $act
694694
if ($isSelfService && !$escalateToManager) {
695695
return null;
696696
}
697+
// Don't fallback to Process Manager for process_variable assignment when no users found
698+
// This preserves the original behavior where invalid users result in no task assignment
699+
if ($assignmentType === 'process_variable') {
700+
return null;
701+
}
697702
$rule = new ProcessManagerAssigned();
698703
if ($token === null) {
699-
throw new ThereIsNoProcessManagerAssignedException($activity);
704+
// Return null instead of throwing exception when no token is available
705+
return null;
700706
}
701707
$user = $rule->getNextUser($activity, $token, $this, $request);
702708
if (!$user) {
703-
throw new ThereIsNoProcessManagerAssignedException($activity);
709+
// Log error when no manager is found, but don't throw exception
710+
// This allows the process to continue without crashing
711+
// but still records the issue for visibility
712+
$exception = new ThereIsNoProcessManagerAssignedException($activity);
713+
$request->logError($exception, $activity);
714+
715+
return null;
704716
}
705717
$user = User::find($user);
706718
}
@@ -808,6 +820,12 @@ private function getNextUserFromProcessVariable($activity, $token)
808820
$this->getConsolidatedUsers($groupId, $users);
809821
}
810822

823+
// If no valid users found, throw exception to prevent token creation
824+
// This preserves the original behavior where invalid users result in no task
825+
if (empty($users)) {
826+
throw new TaskDoesNotHaveUsersException($activity->getId());
827+
}
828+
811829
return $this->getNextUserFromGroupAssignment($activity->getId(), $users);
812830
}
813831

0 commit comments

Comments
 (0)