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