Completed
Push — ezp-30616-follow-up ( 2e0607...b74676 )
by
unknown
35:08 queued 20:12
created

RoleService::unassignRoleFromUserGroup()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 23

Duplication

Lines 23
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 2
dl 23
loc 23
rs 9.552
c 0
b 0
f 0
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\API\Repository\Events\Role\AddPolicyByRoleDraftEvent as AddPolicyByRoleDraftEventInterface;
12
use eZ\Publish\API\Repository\Events\Role\AddPolicyEvent as AddPolicyEventInterface;
13
use eZ\Publish\API\Repository\Events\Role\AssignRoleToUserEvent as AssignRoleToUserEventInterface;
14
use eZ\Publish\API\Repository\Events\Role\AssignRoleToUserGroupEvent as AssignRoleToUserGroupEventInterface;
15
use eZ\Publish\API\Repository\Events\Role\BeforeAddPolicyByRoleDraftEvent as BeforeAddPolicyByRoleDraftEventInterface;
16
use eZ\Publish\API\Repository\Events\Role\BeforeAddPolicyEvent as BeforeAddPolicyEventInterface;
17
use eZ\Publish\API\Repository\Events\Role\BeforeAssignRoleToUserEvent as BeforeAssignRoleToUserEventInterface;
18
use eZ\Publish\API\Repository\Events\Role\BeforeAssignRoleToUserGroupEvent as BeforeAssignRoleToUserGroupEventInterface;
19
use eZ\Publish\API\Repository\Events\Role\BeforeCreateRoleDraftEvent as BeforeCreateRoleDraftEventInterface;
20
use eZ\Publish\API\Repository\Events\Role\BeforeCreateRoleEvent as BeforeCreateRoleEventInterface;
21
use eZ\Publish\API\Repository\Events\Role\BeforeDeletePolicyEvent as BeforeDeletePolicyEventInterface;
22
use eZ\Publish\API\Repository\Events\Role\BeforeDeleteRoleDraftEvent as BeforeDeleteRoleDraftEventInterface;
23
use eZ\Publish\API\Repository\Events\Role\BeforeDeleteRoleEvent as BeforeDeleteRoleEventInterface;
24
use eZ\Publish\API\Repository\Events\Role\BeforePublishRoleDraftEvent as BeforePublishRoleDraftEventInterface;
25
use eZ\Publish\API\Repository\Events\Role\BeforeRemovePolicyByRoleDraftEvent as BeforeRemovePolicyByRoleDraftEventInterface;
26
use eZ\Publish\API\Repository\Events\Role\BeforeRemoveRoleAssignmentEvent as BeforeRemoveRoleAssignmentEventInterface;
27
use eZ\Publish\API\Repository\Events\Role\BeforeUnassignRoleFromUserEvent as BeforeUnassignRoleFromUserEventInterface;
28
use eZ\Publish\API\Repository\Events\Role\BeforeUnassignRoleFromUserGroupEvent as BeforeUnassignRoleFromUserGroupEventInterface;
29
use eZ\Publish\API\Repository\Events\Role\BeforeUpdatePolicyByRoleDraftEvent as BeforeUpdatePolicyByRoleDraftEventInterface;
30
use eZ\Publish\API\Repository\Events\Role\BeforeUpdatePolicyEvent as BeforeUpdatePolicyEventInterface;
31
use eZ\Publish\API\Repository\Events\Role\BeforeUpdateRoleDraftEvent as BeforeUpdateRoleDraftEventInterface;
32
use eZ\Publish\API\Repository\Events\Role\BeforeUpdateRoleEvent as BeforeUpdateRoleEventInterface;
33
use eZ\Publish\API\Repository\Events\Role\CreateRoleDraftEvent as CreateRoleDraftEventInterface;
34
use eZ\Publish\API\Repository\Events\Role\CreateRoleEvent as CreateRoleEventInterface;
35
use eZ\Publish\API\Repository\Events\Role\DeletePolicyEvent as DeletePolicyEventInterface;
36
use eZ\Publish\API\Repository\Events\Role\DeleteRoleDraftEvent as DeleteRoleDraftEventInterface;
37
use eZ\Publish\API\Repository\Events\Role\DeleteRoleEvent as DeleteRoleEventInterface;
38
use eZ\Publish\API\Repository\Events\Role\PublishRoleDraftEvent as PublishRoleDraftEventInterface;
39
use eZ\Publish\API\Repository\Events\Role\RemovePolicyByRoleDraftEvent as RemovePolicyByRoleDraftEventInterface;
40
use eZ\Publish\API\Repository\Events\Role\RemoveRoleAssignmentEvent as RemoveRoleAssignmentEventInterface;
41
use eZ\Publish\API\Repository\Events\Role\UnassignRoleFromUserEvent as UnassignRoleFromUserEventInterface;
42
use eZ\Publish\API\Repository\Events\Role\UnassignRoleFromUserGroupEvent as UnassignRoleFromUserGroupEventInterface;
43
use eZ\Publish\API\Repository\Events\Role\UpdatePolicyByRoleDraftEvent as UpdatePolicyByRoleDraftEventInterface;
44
use eZ\Publish\API\Repository\Events\Role\UpdatePolicyEvent as UpdatePolicyEventInterface;
45
use eZ\Publish\API\Repository\Events\Role\UpdateRoleDraftEvent as UpdateRoleDraftEventInterface;
46
use eZ\Publish\API\Repository\Events\Role\UpdateRoleEvent as UpdateRoleEventInterface;
47
use eZ\Publish\API\Repository\RoleService as RoleServiceInterface;
48
use eZ\Publish\API\Repository\Values\User\Limitation\RoleLimitation;
49
use eZ\Publish\API\Repository\Values\User\Policy;
50
use eZ\Publish\API\Repository\Values\User\PolicyCreateStruct;
51
use eZ\Publish\API\Repository\Values\User\PolicyDraft;
52
use eZ\Publish\API\Repository\Values\User\PolicyUpdateStruct;
53
use eZ\Publish\API\Repository\Values\User\Role;
54
use eZ\Publish\API\Repository\Values\User\RoleAssignment;
55
use eZ\Publish\API\Repository\Values\User\RoleCreateStruct;
56
use eZ\Publish\API\Repository\Values\User\RoleDraft;
57
use eZ\Publish\API\Repository\Values\User\RoleUpdateStruct;
58
use eZ\Publish\API\Repository\Values\User\User;
59
use eZ\Publish\API\Repository\Values\User\UserGroup;
60
use eZ\Publish\API\Repository\Events\Role\AddPolicyByRoleDraftEvent;
61
use eZ\Publish\API\Repository\Events\Role\AddPolicyEvent;
62
use eZ\Publish\API\Repository\Events\Role\AssignRoleToUserEvent;
63
use eZ\Publish\API\Repository\Events\Role\AssignRoleToUserGroupEvent;
64
use eZ\Publish\API\Repository\Events\Role\BeforeAddPolicyByRoleDraftEvent;
65
use eZ\Publish\API\Repository\Events\Role\BeforeAddPolicyEvent;
66
use eZ\Publish\API\Repository\Events\Role\BeforeAssignRoleToUserEvent;
67
use eZ\Publish\API\Repository\Events\Role\BeforeAssignRoleToUserGroupEvent;
68
use eZ\Publish\API\Repository\Events\Role\BeforeCreateRoleDraftEvent;
69
use eZ\Publish\API\Repository\Events\Role\BeforeCreateRoleEvent;
70
use eZ\Publish\API\Repository\Events\Role\BeforeDeletePolicyEvent;
71
use eZ\Publish\API\Repository\Events\Role\BeforeDeleteRoleDraftEvent;
72
use eZ\Publish\API\Repository\Events\Role\BeforeDeleteRoleEvent;
73
use eZ\Publish\API\Repository\Events\Role\BeforePublishRoleDraftEvent;
74
use eZ\Publish\API\Repository\Events\Role\BeforeRemovePolicyByRoleDraftEvent;
75
use eZ\Publish\API\Repository\Events\Role\BeforeRemoveRoleAssignmentEvent;
76
use eZ\Publish\API\Repository\Events\Role\BeforeUnassignRoleFromUserEvent;
77
use eZ\Publish\API\Repository\Events\Role\BeforeUnassignRoleFromUserGroupEvent;
78
use eZ\Publish\API\Repository\Events\Role\BeforeUpdatePolicyByRoleDraftEvent;
79
use eZ\Publish\API\Repository\Events\Role\BeforeUpdatePolicyEvent;
80
use eZ\Publish\API\Repository\Events\Role\BeforeUpdateRoleDraftEvent;
81
use eZ\Publish\API\Repository\Events\Role\BeforeUpdateRoleEvent;
82
use eZ\Publish\API\Repository\Events\Role\CreateRoleDraftEvent;
83
use eZ\Publish\API\Repository\Events\Role\CreateRoleEvent;
84
use eZ\Publish\API\Repository\Events\Role\DeletePolicyEvent;
85
use eZ\Publish\API\Repository\Events\Role\DeleteRoleDraftEvent;
86
use eZ\Publish\API\Repository\Events\Role\DeleteRoleEvent;
87
use eZ\Publish\API\Repository\Events\Role\PublishRoleDraftEvent;
88
use eZ\Publish\API\Repository\Events\Role\RemovePolicyByRoleDraftEvent;
89
use eZ\Publish\API\Repository\Events\Role\RemoveRoleAssignmentEvent;
90
use eZ\Publish\API\Repository\Events\Role\UnassignRoleFromUserEvent;
91
use eZ\Publish\API\Repository\Events\Role\UnassignRoleFromUserGroupEvent;
92
use eZ\Publish\API\Repository\Events\Role\UpdatePolicyByRoleDraftEvent;
93
use eZ\Publish\API\Repository\Events\Role\UpdatePolicyEvent;
94
use eZ\Publish\API\Repository\Events\Role\UpdateRoleDraftEvent;
95
use eZ\Publish\API\Repository\Events\Role\UpdateRoleEvent;
96
use eZ\Publish\SPI\Repository\Decorator\RoleServiceDecorator;
97
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
98
99
class RoleService extends RoleServiceDecorator
100
{
101
    /** @var \Symfony\Contracts\EventDispatcher\EventDispatcherInterface */
102
    protected $eventDispatcher;
103
104
    public function __construct(
105
        RoleServiceInterface $innerService,
106
        EventDispatcherInterface $eventDispatcher
107
    ) {
108
        parent::__construct($innerService);
109
110
        $this->eventDispatcher = $eventDispatcher;
111
    }
112
113
    public function createRole(RoleCreateStruct $roleCreateStruct): RoleDraft
114
    {
115
        $eventData = [$roleCreateStruct];
116
117
        $beforeEvent = new BeforeCreateRoleEvent(...$eventData);
118
119
        $this->eventDispatcher->dispatch($beforeEvent, BeforeCreateRoleEventInterface::class);
120
        if ($beforeEvent->isPropagationStopped()) {
121
            return $beforeEvent->getRoleDraft();
122
        }
123
124
        $roleDraft = $beforeEvent->hasRoleDraft()
125
            ? $beforeEvent->getRoleDraft()
126
            : $this->innerService->createRole($roleCreateStruct);
127
128
        $this->eventDispatcher->dispatch(
129
            new CreateRoleEvent($roleDraft, ...$eventData),
130
            CreateRoleEventInterface::class
131
        );
132
133
        return $roleDraft;
134
    }
135
136
    public function createRoleDraft(Role $role)
137
    {
138
        $eventData = [$role];
139
140
        $beforeEvent = new BeforeCreateRoleDraftEvent(...$eventData);
141
142
        $this->eventDispatcher->dispatch($beforeEvent, BeforeCreateRoleDraftEventInterface::class);
143
        if ($beforeEvent->isPropagationStopped()) {
144
            return $beforeEvent->getRoleDraft();
145
        }
146
147
        $roleDraft = $beforeEvent->hasRoleDraft()
148
            ? $beforeEvent->getRoleDraft()
149
            : $this->innerService->createRoleDraft($role);
150
151
        $this->eventDispatcher->dispatch(
152
            new CreateRoleDraftEvent($roleDraft, ...$eventData),
153
            CreateRoleDraftEventInterface::class
154
        );
155
156
        return $roleDraft;
157
    }
158
159
    public function updateRoleDraft(
160
        RoleDraft $roleDraft,
161
        RoleUpdateStruct $roleUpdateStruct
162
    ) {
163
        $eventData = [
164
            $roleDraft,
165
            $roleUpdateStruct,
166
        ];
167
168
        $beforeEvent = new BeforeUpdateRoleDraftEvent(...$eventData);
0 ignored issues
show
Bug introduced by
The call to BeforeUpdateRoleDraftEvent::__construct() misses a required argument $roleUpdateStruct.

This check looks for function calls that miss required arguments.

Loading history...
169
170
        $this->eventDispatcher->dispatch($beforeEvent, BeforeUpdateRoleDraftEventInterface::class);
171
        if ($beforeEvent->isPropagationStopped()) {
172
            return $beforeEvent->getUpdatedRoleDraft();
173
        }
174
175
        $updatedRoleDraft = $beforeEvent->hasUpdatedRoleDraft()
176
            ? $beforeEvent->getUpdatedRoleDraft()
177
            : $this->innerService->updateRoleDraft($roleDraft, $roleUpdateStruct);
178
179
        $this->eventDispatcher->dispatch(
180
            new UpdateRoleDraftEvent($updatedRoleDraft, ...$eventData),
0 ignored issues
show
Bug introduced by
The call to UpdateRoleDraftEvent::__construct() misses a required argument $roleUpdateStruct.

This check looks for function calls that miss required arguments.

Loading history...
181
            UpdateRoleDraftEventInterface::class
182
        );
183
184
        return $updatedRoleDraft;
185
    }
186
187
    public function addPolicyByRoleDraft(
188
        RoleDraft $roleDraft,
189
        PolicyCreateStruct $policyCreateStruct
190
    ) {
191
        $eventData = [
192
            $roleDraft,
193
            $policyCreateStruct,
194
        ];
195
196
        $beforeEvent = new BeforeAddPolicyByRoleDraftEvent(...$eventData);
0 ignored issues
show
Bug introduced by
The call to BeforeAddPolicyByRoleDraftEvent::__construct() misses a required argument $policyCreateStruct.

This check looks for function calls that miss required arguments.

Loading history...
197
198
        $this->eventDispatcher->dispatch($beforeEvent, BeforeAddPolicyByRoleDraftEventInterface::class);
199
        if ($beforeEvent->isPropagationStopped()) {
200
            return $beforeEvent->getUpdatedRoleDraft();
201
        }
202
203
        $updatedRoleDraft = $beforeEvent->hasUpdatedRoleDraft()
204
            ? $beforeEvent->getUpdatedRoleDraft()
205
            : $this->innerService->addPolicyByRoleDraft($roleDraft, $policyCreateStruct);
206
207
        $this->eventDispatcher->dispatch(
208
            new AddPolicyByRoleDraftEvent($updatedRoleDraft, ...$eventData),
0 ignored issues
show
Bug introduced by
The call to AddPolicyByRoleDraftEvent::__construct() misses a required argument $policyCreateStruct.

This check looks for function calls that miss required arguments.

Loading history...
209
            AddPolicyByRoleDraftEventInterface::class
210
        );
211
212
        return $updatedRoleDraft;
213
    }
214
215
    public function removePolicyByRoleDraft(
216
        RoleDraft $roleDraft,
217
        PolicyDraft $policyDraft
218
    ) {
219
        $eventData = [
220
            $roleDraft,
221
            $policyDraft,
222
        ];
223
224
        $beforeEvent = new BeforeRemovePolicyByRoleDraftEvent(...$eventData);
0 ignored issues
show
Bug introduced by
The call to BeforeRemovePolicyByRoleDraftEvent::__construct() misses a required argument $policyDraft.

This check looks for function calls that miss required arguments.

Loading history...
225
226
        $this->eventDispatcher->dispatch($beforeEvent, BeforeRemovePolicyByRoleDraftEventInterface::class);
227
        if ($beforeEvent->isPropagationStopped()) {
228
            return $beforeEvent->getUpdatedRoleDraft();
229
        }
230
231
        $updatedRoleDraft = $beforeEvent->hasUpdatedRoleDraft()
232
            ? $beforeEvent->getUpdatedRoleDraft()
233
            : $this->innerService->removePolicyByRoleDraft($roleDraft, $policyDraft);
234
235
        $this->eventDispatcher->dispatch(
236
            new RemovePolicyByRoleDraftEvent($updatedRoleDraft, ...$eventData),
0 ignored issues
show
Bug introduced by
The call to RemovePolicyByRoleDraftEvent::__construct() misses a required argument $policyDraft.

This check looks for function calls that miss required arguments.

Loading history...
237
            RemovePolicyByRoleDraftEventInterface::class
238
        );
239
240
        return $updatedRoleDraft;
241
    }
242
243
    public function updatePolicyByRoleDraft(
244
        RoleDraft $roleDraft,
245
        PolicyDraft $policy,
246
        PolicyUpdateStruct $policyUpdateStruct
247
    ) {
248
        $eventData = [
249
            $roleDraft,
250
            $policy,
251
            $policyUpdateStruct,
252
        ];
253
254
        $beforeEvent = new BeforeUpdatePolicyByRoleDraftEvent(...$eventData);
0 ignored issues
show
Bug introduced by
The call to BeforeUpdatePolicyByRoleDraftEvent::__construct() misses some required arguments starting with $policy.
Loading history...
255
256
        $this->eventDispatcher->dispatch($beforeEvent, BeforeUpdatePolicyByRoleDraftEventInterface::class);
257
        if ($beforeEvent->isPropagationStopped()) {
258
            return $beforeEvent->getUpdatedPolicyDraft();
259
        }
260
261
        $updatedPolicyDraft = $beforeEvent->hasUpdatedPolicyDraft()
262
            ? $beforeEvent->getUpdatedPolicyDraft()
263
            : $this->innerService->updatePolicyByRoleDraft($roleDraft, $policy, $policyUpdateStruct);
264
265
        $this->eventDispatcher->dispatch(
266
            new UpdatePolicyByRoleDraftEvent($updatedPolicyDraft, ...$eventData),
0 ignored issues
show
Bug introduced by
The call to UpdatePolicyByRoleDraftEvent::__construct() misses some required arguments starting with $policy.
Loading history...
267
            UpdatePolicyByRoleDraftEventInterface::class
268
        );
269
270
        return $updatedPolicyDraft;
271
    }
272
273
    public function deleteRoleDraft(RoleDraft $roleDraft): void
274
    {
275
        $eventData = [$roleDraft];
276
277
        $beforeEvent = new BeforeDeleteRoleDraftEvent(...$eventData);
278
279
        $this->eventDispatcher->dispatch($beforeEvent, BeforeDeleteRoleDraftEventInterface::class);
280
        if ($beforeEvent->isPropagationStopped()) {
281
            return;
282
        }
283
284
        $this->innerService->deleteRoleDraft($roleDraft);
285
286
        $this->eventDispatcher->dispatch(
287
            new DeleteRoleDraftEvent(...$eventData),
288
            DeleteRoleDraftEventInterface::class
289
        );
290
    }
291
292
    public function publishRoleDraft(RoleDraft $roleDraft): void
293
    {
294
        $eventData = [$roleDraft];
295
296
        $beforeEvent = new BeforePublishRoleDraftEvent(...$eventData);
297
298
        $this->eventDispatcher->dispatch($beforeEvent, BeforePublishRoleDraftEventInterface::class);
299
        if ($beforeEvent->isPropagationStopped()) {
300
            return;
301
        }
302
303
        $this->innerService->publishRoleDraft($roleDraft);
304
305
        $this->eventDispatcher->dispatch(
306
            new PublishRoleDraftEvent(...$eventData),
307
            PublishRoleDraftEventInterface::class
308
        );
309
    }
310
311
    public function updateRole(
312
        Role $role,
313
        RoleUpdateStruct $roleUpdateStruct
314
    ) {
315
        $eventData = [
316
            $role,
317
            $roleUpdateStruct,
318
        ];
319
320
        $beforeEvent = new BeforeUpdateRoleEvent(...$eventData);
0 ignored issues
show
Bug introduced by
The call to BeforeUpdateRoleEvent::__construct() misses a required argument $roleUpdateStruct.

This check looks for function calls that miss required arguments.

Loading history...
321
322
        $this->eventDispatcher->dispatch($beforeEvent, BeforeUpdateRoleEventInterface::class);
323
        if ($beforeEvent->isPropagationStopped()) {
324
            return $beforeEvent->getUpdatedRole();
325
        }
326
327
        $updatedRole = $beforeEvent->hasUpdatedRole()
328
            ? $beforeEvent->getUpdatedRole()
329
            : $this->innerService->updateRole($role, $roleUpdateStruct);
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\API\Repositor...leService::updateRole() has been deprecated with message: since 6.0, use {@see updateRoleDraft}

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
330
331
        $this->eventDispatcher->dispatch(
332
            new UpdateRoleEvent($updatedRole, ...$eventData),
0 ignored issues
show
Bug introduced by
The call to UpdateRoleEvent::__construct() misses a required argument $roleUpdateStruct.

This check looks for function calls that miss required arguments.

Loading history...
333
            UpdateRoleEventInterface::class
334
        );
335
336
        return $updatedRole;
337
    }
338
339
    public function addPolicy(
340
        Role $role,
341
        PolicyCreateStruct $policyCreateStruct
342
    ) {
343
        $eventData = [
344
            $role,
345
            $policyCreateStruct,
346
        ];
347
348
        $beforeEvent = new BeforeAddPolicyEvent(...$eventData);
0 ignored issues
show
Bug introduced by
The call to BeforeAddPolicyEvent::__construct() misses a required argument $policyCreateStruct.

This check looks for function calls that miss required arguments.

Loading history...
349
350
        $this->eventDispatcher->dispatch($beforeEvent, BeforeAddPolicyEventInterface::class);
351
        if ($beforeEvent->isPropagationStopped()) {
352
            return $beforeEvent->getUpdatedRole();
353
        }
354
355
        $updatedRole = $beforeEvent->hasUpdatedRole()
356
            ? $beforeEvent->getUpdatedRole()
357
            : $this->innerService->addPolicy($role, $policyCreateStruct);
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\API\Repository\RoleService::addPolicy() has been deprecated with message: since 6.0, use {@see addPolicyByRoleDraft}

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
358
359
        $this->eventDispatcher->dispatch(
360
            new AddPolicyEvent($updatedRole, ...$eventData),
0 ignored issues
show
Bug introduced by
The call to AddPolicyEvent::__construct() misses a required argument $policyCreateStruct.

This check looks for function calls that miss required arguments.

Loading history...
361
            AddPolicyEventInterface::class
362
        );
363
364
        return $updatedRole;
365
    }
366
367
    public function deletePolicy(Policy $policy): void
368
    {
369
        $eventData = [$policy];
370
371
        $beforeEvent = new BeforeDeletePolicyEvent(...$eventData);
372
373
        $this->eventDispatcher->dispatch($beforeEvent, BeforeDeletePolicyEventInterface::class);
374
        if ($beforeEvent->isPropagationStopped()) {
375
            return;
376
        }
377
378
        $this->innerService->deletePolicy($policy);
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\API\Repositor...Service::deletePolicy() has been deprecated with message: since 6.0, use {@link removePolicyByRoleDraft()} instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
379
380
        $this->eventDispatcher->dispatch(
381
            new DeletePolicyEvent(...$eventData),
382
            DeletePolicyEventInterface::class
383
        );
384
    }
385
386
    public function updatePolicy(
387
        Policy $policy,
388
        PolicyUpdateStruct $policyUpdateStruct
389
    ) {
390
        $eventData = [
391
            $policy,
392
            $policyUpdateStruct,
393
        ];
394
395
        $beforeEvent = new BeforeUpdatePolicyEvent(...$eventData);
0 ignored issues
show
Bug introduced by
The call to BeforeUpdatePolicyEvent::__construct() misses a required argument $policyUpdateStruct.

This check looks for function calls that miss required arguments.

Loading history...
396
397
        $this->eventDispatcher->dispatch($beforeEvent, BeforeUpdatePolicyEventInterface::class);
398
        if ($beforeEvent->isPropagationStopped()) {
399
            return $beforeEvent->getUpdatedPolicy();
400
        }
401
402
        $updatedPolicy = $beforeEvent->hasUpdatedPolicy()
403
            ? $beforeEvent->getUpdatedPolicy()
404
            : $this->innerService->updatePolicy($policy, $policyUpdateStruct);
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\API\Repositor...Service::updatePolicy() has been deprecated with message: since 6.0, use {@link updatePolicyByRoleDraft()} instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
405
406
        $this->eventDispatcher->dispatch(
407
            new UpdatePolicyEvent($updatedPolicy, ...$eventData),
0 ignored issues
show
Bug introduced by
The call to UpdatePolicyEvent::__construct() misses a required argument $policyUpdateStruct.

This check looks for function calls that miss required arguments.

Loading history...
408
            UpdatePolicyEventInterface::class
409
        );
410
411
        return $updatedPolicy;
412
    }
413
414
    public function deleteRole(Role $role): void
415
    {
416
        $eventData = [$role];
417
418
        $beforeEvent = new BeforeDeleteRoleEvent(...$eventData);
419
420
        $this->eventDispatcher->dispatch($beforeEvent, BeforeDeleteRoleEventInterface::class);
421
        if ($beforeEvent->isPropagationStopped()) {
422
            return;
423
        }
424
425
        $this->innerService->deleteRole($role);
426
427
        $this->eventDispatcher->dispatch(
428
            new DeleteRoleEvent(...$eventData),
429
            DeleteRoleEventInterface::class
430
        );
431
    }
432
433 View Code Duplication
    public function assignRoleToUserGroup(
434
        Role $role,
435
        UserGroup $userGroup,
436
        RoleLimitation $roleLimitation = null
437
    ): void {
438
        $eventData = [
439
            $role,
440
            $userGroup,
441
            $roleLimitation,
442
        ];
443
444
        $beforeEvent = new BeforeAssignRoleToUserGroupEvent(...$eventData);
0 ignored issues
show
Bug introduced by
The call to BeforeAssignRoleToUserGroupEvent::__construct() misses a required argument $userGroup.

This check looks for function calls that miss required arguments.

Loading history...
445
446
        $this->eventDispatcher->dispatch($beforeEvent, BeforeAssignRoleToUserGroupEventInterface::class);
447
        if ($beforeEvent->isPropagationStopped()) {
448
            return;
449
        }
450
451
        $this->innerService->assignRoleToUserGroup($role, $userGroup, $roleLimitation);
452
453
        $this->eventDispatcher->dispatch(
454
            new AssignRoleToUserGroupEvent(...$eventData),
0 ignored issues
show
Bug introduced by
The call to AssignRoleToUserGroupEvent::__construct() misses a required argument $userGroup.

This check looks for function calls that miss required arguments.

Loading history...
455
            AssignRoleToUserGroupEventInterface::class
456
        );
457
    }
458
459 View Code Duplication
    public function unassignRoleFromUserGroup(
460
        Role $role,
461
        UserGroup $userGroup
462
    ): void {
463
        $eventData = [
464
            $role,
465
            $userGroup,
466
        ];
467
468
        $beforeEvent = new BeforeUnassignRoleFromUserGroupEvent(...$eventData);
0 ignored issues
show
Bug introduced by
The call to BeforeUnassignRoleFromUs...oupEvent::__construct() misses a required argument $userGroup.

This check looks for function calls that miss required arguments.

Loading history...
469
470
        $this->eventDispatcher->dispatch($beforeEvent, BeforeUnassignRoleFromUserGroupEventInterface::class);
471
        if ($beforeEvent->isPropagationStopped()) {
472
            return;
473
        }
474
475
        $this->innerService->unassignRoleFromUserGroup($role, $userGroup);
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\API\Repositor...signRoleFromUserGroup() has been deprecated with message: since 6.0, use {@see removeRoleAssignment} instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
476
477
        $this->eventDispatcher->dispatch(
478
            new UnassignRoleFromUserGroupEvent(...$eventData),
0 ignored issues
show
Bug introduced by
The call to UnassignRoleFromUserGroupEvent::__construct() misses a required argument $userGroup.

This check looks for function calls that miss required arguments.

Loading history...
479
            UnassignRoleFromUserGroupEventInterface::class
480
        );
481
    }
482
483 View Code Duplication
    public function assignRoleToUser(
484
        Role $role,
485
        User $user,
486
        RoleLimitation $roleLimitation = null
487
    ): void {
488
        $eventData = [
489
            $role,
490
            $user,
491
            $roleLimitation,
492
        ];
493
494
        $beforeEvent = new BeforeAssignRoleToUserEvent(...$eventData);
0 ignored issues
show
Bug introduced by
The call to BeforeAssignRoleToUserEvent::__construct() misses a required argument $user.

This check looks for function calls that miss required arguments.

Loading history...
495
496
        $this->eventDispatcher->dispatch($beforeEvent, BeforeAssignRoleToUserEventInterface::class);
497
        if ($beforeEvent->isPropagationStopped()) {
498
            return;
499
        }
500
501
        $this->innerService->assignRoleToUser($role, $user, $roleLimitation);
502
503
        $this->eventDispatcher->dispatch(
504
            new AssignRoleToUserEvent(...$eventData),
0 ignored issues
show
Bug introduced by
The call to AssignRoleToUserEvent::__construct() misses a required argument $user.

This check looks for function calls that miss required arguments.

Loading history...
505
            AssignRoleToUserEventInterface::class
506
        );
507
    }
508
509 View Code Duplication
    public function unassignRoleFromUser(
510
        Role $role,
511
        User $user
512
    ): void {
513
        $eventData = [
514
            $role,
515
            $user,
516
        ];
517
518
        $beforeEvent = new BeforeUnassignRoleFromUserEvent(...$eventData);
0 ignored issues
show
Bug introduced by
The call to BeforeUnassignRoleFromUserEvent::__construct() misses a required argument $user.

This check looks for function calls that miss required arguments.

Loading history...
519
520
        $this->eventDispatcher->dispatch($beforeEvent, BeforeUnassignRoleFromUserEventInterface::class);
521
        if ($beforeEvent->isPropagationStopped()) {
522
            return;
523
        }
524
525
        $this->innerService->unassignRoleFromUser($role, $user);
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\API\Repositor...:unassignRoleFromUser() has been deprecated with message: since 6.0, use {@see removeRoleAssignment} instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
526
527
        $this->eventDispatcher->dispatch(
528
            new UnassignRoleFromUserEvent(...$eventData),
0 ignored issues
show
Bug introduced by
The call to UnassignRoleFromUserEvent::__construct() misses a required argument $user.

This check looks for function calls that miss required arguments.

Loading history...
529
            UnassignRoleFromUserEventInterface::class
530
        );
531
    }
532
533
    public function removeRoleAssignment(RoleAssignment $roleAssignment): void
534
    {
535
        $eventData = [$roleAssignment];
536
537
        $beforeEvent = new BeforeRemoveRoleAssignmentEvent(...$eventData);
538
539
        $this->eventDispatcher->dispatch($beforeEvent, BeforeRemoveRoleAssignmentEventInterface::class);
540
        if ($beforeEvent->isPropagationStopped()) {
541
            return;
542
        }
543
544
        $this->innerService->removeRoleAssignment($roleAssignment);
545
546
        $this->eventDispatcher->dispatch(
547
            new RemoveRoleAssignmentEvent(...$eventData),
548
            RemoveRoleAssignmentEventInterface::class
549
        );
550
    }
551
}
552