Skip to content

Commit

Permalink
FOUR-21166 Only minor changes are introduced.
Browse files Browse the repository at this point in the history
  • Loading branch information
gproly committed Dec 16, 2024
1 parent bfdbc16 commit ed2cd69
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 139 deletions.
4 changes: 4 additions & 0 deletions ProcessMaker/Http/Controllers/Api/TaskController.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ public function index(Request $request, $getTotal = false, User $user = null)
// Apply filter overdue
$query->overdue($request->input('overdue'));

if ($request->input('processesIManage') === 'true') {
$this->applyProcessManager($query, $user);
}

// If only the total is being requested (by a Saved Search), send it now
if ($getTotal === true) {
return $query->count();
Expand Down
4 changes: 2 additions & 2 deletions ProcessMaker/Http/Controllers/Api/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ public function getUsersTaskCount(Request $request)
} elseif ($request->has('assignable_for_task_id')) {
$task = ProcessRequestToken::findOrFail($request->input('assignable_for_task_id'));
if ($task->getAssignmentRule() === 'user_group') {
// Limit the list of users to those that can be assigned to the task.
$include_ids = [];
// Limit the list of users to those that can be assigned to the task
$include_ids = $task->process->getAssignableUsers($task->element_id);
}
}

Expand Down
40 changes: 0 additions & 40 deletions ProcessMaker/Models/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
Expand Down Expand Up @@ -257,13 +256,6 @@ public static function boot()
$model->updated_by = $user?->id;
self::clearAndRebuildUserProjectAssetsCache();
});

static::saved(function ($model) {
$userIds = Cache::get("cache_is_manager_of_some_process_ids", []);
foreach ($userIds as $userId) {
Cache::forget("cache_is_manager_of_some_process_{$userId}");
}
});
}

/**
Expand Down Expand Up @@ -1874,36 +1866,4 @@ public function scopeOrderByRecentRequests($query)
->limit(1)
);
}

/**
* Check if the user is the manager of the process.
* The result is stored in cache to avoid repeated queries.
* It is necessary to store the user ID to prevent inconsistency if any process has changed.
*
* @param User $user
*
* @return bool
*/
public static function isManagerOfSomeProcess($user)
{
$cacheKey = "cache_is_manager_of_some_process_ids";
$userIds = Cache::get($cacheKey, []);
if (!in_array($user->id, $userIds)) {
$userIds[] = $user->id;
Cache::put($cacheKey, $userIds, 3600);
}

$result = Cache::rememberForever("cache_is_manager_of_some_process_{$user->id}", function () use ($user) {
$record = Process::select('id', 'properties->manager_id')
->whereNotNull('properties->manager_id')
->where('properties->manager_id', '=', $user->id)
->where('status', 'ACTIVE')
->first();
if ($record) {
return true;
}
return false;
});
return $result;
}
}
17 changes: 0 additions & 17 deletions ProcessMaker/Traits/TaskControllerIndexMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,11 +311,6 @@ private function applyForCurrentUser($query, $user)
return $query;
}

if ($this->isManagerOfProcess($user)) {
$this->applyProcessManager($query, $user);
return $query;
}

if ($user->can('view-all_requests')) {
return $query;
}
Expand All @@ -339,16 +334,4 @@ public function applyProcessManager($query, $user)
->where('process_request_tokens.status', 'ACTIVE');
});
}

/**
* Check if the user is the manager of the process
*
* @param User $user
*
* @return bool
*/
private function isManagerOfProcess($user)
{
return Process::isManagerOfSomeProcess($user);
}
}
1 change: 1 addition & 0 deletions resources/js/tasks/components/ListMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ const ListMixin = {
}${filterParams
}${this.getSortParam()
}&non_system=true` +
`&processesIManage=${(this.processesIManage ? 'true' : 'false')}` +
advancedFilter +
this.columnsQuery,
{
Expand Down
4 changes: 4 additions & 0 deletions resources/js/tasks/components/TasksList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,10 @@ export default {
noResultsMessage: {
type: String,
default: "tasks",
},
processesIManage: {
type: Boolean,
default: false
}
},
data() {
Expand Down
64 changes: 0 additions & 64 deletions tests/Traits/TaskControllerIndexMethodsTest.php

This file was deleted.

16 changes: 0 additions & 16 deletions tests/unit/ProcessMaker/Models/ProcessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,4 @@ public function testGetConsolidatedUsers()

$this->assertEquals([$groupAUser->id, $groupBUser->id], $users);
}

/**
* @testdox Test that isManagerOfSomeProcess returns true for a manager of a process.
*/
public function testIsManagerOfSomeProcess()
{
$user = User::factory()->create();
$process = Process::factory()->create([
'properties' => ['manager_id' => $user->id],
'status' => 'ACTIVE'
]);
$this->assertTrue(Process::isManagerOfSomeProcess($user));

$user2 = User::factory()->create();
$this->assertFalse(Process::isManagerOfSomeProcess($user2));
}
}

0 comments on commit ed2cd69

Please sign in to comment.