Skip to content

Commit c09606b

Browse files
committed
Merge branch 'develop' into bugfix/FOUR-26915
2 parents 3edc98e + d3cb6b9 commit c09606b

35 files changed

+673
-102
lines changed

ProcessMaker/Console/Kernel.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ protected function schedule(Schedule $schedule)
8888
$schedule->command('metrics:clear')->cron("*/{$clearInterval} * * * *");
8989
break;
9090
}
91+
92+
// 5 minutes is recommended in https://laravel.com/docs/12.x/horizon#metrics
93+
$schedule->command('horizon:snapshot')->everyFiveMinutes();
9194
}
9295

9396
/**

ProcessMaker/Exception/MultitenancyAccessedLandlord.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,21 @@
55
use Exception;
66
use Illuminate\Http\Request;
77
use Illuminate\Http\Response;
8+
use ProcessMaker\Facades\Metrics;
89

910
class MultitenancyAccessedLandlord extends Exception
1011
{
1112
public function render(Request $request): Response
1213
{
14+
// If we're trying to access the /metrics route, collect landlord metrics and render them
15+
if ($request->path() === 'metrics') {
16+
Metrics::collectQueueMetrics();
17+
18+
return response(Metrics::renderMetrics(), 200, [
19+
'Content-Type' => 'text/plain; version=0.0.4',
20+
]);
21+
}
22+
1323
return response()->view('multitenancy.landlord-landing-page');
1424
}
1525

ProcessMaker/Http/Controllers/Admin/TenantQueueController.php

Lines changed: 27 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -14,36 +14,12 @@
1414

1515
class TenantQueueController extends Controller
1616
{
17-
/**
18-
* Constructor to check if tenant tracking is enabled.
19-
*/
20-
public function __construct()
21-
{
22-
// Check if tenant job tracking is enabled
23-
$enabled = TenantQueueServiceProvider::enabled();
24-
25-
if (!$enabled) {
26-
if (!app()->runningInConsole()) {
27-
abort(404, 'Tenant queue tracking is disabled');
28-
}
29-
}
30-
31-
// If the route binding has a tenant id, check if the user is allowed to access the tenant queue
32-
if ($id = (int) request()->route('tenantId')) {
33-
if (!TenantQueueServiceProvider::allowAllTenats() && $id !== app('currentTenant')?->id) {
34-
throw new AuthorizationException();
35-
}
36-
}
37-
}
38-
3917
/**
4018
* Show the tenant jobs dashboard.
4119
*/
4220
public function index()
4321
{
44-
if (!Auth::user()->is_administrator) {
45-
throw new AuthorizationException();
46-
}
22+
$this->checkPermissions();
4723

4824
return view('admin.tenant-queues.index');
4925
}
@@ -53,9 +29,7 @@ public function index()
5329
*/
5430
public function getTenants(): JsonResponse
5531
{
56-
if (!Auth::user()->is_administrator) {
57-
throw new AuthorizationException();
58-
}
32+
$this->checkPermissions();
5933

6034
$tenantsWithJobs = TenantQueueServiceProvider::getTenantsWithJobs();
6135

@@ -87,9 +61,7 @@ public function getTenants(): JsonResponse
8761
*/
8862
public function getTenantJobs(Request $request, string $tenantId): JsonResponse
8963
{
90-
if (!Auth::user()->is_administrator) {
91-
throw new AuthorizationException();
92-
}
64+
$this->checkPermissions();
9365

9466
$status = $request->get('status');
9567
$limit = min((int) $request->get('limit', 50), 100); // Max 100 jobs
@@ -125,9 +97,7 @@ public function getTenantStats(string $tenantId): JsonResponse
12597
*/
12698
public function getOverallStats(): JsonResponse
12799
{
128-
if (!Auth::user()->is_administrator) {
129-
throw new AuthorizationException();
130-
}
100+
$this->checkPermissions();
131101

132102
$tenantsWithJobs = TenantQueueServiceProvider::getTenantsWithJobs();
133103

@@ -163,9 +133,7 @@ public function getOverallStats(): JsonResponse
163133
*/
164134
public function getJobDetails(string $tenantId, string $jobId): JsonResponse
165135
{
166-
if (!Auth::user()->is_administrator) {
167-
throw new AuthorizationException();
168-
}
136+
$this->checkPermissions();
169137

170138
$tenantKey = "tenant_jobs:{$tenantId}:{$jobId}";
171139
$jobData = Redis::hgetall($tenantKey);
@@ -199,9 +167,7 @@ public function getJobDetails(string $tenantId, string $jobId): JsonResponse
199167
*/
200168
public function clearTenantJobs(string $tenantId): JsonResponse
201169
{
202-
if (!Auth::user()->is_administrator) {
203-
throw new AuthorizationException();
204-
}
170+
$this->checkPermissions();
205171

206172
try {
207173
$pattern = "tenant_jobs:{$tenantId}:*";
@@ -228,4 +194,25 @@ public function clearTenantJobs(string $tenantId): JsonResponse
228194
return response()->json(['error' => 'Failed to clear tenant job data'], 500);
229195
}
230196
}
197+
198+
private function checkPermissions(): void
199+
{
200+
// Check if tenant job tracking is enabled
201+
$enabled = TenantQueueServiceProvider::enabled();
202+
203+
if (!$enabled) {
204+
throw new AuthorizationException('Tenant queue tracking is disabled');
205+
}
206+
207+
if (!Auth::user()->is_administrator) {
208+
throw new AuthorizationException();
209+
}
210+
211+
// If the route binding has a tenant id, check if the user is allowed to access the tenant queue
212+
if ($id = (int) request()->route('tenantId')) {
213+
if (!TenantQueueServiceProvider::allowAllTenats() && $id !== app('currentTenant')?->id) {
214+
throw new AuthorizationException();
215+
}
216+
}
217+
}
231218
}

ProcessMaker/Http/Controllers/Api/ScriptExecutorController.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,15 @@ public function index(Request $request)
5959
{
6060
$this->checkAuth($request);
6161

62-
return new ApiCollection(ScriptExecutor::nonSystem()->get());
62+
$query = ScriptExecutor::nonSystem();
63+
64+
if ($request->has('order_by')) {
65+
$order_by = $request->input('order_by');
66+
$order_direction = $request->input('order_direction', 'ASC');
67+
$query->orderBy($order_by, $order_direction);
68+
}
69+
70+
return new ApiCollection($query->get());
6371
}
6472

6573
/**

ProcessMaker/Http/Controllers/Api/TaskController.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,15 @@ public function index(Request $request, $getTotal = false, User $user = null)
146146

147147
$this->applyAdvancedFilter($query, $request);
148148

149-
$this->applyForCurrentUser($query, $user);
150-
151-
// Apply filter overdue
152-
$query->overdue($request->input('overdue'));
153-
154149
if ($request->input('processesIManage') === 'true') {
155150
$this->applyProcessManager($query, $user);
151+
} else {
152+
$this->applyForCurrentUser($query, $user);
156153
}
157154

155+
// Apply filter overdue
156+
$query->overdue($request->input('overdue'));
157+
158158
// If only the total is being requested (by a Saved Search), send it now
159159
if ($getTotal === true) {
160160
return $query->count();
@@ -168,6 +168,11 @@ public function index(Request $request, $getTotal = false, User $user = null)
168168

169169
$response = $this->applyUserFilter($response, $request, $user);
170170

171+
if ($response->total() > 0 && $request->input('processesIManage') === 'true') {
172+
// enable user manager in cache
173+
$this->enableUserManager($user);
174+
}
175+
171176
$inOverdueQuery = ProcessRequestToken::query()
172177
->whereIn('id', $response->pluck('id'))
173178
->where('due_at', '<', Carbon::now());

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/Http/Kernel.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ class Kernel extends HttpKernel
9292
'session_kill' => Middleware\SessionControlKill::class,
9393
'no-cache' => Middleware\NoCache::class,
9494
'admin' => Middleware\IsAdmin::class,
95+
'manager' => Middleware\IsManager::class,
9596
'etag' => Middleware\Etag\HandleEtag::class,
9697
'file_size_check' => Middleware\FileSizeCheck::class,
9798
];

0 commit comments

Comments
 (0)