1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use EasyPanel\Contracts\CRUDComponent; |
4
|
|
|
|
5
|
|
|
if(! function_exists('getRouteName')) { |
6
|
|
|
function getRouteName(){ |
7
|
|
|
$routeName = config('easy_panel.route_prefix'); |
8
|
|
|
$routeName = trim($routeName, '/'); |
9
|
|
|
$routeName = str_replace('/', '.', $routeName); |
10
|
|
|
return $routeName; |
11
|
|
|
} |
12
|
|
|
} |
13
|
|
|
|
14
|
|
|
if(! function_exists('getCrudConfig')) { |
15
|
|
|
function getCrudConfig($name){ |
16
|
|
|
$className = ucwords($name); |
17
|
|
|
$namespace = "\\App\\CRUD\\{$className}Component"; |
18
|
|
|
$appFilePath = app_path("/CRUD/{$name}Component.php"); |
19
|
|
|
$nsExist = class_exists($namespace); |
20
|
|
|
$filePathExist = file_exists($appFilePath); |
21
|
|
|
|
22
|
|
|
if (!$filePathExist or !$nsExist){ |
23
|
|
|
abort(403, "Class with {$namespace} namespace or {$appFilePath} doesn't exist, "); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
$instance = app()->make($namespace); |
27
|
|
|
|
28
|
|
|
if (!$instance instanceof CRUDComponent){ |
29
|
|
|
abort(403, "{$namespace} should implement CRUDComponent interface"); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
return $instance; |
33
|
|
|
} |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
if(! function_exists('crud')) { |
37
|
|
|
function crud($name){ |
38
|
|
|
return \EasyPanel\Models\CRUD::query()->where('name', $name)->first(); |
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
if (! function_exists('hasPermission')) { |
43
|
|
|
function hasPermission($routeName, $withAcl, $withPolicy = false, $entity = []) { |
44
|
|
|
$showButton = true; |
45
|
|
|
|
46
|
|
|
if ($withAcl) { |
47
|
|
|
if (!auth()->user()->hasPermission($routeName)) { |
48
|
|
|
$showButton = false; |
49
|
|
|
} else if ($withPolicy && !auth()->user()->hasPermission($routeName, $entity)) { |
50
|
|
|
$showButton = false; |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
return $showButton; |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|