1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Backpack\PermissionManager\app\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use Backpack\CRUD\app\Http\Controllers\CrudController; |
6
|
|
|
|
7
|
|
|
// VALIDATION |
8
|
|
|
|
9
|
|
|
class PermissionCrudController extends CrudController |
10
|
|
|
{ |
11
|
|
|
use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation; |
12
|
|
|
use \Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation; |
13
|
|
|
use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation; |
14
|
|
|
use \Backpack\CRUD\app\Http\Controllers\Operations\DeleteOperation; |
15
|
|
|
|
16
|
|
|
public function setup() |
17
|
|
|
{ |
18
|
|
|
$role_model = config('backpack.permissionmanager.models.role'); |
|
|
|
|
19
|
|
|
$permission_model = config('backpack.permissionmanager.models.permission'); |
20
|
|
|
|
21
|
|
|
$this->crud->setModel($permission_model); |
22
|
|
|
$this->crud->setEntityNameStrings(trans('backpack::permissionmanager.permission_singular'), trans('backpack::permissionmanager.permission_plural')); |
23
|
|
|
$this->crud->setRoute(backpack_url('permission')); |
24
|
|
|
|
25
|
|
|
// deny access according to configuration file |
26
|
|
|
if (config('backpack.permissionmanager.allow_permission_create') == false) { |
27
|
|
|
$this->crud->denyAccess('create'); |
28
|
|
|
} |
29
|
|
|
if (config('backpack.permissionmanager.allow_permission_update') == false) { |
30
|
|
|
$this->crud->denyAccess('update'); |
31
|
|
|
} |
32
|
|
|
if (config('backpack.permissionmanager.allow_permission_delete') == false) { |
33
|
|
|
$this->crud->denyAccess('delete'); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
$this->crud->operation('list', function () { |
37
|
|
|
$this->crud->addColumn([ |
38
|
|
|
'name' => 'name', |
39
|
|
|
'label' => trans('backpack::permissionmanager.name'), |
40
|
|
|
'type' => 'text', |
41
|
|
|
]); |
42
|
|
|
|
43
|
|
View Code Duplication |
if (config('backpack.permissionmanager.multiple_guards')) { |
|
|
|
|
44
|
|
|
$this->crud->addColumn([ |
45
|
|
|
'name' => 'guard_name', |
46
|
|
|
'label' => trans('backpack::permissionmanager.guard_type'), |
47
|
|
|
'type' => 'text', |
48
|
|
|
]); |
49
|
|
|
} |
50
|
|
|
}); |
51
|
|
|
|
52
|
|
|
$this->crud->operation(['create', 'update'], function () { |
53
|
|
|
$this->crud->addField([ |
54
|
|
|
'name' => 'name', |
55
|
|
|
'label' => trans('backpack::permissionmanager.name'), |
56
|
|
|
'type' => 'text', |
57
|
|
|
]); |
58
|
|
|
|
59
|
|
View Code Duplication |
if (config('backpack.permissionmanager.multiple_guards')) { |
|
|
|
|
60
|
|
|
$this->crud->addField([ |
61
|
|
|
'name' => 'guard_name', |
62
|
|
|
'label' => trans('backpack::permissionmanager.guard_type'), |
63
|
|
|
'type' => 'select_from_array', |
64
|
|
|
'options' => $this->getGuardTypes(), |
65
|
|
|
]); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
//otherwise, changes won't have effect |
69
|
|
|
\Cache::forget('spatie.permission.cache'); |
70
|
|
|
}); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/* |
74
|
|
|
* Get an array list of all available guard types |
75
|
|
|
* that have been defined in app/config/auth.php |
76
|
|
|
* |
77
|
|
|
* @return array |
78
|
|
|
**/ |
79
|
|
View Code Duplication |
private function getGuardTypes() |
|
|
|
|
80
|
|
|
{ |
81
|
|
|
$guards = config('auth.guards'); |
82
|
|
|
|
83
|
|
|
$returnable = []; |
84
|
|
|
foreach ($guards as $key => $details) { |
85
|
|
|
$returnable[$key] = $key; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
return $returnable; |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
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.