Skip to content

Commit

Permalink
Merge pull request ProcessMaker#4597 from ProcessMaker/FOUR-7187
Browse files Browse the repository at this point in the history
Including user permissions data regarding the request - FOUR-7187
  • Loading branch information
ryancooley authored Feb 24, 2023
2 parents 1355d2b + 2336743 commit 6158981
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions ProcessMaker/Http/Resources/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

namespace ProcessMaker\Http\Resources;

use Illuminate\Support\Facades\Auth;
use ProcessMaker\Http\Resources\ApiCollection;
use ProcessMaker\Http\Resources\Screen as ScreenResource;
use ProcessMaker\Http\Resources\ScreenVersion as ScreenVersionResource;
use ProcessMaker\Http\Resources\Users;
use ProcessMaker\Managers\DataManager;
use ProcessMaker\Models\GroupMember;
use ProcessMaker\Models\ProcessRequest;
use ProcessMaker\Models\ProcessRequestToken;
use ProcessMaker\Models\User;
use StdClass;
Expand Down Expand Up @@ -73,6 +75,9 @@ public function toArray($request)
$array['allow_interstitial'] = $interstitial['allow_interstitial'];
$array['interstitial_screen'] = $interstitial['interstitial_screen'];
}
if (in_array('userRequestPermission', $include)) {
$array['user_request_permission'] = $this->loadUserRequestPermission($this->processRequest, Auth::user(), []);
}
/**
* @deprecated since 4.1 Use instead `/api/1.0/users`
*/
Expand Down Expand Up @@ -104,6 +109,20 @@ public function toArray($request)
return $array;
}

private function loadUserRequestPermission(ProcessRequest $request, User $user = null, array $permissions)
{
$permissions[] = [
'process_request_id' => $request->id,
'allowed' => $user ? $user->can('view', $request) : false
];

if ($request->parentRequest && $user) {
$permissions = $this->loadUserRequestPermission($request->parentRequest, $user, $permissions);
}

return $permissions;
}

private function addUser($data, $user)
{
if (!$user) {
Expand Down

0 comments on commit 6158981

Please sign in to comment.