1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Cortex\Tenants\Policies; |
6
|
|
|
|
7
|
|
|
use Rinvex\Fort\Models\User; |
8
|
|
|
use Rinvex\Tenants\Models\Tenant; |
9
|
|
|
use Illuminate\Auth\Access\HandlesAuthorization; |
10
|
|
|
|
11
|
|
|
class TenantPolicy |
12
|
|
|
{ |
13
|
|
|
use HandlesAuthorization; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Determine whether the user can list tenants. |
17
|
|
|
* |
18
|
|
|
* @param string $ability |
19
|
|
|
* @param \Rinvex\Fort\Models\User $user |
20
|
|
|
* |
21
|
|
|
* @return bool |
22
|
|
|
*/ |
23
|
|
|
public function list($ability, User $user): bool |
24
|
|
|
{ |
25
|
|
|
return $user->allAbilities->pluck('slug')->contains($ability); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Determine whether the user can create tenants. |
30
|
|
|
* |
31
|
|
|
* @param string $ability |
32
|
|
|
* @param \Rinvex\Fort\Models\User $user |
33
|
|
|
* |
34
|
|
|
* @return bool |
35
|
|
|
*/ |
36
|
|
|
public function create($ability, User $user): bool |
37
|
|
|
{ |
38
|
|
|
return $user->allAbilities->pluck('slug')->contains($ability); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Determine whether the user can update the tenant. |
43
|
|
|
* |
44
|
|
|
* @param string $ability |
45
|
|
|
* @param \Rinvex\Fort\Models\User $user |
46
|
|
|
* @param \Rinvex\Tenants\Models\Tenant $resource |
47
|
|
|
* |
48
|
|
|
* @return bool |
49
|
|
|
*/ |
50
|
|
|
public function update($ability, User $user, Tenant $resource): bool |
|
|
|
|
51
|
|
|
{ |
52
|
|
|
return $user->allAbilities->pluck('slug')->contains($ability); // User can update tenants |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Determine whether the user can delete the tenant. |
57
|
|
|
* |
58
|
|
|
* @param string $ability |
59
|
|
|
* @param \Rinvex\Fort\Models\User $user |
60
|
|
|
* @param \Rinvex\Tenants\Models\Tenant $resource |
61
|
|
|
* |
62
|
|
|
* @return bool |
63
|
|
|
*/ |
64
|
|
|
public function delete($ability, User $user, Tenant $resource): bool |
|
|
|
|
65
|
|
|
{ |
66
|
|
|
return $user->allAbilities->pluck('slug')->contains($ability); // User can delete tenants |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Determine whether the user can list tenant media. |
71
|
|
|
* |
72
|
|
|
* @param string $ability |
73
|
|
|
* @param \Rinvex\Fort\Models\User $user |
74
|
|
|
* |
75
|
|
|
* @return bool |
76
|
|
|
*/ |
77
|
|
|
public function listMedia($ability, User $user): bool |
78
|
|
|
{ |
79
|
|
|
return $user->allAbilities->pluck('slug')->contains($ability); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Determine whether the user can create tenant media. |
84
|
|
|
* |
85
|
|
|
* @param string $ability |
86
|
|
|
* @param \Rinvex\Fort\Models\User $user |
87
|
|
|
* |
88
|
|
|
* @return bool |
89
|
|
|
*/ |
90
|
|
|
public function createMedia($ability, User $user): bool |
91
|
|
|
{ |
92
|
|
|
return $user->allAbilities->pluck('slug')->contains($ability); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Determine whether the user can delete the tenant media. |
97
|
|
|
* |
98
|
|
|
* @param string $ability |
99
|
|
|
* @param \Rinvex\Fort\Models\User $user |
100
|
|
|
* @param \Rinvex\Tenants\Models\Tenant $resource |
101
|
|
|
* |
102
|
|
|
* @return bool |
103
|
|
|
*/ |
104
|
|
|
public function deleteMedia($ability, User $user, Tenant $resource): bool |
|
|
|
|
105
|
|
|
{ |
106
|
|
|
return $user->allAbilities->pluck('slug')->contains($ability); // User can delete tenant media |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.