1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Terranet\Administrator\Controllers; |
4
|
|
|
|
5
|
|
|
use App\Http\Controllers\Controller as BaseController; |
|
|
|
|
6
|
|
|
use Illuminate\Http\Request; |
7
|
|
|
use Illuminate\Translation\Translator; |
|
|
|
|
8
|
|
|
use Symfony\Component\HttpKernel\Exception\HttpException; |
9
|
|
|
use Terranet\Administrator\Contracts\Module; |
10
|
|
|
use Terranet\Administrator\Middleware\Authenticate; |
11
|
|
|
use Terranet\Administrator\Middleware\AuthProvider; |
12
|
|
|
use Terranet\Administrator\Middleware\Resources; |
13
|
|
|
|
14
|
|
|
abstract class AdminController extends BaseController |
15
|
|
|
{ |
16
|
|
|
public function __construct() |
17
|
|
|
{ |
18
|
|
|
$this->middleware([ |
19
|
|
|
AuthProvider::class, |
20
|
6 |
|
Authenticate::class, |
21
|
|
|
Resources::class, |
22
|
6 |
|
]); |
23
|
6 |
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Authorize a given action against a set of arguments. |
27
|
|
|
* |
28
|
6 |
|
* @param mixed $ability |
29
|
6 |
|
* @param array|mixed $arguments |
30
|
|
|
* @return bool |
31
|
|
|
*/ |
32
|
|
|
public function authorize($ability, $arguments = null) |
33
|
|
|
{ |
34
|
|
|
/** @var Module $resource */ |
35
|
|
|
$resource = app('scaffold.module'); |
|
|
|
|
36
|
|
|
|
37
|
|
|
if (!$response = $resource->actions()->authorize($ability, $arguments)) { |
|
|
|
|
38
|
|
|
throw $this->createGateUnauthorizedException( |
39
|
2 |
|
$ability, |
40
|
|
|
trans('administrator::errors.unauthorized') |
|
|
|
|
41
|
2 |
|
); |
42
|
1 |
|
} |
43
|
1 |
|
|
44
|
1 |
|
return $response; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
protected function redirectTo($module, $key, Request $request) |
48
|
1 |
|
{ |
49
|
|
|
if ($next = $request->get('back_to')) { |
50
|
|
|
return redirect()->to($next); |
|
|
|
|
51
|
3 |
|
} |
52
|
|
|
|
53
|
3 |
|
if ($request->exists('save')) { |
54
|
1 |
|
return redirect()->route('scaffold.edit', ['module' => $module, 'id' => $key]); |
55
|
|
|
} |
56
|
|
|
|
57
|
2 |
|
return redirect()->route( |
58
|
1 |
|
$request->exists('save_return') ? 'scaffold.index' : 'scaffold.create', |
59
|
|
|
['module' => $module] |
60
|
|
|
); |
61
|
1 |
|
} |
62
|
1 |
|
|
63
|
1 |
|
/** |
64
|
|
|
* Throw an unauthorized exception based on gate results. |
65
|
|
|
* |
66
|
|
|
* @param string $ability |
67
|
|
|
* @param string $message |
68
|
|
|
* @param \Exception $previousException |
69
|
|
|
* @return \Symfony\Component\HttpKernel\Exception\HttpException |
70
|
|
|
*/ |
71
|
|
|
protected function createGateUnauthorizedException( |
72
|
|
|
$ability, |
73
|
|
|
$message = 'This action is unauthorized.', |
74
|
|
|
$previousException = null |
75
|
|
|
) { |
76
|
1 |
|
$message = sprintf($message.' [%s]', $ability); |
77
|
|
|
|
78
|
|
|
return new HttpException(403, $message, $previousException); |
79
|
|
|
} |
80
|
|
|
|
81
|
1 |
|
public function translator() |
82
|
|
|
{ |
83
|
1 |
|
return app(Translator::class); |
|
|
|
|
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