1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Policies; |
4
|
|
|
|
5
|
|
|
use App\Models\EquipmentCategory; |
6
|
|
|
use App\Models\User; |
7
|
|
|
use App\Models\UserRolePermissions; |
8
|
|
|
use Illuminate\Auth\Access\HandlesAuthorization; |
9
|
|
|
use Illuminate\Support\Facades\Log; |
10
|
|
|
|
11
|
|
|
class EquipmentCategoryPolicy |
12
|
|
|
{ |
13
|
|
|
use HandlesAuthorization; |
14
|
|
|
|
15
|
|
|
/* |
16
|
|
|
* Allow anyone with "Manage Equipment" permission |
17
|
|
|
*/ |
18
|
|
|
public function before(User $user, $method) |
19
|
|
|
{ |
20
|
|
|
$allowed = UserRolePermissions::whereRoleId($user->role_id)->whereHas('UserRolePermissionTypes', function($q) |
21
|
|
|
{ |
22
|
|
|
$q->where('description', 'Manage Equipment'); |
23
|
|
|
})->first(); |
24
|
|
|
|
25
|
|
|
Log::channel('auth')->debug('User '.$user->username.' is checking User Policy access to '.$method.'. Result - '.($allowed->allow ? 'Allow' : 'Deny')); |
26
|
|
|
|
27
|
|
|
if($allowed->allow) |
28
|
|
|
{ |
29
|
|
|
return $allowed->allow; |
30
|
|
|
} |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Determine whether the user can view any models. |
35
|
|
|
* |
36
|
|
|
* @param \App\Models\User $user |
37
|
|
|
* @return mixed |
38
|
|
|
*/ |
39
|
|
|
public function viewAny(User $user) |
|
|
|
|
40
|
|
|
{ |
41
|
|
|
return false; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Determine whether the user can view the model. |
46
|
|
|
* |
47
|
|
|
* @param \App\Models\User $user |
48
|
|
|
* @param \App\Models\EquipmentCategory $equipmentCategory |
49
|
|
|
* @return mixed |
50
|
|
|
*/ |
51
|
|
|
public function view(User $user, EquipmentCategory $equipmentCategory) |
|
|
|
|
52
|
|
|
{ |
53
|
|
|
return false; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Determine whether the user can create models. |
58
|
|
|
* |
59
|
|
|
* @param \App\Models\User $user |
60
|
|
|
* @return mixed |
61
|
|
|
*/ |
62
|
|
|
public function create(User $user) |
|
|
|
|
63
|
|
|
{ |
64
|
|
|
return false; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Determine whether the user can update the model. |
69
|
|
|
* |
70
|
|
|
* @param \App\Models\User $user |
71
|
|
|
* @param \App\Models\EquipmentCategory $equipmentCategory |
72
|
|
|
* @return mixed |
73
|
|
|
*/ |
74
|
|
|
public function update(User $user, EquipmentCategory $equipmentCategory) |
|
|
|
|
75
|
|
|
{ |
76
|
|
|
return false; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Determine whether the user can delete the model. |
81
|
|
|
* |
82
|
|
|
* @param \App\Models\User $user |
83
|
|
|
* @param \App\Models\EquipmentCategory $equipmentCategory |
84
|
|
|
* @return mixed |
85
|
|
|
*/ |
86
|
|
|
public function delete(User $user, EquipmentCategory $equipmentCategory) |
|
|
|
|
87
|
|
|
{ |
88
|
|
|
return false; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Determine whether the user can restore the model. |
93
|
|
|
* |
94
|
|
|
* @param \App\Models\User $user |
95
|
|
|
* @param \App\Models\EquipmentCategory $equipmentCategory |
96
|
|
|
* @return mixed |
97
|
|
|
*/ |
98
|
|
|
public function restore(User $user, EquipmentCategory $equipmentCategory) |
|
|
|
|
99
|
|
|
{ |
100
|
|
|
return false; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Determine whether the user can permanently delete the model. |
105
|
|
|
* |
106
|
|
|
* @param \App\Models\User $user |
107
|
|
|
* @param \App\Models\EquipmentCategory $equipmentCategory |
108
|
|
|
* @return mixed |
109
|
|
|
*/ |
110
|
|
|
public function forceDelete(User $user, EquipmentCategory $equipmentCategory) |
|
|
|
|
111
|
|
|
{ |
112
|
|
|
return false; |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.