1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* NOTICE OF LICENSE |
5
|
|
|
* |
6
|
|
|
* Part of the Rinvex Fort Package. |
7
|
|
|
* |
8
|
|
|
* This source file is subject to The MIT License (MIT) |
9
|
|
|
* that is bundled with this package in the LICENSE file. |
10
|
|
|
* |
11
|
|
|
* Package: Rinvex Fort Package |
12
|
|
|
* License: The MIT License (MIT) |
13
|
|
|
* Link: https://rinvex.com |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
namespace Rinvex\Fort\Policies; |
17
|
|
|
|
18
|
|
|
use Rinvex\Fort\Models\User; |
19
|
|
|
use Illuminate\Auth\Access\HandlesAuthorization; |
20
|
|
|
|
21
|
|
|
class UserPolicy |
22
|
|
|
{ |
23
|
|
|
use HandlesAuthorization; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Determine whether the user can view the user. |
27
|
|
|
* |
28
|
|
|
* @param \Rinvex\Fort\Models\User $user |
29
|
|
|
* @param \Rinvex\Fort\Models\User $model |
30
|
|
|
* |
31
|
|
|
* @return bool |
32
|
|
|
*/ |
33
|
|
|
public function view(User $user, User $model) |
|
|
|
|
34
|
|
|
{ |
35
|
|
|
return true; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Determine whether the user can create users. |
40
|
|
|
* |
41
|
|
|
* @param \Rinvex\Fort\Models\User $user |
42
|
|
|
* |
43
|
|
|
* @return bool |
44
|
|
|
*/ |
45
|
|
|
public function create(User $user) |
|
|
|
|
46
|
|
|
{ |
47
|
|
|
return true; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Determine whether the user can update the user. |
52
|
|
|
* |
53
|
|
|
* @param \Rinvex\Fort\Models\User $user |
54
|
|
|
* @param \Rinvex\Fort\Models\User $model |
55
|
|
|
* |
56
|
|
|
* @return bool |
57
|
|
|
*/ |
58
|
|
|
public function update(User $user, User $model) |
59
|
|
|
{ |
60
|
|
|
// Super admins & protected users can be controlled by super admins only! |
61
|
|
|
return $model->isProtected() || ($model->isSuperadmin() && ! $user->isSuperadmin()) ? false : true; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Determine whether the user can delete the user. |
66
|
|
|
* |
67
|
|
|
* @param \Rinvex\Fort\Models\User $user |
68
|
|
|
* @param \Rinvex\Fort\Models\User $model |
69
|
|
|
* |
70
|
|
|
* @return bool |
71
|
|
|
*/ |
72
|
|
|
public function delete(User $user, User $model) |
73
|
|
|
{ |
74
|
|
|
// Super admins & protected users can be controlled by super admins only! Users can NOT delete themeselves! |
75
|
|
|
return $model->isProtected() || ($model->isSuperadmin() && ! $user->isSuperadmin()) || $model->id === $user->id ? false : true; |
|
|
|
|
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Determine whether the user can import the users. |
80
|
|
|
* |
81
|
|
|
* @param \Rinvex\Fort\Models\User $user |
82
|
|
|
* |
83
|
|
|
* @return bool |
84
|
|
|
*/ |
85
|
|
|
public function import(User $user) |
|
|
|
|
86
|
|
|
{ |
87
|
|
|
return true; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Determine whether the user can export the users. |
92
|
|
|
* |
93
|
|
|
* @param \Rinvex\Fort\Models\User $user |
94
|
|
|
* |
95
|
|
|
* @return bool |
96
|
|
|
*/ |
97
|
|
|
public function export(User $user) |
|
|
|
|
98
|
|
|
{ |
99
|
|
|
return true; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Determine whether the user can activate the user. |
104
|
|
|
* |
105
|
|
|
* @param \Rinvex\Fort\Models\User $user |
106
|
|
|
* @param \Rinvex\Fort\Models\Ability $model |
|
|
|
|
107
|
|
|
* |
108
|
|
|
* @return bool |
109
|
|
|
*/ |
110
|
|
|
public function activate(User $user, User $model) |
111
|
|
|
{ |
112
|
|
|
// Super admins & protected users can be activated by super |
113
|
|
|
// admins only! Users can NOT activate their own accounts! |
114
|
|
|
return $model->isProtected() || ($model->isSuperadmin() && ! $user->isSuperadmin()) || $model->id === $user->id ? false : true; |
|
|
|
|
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Determine whether the user can deactivate the user. |
119
|
|
|
* |
120
|
|
|
* @param \Rinvex\Fort\Models\User $user |
121
|
|
|
* @param \Rinvex\Fort\Models\Ability $model |
|
|
|
|
122
|
|
|
* |
123
|
|
|
* @return bool |
124
|
|
|
*/ |
125
|
|
|
public function deactivate(User $user, User $model) |
126
|
|
|
{ |
127
|
|
|
// Super admins & protected users can be de-activated by super |
128
|
|
|
// admins only! Users can NOT de-activate their own accounts! |
129
|
|
|
return $model->isProtected() || ($model->isSuperadmin() && ! $user->isSuperadmin()) || $model->id === $user->id ? false : true; |
|
|
|
|
130
|
|
|
} |
131
|
|
|
} |
132
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.