|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Terranet\Administrator\Traits\Actions; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
|
|
|
|
|
6
|
|
|
use Illuminate\Foundation\Auth\User; |
|
|
|
|
|
|
7
|
|
|
use Terranet\Administrator\Contracts\Module; |
|
8
|
|
|
|
|
9
|
|
|
trait ActionSkeleton |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* Check if specified user is authorized to execute this action. |
|
13
|
|
|
* |
|
14
|
|
|
* @param User $viewer |
|
15
|
|
|
* @param Model $model |
|
16
|
|
|
* @return bool |
|
17
|
|
|
*/ |
|
18
|
|
|
public function authorize(User $viewer, Model $model = null) |
|
|
|
|
|
|
19
|
|
|
{ |
|
20
|
|
|
/** @var Module $resource */ |
|
21
|
|
|
$resource = app('scaffold.module'); |
|
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
return $resource->actionsManager()->authorize( |
|
24
|
|
|
snake_case(class_basename($this)), |
|
|
|
|
|
|
25
|
|
|
$model |
|
26
|
|
|
); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @param Model $model |
|
31
|
|
|
* @return string |
|
32
|
|
|
*/ |
|
33
|
|
|
protected function route(Model $model = null) |
|
34
|
|
|
{ |
|
35
|
|
|
return route('scaffold.action', [ |
|
|
|
|
|
|
36
|
|
|
'module' => app('scaffold.module'), |
|
|
|
|
|
|
37
|
|
|
'id' => $model ? $model->getKey() : null, |
|
38
|
|
|
'action' => $this->action($model), |
|
|
|
|
|
|
39
|
|
|
]); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Confirmation message, if required. |
|
44
|
|
|
* |
|
45
|
|
|
* @return mixed null|string |
|
46
|
|
|
*/ |
|
47
|
|
|
public function confirmationMessage(): ?string |
|
48
|
|
|
{ |
|
49
|
|
|
return null; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Hide an action from index page. |
|
54
|
|
|
* |
|
55
|
|
|
* @return bool |
|
56
|
|
|
*/ |
|
57
|
|
|
public function hideFromIndex(): bool |
|
58
|
|
|
{ |
|
59
|
|
|
return false; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Hide an action from view page. |
|
64
|
|
|
* |
|
65
|
|
|
* @return bool |
|
66
|
|
|
*/ |
|
67
|
|
|
public function hideFromView(): bool |
|
68
|
|
|
{ |
|
69
|
|
|
return false; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @param Model $model |
|
74
|
|
|
* @return string |
|
75
|
|
|
*/ |
|
76
|
|
|
protected function attributes(Model $model = null) |
|
|
|
|
|
|
77
|
|
|
{ |
|
78
|
|
|
$attributes = []; |
|
79
|
|
|
if ($msg = $this->confirmationMessage()) { |
|
|
|
|
|
|
80
|
|
|
$attributes["onclick"] = "return window.confirm('{$msg}')"; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
return \admin\helpers\html_attributes($attributes); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths