|
1
|
|
|
<?php namespace Arcanesoft\Auth\Http\Controllers\Admin; |
|
2
|
|
|
|
|
3
|
|
|
use Arcanesoft\Auth\Policies\PermissionsPolicy; |
|
4
|
|
|
use Arcanesoft\Contracts\Auth\Models\Permission; |
|
5
|
|
|
use Arcanesoft\Contracts\Auth\Models\PermissionsGroup; |
|
6
|
|
|
use Arcanesoft\Contracts\Auth\Models\Role; |
|
7
|
|
|
use Log; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class PermissionsController |
|
11
|
|
|
* |
|
12
|
|
|
* @package Arcanesoft\Auth\Http\Controllers\Admin |
|
13
|
|
|
* @author ARCANEDEV <[email protected]> |
|
14
|
|
|
*/ |
|
15
|
|
|
class PermissionsController extends Controller |
|
16
|
|
|
{ |
|
17
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
18
|
|
|
| Properties |
|
19
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
20
|
|
|
*/ |
|
21
|
|
|
/** @var \Arcanesoft\Contracts\Auth\Models\Permission */ |
|
22
|
|
|
protected $permission; |
|
23
|
|
|
|
|
24
|
|
|
/** @var int */ |
|
25
|
|
|
protected $perPage = 30; |
|
26
|
|
|
|
|
27
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
28
|
|
|
| Constructor |
|
29
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
30
|
|
|
*/ |
|
31
|
|
|
/** |
|
32
|
|
|
* Instantiate the controller. |
|
33
|
|
|
* |
|
34
|
|
|
* @param \Arcanesoft\Contracts\Auth\Models\Permission $permission |
|
35
|
|
|
*/ |
|
36
|
|
|
public function __construct(Permission $permission) |
|
37
|
|
|
{ |
|
38
|
|
|
parent::__construct(); |
|
39
|
|
|
|
|
40
|
|
|
$this->permission = $permission; |
|
41
|
|
|
|
|
42
|
|
|
$this->setCurrentPage('auth-permissions'); |
|
43
|
|
|
$this->addBreadcrumbRoute('Permissions', 'admin::auth.permissions.index'); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/* ------------------------------------------------------------------------------------------------ |
|
47
|
|
|
| Main Functions |
|
48
|
|
|
| ------------------------------------------------------------------------------------------------ |
|
49
|
|
|
*/ |
|
50
|
|
|
public function index() |
|
51
|
|
|
{ |
|
52
|
|
|
$this->authorize(PermissionsPolicy::PERMISSION_LIST); |
|
53
|
|
|
|
|
54
|
|
|
$permissions = $this->permission->with('group', 'roles') |
|
|
|
|
|
|
55
|
|
|
->orderBy('group_id') |
|
56
|
|
|
->paginate($this->perPage); |
|
57
|
|
|
|
|
58
|
|
|
$this->setTitle($title = 'List of permissions'); |
|
59
|
|
|
$this->addBreadcrumb($title); |
|
60
|
|
|
|
|
61
|
|
|
return $this->view('admin.permissions.list', compact('permissions')); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function group(PermissionsGroup $group) |
|
65
|
|
|
{ |
|
66
|
|
|
$this->authorize(PermissionsPolicy::PERMISSION_LIST); |
|
67
|
|
|
|
|
68
|
|
|
$groupId = $group->id ? $group->id : 0; |
|
|
|
|
|
|
69
|
|
|
|
|
70
|
|
|
$permissions = $this->permission->where('group_id', $groupId) |
|
|
|
|
|
|
71
|
|
|
->with('group', 'roles') |
|
72
|
|
|
->paginate($this->perPage); |
|
73
|
|
|
|
|
74
|
|
|
$groupName = $groupId == 0 ? 'Custom' : $group->name; |
|
|
|
|
|
|
75
|
|
|
|
|
76
|
|
|
$this->setTitle($title = "List of permissions - $groupName"); |
|
77
|
|
|
$this->addBreadcrumbRoute('List of permissions', 'admin::auth.permissions.index'); |
|
78
|
|
|
$this->addBreadcrumb($groupName); |
|
79
|
|
|
|
|
80
|
|
|
return $this->view('admin.permissions.list', compact('permissions')); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
public function show(Permission $permission) |
|
84
|
|
|
{ |
|
85
|
|
|
$this->authorize(PermissionsPolicy::PERMISSION_SHOW); |
|
86
|
|
|
|
|
87
|
|
|
$permission->load(['roles', 'roles.users']); |
|
88
|
|
|
|
|
89
|
|
|
$this->setTitle($title = 'Permission details'); |
|
90
|
|
|
$this->addBreadcrumb($title); |
|
91
|
|
|
|
|
92
|
|
|
return $this->view('admin.permissions.show', compact('permission')); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
public function detachRole(Permission $permission, Role $role) |
|
96
|
|
|
{ |
|
97
|
|
|
self::onlyAjax(); |
|
98
|
|
|
$this->authorize(PermissionsPolicy::PERMISSION_UPDATE); |
|
99
|
|
|
|
|
100
|
|
|
try { |
|
101
|
|
|
$permission->detachRole($role, false); |
|
102
|
|
|
|
|
103
|
|
|
$title = 'Role detached !'; |
|
104
|
|
|
$message = "The role {$role->name} has been successfully detached from {$permission->name} !"; |
|
|
|
|
|
|
105
|
|
|
|
|
106
|
|
|
Log::info($message, compact('permission', 'role')); |
|
107
|
|
|
$this->notifySuccess($message, $title); |
|
108
|
|
|
|
|
109
|
|
|
$ajax = [ |
|
110
|
|
|
'status' => 'success', |
|
111
|
|
|
'message' => $message, |
|
112
|
|
|
]; |
|
113
|
|
|
} |
|
114
|
|
|
catch(\Exception $e) { |
|
115
|
|
|
$ajax = [ |
|
116
|
|
|
'status' => 'error', |
|
117
|
|
|
'message' => $e->getMessage(), |
|
118
|
|
|
]; |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
return response()->json($ajax); |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.