1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of Webcook security bundle. |
5
|
|
|
* |
6
|
|
|
* See LICENSE file in the root of the bundle. Webcook |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Webcook\Cms\SecurityBundle\Entity; |
10
|
|
|
|
11
|
|
|
use Webcook\Cms\CoreBundle\Base\BasicEntity; |
12
|
|
|
use Doctrine\ORM\Mapping as ORM; |
13
|
|
|
use Webcook\Cms\SecurityBundle\Authorization\Voter\WebcookCmsVoter; |
14
|
|
|
use ApiPlatform\Core\Annotation\ApiProperty; |
15
|
|
|
use ApiPlatform\Core\Annotation\ApiResource; |
16
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Role resource entity. |
20
|
|
|
* |
21
|
|
|
* @ORM\Table(name="Security_role_resource") |
22
|
|
|
* @ORM\Entity() |
23
|
|
|
*/ |
24
|
|
|
class RoleResource extends BasicEntity |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* View permission. |
28
|
|
|
* |
29
|
|
|
* @ORM\Column(name="view", type="boolean") |
30
|
|
|
*/ |
31
|
|
|
private $view = true; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Insert permission. |
35
|
|
|
* |
36
|
|
|
* @ORM\Column(name="`insert`", type="boolean") |
37
|
|
|
*/ |
38
|
|
|
private $insert = false; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Edit permission. |
42
|
|
|
* |
43
|
|
|
* @ORM\Column(name="edit", type="boolean") |
44
|
|
|
*/ |
45
|
|
|
private $edit = false; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Delete permission. |
49
|
|
|
* |
50
|
|
|
* @ORM\Column(name="`delete`", type="boolean") |
51
|
|
|
*/ |
52
|
|
|
private $delete = false; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Resource object. |
56
|
|
|
* |
57
|
|
|
* @ORM\ManyToOne(targetEntity="Resource", fetch="EAGER") |
58
|
|
|
* @ORM\JoinColumn(name="resource_id", referencedColumnName="id", nullable=true, onDelete="CASCADE") |
59
|
|
|
**/ |
60
|
|
|
private $resource; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Role object. |
64
|
|
|
* |
65
|
|
|
* @ORM\ManyToOne(targetEntity="Role", inversedBy="resources") |
66
|
|
|
**/ |
67
|
|
|
private $role; |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Check whether role resource has a permission. |
71
|
|
|
* |
72
|
|
|
* @param [type] $attribute [description] |
|
|
|
|
73
|
30 |
|
* |
74
|
|
|
* @return boolean|null [description] |
75
|
|
|
*/ |
76
|
30 |
|
public function isGranted($attribute) |
77
|
12 |
|
{ |
78
|
|
|
switch ($attribute) { |
79
|
|
|
case WebcookCmsVoter::ACTION_VIEW: |
80
|
21 |
|
return $this->view; |
81
|
7 |
|
break; |
|
|
|
|
82
|
|
|
|
83
|
|
|
case WebcookCmsVoter::ACTION_INSERT: |
84
|
14 |
|
return $this->insert; |
85
|
11 |
|
break; |
|
|
|
|
86
|
|
|
|
87
|
|
|
case WebcookCmsVoter::ACTION_EDIT: |
88
|
4 |
|
return $this->edit; |
89
|
4 |
|
break; |
|
|
|
|
90
|
|
|
|
91
|
|
|
case WebcookCmsVoter::ACTION_DELETE: |
92
|
|
|
return $this->delete; |
93
|
1 |
|
break; |
|
|
|
|
94
|
|
|
|
95
|
|
|
default: |
96
|
|
|
return false; |
97
|
|
|
break; |
|
|
|
|
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Gets the value of view. |
103
|
4 |
|
* |
104
|
|
|
* @return boolean |
105
|
4 |
|
*/ |
106
|
|
|
public function getView() |
107
|
|
|
{ |
108
|
|
|
return $this->view; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Sets the value of view. |
113
|
|
|
* |
114
|
|
|
* @param mixed $view the view |
115
|
1 |
|
* |
116
|
|
|
* @return self |
117
|
1 |
|
*/ |
118
|
|
|
public function setView($view) |
119
|
1 |
|
{ |
120
|
|
|
$this->view = $view; |
121
|
|
|
|
122
|
|
|
return $this; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Gets the value of edit. |
127
|
4 |
|
* |
128
|
|
|
* @return boolean |
129
|
4 |
|
*/ |
130
|
|
|
public function getEdit() |
131
|
|
|
{ |
132
|
|
|
return $this->edit; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Sets the value of edit. |
137
|
|
|
* |
138
|
|
|
* @param boolean $edit the edit |
139
|
49 |
|
* |
140
|
|
|
* @return self |
141
|
49 |
|
*/ |
142
|
|
|
public function setEdit($edit) |
143
|
49 |
|
{ |
144
|
|
|
$this->edit = $edit; |
145
|
|
|
|
146
|
|
|
return $this; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* Gets the value of delete. |
151
|
4 |
|
* |
152
|
|
|
* @return boolean |
153
|
4 |
|
*/ |
154
|
|
|
public function getDelete() |
155
|
|
|
{ |
156
|
|
|
return $this->delete; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* Sets the value of delete. |
161
|
|
|
* |
162
|
|
|
* @param boolean $delete the delete |
163
|
49 |
|
* |
164
|
|
|
* @return self |
165
|
49 |
|
*/ |
166
|
|
|
public function setDelete($delete) |
167
|
49 |
|
{ |
168
|
|
|
$this->delete = $delete; |
169
|
|
|
|
170
|
|
|
return $this; |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* Gets the value of resource. |
175
|
31 |
|
* |
176
|
|
|
* @return mixed |
177
|
31 |
|
*/ |
178
|
|
|
public function getResource() |
179
|
|
|
{ |
180
|
|
|
return $this->resource; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* Sets the value of resource. |
185
|
|
|
* |
186
|
|
|
* @param mixed $resource the resource |
187
|
49 |
|
* |
188
|
|
|
* @return self |
189
|
49 |
|
*/ |
190
|
|
|
public function setResource($resource) |
191
|
49 |
|
{ |
192
|
|
|
$this->resource = $resource; |
193
|
|
|
|
194
|
|
|
return $this; |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* Gets the value of role. |
199
|
3 |
|
* |
200
|
|
|
* @return mixed |
201
|
3 |
|
*/ |
202
|
|
|
public function getRole() |
203
|
|
|
{ |
204
|
|
|
return $this->role; |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* Sets the value of role. |
209
|
|
|
* |
210
|
|
|
* @param mixed $role the role |
211
|
49 |
|
* |
212
|
|
|
* @return self |
213
|
49 |
|
*/ |
214
|
|
|
public function setRole($role) |
215
|
49 |
|
{ |
216
|
|
|
$this->role = $role; |
217
|
|
|
|
218
|
|
|
return $this; |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* Gets the Insert permission. |
223
|
3 |
|
* |
224
|
|
|
* @return boolean |
225
|
3 |
|
*/ |
226
|
|
|
public function getInsert() |
227
|
|
|
{ |
228
|
|
|
return $this->insert; |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
/** |
232
|
|
|
* Sets the Insert permission. |
233
|
|
|
* |
234
|
|
|
* @param boolean $insert the insert |
235
|
49 |
|
* |
236
|
|
|
* @return self |
237
|
49 |
|
*/ |
238
|
|
|
public function setInsert($insert) |
239
|
49 |
|
{ |
240
|
|
|
$this->insert = $insert; |
241
|
|
|
|
242
|
|
|
return $this; |
243
|
|
|
} |
244
|
|
|
} |
245
|
|
|
|
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.