forked from ProcessMaker/processmaker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScreenPolicy.php
More file actions
60 lines (47 loc) · 1.46 KB
/
ScreenPolicy.php
File metadata and controls
60 lines (47 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
namespace ProcessMaker\Policies;
use Illuminate\Auth\Access\HandlesAuthorization;
use ProcessMaker\Assets\ScreensInScreen;
use ProcessMaker\Models\ProcessRequestToken;
use ProcessMaker\Models\Screen;
use ProcessMaker\Models\User;
class ScreenPolicy
{
use HandlesAuthorization;
/**
* Determine whether the user can view the screen.
*
* @param \ProcessMaker\Models\User $user
* @param \ProcessMaker\Screen $screen
* @return mixed
*/
public function view(User $user, Screen $screen)
{
if ($user->is_administrator) {
return true;
}
$taskId = request()->input('task');
if (!$taskId) {
return false;
}
$task = ProcessRequestToken::findOrFail($taskId);
if (!$user->can('update', $task)) {
return false;
}
$taskScreenVersion = $task->getScreenVersion();
if ($taskScreenVersion->screen_id === $screen->id) {
return true;
}
// Check for nested screen
$screenFinder = new ScreensInScreen();
$screenFinder->setProcessRequest($task->processRequest);
$nestedScreens = $screenFinder->referencesToExport($taskScreenVersion->parent);
$nestedScreenIds = array_map(function ($screen) {
return $screen[1];
}, $nestedScreens);
if (in_array($screen->id, $nestedScreenIds)) {
return true;
}
return false;
}
}