Skip to content

Commit 52c9bc8

Browse files
authored
Merge pull request #8159 from ProcessMaker/epic/FOUR-22597
FOUR-22597: [SUMMER 25] Reassignment Capability - Observations and adjustments
2 parents e8e1468 + c1c2164 commit 52c9bc8

14 files changed

Lines changed: 425 additions & 139 deletions

File tree

ProcessMaker/Http/Controllers/Api/TaskController.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,8 @@ public function update(Request $request, ProcessRequestToken $task)
341341
return new Resource($task->refresh());
342342
} elseif (!empty($request->input('user_id'))) {
343343
$userToAssign = $request->input('user_id');
344-
$task->reassign($userToAssign, $request->user());
344+
$comments = $request->input('comments');
345+
$task->reassign($userToAssign, $request->user(), $comments);
345346

346347
$taskRefreshed = $task->refresh();
347348

@@ -426,7 +427,7 @@ public function setPriority(Request $request, ProcessRequestToken $task)
426427
}
427428

428429
/**
429-
* Only send data for a screens fields
430+
* Only send data for a screen's fields
430431
*
431432
* @param ProcessRequestToken $task
432433
*

ProcessMaker/Http/Controllers/Api/UserController.php

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,7 @@ public function index(Request $request)
186186
*/
187187
public function getUsersTaskCount(Request $request)
188188
{
189-
$query = User::nonSystem();
190-
$query->select('id', 'username', 'firstname', 'lastname');
189+
$query = User::select('id', 'username', 'firstname', 'lastname');
191190

192191
$filter = $request->input('filter', '');
193192
if (!empty($filter)) {
@@ -199,34 +198,32 @@ public function getUsersTaskCount(Request $request)
199198
});
200199
}
201200

202-
$query->where('status', 'ACTIVE');
203-
204-
$query->withCount('activeTasks');
205-
206201
$include_ids = [];
207202
$include_ids_string = $request->input('include_ids', '');
208203
if (!empty($include_ids_string)) {
209204
$include_ids = explode(',', $include_ids_string);
210205
} elseif ($request->has('assignable_for_task_id')) {
211-
$task = ProcessRequestToken::findOrFail($request->input('assignable_for_task_id'));
212-
$assignmentRule = $task->getAssignmentRule();
213-
if ($assignmentRule === 'user_group') {
214-
// Limit the list of users to those that can be assigned to the task
215-
$include_ids = $task->process->getAssignableUsers($task->element_id);
206+
$processRequestToken = ProcessRequestToken::findOrFail($request->input('assignable_for_task_id'));
207+
$assignmentRule = $processRequestToken->getAssignmentRule();
208+
if (config('app.reassign_restrict_to_assignable_users')) {
209+
$include_ids = $processRequestToken->process->getAssignableUsersByAssignmentType($processRequestToken);
216210
}
217211
if ($assignmentRule === 'rule_expression' && $request->has('form_data')) {
218-
$include_ids = $task->getAssigneesFromExpression($request->input('form_data'));
212+
$include_ids = $processRequestToken->getAssigneesFromExpression($request->input('form_data'));
219213
}
220214
}
221215

222216
if (!empty($include_ids)) {
223217
$query->whereIn('id', $include_ids);
224218
}
225219

226-
$response = $query->orderBy(
227-
$request->input('order_by', 'username'),
228-
$request->input('order_direction', 'ASC')
229-
)
220+
$response = $query
221+
->where('is_system', false)
222+
->where('status', 'ACTIVE')
223+
->withCount('activeTasks')
224+
->orderBy(
225+
$request->input('order_by', 'username'),
226+
$request->input('order_direction', 'ASC'))
230227
->paginate(50);
231228

232229
return new ApiCollection($response);

ProcessMaker/Models/Process.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,6 +1044,40 @@ public function getAssignableUsers($processTaskUuid)
10441044
return array_values($users);
10451045
}
10461046

1047+
/**
1048+
* This method is used to get the assignable users for a task based on the assignment rule.
1049+
* The assignment rule can be:
1050+
* - user_group: would assign it to those in the group or the Process Manager.
1051+
* - process_variable: would assign it to those in the group or the Process Manager.
1052+
* - rule_expression: would assign it to those in the group or the Process Manager.
1053+
* - previous_task_assignee: would assign it to the Process Manager.
1054+
* - requester: would assign it to the Process Manager.
1055+
* - process_manager: would assign it to the same Process Manager.
1056+
*
1057+
* @param ProcessRequestToken $processRequestToken
1058+
* @return array
1059+
*/
1060+
public function getAssignableUsersByAssignmentType(ProcessRequestToken $processRequestToken): array
1061+
{
1062+
$users = [];
1063+
switch ($processRequestToken->getAssignmentRule()) {
1064+
case 'user_group':
1065+
case 'process_variable':
1066+
case 'rule_expression':
1067+
$users = $this->getAssignableUsers($processRequestToken->element_id);
1068+
$users[] = $processRequestToken->process->properties["manager_id"];
1069+
break;
1070+
case 'previous_task_assignee':
1071+
case 'requester':
1072+
$users[] = $processRequestToken->process->properties["manager_id"];
1073+
break;
1074+
case 'process_manager':
1075+
$users[] = $processRequestToken->process->properties["manager_id"];
1076+
break;
1077+
}
1078+
return $users;
1079+
}
1080+
10471081
/**
10481082
* Get a consolidated list of users within groups.
10491083
*

ProcessMaker/Models/ProcessRequestToken.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1341,7 +1341,7 @@ public function sendActivityActivatedNotifications()
13411341
* @param User $requestingUser
13421342
* @return void
13431343
*/
1344-
public function reassign($toUserId, User $requestingUser)
1344+
public function reassign($toUserId, User $requestingUser, $comments = '')
13451345
{
13461346
$sendActivityActivatedNotifications = false;
13471347
$reassingAction = false;
@@ -1366,6 +1366,9 @@ public function reassign($toUserId, User $requestingUser)
13661366
$this->persistUserData($toUserId);
13671367
$reassingAction = true;
13681368
}
1369+
if ($comments != null && $comments !== '') {
1370+
$this->comments = $comments;
1371+
}
13691372
$this->save();
13701373

13711374
if ($sendActivityActivatedNotifications) {

config/app.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,5 +300,6 @@
300300

301301
'multitenancy' => env('MULTITENANCY', false),
302302

303+
'reassign_restrict_to_assignable_users' => env('REASSIGN_RESTRICT_TO_ASSIGNABLE_USERS', true),
303304
'resources_core_path' => base_path('resources-core'),
304305
];
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::table('process_request_tokens', function (Blueprint $table) {
15+
$table->longText('comments')->nullable();
16+
});
17+
}
18+
19+
/**
20+
* Reverse the migrations.
21+
*/
22+
public function down(): void
23+
{
24+
Schema::table('process_request_tokens', function (Blueprint $table) {
25+
$table->dropColumn('comments');
26+
});
27+
}
28+
};

resources/js/tasks/api/index.js

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,44 @@
1-
import { api } from "../variables/index";
1+
import { getApi } from "../variables/index";
22

3-
export const updateCollection = async ({ collectionId, recordId, data }) => {
4-
const response = await api.put(`collections/${collectionId}/records/${recordId}`, data);
3+
export const getReassignUsers = async (filter = null, taskId = null, currentTaskUserId = null) => {
4+
const api = getApi();
5+
const response = await api.get("users_task_count", { params: { filter, assignable_for_task_id: taskId, include_current_user: true } });
6+
const data = response.data;
7+
if (currentTaskUserId && Array.isArray(data?.data)) {
8+
data.data = data.data.filter((user) => user.id !== currentTaskUserId);
9+
}
10+
return data;
11+
};
12+
13+
export const updateReassignUser = async (taskId, userId, comments = null) => {
14+
const api = getApi();
15+
const response = await api.put(`tasks/${taskId}`, { user_id: userId, comments });
16+
return response.data;
17+
};
518

19+
export const updateComment = async ({
20+
body,
21+
subject,
22+
commentableId,
23+
commentableType,
24+
parentId = 0,
25+
type = "COMMENT",
26+
}) => {
27+
const api = getApi();
28+
const response = await api.post("comments/comments", {
29+
body,
30+
subject,
31+
commentable_id: commentableId,
32+
commentable_type: commentableType,
33+
type,
34+
parent_id: parentId,
35+
});
636
return response.data;
737
};
838

9-
export default {
10-
updateCollection,
39+
export const updateCollection = async ({ collectionId, recordId, data }) => {
40+
const api = getApi();
41+
const response = await api.put(`collections/${collectionId}/records/${recordId}`, data);
42+
43+
return response.data;
1144
};

resources/js/tasks/components/PreviewMixin.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ const PreviewMixin = {
172172
}
173173
this.prevTask = prevTask;
174174
this.nextTask = nextTask;
175+
this.showReassignment = false;
175176
},
176177
/**
177178
* Expand Open task

0 commit comments

Comments
 (0)