1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Policies; |
4
|
|
|
|
5
|
|
|
use App\Models\Role; |
6
|
|
|
use App\Models\User; |
7
|
|
|
use Illuminate\Auth\Access\HandlesAuthorization; |
8
|
|
|
|
9
|
|
|
class RolePolicy |
10
|
|
|
{ |
11
|
|
|
use HandlesAuthorization; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Perform pre-authorization checks. |
15
|
|
|
* |
16
|
|
|
* @param \App\Models\User $user |
17
|
|
|
* @param string $ability |
18
|
|
|
* @return void|bool |
19
|
|
|
*/ |
20
|
24 |
|
public function before(User $user, $ability) |
|
|
|
|
21
|
|
|
{ |
22
|
24 |
|
if ($user->hasRole(Role::ROLE_ADMIN)) { |
23
|
24 |
|
return true; |
24
|
|
|
} |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Determine whether the user can view any models. |
29
|
|
|
* |
30
|
|
|
* @param \App\Models\User $user |
31
|
|
|
* @return \Illuminate\Auth\Access\Response|bool |
32
|
|
|
*/ |
33
|
|
|
public function viewAny(User $user) |
34
|
|
|
{ |
35
|
|
|
return $user->hasRole(Role::ROLE_STAFF); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Determine whether the user can view the model. |
40
|
|
|
* |
41
|
|
|
* @param \App\Models\User $user |
42
|
|
|
* @param \App\Models\Role $role |
43
|
|
|
* @return \Illuminate\Auth\Access\Response|bool |
44
|
|
|
*/ |
45
|
|
|
public function view(User $user, Role $role) |
|
|
|
|
46
|
|
|
{ |
47
|
|
|
return $user->hasRole(Role::ROLE_STAFF); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Determine whether the user can create models. |
52
|
|
|
* |
53
|
|
|
* @param \App\Models\User $user |
54
|
|
|
* @return \Illuminate\Auth\Access\Response|bool |
55
|
|
|
*/ |
56
|
|
|
public function create(User $user) |
|
|
|
|
57
|
|
|
{ |
58
|
|
|
return false; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Determine whether the user can update the model. |
63
|
|
|
* |
64
|
|
|
* @param \App\Models\User $user |
65
|
|
|
* @param \App\Models\Role $role |
66
|
|
|
* @return \Illuminate\Auth\Access\Response|bool |
67
|
|
|
*/ |
68
|
|
|
public function update(User $user, Role $role) |
|
|
|
|
69
|
|
|
{ |
70
|
|
|
return false; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Determine whether the user can delete the model. |
75
|
|
|
* |
76
|
|
|
* @param \App\Models\User $user |
77
|
|
|
* @param \App\Models\Role $role |
78
|
|
|
* @return \Illuminate\Auth\Access\Response|bool |
79
|
|
|
*/ |
80
|
|
|
public function delete(User $user, Role $role) |
|
|
|
|
81
|
|
|
{ |
82
|
|
|
return false; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Determine whether the user can restore the model. |
87
|
|
|
* |
88
|
|
|
* @param \App\Models\User $user |
89
|
|
|
* @param \App\Models\Role $role |
90
|
|
|
* @return \Illuminate\Auth\Access\Response|bool |
91
|
|
|
*/ |
92
|
|
|
public function restore(User $user, Role $role) |
|
|
|
|
93
|
|
|
{ |
94
|
|
|
return false; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Determine whether the user can permanently delete the model. |
99
|
|
|
* |
100
|
|
|
* @param \App\Models\User $user |
101
|
|
|
* @param \App\Models\Role $role |
102
|
|
|
* @return \Illuminate\Auth\Access\Response|bool |
103
|
|
|
*/ |
104
|
|
|
public function forceDelete(User $user, Role $role) |
|
|
|
|
105
|
|
|
{ |
106
|
|
|
return false; |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.