1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Backpack\PermissionManager\app\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use Backpack\CRUD\app\Http\Controllers\CrudController; |
6
|
|
|
// VALIDATION |
7
|
|
|
use Backpack\PermissionManager\app\Http\Requests\PermissionCrudRequest as StoreRequest; |
8
|
|
|
use Backpack\PermissionManager\app\Http\Requests\PermissionCrudRequest as UpdateRequest; |
9
|
|
|
|
10
|
|
|
class PermissionCrudController extends CrudController |
11
|
|
|
{ |
12
|
|
|
public function setup() |
13
|
|
|
{ |
14
|
|
|
$role_model = config('backpack.permissionmanager.models.role'); |
|
|
|
|
15
|
|
|
$permission_model = config('backpack.permissionmanager.models.permission'); |
16
|
|
|
|
17
|
|
|
$this->crud->setModel($permission_model); |
18
|
|
|
$this->crud->setEntityNameStrings(trans('backpack::permissionmanager.permission_singular'), trans('backpack::permissionmanager.permission_plural')); |
|
|
|
|
19
|
|
|
$this->crud->setRoute(backpack_url('permission')); |
20
|
|
|
|
21
|
|
|
$this->crud->addColumn([ |
22
|
|
|
'name' => 'name', |
23
|
|
|
'label' => trans('backpack::permissionmanager.name'), |
24
|
|
|
'type' => 'text', |
25
|
|
|
]); |
26
|
|
|
|
27
|
|
View Code Duplication |
if (config('backpack.permissionmanager.multiple_guards')) { |
|
|
|
|
28
|
|
|
$this->crud->addColumn([ |
29
|
|
|
'name' => 'guard_name', |
30
|
|
|
'label' => trans('backpack::permissionmanager.guard_type'), |
31
|
|
|
'type' => 'text', |
32
|
|
|
]); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
$this->crud->addField([ |
36
|
|
|
'name' => 'name', |
37
|
|
|
'label' => trans('backpack::permissionmanager.name'), |
38
|
|
|
'type' => 'text', |
39
|
|
|
]); |
40
|
|
|
|
41
|
|
View Code Duplication |
if (config('backpack.permissionmanager.multiple_guards')) { |
|
|
|
|
42
|
|
|
$this->crud->addField([ |
43
|
|
|
'name' => 'guard_name', |
44
|
|
|
'label' => trans('backpack::permissionmanager.guard_type'), |
45
|
|
|
'type' => 'select_from_array', |
46
|
|
|
'options' => $this->getGuardTypes(), |
47
|
|
|
]); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
if (config('backpack.permissionmanager.allow_permission_create') == false) { |
51
|
|
|
$this->crud->denyAccess('create'); |
52
|
|
|
} |
53
|
|
|
if (config('backpack.permissionmanager.allow_permission_update') == false) { |
54
|
|
|
$this->crud->denyAccess('update'); |
55
|
|
|
} |
56
|
|
|
if (config('backpack.permissionmanager.allow_permission_delete') == false) { |
57
|
|
|
$this->crud->denyAccess('delete'); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function store(StoreRequest $request) |
62
|
|
|
{ |
63
|
|
|
//otherwise, changes won't have effect |
64
|
|
|
\Cache::forget('spatie.permission.cache'); |
65
|
|
|
|
66
|
|
|
return parent::storeCrud(); |
|
|
|
|
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function update(UpdateRequest $request) |
70
|
|
|
{ |
71
|
|
|
//otherwise, changes won't have effect |
72
|
|
|
\Cache::forget('spatie.permission.cache'); |
73
|
|
|
|
74
|
|
|
return parent::updateCrud(); |
|
|
|
|
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/* |
78
|
|
|
* Get an array list of all available guard types |
79
|
|
|
* that have been defined in app/config/auth.php |
80
|
|
|
* |
81
|
|
|
* @return array |
82
|
|
|
**/ |
83
|
|
View Code Duplication |
private function getGuardTypes() |
|
|
|
|
84
|
|
|
{ |
85
|
|
|
$guards = config('auth.guards'); |
86
|
|
|
|
87
|
|
|
$returnable = []; |
88
|
|
|
foreach ($guards as $key => $details) { |
89
|
|
|
$returnable[$key] = $key; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
return $returnable; |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.