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