1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
5
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
6
|
|
|
*/ |
7
|
|
|
declare(strict_types=1); |
8
|
|
|
|
9
|
|
|
namespace eZ\Publish\Core\Event; |
10
|
|
|
|
11
|
|
|
use eZ\Publish\SPI\Repository\Decorator\RoleServiceDecorator; |
12
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
13
|
|
|
use eZ\Publish\API\Repository\RoleService as RoleServiceInterface; |
14
|
|
|
use eZ\Publish\API\Repository\Values\User\Limitation\RoleLimitation; |
15
|
|
|
use eZ\Publish\API\Repository\Values\User\Policy; |
16
|
|
|
use eZ\Publish\API\Repository\Values\User\PolicyCreateStruct; |
17
|
|
|
use eZ\Publish\API\Repository\Values\User\PolicyDraft; |
18
|
|
|
use eZ\Publish\API\Repository\Values\User\PolicyUpdateStruct; |
19
|
|
|
use eZ\Publish\API\Repository\Values\User\Role; |
20
|
|
|
use eZ\Publish\API\Repository\Values\User\RoleAssignment; |
21
|
|
|
use eZ\Publish\API\Repository\Values\User\RoleCreateStruct; |
22
|
|
|
use eZ\Publish\API\Repository\Values\User\RoleDraft; |
23
|
|
|
use eZ\Publish\API\Repository\Values\User\RoleUpdateStruct; |
24
|
|
|
use eZ\Publish\API\Repository\Values\User\User; |
25
|
|
|
use eZ\Publish\API\Repository\Values\User\UserGroup; |
26
|
|
|
use eZ\Publish\Core\Event\Role\AddPolicyByRoleDraftEvent; |
27
|
|
|
use eZ\Publish\Core\Event\Role\AddPolicyEvent; |
28
|
|
|
use eZ\Publish\Core\Event\Role\AssignRoleToUserEvent; |
29
|
|
|
use eZ\Publish\Core\Event\Role\AssignRoleToUserGroupEvent; |
30
|
|
|
use eZ\Publish\Core\Event\Role\BeforeAddPolicyByRoleDraftEvent; |
31
|
|
|
use eZ\Publish\Core\Event\Role\BeforeAddPolicyEvent; |
32
|
|
|
use eZ\Publish\Core\Event\Role\BeforeAssignRoleToUserEvent; |
33
|
|
|
use eZ\Publish\Core\Event\Role\BeforeAssignRoleToUserGroupEvent; |
34
|
|
|
use eZ\Publish\Core\Event\Role\BeforeCreateRoleDraftEvent; |
35
|
|
|
use eZ\Publish\Core\Event\Role\BeforeCreateRoleEvent; |
36
|
|
|
use eZ\Publish\Core\Event\Role\BeforeDeletePolicyEvent; |
37
|
|
|
use eZ\Publish\Core\Event\Role\BeforeDeleteRoleDraftEvent; |
38
|
|
|
use eZ\Publish\Core\Event\Role\BeforeDeleteRoleEvent; |
39
|
|
|
use eZ\Publish\Core\Event\Role\BeforePublishRoleDraftEvent; |
40
|
|
|
use eZ\Publish\Core\Event\Role\BeforeRemovePolicyByRoleDraftEvent; |
41
|
|
|
use eZ\Publish\Core\Event\Role\BeforeRemoveRoleAssignmentEvent; |
42
|
|
|
use eZ\Publish\Core\Event\Role\BeforeUnassignRoleFromUserEvent; |
43
|
|
|
use eZ\Publish\Core\Event\Role\BeforeUnassignRoleFromUserGroupEvent; |
44
|
|
|
use eZ\Publish\Core\Event\Role\BeforeUpdatePolicyByRoleDraftEvent; |
45
|
|
|
use eZ\Publish\Core\Event\Role\BeforeUpdatePolicyEvent; |
46
|
|
|
use eZ\Publish\Core\Event\Role\BeforeUpdateRoleDraftEvent; |
47
|
|
|
use eZ\Publish\Core\Event\Role\BeforeUpdateRoleEvent; |
48
|
|
|
use eZ\Publish\Core\Event\Role\CreateRoleDraftEvent; |
49
|
|
|
use eZ\Publish\Core\Event\Role\CreateRoleEvent; |
50
|
|
|
use eZ\Publish\Core\Event\Role\DeletePolicyEvent; |
51
|
|
|
use eZ\Publish\Core\Event\Role\DeleteRoleDraftEvent; |
52
|
|
|
use eZ\Publish\Core\Event\Role\DeleteRoleEvent; |
53
|
|
|
use eZ\Publish\Core\Event\Role\PublishRoleDraftEvent; |
54
|
|
|
use eZ\Publish\Core\Event\Role\RemovePolicyByRoleDraftEvent; |
55
|
|
|
use eZ\Publish\Core\Event\Role\RemoveRoleAssignmentEvent; |
56
|
|
|
use eZ\Publish\Core\Event\Role\RoleEvents; |
57
|
|
|
use eZ\Publish\Core\Event\Role\UnassignRoleFromUserEvent; |
58
|
|
|
use eZ\Publish\Core\Event\Role\UnassignRoleFromUserGroupEvent; |
59
|
|
|
use eZ\Publish\Core\Event\Role\UpdatePolicyByRoleDraftEvent; |
60
|
|
|
use eZ\Publish\Core\Event\Role\UpdatePolicyEvent; |
61
|
|
|
use eZ\Publish\Core\Event\Role\UpdateRoleDraftEvent; |
62
|
|
|
use eZ\Publish\Core\Event\Role\UpdateRoleEvent; |
63
|
|
|
|
64
|
|
|
class RoleService extends RoleServiceDecorator implements RoleServiceInterface |
65
|
|
|
{ |
66
|
|
|
/** |
67
|
|
|
* @var \Symfony\Component\EventDispatcher\EventDispatcherInterface |
68
|
|
|
*/ |
69
|
|
|
protected $eventDispatcher; |
70
|
|
|
|
71
|
|
|
public function __construct( |
72
|
|
|
RoleServiceInterface $innerService, |
73
|
|
|
EventDispatcherInterface $eventDispatcher |
74
|
|
|
) { |
75
|
|
|
parent::__construct($innerService); |
76
|
|
|
|
77
|
|
|
$this->eventDispatcher = $eventDispatcher; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
View Code Duplication |
public function createRole(RoleCreateStruct $roleCreateStruct): RoleDraft |
81
|
|
|
{ |
82
|
|
|
$eventData = [$roleCreateStruct]; |
83
|
|
|
|
84
|
|
|
$beforeEvent = new BeforeCreateRoleEvent(...$eventData); |
85
|
|
|
if ($this->eventDispatcher->dispatch(RoleEvents::BEFORE_CREATE_ROLE, $beforeEvent)->isPropagationStopped()) { |
86
|
|
|
return $beforeEvent->getReturnValue(); |
87
|
|
|
} else { |
88
|
|
|
$roleDraft = parent::createRole($roleCreateStruct); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
$this->eventDispatcher->dispatch( |
92
|
|
|
RoleEvents::CREATE_ROLE, |
93
|
|
|
new CreateRoleEvent($roleDraft, ...$eventData) |
94
|
|
|
); |
95
|
|
|
|
96
|
|
|
return $roleDraft; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
View Code Duplication |
public function createRoleDraft(Role $role) |
100
|
|
|
{ |
101
|
|
|
$eventData = [$role]; |
102
|
|
|
|
103
|
|
|
$beforeEvent = new BeforeCreateRoleDraftEvent(...$eventData); |
104
|
|
|
if ($this->eventDispatcher->dispatch(RoleEvents::BEFORE_CREATE_ROLE_DRAFT, $beforeEvent)->isPropagationStopped()) { |
105
|
|
|
return $beforeEvent->getReturnValue(); |
106
|
|
|
} else { |
107
|
|
|
$roleDraft = parent::createRoleDraft($role); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
$this->eventDispatcher->dispatch( |
111
|
|
|
RoleEvents::CREATE_ROLE_DRAFT, |
112
|
|
|
new CreateRoleDraftEvent($roleDraft, ...$eventData) |
|
|
|
|
113
|
|
|
); |
114
|
|
|
|
115
|
|
|
return $roleDraft; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
View Code Duplication |
public function updateRoleDraft( |
119
|
|
|
RoleDraft $roleDraft, |
120
|
|
|
RoleUpdateStruct $roleUpdateStruct |
121
|
|
|
) { |
122
|
|
|
$eventData = [ |
123
|
|
|
$roleDraft, |
124
|
|
|
$roleUpdateStruct, |
125
|
|
|
]; |
126
|
|
|
|
127
|
|
|
$beforeEvent = new BeforeUpdateRoleDraftEvent(...$eventData); |
|
|
|
|
128
|
|
|
if ($this->eventDispatcher->dispatch(RoleEvents::BEFORE_UPDATE_ROLE_DRAFT, $beforeEvent)->isPropagationStopped()) { |
129
|
|
|
return $beforeEvent->getReturnValue(); |
130
|
|
|
} else { |
131
|
|
|
$updatedRoleDraft = parent::updateRoleDraft($roleDraft, $roleUpdateStruct); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
$this->eventDispatcher->dispatch( |
135
|
|
|
RoleEvents::UPDATE_ROLE_DRAFT, |
136
|
|
|
new UpdateRoleDraftEvent($updatedRoleDraft, ...$eventData) |
|
|
|
|
137
|
|
|
); |
138
|
|
|
|
139
|
|
|
return $updatedRoleDraft; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
View Code Duplication |
public function addPolicyByRoleDraft( |
143
|
|
|
RoleDraft $roleDraft, |
144
|
|
|
PolicyCreateStruct $policyCreateStruct |
145
|
|
|
) { |
146
|
|
|
$eventData = [ |
147
|
|
|
$roleDraft, |
148
|
|
|
$policyCreateStruct, |
149
|
|
|
]; |
150
|
|
|
|
151
|
|
|
$beforeEvent = new BeforeAddPolicyByRoleDraftEvent(...$eventData); |
|
|
|
|
152
|
|
|
if ($this->eventDispatcher->dispatch(RoleEvents::BEFORE_ADD_POLICY_BY_ROLE_DRAFT, $beforeEvent)->isPropagationStopped()) { |
153
|
|
|
return $beforeEvent->getReturnValue(); |
154
|
|
|
} else { |
155
|
|
|
$updatedRoleDraft = parent::addPolicyByRoleDraft($roleDraft, $policyCreateStruct); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
$this->eventDispatcher->dispatch( |
159
|
|
|
RoleEvents::ADD_POLICY_BY_ROLE_DRAFT, |
160
|
|
|
new AddPolicyByRoleDraftEvent($updatedRoleDraft, ...$eventData) |
|
|
|
|
161
|
|
|
); |
162
|
|
|
|
163
|
|
|
return $updatedRoleDraft; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
View Code Duplication |
public function removePolicyByRoleDraft( |
167
|
|
|
RoleDraft $roleDraft, |
168
|
|
|
PolicyDraft $policyDraft |
169
|
|
|
) { |
170
|
|
|
$eventData = [ |
171
|
|
|
$roleDraft, |
172
|
|
|
$policyDraft, |
173
|
|
|
]; |
174
|
|
|
|
175
|
|
|
$beforeEvent = new BeforeRemovePolicyByRoleDraftEvent(...$eventData); |
|
|
|
|
176
|
|
|
if ($this->eventDispatcher->dispatch(RoleEvents::BEFORE_REMOVE_POLICY_BY_ROLE_DRAFT, $beforeEvent)->isPropagationStopped()) { |
177
|
|
|
return $beforeEvent->getReturnValue(); |
178
|
|
|
} else { |
179
|
|
|
$updatedRoleDraft = parent::removePolicyByRoleDraft($roleDraft, $policyDraft); |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
$this->eventDispatcher->dispatch( |
183
|
|
|
RoleEvents::REMOVE_POLICY_BY_ROLE_DRAFT, |
184
|
|
|
new RemovePolicyByRoleDraftEvent($updatedRoleDraft, ...$eventData) |
|
|
|
|
185
|
|
|
); |
186
|
|
|
|
187
|
|
|
return $updatedRoleDraft; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
View Code Duplication |
public function updatePolicyByRoleDraft( |
191
|
|
|
RoleDraft $roleDraft, |
192
|
|
|
PolicyDraft $policy, |
193
|
|
|
PolicyUpdateStruct $policyUpdateStruct |
194
|
|
|
) { |
195
|
|
|
$eventData = [ |
196
|
|
|
$roleDraft, |
197
|
|
|
$policy, |
198
|
|
|
$policyUpdateStruct, |
199
|
|
|
]; |
200
|
|
|
|
201
|
|
|
$beforeEvent = new BeforeUpdatePolicyByRoleDraftEvent(...$eventData); |
|
|
|
|
202
|
|
|
if ($this->eventDispatcher->dispatch(RoleEvents::BEFORE_UPDATE_POLICY_BY_ROLE_DRAFT, $beforeEvent)->isPropagationStopped()) { |
203
|
|
|
return $beforeEvent->getReturnValue(); |
204
|
|
|
} else { |
205
|
|
|
$updatedPolicyDraft = parent::updatePolicyByRoleDraft($roleDraft, $policy, $policyUpdateStruct); |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
$this->eventDispatcher->dispatch( |
209
|
|
|
RoleEvents::UPDATE_POLICY_BY_ROLE_DRAFT, |
210
|
|
|
new UpdatePolicyByRoleDraftEvent($updatedPolicyDraft, ...$eventData) |
|
|
|
|
211
|
|
|
); |
212
|
|
|
|
213
|
|
|
return $updatedPolicyDraft; |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
public function deleteRoleDraft(RoleDraft $roleDraft): void |
217
|
|
|
{ |
218
|
|
|
$eventData = [$roleDraft]; |
219
|
|
|
|
220
|
|
|
$beforeEvent = new BeforeDeleteRoleDraftEvent(...$eventData); |
221
|
|
|
if ($this->eventDispatcher->dispatch(RoleEvents::BEFORE_DELETE_ROLE_DRAFT, $beforeEvent)->isPropagationStopped()) { |
222
|
|
|
return; |
223
|
|
|
} else { |
224
|
|
|
parent::deleteRoleDraft($roleDraft); |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
$this->eventDispatcher->dispatch( |
228
|
|
|
RoleEvents::DELETE_ROLE_DRAFT, |
229
|
|
|
new DeleteRoleDraftEvent(...$eventData) |
230
|
|
|
); |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
public function publishRoleDraft(RoleDraft $roleDraft): void |
234
|
|
|
{ |
235
|
|
|
$eventData = [$roleDraft]; |
236
|
|
|
|
237
|
|
|
$beforeEvent = new BeforePublishRoleDraftEvent(...$eventData); |
238
|
|
|
if ($this->eventDispatcher->dispatch(RoleEvents::BEFORE_PUBLISH_ROLE_DRAFT, $beforeEvent)->isPropagationStopped()) { |
239
|
|
|
return; |
240
|
|
|
} else { |
241
|
|
|
parent::publishRoleDraft($roleDraft); |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
$this->eventDispatcher->dispatch( |
245
|
|
|
RoleEvents::PUBLISH_ROLE_DRAFT, |
246
|
|
|
new PublishRoleDraftEvent(...$eventData) |
247
|
|
|
); |
248
|
|
|
} |
249
|
|
|
|
250
|
|
View Code Duplication |
public function updateRole( |
251
|
|
|
Role $role, |
252
|
|
|
RoleUpdateStruct $roleUpdateStruct |
253
|
|
|
) { |
254
|
|
|
$eventData = [ |
255
|
|
|
$role, |
256
|
|
|
$roleUpdateStruct, |
257
|
|
|
]; |
258
|
|
|
|
259
|
|
|
$beforeEvent = new BeforeUpdateRoleEvent(...$eventData); |
|
|
|
|
260
|
|
|
if ($this->eventDispatcher->dispatch(RoleEvents::BEFORE_UPDATE_ROLE, $beforeEvent)->isPropagationStopped()) { |
261
|
|
|
return $beforeEvent->getReturnValue(); |
262
|
|
|
} else { |
263
|
|
|
$updatedRole = parent::updateRole($role, $roleUpdateStruct); |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
$this->eventDispatcher->dispatch( |
267
|
|
|
RoleEvents::UPDATE_ROLE, |
268
|
|
|
new UpdateRoleEvent($updatedRole, ...$eventData) |
|
|
|
|
269
|
|
|
); |
270
|
|
|
|
271
|
|
|
return $updatedRole; |
272
|
|
|
} |
273
|
|
|
|
274
|
|
View Code Duplication |
public function addPolicy( |
275
|
|
|
Role $role, |
276
|
|
|
PolicyCreateStruct $policyCreateStruct |
277
|
|
|
) { |
278
|
|
|
$eventData = [ |
279
|
|
|
$role, |
280
|
|
|
$policyCreateStruct, |
281
|
|
|
]; |
282
|
|
|
|
283
|
|
|
$beforeEvent = new BeforeAddPolicyEvent(...$eventData); |
|
|
|
|
284
|
|
|
if ($this->eventDispatcher->dispatch(RoleEvents::BEFORE_ADD_POLICY, $beforeEvent)->isPropagationStopped()) { |
285
|
|
|
return $beforeEvent->getReturnValue(); |
286
|
|
|
} else { |
287
|
|
|
$updatedRole = parent::addPolicy($role, $policyCreateStruct); |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
$this->eventDispatcher->dispatch( |
291
|
|
|
RoleEvents::ADD_POLICY, |
292
|
|
|
new AddPolicyEvent($updatedRole, ...$eventData) |
|
|
|
|
293
|
|
|
); |
294
|
|
|
|
295
|
|
|
return $updatedRole; |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
public function deletePolicy(Policy $policy) |
299
|
|
|
{ |
300
|
|
|
$eventData = [$policy]; |
301
|
|
|
|
302
|
|
|
$beforeEvent = new BeforeDeletePolicyEvent(...$eventData); |
303
|
|
|
if ($this->eventDispatcher->dispatch(RoleEvents::BEFORE_DELETE_POLICY, $beforeEvent)->isPropagationStopped()) { |
304
|
|
|
return; |
305
|
|
|
} else { |
306
|
|
|
parent::deletePolicy($policy); |
307
|
|
|
} |
308
|
|
|
|
309
|
|
|
$this->eventDispatcher->dispatch( |
310
|
|
|
RoleEvents::DELETE_POLICY, |
311
|
|
|
new DeletePolicyEvent(...$eventData) |
312
|
|
|
); |
313
|
|
|
} |
314
|
|
|
|
315
|
|
View Code Duplication |
public function updatePolicy( |
316
|
|
|
Policy $policy, |
317
|
|
|
PolicyUpdateStruct $policyUpdateStruct |
318
|
|
|
) { |
319
|
|
|
$eventData = [ |
320
|
|
|
$policy, |
321
|
|
|
$policyUpdateStruct, |
322
|
|
|
]; |
323
|
|
|
|
324
|
|
|
$beforeEvent = new BeforeUpdatePolicyEvent(...$eventData); |
|
|
|
|
325
|
|
|
if ($this->eventDispatcher->dispatch(RoleEvents::BEFORE_UPDATE_POLICY, $beforeEvent)->isPropagationStopped()) { |
326
|
|
|
return $beforeEvent->getReturnValue(); |
327
|
|
|
} else { |
328
|
|
|
$updatedPolicy = parent::updatePolicy($policy, $policyUpdateStruct); |
329
|
|
|
} |
330
|
|
|
|
331
|
|
|
$this->eventDispatcher->dispatch( |
332
|
|
|
RoleEvents::UPDATE_POLICY, |
333
|
|
|
new UpdatePolicyEvent($updatedPolicy, ...$eventData) |
|
|
|
|
334
|
|
|
); |
335
|
|
|
|
336
|
|
|
return $updatedPolicy; |
337
|
|
|
} |
338
|
|
|
|
339
|
|
|
public function deleteRole(Role $role) |
340
|
|
|
{ |
341
|
|
|
$eventData = [$role]; |
342
|
|
|
|
343
|
|
|
$beforeEvent = new BeforeDeleteRoleEvent(...$eventData); |
344
|
|
|
if ($this->eventDispatcher->dispatch(RoleEvents::BEFORE_DELETE_ROLE, $beforeEvent)->isPropagationStopped()) { |
345
|
|
|
return; |
346
|
|
|
} else { |
347
|
|
|
parent::deleteRole($role); |
348
|
|
|
} |
349
|
|
|
|
350
|
|
|
$this->eventDispatcher->dispatch( |
351
|
|
|
RoleEvents::DELETE_ROLE, |
352
|
|
|
new DeleteRoleEvent(...$eventData) |
353
|
|
|
); |
354
|
|
|
} |
355
|
|
|
|
356
|
|
View Code Duplication |
public function assignRoleToUserGroup( |
357
|
|
|
Role $role, |
358
|
|
|
UserGroup $userGroup, |
359
|
|
|
RoleLimitation $roleLimitation = null |
360
|
|
|
) { |
361
|
|
|
$eventData = [ |
362
|
|
|
$role, |
363
|
|
|
$userGroup, |
364
|
|
|
$roleLimitation, |
365
|
|
|
]; |
366
|
|
|
|
367
|
|
|
$beforeEvent = new BeforeAssignRoleToUserGroupEvent(...$eventData); |
|
|
|
|
368
|
|
|
if ($this->eventDispatcher->dispatch(RoleEvents::BEFORE_ASSIGN_ROLE_TO_USER_GROUP, $beforeEvent)->isPropagationStopped()) { |
369
|
|
|
return; |
370
|
|
|
} else { |
371
|
|
|
parent::assignRoleToUserGroup($role, $userGroup, $roleLimitation); |
372
|
|
|
} |
373
|
|
|
|
374
|
|
|
$this->eventDispatcher->dispatch( |
375
|
|
|
RoleEvents::ASSIGN_ROLE_TO_USER_GROUP, |
376
|
|
|
new AssignRoleToUserGroupEvent(...$eventData) |
|
|
|
|
377
|
|
|
); |
378
|
|
|
} |
379
|
|
|
|
380
|
|
|
public function unassignRoleFromUserGroup( |
381
|
|
|
Role $role, |
382
|
|
|
UserGroup $userGroup |
383
|
|
|
) { |
384
|
|
|
$eventData = [ |
385
|
|
|
$role, |
386
|
|
|
$userGroup, |
387
|
|
|
]; |
388
|
|
|
|
389
|
|
|
$beforeEvent = new BeforeUnassignRoleFromUserGroupEvent(...$eventData); |
|
|
|
|
390
|
|
|
if ($this->eventDispatcher->dispatch(RoleEvents::BEFORE_UNASSIGN_ROLE_FROM_USER_GROUP, $beforeEvent)->isPropagationStopped()) { |
391
|
|
|
return; |
392
|
|
|
} else { |
393
|
|
|
parent::unassignRoleFromUserGroup($role, $userGroup); |
394
|
|
|
} |
395
|
|
|
|
396
|
|
|
$this->eventDispatcher->dispatch( |
397
|
|
|
RoleEvents::UNASSIGN_ROLE_FROM_USER_GROUP, |
398
|
|
|
new UnassignRoleFromUserGroupEvent(...$eventData) |
|
|
|
|
399
|
|
|
); |
400
|
|
|
} |
401
|
|
|
|
402
|
|
View Code Duplication |
public function assignRoleToUser( |
403
|
|
|
Role $role, |
404
|
|
|
User $user, |
405
|
|
|
RoleLimitation $roleLimitation = null |
406
|
|
|
) { |
407
|
|
|
$eventData = [ |
408
|
|
|
$role, |
409
|
|
|
$user, |
410
|
|
|
$roleLimitation, |
411
|
|
|
]; |
412
|
|
|
|
413
|
|
|
$beforeEvent = new BeforeAssignRoleToUserEvent(...$eventData); |
|
|
|
|
414
|
|
|
if ($this->eventDispatcher->dispatch(RoleEvents::BEFORE_ASSIGN_ROLE_TO_USER, $beforeEvent)->isPropagationStopped()) { |
415
|
|
|
return; |
416
|
|
|
} else { |
417
|
|
|
parent::assignRoleToUser($role, $user, $roleLimitation); |
418
|
|
|
} |
419
|
|
|
|
420
|
|
|
$this->eventDispatcher->dispatch( |
421
|
|
|
RoleEvents::ASSIGN_ROLE_TO_USER, |
422
|
|
|
new AssignRoleToUserEvent(...$eventData) |
|
|
|
|
423
|
|
|
); |
424
|
|
|
} |
425
|
|
|
|
426
|
|
|
public function unassignRoleFromUser( |
427
|
|
|
Role $role, |
428
|
|
|
User $user |
429
|
|
|
) { |
430
|
|
|
$eventData = [ |
431
|
|
|
$role, |
432
|
|
|
$user, |
433
|
|
|
]; |
434
|
|
|
|
435
|
|
|
$beforeEvent = new BeforeUnassignRoleFromUserEvent(...$eventData); |
|
|
|
|
436
|
|
|
if ($this->eventDispatcher->dispatch(RoleEvents::BEFORE_UNASSIGN_ROLE_FROM_USER, $beforeEvent)->isPropagationStopped()) { |
437
|
|
|
return; |
438
|
|
|
} else { |
439
|
|
|
parent::unassignRoleFromUser($role, $user); |
440
|
|
|
} |
441
|
|
|
|
442
|
|
|
$this->eventDispatcher->dispatch( |
443
|
|
|
RoleEvents::UNASSIGN_ROLE_FROM_USER, |
444
|
|
|
new UnassignRoleFromUserEvent(...$eventData) |
|
|
|
|
445
|
|
|
); |
446
|
|
|
} |
447
|
|
|
|
448
|
|
|
public function removeRoleAssignment(RoleAssignment $roleAssignment) |
449
|
|
|
{ |
450
|
|
|
$eventData = [$roleAssignment]; |
451
|
|
|
|
452
|
|
|
$beforeEvent = new BeforeRemoveRoleAssignmentEvent(...$eventData); |
453
|
|
|
if ($this->eventDispatcher->dispatch(RoleEvents::BEFORE_REMOVE_ROLE_ASSIGNMENT, $beforeEvent)->isPropagationStopped()) { |
454
|
|
|
return; |
455
|
|
|
} else { |
456
|
|
|
parent::removeRoleAssignment($roleAssignment); |
457
|
|
|
} |
458
|
|
|
|
459
|
|
|
$this->eventDispatcher->dispatch( |
460
|
|
|
RoleEvents::REMOVE_ROLE_ASSIGNMENT, |
461
|
|
|
new RemoveRoleAssignmentEvent(...$eventData) |
462
|
|
|
); |
463
|
|
|
} |
464
|
|
|
} |
465
|
|
|
|
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: