Completed
Push — EZP-31383 ( 83ce0c )
by
unknown
19:12
created

RoleService::unassignRoleFromUser()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * RoleService class.
5
 *
6
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
7
 * @license For full copyright and license information view LICENSE file distributed with this source code.
8
 */
9
namespace eZ\Publish\Core\SignalSlot;
10
11
use eZ\Publish\API\Repository\RoleService as RoleServiceInterface;
12
use eZ\Publish\API\Repository\Values\User\Limitation\RoleLimitation;
13
use eZ\Publish\API\Repository\Values\User\Policy;
14
use eZ\Publish\API\Repository\Values\User\PolicyCreateStruct;
15
use eZ\Publish\API\Repository\Values\User\PolicyDraft;
16
use eZ\Publish\API\Repository\Values\User\PolicyUpdateStruct;
17
use eZ\Publish\API\Repository\Values\User\Role;
18
use eZ\Publish\API\Repository\Values\User\RoleAssignment;
19
use eZ\Publish\API\Repository\Values\User\RoleCopyStruct;
20
use eZ\Publish\API\Repository\Values\User\RoleCreateStruct;
21
use eZ\Publish\API\Repository\Values\User\RoleDraft;
22
use eZ\Publish\API\Repository\Values\User\RoleUpdateStruct;
23
use eZ\Publish\API\Repository\Values\User\User;
24
use eZ\Publish\API\Repository\Values\User\UserGroup;
25
use eZ\Publish\Core\SignalSlot\Signal\RoleService\AddPolicyByRoleDraftSignal;
26
use eZ\Publish\Core\SignalSlot\Signal\RoleService\AddPolicySignal;
27
use eZ\Publish\Core\SignalSlot\Signal\RoleService\AssignRoleToUserGroupSignal;
28
use eZ\Publish\Core\SignalSlot\Signal\RoleService\AssignRoleToUserSignal;
29
use eZ\Publish\Core\SignalSlot\Signal\RoleService\CopyRoleSignal;
30
use eZ\Publish\Core\SignalSlot\Signal\RoleService\CreateRoleDraftSignal;
31
use eZ\Publish\Core\SignalSlot\Signal\RoleService\CreateRoleSignal;
32
use eZ\Publish\Core\SignalSlot\Signal\RoleService\DeleteRoleDraftSignal;
33
use eZ\Publish\Core\SignalSlot\Signal\RoleService\DeleteRoleSignal;
34
use eZ\Publish\Core\SignalSlot\Signal\RoleService\PublishRoleDraftSignal;
35
use eZ\Publish\Core\SignalSlot\Signal\RoleService\RemovePolicyByRoleDraftSignal;
36
use eZ\Publish\Core\SignalSlot\Signal\RoleService\RemovePolicySignal;
37
use eZ\Publish\Core\SignalSlot\Signal\RoleService\RemoveRoleAssignmentSignal;
38
use eZ\Publish\Core\SignalSlot\Signal\RoleService\UnassignRoleFromUserGroupSignal;
39
use eZ\Publish\Core\SignalSlot\Signal\RoleService\UnassignRoleFromUserSignal;
40
use eZ\Publish\Core\SignalSlot\Signal\RoleService\UpdatePolicySignal;
41
use eZ\Publish\Core\SignalSlot\Signal\RoleService\UpdateRoleDraftSignal;
42
use eZ\Publish\Core\SignalSlot\Signal\RoleService\UpdateRoleSignal;
43
44
/**
45
 * RoleService class.
46
 */
47
class RoleService implements RoleServiceInterface
48
{
49
    /**
50
     * Aggregated service.
51
     *
52
     * @var \eZ\Publish\API\Repository\RoleService
53
     */
54
    protected $service;
55
56
    /**
57
     * SignalDispatcher.
58
     *
59
     * @var \eZ\Publish\Core\SignalSlot\SignalDispatcher
60
     */
61
    protected $signalDispatcher;
62
63
    /**
64
     * Constructor.
65
     *
66
     * Construct service object from aggregated service and signal
67
     * dispatcher
68
     *
69
     * @param \eZ\Publish\API\Repository\RoleService $service
70
     * @param \eZ\Publish\Core\SignalSlot\SignalDispatcher $signalDispatcher
71
     */
72
    public function __construct(RoleServiceInterface $service, SignalDispatcher $signalDispatcher)
73
    {
74
        $this->service = $service;
75
        $this->signalDispatcher = $signalDispatcher;
76
    }
77
78
    /**
79
     * Creates a new RoleDraft.
80
     *
81
     * @since 6.0
82
     *
83
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to create a role
84
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
85
     *         if the name of the role already exists or if limitation of the same type
86
     *         is repeated in the policy create struct or if limitation is not allowed on module/function
87
     * @throws \eZ\Publish\API\Repository\Exceptions\LimitationValidationException if a policy limitation in the $roleCreateStruct is not valid
88
     *
89
     * @param \eZ\Publish\API\Repository\Values\User\RoleCreateStruct $roleCreateStruct
90
     *
91
     * @return \eZ\Publish\API\Repository\Values\User\RoleDraft
92
     */
93
    public function createRole(RoleCreateStruct $roleCreateStruct)
94
    {
95
        $returnValue = $this->service->createRole($roleCreateStruct);
96
        $this->signalDispatcher->emit(
97
            new CreateRoleSignal(
98
                [
99
                    'roleId' => $returnValue->id,
100
                ]
101
            )
102
        );
103
104
        return $returnValue;
105
    }
106
107
    /**
108
     * Creates a new RoleDraft for existing Role.
109
     *
110
     * @since 6.0
111
     *
112
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to create a role
113
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the Role already has a Role Draft that will need to be removed first
114
     * @throws \eZ\Publish\API\Repository\Exceptions\LimitationValidationException if a policy limitation in the $roleCreateStruct is not valid
115
     *
116
     * @param \eZ\Publish\API\Repository\Values\User\Role $role
117
     *
118
     * @return \eZ\Publish\API\Repository\Values\User\RoleDraft
119
     */
120
    public function createRoleDraft(Role $role)
121
    {
122
        $returnValue = $this->service->createRoleDraft($role);
123
        $this->signalDispatcher->emit(
124
            new CreateRoleDraftSignal(
125
                [
126
                    'roleId' => $returnValue->id,
127
                ]
128
            )
129
        );
130
131
        return $returnValue;
132
    }
133
134
    /**
135
     * Creates a new RoleDraft.
136
     *
137
     * @since 7.5
138
     *
139
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to copy a role
140
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
141
     *         if the name of the role already exists or if limitation of the same type
142
     *         is repeated in the policy create struct or if limitation is not allowed on module/function
143
     * @throws \eZ\Publish\API\Repository\Exceptions\LimitationValidationException if a policy limitation in the $roleCopyStruct is not valid
144
     *
145
     * @param \eZ\Publish\API\Repository\Values\User\RoleCopyStruct $roleCopyStruct
146
     *
147
     * @return \eZ\Publish\API\Repository\Values\User\RoleDraft
148
     */
149
    public function copyRole(Role $role, RoleCopyStruct $roleCopyStruct)
150
    {
151
        $returnValue = $this->service->copyRole($role, $roleCopyStruct);
152
        $this->signalDispatcher->emit(
153
            new CopyRoleSignal(
154
                [
155
                    'roleId' => $returnValue->id,
156
                ]
157
            )
158
        );
159
160
        return $returnValue;
161
    }
162
163
    /**
164
     * Loads a role for the given id.
165
     *
166
     * @since 6.0
167
     *
168
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to read this role
169
     * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if a role with the given id was not found
170
     *
171
     * @param mixed $id
172
     *
173
     * @return \eZ\Publish\API\Repository\Values\User\RoleDraft
174
     */
175
    public function loadRoleDraft($id)
176
    {
177
        return $this->service->loadRoleDraft($id);
178
    }
179
180
    /**
181
     * Loads a RoleDraft by the ID of the role it was created from.
182
     *
183
     * @param mixed $roleId ID of the role the draft was created from.
184
     *
185
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to read this role
186
     * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if a RoleDraft with the given id was not found
187
     *
188
     * @return \eZ\Publish\API\Repository\Values\User\RoleDraft
189
     */
190
    public function loadRoleDraftByRoleId($roleId)
191
    {
192
        return $this->service->loadRoleDraftByRoleId($roleId);
193
    }
194
195
    /**
196
     * Updates the properties of a role draft.
197
     *
198
     * @since 6.0
199
     *
200
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to update a role
201
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the identifier of the role already exists
202
     *
203
     * @param \eZ\Publish\API\Repository\Values\User\RoleDraft $roleDraft
204
     * @param \eZ\Publish\API\Repository\Values\User\RoleUpdateStruct $roleUpdateStruct
205
     *
206
     * @return \eZ\Publish\API\Repository\Values\User\RoleDraft
207
     */
208
    public function updateRoleDraft(RoleDraft $roleDraft, RoleUpdateStruct $roleUpdateStruct)
209
    {
210
        $returnValue = $this->service->updateRoleDraft($roleDraft, $roleUpdateStruct);
211
        $this->signalDispatcher->emit(
212
            new UpdateRoleDraftSignal(
213
                [
214
                    'roleId' => $roleDraft->id,
215
                ]
216
            )
217
        );
218
219
        return $returnValue;
220
    }
221
222
    /**
223
     * Adds a new policy to the role draft.
224
     *
225
     * @since 6.0
226
     *
227
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to add  a policy
228
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if limitation of the same type is repeated in policy create
229
     *                                                                        struct or if limitation is not allowed on module/function
230
     * @throws \eZ\Publish\API\Repository\Exceptions\LimitationValidationException if a limitation in the $policyCreateStruct is not valid
231
     *
232
     * @param \eZ\Publish\API\Repository\Values\User\RoleDraft $roleDraft
233
     * @param \eZ\Publish\API\Repository\Values\User\PolicyCreateStruct $policyCreateStruct
234
     *
235
     * @return \eZ\Publish\API\Repository\Values\User\RoleDraft
236
     */
237
    public function addPolicyByRoleDraft(RoleDraft $roleDraft, PolicyCreateStruct $policyCreateStruct)
238
    {
239
        $returnValue = $this->service->addPolicyByRoleDraft($roleDraft, $policyCreateStruct);
240
        $this->signalDispatcher->emit(
241
            new AddPolicyByRoleDraftSignal(
242
                [
243
                    'roleId' => $roleDraft->id,
244
                    'policyId' => $returnValue->id,
245
                ]
246
            )
247
        );
248
249
        return $returnValue;
250
    }
251
252
    /**
253
     * Removes a policy from a role draft.
254
     *
255
     * @since 6.0
256
     *
257
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to remove a policy
258
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if policy does not belong to the given RoleDraft
259
     *
260
     * @param \eZ\Publish\API\Repository\Values\User\RoleDraft $roleDraft
261
     * @param PolicyDraft $policyDraft the policy to remove from the role
262
     * @return RoleDraft if the authenticated user is not allowed to remove a policy
263
     */
264
    public function removePolicyByRoleDraft(RoleDraft $roleDraft, PolicyDraft $policyDraft)
265
    {
266
        $returnValue = $this->service->removePolicyByRoleDraft($roleDraft, $policyDraft);
267
        $this->signalDispatcher->emit(
268
            new RemovePolicyByRoleDraftSignal(
269
                [
270
                    'roleId' => $roleDraft->id,
271
                    'policyId' => $policyDraft->id,
272
                ]
273
            )
274
        );
275
276
        return $returnValue;
277
    }
278
279
    /**
280
     * Updates the limitations of a policy. The module and function cannot be changed and
281
     * the limitations are replaced by the ones in $roleUpdateStruct.
282
     *
283
     * @since 6.0
284
     *
285
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to update a policy
286
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if limitation of the same type is repeated in policy update
287
     *                                                                        struct or if limitation is not allowed on module/function
288
     * @throws \eZ\Publish\API\Repository\Exceptions\LimitationValidationException if a limitation in the $policyUpdateStruct is not valid
289
     *
290
     * @param \eZ\Publish\API\Repository\Values\User\RoleDraft $roleDraft
291
     * @param \eZ\Publish\API\Repository\Values\User\PolicyDraft $policy
292
     * @param \eZ\Publish\API\Repository\Values\User\PolicyUpdateStruct $policyUpdateStruct
293
     *
294
     * @return \eZ\Publish\API\Repository\Values\User\PolicyDraft
295
     */
296 View Code Duplication
    public function updatePolicyByRoleDraft(RoleDraft $roleDraft, PolicyDraft $policy, PolicyUpdateStruct $policyUpdateStruct)
297
    {
298
        $returnValue = $this->service->updatePolicyByRoleDraft($roleDraft, $policy, $policyUpdateStruct);
299
        $this->signalDispatcher->emit(
300
            new UpdatePolicySignal(
301
                [
302
                    'policyId' => $policy->id,
303
                ]
304
            )
305
        );
306
307
        return $returnValue;
308
    }
309
310
    /**
311
     * Deletes the given role draft.
312
     *
313
     * @since 6.0
314
     *
315
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to delete this role
316
     *
317
     * @param \eZ\Publish\API\Repository\Values\User\RoleDraft $roleDraft
318
     */
319
    public function deleteRoleDraft(RoleDraft $roleDraft)
320
    {
321
        $returnValue = $this->service->deleteRoleDraft($roleDraft);
322
        $this->signalDispatcher->emit(
323
            new DeleteRoleDraftSignal(
324
                [
325
                    'roleId' => $roleDraft->id,
326
                ]
327
            )
328
        );
329
330
        return $returnValue;
331
    }
332
333
    /**
334
     * Publishes a given Role draft.
335
     *
336
     * @since 6.0
337
     *
338
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to publish this role
339
     *
340
     * @param \eZ\Publish\API\Repository\Values\User\RoleDraft $roleDraft
341
     */
342
    public function publishRoleDraft(RoleDraft $roleDraft)
343
    {
344
        $returnValue = $this->service->publishRoleDraft($roleDraft);
345
        $this->signalDispatcher->emit(
346
            new PublishRoleDraftSignal(
347
                [
348
                    'roleId' => $roleDraft->id,
349
                ]
350
            )
351
        );
352
353
        return $returnValue;
354
    }
355
356
    /**
357
     * Updates the name of the role.
358
     *
359
     * @deprecated since 6.0, use {@see updateRoleDraft}
360
     *
361
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to update a role
362
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the name of the role already exists
363
     *
364
     * @param \eZ\Publish\API\Repository\Values\User\Role $role
365
     * @param \eZ\Publish\API\Repository\Values\User\RoleUpdateStruct $roleUpdateStruct
366
     *
367
     * @return \eZ\Publish\API\Repository\Values\User\Role
368
     */
369
    public function updateRole(Role $role, RoleUpdateStruct $roleUpdateStruct)
370
    {
371
        $returnValue = $this->service->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...
372
        $this->signalDispatcher->emit(
373
            new UpdateRoleSignal(
374
                [
375
                    'roleId' => $role->id,
376
                ]
377
            )
378
        );
379
380
        return $returnValue;
381
    }
382
383
    /**
384
     * Adds a new policy to the role.
385
     *
386
     * @deprecated since 6.0, use {@see addPolicyByRoleDraft}
387
     *
388
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to add  a policy
389
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if limitation of the same type is repeated in policy create
390
     *                                                                        struct or if limitation is not allowed on module/function
391
     * @throws \eZ\Publish\API\Repository\Exceptions\LimitationValidationException if a limitation in the $policyCreateStruct is not valid
392
     *
393
     * @param \eZ\Publish\API\Repository\Values\User\Role $role
394
     * @param \eZ\Publish\API\Repository\Values\User\PolicyCreateStruct $policyCreateStruct
395
     *
396
     * @return \eZ\Publish\API\Repository\Values\User\Role
397
     */
398
    public function addPolicy(Role $role, PolicyCreateStruct $policyCreateStruct)
399
    {
400
        $returnValue = $this->service->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...
401
        $this->signalDispatcher->emit(
402
            new AddPolicySignal(
403
                [
404
                    'roleId' => $role->id,
405
                    'policyId' => $returnValue->id,
406
                ]
407
            )
408
        );
409
410
        return $returnValue;
411
    }
412
413
    /**
414
     * Delete a policy.
415
     *
416
     * @deprecated since 6.0, use {@link removePolicyByRoleDraft()} instead.
417
     *
418
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to remove a policy
419
     *
420
     * @param \eZ\Publish\API\Repository\Values\User\Policy $policy the policy to delete
421
     */
422
    public function deletePolicy(Policy $policy)
423
    {
424
        $returnValue = $this->service->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...
425
        $this->signalDispatcher->emit(
426
            new RemovePolicySignal(
427
                [
428
                    'roleId' => $policy->roleId,
429
                    'policyId' => $policy->id,
430
                ]
431
            )
432
        );
433
434
        return $returnValue;
435
    }
436
437
    /**
438
     * Updates the limitations of a policy. The module and function cannot be changed and
439
     * the limitations are replaced by the ones in $roleUpdateStruct.
440
     *
441
     * @deprecated since 6.0, use {@link updatePolicyByRoleDraft()} instead.
442
     *
443
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to update a policy
444
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if limitation of the same type is repeated in policy update
445
     *                                                                        struct or if limitation is not allowed on module/function
446
     * @throws \eZ\Publish\API\Repository\Exceptions\LimitationValidationException if a limitation in the $policyUpdateStruct is not valid
447
     *
448
     * @param \eZ\Publish\API\Repository\Values\User\PolicyUpdateStruct $policyUpdateStruct
449
     * @param \eZ\Publish\API\Repository\Values\User\Policy $policy
450
     *
451
     * @return \eZ\Publish\API\Repository\Values\User\Policy
452
     */
453 View Code Duplication
    public function updatePolicy(Policy $policy, PolicyUpdateStruct $policyUpdateStruct)
454
    {
455
        $returnValue = $this->service->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...
456
        $this->signalDispatcher->emit(
457
            new UpdatePolicySignal(
458
                [
459
                    'policyId' => $policy->id,
460
                ]
461
            )
462
        );
463
464
        return $returnValue;
465
    }
466
467
    /**
468
     * Loads a role for the given id.
469
     *
470
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to read this role
471
     * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if a role with the given name was not found
472
     *
473
     * @param mixed $id
474
     *
475
     * @return \eZ\Publish\API\Repository\Values\User\Role
476
     */
477
    public function loadRole($id)
478
    {
479
        return $this->service->loadRole($id);
480
    }
481
482
    /**
483
     * Loads a role for the given identifier.
484
     *
485
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to read this role
486
     * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if a role with the given name was not found
487
     *
488
     * @param string $identifier
489
     *
490
     * @return \eZ\Publish\API\Repository\Values\User\Role
491
     */
492
    public function loadRoleByIdentifier($identifier)
493
    {
494
        return $this->service->loadRoleByIdentifier($identifier);
495
    }
496
497
    /**
498
     * Loads all roles, excluding the ones the current user is not allowed to read.
499
     *
500
     * @return \eZ\Publish\API\Repository\Values\User\Role[]
501
     */
502
    public function loadRoles()
503
    {
504
        return $this->service->loadRoles();
505
    }
506
507
    /**
508
     * Deletes the given role.
509
     *
510
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to delete this role
511
     *
512
     * @param \eZ\Publish\API\Repository\Values\User\Role $role
513
     */
514
    public function deleteRole(Role $role)
515
    {
516
        $returnValue = $this->service->deleteRole($role);
517
        $this->signalDispatcher->emit(
518
            new DeleteRoleSignal(
519
                [
520
                    'roleId' => $role->id,
521
                ]
522
            )
523
        );
524
525
        return $returnValue;
526
    }
527
528
    /**
529
     * Loads all policies from roles which are assigned to a user or to user groups to which the user belongs.
530
     *
531
     * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if a user with the given id was not found
532
     *
533
     * @param mixed $userId
534
     *
535
     * @return \eZ\Publish\API\Repository\Values\User\Policy[]
536
     */
537
    public function loadPoliciesByUserId($userId)
538
    {
539
        return $this->service->loadPoliciesByUserId($userId);
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\API\Repositor...:loadPoliciesByUserId() has been deprecated with message: Since 6.8, not currently in use as permission system needs to know about role assignment limitations.

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...
540
    }
541
542
    /**
543
     * Assigns a role to the given user group.
544
     *
545
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to assign a role
546
     * @throws \eZ\Publish\API\Repository\Exceptions\LimitationValidationException if $roleLimitation is not valid
547
     *
548
     * @param \eZ\Publish\API\Repository\Values\User\Role $role
549
     * @param \eZ\Publish\API\Repository\Values\User\UserGroup $userGroup
550
     * @param \eZ\Publish\API\Repository\Values\User\Limitation\RoleLimitation $roleLimitation an optional role limitation (which is either a subtree limitation or section limitation)
551
     */
552 View Code Duplication
    public function assignRoleToUserGroup(Role $role, UserGroup $userGroup, RoleLimitation $roleLimitation = null)
553
    {
554
        $returnValue = $this->service->assignRoleToUserGroup($role, $userGroup, $roleLimitation);
555
        $this->signalDispatcher->emit(
556
            new AssignRoleToUserGroupSignal(
557
                [
558
                    'roleId' => $role->id,
559
                    'userGroupId' => $userGroup->id,
560
                    'roleLimitation' => $roleLimitation,
561
                ]
562
            )
563
        );
564
565
        return $returnValue;
566
    }
567
568
    /**
569
     * removes a role from the given user group.
570
     *
571
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to remove a role
572
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException  If the role is not assigned to the given user group
573
     *
574
     * @param \eZ\Publish\API\Repository\Values\User\Role $role
575
     * @param \eZ\Publish\API\Repository\Values\User\UserGroup $userGroup
576
     */
577
    public function unassignRoleFromUserGroup(Role $role, UserGroup $userGroup)
578
    {
579
        $returnValue = $this->service->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...
580
        $this->signalDispatcher->emit(
581
            new UnassignRoleFromUserGroupSignal(
582
                [
583
                    'roleId' => $role->id,
584
                    'userGroupId' => $userGroup->id,
585
                ]
586
            )
587
        );
588
589
        return $returnValue;
590
    }
591
592
    /**
593
     * Assigns a role to the given user.
594
     *
595
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to assign a role
596
     * @throws \eZ\Publish\API\Repository\Exceptions\LimitationValidationException if $roleLimitation is not valid
597
     *
598
     * @param \eZ\Publish\API\Repository\Values\User\Role $role
599
     * @param \eZ\Publish\API\Repository\Values\User\User $user
600
     * @param \eZ\Publish\API\Repository\Values\User\Limitation\RoleLimitation $roleLimitation an optional role limitation (which is either a subtree limitation or section limitation)
601
     */
602 View Code Duplication
    public function assignRoleToUser(Role $role, User $user, RoleLimitation $roleLimitation = null)
603
    {
604
        $returnValue = $this->service->assignRoleToUser($role, $user, $roleLimitation);
605
        $this->signalDispatcher->emit(
606
            new AssignRoleToUserSignal(
607
                [
608
                    'roleId' => $role->id,
609
                    'userId' => $user->id,
610
                    'roleLimitation' => $roleLimitation,
611
                ]
612
            )
613
        );
614
615
        return $returnValue;
616
    }
617
618
    /**
619
     * removes a role from the given user.
620
     *
621
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to remove a role
622
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException If the role is not assigned to the user
623
     *
624
     * @param \eZ\Publish\API\Repository\Values\User\Role $role
625
     * @param \eZ\Publish\API\Repository\Values\User\User $user
626
     */
627
    public function unassignRoleFromUser(Role $role, User $user)
628
    {
629
        $returnValue = $this->service->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...
630
        $this->signalDispatcher->emit(
631
            new UnassignRoleFromUserSignal(
632
                [
633
                    'roleId' => $role->id,
634
                    'userId' => $user->id,
635
                ]
636
            )
637
        );
638
639
        return $returnValue;
640
    }
641
642
    /**
643
     * Removes the given role assignment.
644
     *
645
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to remove a role assignment
646
     *
647
     * @param \eZ\Publish\API\Repository\Values\User\RoleAssignment $roleAssignment
648
     */
649
    public function removeRoleAssignment(RoleAssignment $roleAssignment)
650
    {
651
        $returnValue = $this->service->removeRoleAssignment($roleAssignment);
652
        $this->signalDispatcher->emit(
653
            new RemoveRoleAssignmentSignal([
654
                'roleAssignmentId' => $roleAssignment->id,
655
            ])
656
        );
657
658
        return $returnValue;
659
    }
660
661
    /**
662
     * Loads a role assignment for the given id.
663
     *
664
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to read this role
665
     * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException If the role assignment was not found
666
     *
667
     * @param mixed $roleAssignmentId
668
     *
669
     * @return \eZ\Publish\API\Repository\Values\User\RoleAssignment
670
     */
671
    public function loadRoleAssignment($roleAssignmentId)
672
    {
673
        return $this->service->loadRoleAssignment($roleAssignmentId);
674
    }
675
676
    /**
677
     * Returns the assigned user and user groups to this role.
678
     *
679
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to read a role
680
     *
681
     * @param \eZ\Publish\API\Repository\Values\User\Role $role
682
     *
683
     * @return \eZ\Publish\API\Repository\Values\User\RoleAssignment[]
684
     */
685
    public function getRoleAssignments(Role $role)
686
    {
687
        return $this->service->getRoleAssignments($role);
688
    }
689
690
    /**
691
     * @see \eZ\Publish\API\Repository\RoleService::getRoleAssignmentsForUser()
692
     */
693
    public function getRoleAssignmentsForUser(User $user, $inherited = false)
694
    {
695
        return $this->service->getRoleAssignmentsForUser($user, $inherited);
696
    }
697
698
    /**
699
     * Returns the roles assigned to the given user group, excluding the ones the current user is not allowed to read.
700
     *
701
     * @param \eZ\Publish\API\Repository\Values\User\UserGroup $userGroup
702
     *
703
     * @return \eZ\Publish\API\Repository\Values\User\UserGroupRoleAssignment[]
704
     */
705
    public function getRoleAssignmentsForUserGroup(UserGroup $userGroup)
706
    {
707
        return $this->service->getRoleAssignmentsForUserGroup($userGroup);
708
    }
709
710
    /**
711
     * Instantiates a role create class.
712
     *
713
     * @param string $name
714
     *
715
     * @return \eZ\Publish\API\Repository\Values\User\RoleCreateStruct
716
     */
717
    public function newRoleCreateStruct($name)
718
    {
719
        return $this->service->newRoleCreateStruct($name);
720
    }
721
722
    /**
723
     * Instantiates a role copy class.
724
     *
725
     * @param string $name
726
     *
727
     * @return \eZ\Publish\API\Repository\Values\User\RoleCopyStruct
728
     */
729
    public function newRoleCopyStruct($name)
730
    {
731
        return $this->service->newRoleCopyStruct($name);
732
    }
733
734
    /**
735
     * Instantiates a policy create class.
736
     *
737
     * @param string $module
738
     * @param string $function
739
     *
740
     * @return \eZ\Publish\API\Repository\Values\User\PolicyCreateStruct
741
     */
742
    public function newPolicyCreateStruct($module, $function)
743
    {
744
        return $this->service->newPolicyCreateStruct($module, $function);
745
    }
746
747
    /**
748
     * Instantiates a policy update class.
749
     *
750
     * @return \eZ\Publish\API\Repository\Values\User\PolicyUpdateStruct
751
     */
752
    public function newPolicyUpdateStruct()
753
    {
754
        return $this->service->newPolicyUpdateStruct();
755
    }
756
757
    /**
758
     * Instantiates a policy update class.
759
     *
760
     * @return \eZ\Publish\API\Repository\Values\User\RoleUpdateStruct
761
     */
762
    public function newRoleUpdateStruct()
763
    {
764
        return $this->service->newRoleUpdateStruct();
765
    }
766
767
    /**
768
     * Returns the LimitationType registered with the given identifier.
769
     *
770
     * @param string $identifier
771
     *
772
     * @return \eZ\Publish\SPI\Limitation\Type
773
     *
774
     * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if there is no LimitationType with $identifier
775
     */
776
    public function getLimitationType($identifier)
777
    {
778
        return $this->service->getLimitationType($identifier);
779
    }
780
781
    /**
782
     * Returns the LimitationType's assigned to a given module/function.
783
     *
784
     * Typically used for:
785
     *  - Internal validation limitation value use on Policies
786
     *  - Role admin gui for editing policy limitations incl list limitation options via valueSchema()
787
     *
788
     * @param string $module Legacy name of "controller", it's a unique identifier like "content"
789
     * @param string $function Legacy name of a controller "action", it's a unique within the controller like "read"
790
     *
791
     * @return \eZ\Publish\SPI\Limitation\Type[]
792
     *
793
     * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException If module/function to limitation type mapping
794
     *                                                                 refers to a non existing identifier.
795
     */
796
    public function getLimitationTypesByModuleFunction($module, $function)
797
    {
798
        return $this->service->getLimitationTypesByModuleFunction($module, $function);
799
    }
800
}
801