Exponential 5.x Kernel 7.5.40 Exponential New Stack (Symfony-based) Kernel — PHP Class Reference

Publish/Core/REST/Server/Controller/User.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\REST\Server\Controller;
8
9 use eZ\Publish\API\Repository\Values\Content\Language;
10 use eZ\Publish\Core\REST\Common\Message;
11 use eZ\Publish\Core\REST\Server\Values;
12 use eZ\Publish\Core\REST\Server\Exceptions;
13 use eZ\Publish\Core\REST\Server\Controller as RestController;
14 use eZ\Publish\API\Repository\UserService;
15 use eZ\Publish\API\Repository\ContentService;
16 use eZ\Publish\API\Repository\ContentTypeService;
17 use eZ\Publish\API\Repository\RoleService;
18 use eZ\Publish\API\Repository\LocationService;
19 use eZ\Publish\API\Repository\SectionService;
20 use eZ\Publish\API\Repository\Repository;
21 use eZ\Publish\API\Repository\Values\User\UserRoleAssignment;
22 use eZ\Publish\API\Repository\Values\User\UserGroupRoleAssignment;
23 use eZ\Publish\API\Repository\Values\User\User as RepositoryUser;
24 use eZ\Publish\API\Repository\Exceptions as ApiExceptions;
25 use eZ\Publish\Core\REST\Server\Exceptions\ForbiddenException;
26 use eZ\Publish\Core\REST\Common\Exceptions\NotFoundException;
27 use eZ\Publish\Core\Base\Exceptions\UnauthorizedException;
28 use Symfony\Component\HttpFoundation\Request;
29 use Symfony\Component\Security\Csrf\TokenStorage\TokenStorageInterface;
30
34 class User extends RestController
35 {
41 protected $userService;
42
48 protected $roleService;
49
55 protected $contentService;
56
62 protected $contentTypeService;
63
69 protected $locationService;
70
76 protected $sectionService;
77
83 protected $repository;
84
90 private $csrfTokenStorage;
91
97 private $sessionController;
98
109 public function __construct(
110 UserService $userService,
111 RoleService $roleService,
112 ContentService $contentService,
113 ContentTypeService $contentTypeService,
114 LocationService $locationService,
115 SectionService $sectionService,
116 Repository $repository
117 ) {
118 $this->userService = $userService;
119 $this->roleService = $roleService;
120 $this->contentService = $contentService;
121 $this->contentTypeService = $contentTypeService;
122 $this->locationService = $locationService;
123 $this->sectionService = $sectionService;
124 $this->repository = $repository;
125 }
126
132 public function loadRootUserGroup()
133 {
134 //@todo Replace hardcoded value with one loaded from settings
135 return new Values\PermanentRedirect(
136 $this->router->generate('ezpublish_rest_loadUserGroup', ['groupPath' => '/1/5'])
137 );
138 }
139
147 public function loadUserGroup($groupPath)
148 {
149 $userGroupLocation = $this->locationService->loadLocation(
150 $this->extractLocationIdFromPath($groupPath)
151 );
152
153 if (trim($userGroupLocation->pathString, '/') != $groupPath) {
154 throw new NotFoundException(
155 "Could not find location with path string $groupPath"
156 );
157 }
158
159 $userGroup = $this->userService->loadUserGroup(
160 $userGroupLocation->contentId,
161 Language::ALL
162 );
163 $userGroupContentInfo = $userGroup->getVersionInfo()->getContentInfo();
164 $contentType = $this->contentTypeService->loadContentType($userGroupContentInfo->contentTypeId);
165
166 return new Values\CachedValue(
167 new Values\RestUserGroup(
168 $userGroup,
169 $contentType,
170 $userGroupContentInfo,
171 $userGroupLocation,
172 $this->contentService->loadRelations($userGroup->getVersionInfo())
173 ),
174 ['locationId' => $userGroupLocation->id]
175 );
176 }
177
185 public function loadUser($userId)
186 {
187 $user = $this->userService->loadUser($userId, Language::ALL);
188
189 $userContentInfo = $user->getVersionInfo()->getContentInfo();
190 $contentType = $this->contentTypeService->loadContentType($userContentInfo->contentTypeId);
191
192 try {
193 $userMainLocation = $this->locationService->loadLocation($userContentInfo->mainLocationId);
194 $relations = $this->contentService->loadRelations($user->getVersionInfo());
195 } catch (UnauthorizedException $e) {
196 // TODO: Hack for special case to allow current logged in user to load him/here self (but not relations)
197 if ($user->id == $this->repository->getCurrentUser()->id) {
198 $userMainLocation = $this->repository->sudo(
199 function () use ($userContentInfo) {
200 return $this->locationService->loadLocation($userContentInfo->mainLocationId);
201 }
202 );
203 // user may not have permissions to read related content, for security reasons do not use sudo().
204 $relations = [];
205 } else {
206 throw $e;
207 }
208 }
209
210 return new Values\CachedValue(
211 new Values\RestUser(
212 $user,
213 $contentType,
214 $userContentInfo,
215 $userMainLocation,
216 $relations
217 ),
218 ['locationId' => $userContentInfo->mainLocationId]
219 );
220 }
221
232 public function createUserGroup($groupPath, Request $request)
233 {
234 $userGroupLocation = $this->locationService->loadLocation(
235 $this->extractLocationIdFromPath($groupPath)
236 );
237
238 $createdUserGroup = $this->userService->createUserGroup(
239 $this->inputDispatcher->parse(
240 new Message(
241 ['Content-Type' => $request->headers->get('Content-Type')],
242 $request->getContent()
243 )
244 ),
245 $this->userService->loadUserGroup(
246 $userGroupLocation->contentId
247 )
248 );
249
250 $createdContentInfo = $createdUserGroup->getVersionInfo()->getContentInfo();
251 $createdLocation = $this->locationService->loadLocation($createdContentInfo->mainLocationId);
252 $contentType = $this->contentTypeService->loadContentType($createdContentInfo->contentTypeId);
253
254 return new Values\CreatedUserGroup(
255 [
256 'userGroup' => new Values\RestUserGroup(
257 $createdUserGroup,
258 $contentType,
259 $createdContentInfo,
260 $createdLocation,
261 $this->contentService->loadRelations($createdUserGroup->getVersionInfo())
262 ),
263 ]
264 );
265 }
266
276 public function createUser($groupPath, Request $request)
277 {
278 $userGroupLocation = $this->locationService->loadLocation(
279 $this->extractLocationIdFromPath($groupPath)
280 );
281 $userGroup = $this->userService->loadUserGroup($userGroupLocation->contentId);
282
283 $userCreateStruct = $this->inputDispatcher->parse(
284 new Message(
285 ['Content-Type' => $request->headers->get('Content-Type')],
286 $request->getContent()
287 )
288 );
289
290 try {
291 $createdUser = $this->userService->createUser($userCreateStruct, [$userGroup]);
292 } catch (ApiExceptions\InvalidArgumentException $e) {
293 throw new ForbiddenException($e->getMessage());
294 }
295
296 $createdContentInfo = $createdUser->getVersionInfo()->getContentInfo();
297 $createdLocation = $this->locationService->loadLocation($createdContentInfo->mainLocationId);
298 $contentType = $this->contentTypeService->loadContentType($createdContentInfo->contentTypeId);
299
300 return new Values\CreatedUser(
301 [
302 'user' => new Values\RestUser(
303 $createdUser,
304 $contentType,
305 $createdContentInfo,
306 $createdLocation,
307 $this->contentService->loadRelations($createdUser->getVersionInfo())
308 ),
309 ]
310 );
311 }
312
320 public function updateUserGroup($groupPath, Request $request)
321 {
322 $userGroupLocation = $this->locationService->loadLocation(
323 $this->extractLocationIdFromPath($groupPath)
324 );
325
326 $userGroup = $this->userService->loadUserGroup(
327 $userGroupLocation->contentId
328 );
329
330 $updateStruct = $this->inputDispatcher->parse(
331 new Message(
332 [
333 'Content-Type' => $request->headers->get('Content-Type'),
334 // @todo Needs refactoring! Temporary solution so parser has access to URL
335 'Url' => $request->getPathInfo(),
336 ],
337 $request->getContent()
338 )
339 );
340
341 if ($updateStruct->sectionId !== null) {
342 $section = $this->sectionService->loadSection($updateStruct->sectionId);
343 $this->sectionService->assignSection(
344 $userGroup->getVersionInfo()->getContentInfo(),
345 $section
346 );
347 }
348
349 $updatedGroup = $this->userService->updateUserGroup($userGroup, $updateStruct->userGroupUpdateStruct);
350 $contentType = $this->contentTypeService->loadContentType(
351 $updatedGroup->getVersionInfo()->getContentInfo()->contentTypeId
352 );
353
354 return new Values\RestUserGroup(
355 $updatedGroup,
356 $contentType,
357 $updatedGroup->getVersionInfo()->getContentInfo(),
358 $userGroupLocation,
359 $this->contentService->loadRelations($updatedGroup->getVersionInfo())
360 );
361 }
362
370 public function updateUser($userId, Request $request)
371 {
372 $user = $this->userService->loadUser($userId);
373
374 $updateStruct = $this->inputDispatcher->parse(
375 new Message(
376 [
377 'Content-Type' => $request->headers->get('Content-Type'),
378 // @todo Needs refactoring! Temporary solution so parser has access to URL
379 'Url' => $request->getPathInfo(),
380 ],
381 $request->getContent()
382 )
383 );
384
385 if ($updateStruct->sectionId !== null) {
386 $section = $this->sectionService->loadSection($updateStruct->sectionId);
387 $this->sectionService->assignSection(
388 $user->getVersionInfo()->getContentInfo(),
389 $section
390 );
391 }
392
393 $updatedUser = $this->userService->updateUser($user, $updateStruct->userUpdateStruct);
394 $updatedContentInfo = $updatedUser->getVersionInfo()->getContentInfo();
395 $mainLocation = $this->locationService->loadLocation($updatedContentInfo->mainLocationId);
396 $contentType = $this->contentTypeService->loadContentType($updatedContentInfo->contentTypeId);
397
398 return new Values\RestUser(
399 $updatedUser,
400 $contentType,
401 $updatedContentInfo,
402 $mainLocation,
403 $this->contentService->loadRelations($updatedUser->getVersionInfo())
404 );
405 }
406
416 public function deleteUserGroup($groupPath)
417 {
418 $userGroupLocation = $this->locationService->loadLocation(
419 $this->extractLocationIdFromPath($groupPath)
420 );
421
422 $userGroup = $this->userService->loadUserGroup(
423 $userGroupLocation->contentId
424 );
425
426 // Load one user to see if user group is empty or not
427 $users = $this->userService->loadUsersOfUserGroup($userGroup, 0, 1);
428 if (!empty($users)) {
429 throw new Exceptions\ForbiddenException('Non-empty user groups cannot be deleted');
430 }
431
432 $this->userService->deleteUserGroup($userGroup);
433
434 return new Values\NoContent();
435 }
436
446 public function deleteUser($userId)
447 {
448 $user = $this->userService->loadUser($userId);
449
450 if ($user->id == $this->repository->getCurrentUser()->id) {
451 throw new Exceptions\ForbiddenException('Currently authenticated user cannot be deleted');
452 }
453
454 $this->userService->deleteUser($user);
455
456 return new Values\NoContent();
457 }
458
464 public function loadUsers(Request $request)
465 {
466 $restUsers = [];
467
468 try {
469 if ($request->query->has('roleId')) {
470 $restUsers = $this->loadUsersAssignedToRole(
471 $this->requestParser->parseHref($request->query->get('roleId'), 'roleId')
472 );
473 } elseif ($request->query->has('remoteId')) {
474 $restUsers = [
475 $this->buildRestUserObject(
476 $this->userService->loadUser(
477 $this->contentService->loadContentInfoByRemoteId($request->query->get('remoteId'))->id,
478 Language::ALL
479 )
480 ),
481 ];
482 } elseif ($request->query->has('login')) {
483 $restUsers = [
484 $this->buildRestUserObject(
485 $this->userService->loadUserByLogin($request->query->get('login'), Language::ALL)
486 ),
487 ];
488 } elseif ($request->query->has('email')) {
489 foreach ($this->userService->loadUsersByEmail($request->query->get('email'), Language::ALL) as $user) {
490 $restUsers[] = $this->buildRestUserObject($user);
491 }
492 }
493 } catch (ApiExceptions\UnauthorizedException $e) {
494 $restUsers = [];
495 }
496
497 if (empty($restUsers)) {
498 throw new NotFoundException('No users were found with the given filter');
499 }
500
501 if ($this->getMediaType($request) === 'application/vnd.ez.api.userlist') {
502 return new Values\UserList($restUsers, $request->getPathInfo());
503 }
504
505 return new Values\UserRefList($restUsers, $request->getPathInfo());
506 }
507
508 public function verifyUsers(Request $request)
509 {
510 // We let the NotFoundException loadUsers throws if there are no results pass.
511 $this->loadUsers($request)->users;
512
513 return new Values\OK();
514 }
515
523 public function loadUsersAssignedToRole($roleId)
524 {
525 $role = $this->roleService->loadRole($roleId);
526 $roleAssignments = $this->roleService->getRoleAssignments($role);
527
528 $restUsers = [];
529
530 foreach ($roleAssignments as $roleAssignment) {
531 if ($roleAssignment instanceof UserRoleAssignment) {
532 $restUsers[] = $this->buildRestUserObject($roleAssignment->getUser());
533 }
534 }
535
536 return $restUsers;
537 }
538
542 private function buildRestUserObject(RepositoryUser $user)
543 {
544 return new Values\RestUser(
545 $user,
546 $this->contentTypeService->loadContentType($user->contentInfo->contentTypeId),
547 $user->contentInfo,
548 $this->locationService->loadLocation($user->contentInfo->mainLocationId),
549 $this->contentService->loadRelations($user->getVersionInfo())
550 );
551 }
552
558 public function loadUserGroups(Request $request)
559 {
560 $restUserGroups = [];
561 if ($request->query->has('id')) {
562 $userGroup = $this->userService->loadUserGroup($request->query->get('id'), Language::ALL);
563 $userGroupContentInfo = $userGroup->getVersionInfo()->getContentInfo();
564 $userGroupMainLocation = $this->locationService->loadLocation($userGroupContentInfo->mainLocationId);
565 $contentType = $this->contentTypeService->loadContentType($userGroupContentInfo->contentTypeId);
566
567 $restUserGroups = [
568 new Values\RestUserGroup(
569 $userGroup,
570 $contentType,
571 $userGroupContentInfo,
572 $userGroupMainLocation,
573 $this->contentService->loadRelations($userGroup->getVersionInfo())
574 ),
575 ];
576 } elseif ($request->query->has('roleId')) {
577 $restUserGroups = $this->loadUserGroupsAssignedToRole($request->query->get('roleId'));
578 } elseif ($request->query->has('remoteId')) {
579 $restUserGroups = [
580 $this->loadUserGroupByRemoteId($request),
581 ];
582 }
583
584 if ($this->getMediaType($request) === 'application/vnd.ez.api.usergrouplist') {
585 return new Values\UserGroupList($restUserGroups, $request->getPathInfo());
586 }
587
588 return new Values\UserGroupRefList($restUserGroups, $request->getPathInfo());
589 }
590
596 public function loadUserGroupByRemoteId(Request $request)
597 {
598 $contentInfo = $this->contentService->loadContentInfoByRemoteId($request->query->get('remoteId'));
599 $userGroup = $this->userService->loadUserGroup($contentInfo->id, Language::ALL);
600 $userGroupLocation = $this->locationService->loadLocation($contentInfo->mainLocationId);
601 $contentType = $this->contentTypeService->loadContentType($contentInfo->contentTypeId);
602
603 return new Values\RestUserGroup(
604 $userGroup,
605 $contentType,
606 $contentInfo,
607 $userGroupLocation,
608 $this->contentService->loadRelations($userGroup->getVersionInfo())
609 );
610 }
611
619 public function loadUserGroupsAssignedToRole($roleId)
620 {
621 $role = $this->roleService->loadRole($roleId);
622 $roleAssignments = $this->roleService->getRoleAssignments($role);
623
624 $restUserGroups = [];
625
626 foreach ($roleAssignments as $roleAssignment) {
627 if ($roleAssignment instanceof UserGroupRoleAssignment) {
628 $userGroup = $roleAssignment->getUserGroup();
629 $userGroupContentInfo = $userGroup->getVersionInfo()->getContentInfo();
630 $userGroupLocation = $this->locationService->loadLocation($userGroupContentInfo->mainLocationId);
631 $contentType = $this->contentTypeService->loadContentType($userGroupContentInfo->contentTypeId);
632
633 $restUserGroups[] = new Values\RestUserGroup(
634 $userGroup,
635 $contentType,
636 $userGroupContentInfo,
637 $userGroupLocation,
638 $this->contentService->loadRelations($userGroup->getVersionInfo())
639 );
640 }
641 }
642
643 return $restUserGroups;
644 }
645
653 public function loadUserDrafts($userId, Request $request)
654 {
655 $contentDrafts = $this->contentService->loadContentDrafts(
656 $this->userService->loadUser($userId)
657 );
658
659 return new Values\VersionList($contentDrafts, $request->getPathInfo());
660 }
661
671 public function moveUserGroup($groupPath, Request $request)
672 {
673 $userGroupLocation = $this->locationService->loadLocation(
674 $this->extractLocationIdFromPath($groupPath)
675 );
676
677 $userGroup = $this->userService->loadUserGroup(
678 $userGroupLocation->contentId
679 );
680
681 $locationPath = $this->requestParser->parseHref(
682 $request->headers->get('Destination'),
683 'groupPath'
684 );
685
686 try {
687 $destinationGroupLocation = $this->locationService->loadLocation(
688 $this->extractLocationIdFromPath($locationPath)
689 );
690 } catch (ApiExceptions\NotFoundException $e) {
691 throw new Exceptions\ForbiddenException($e->getMessage());
692 }
693
694 try {
695 $destinationGroup = $this->userService->loadUserGroup($destinationGroupLocation->contentId);
696 } catch (ApiExceptions\NotFoundException $e) {
697 throw new Exceptions\ForbiddenException($e->getMessage());
698 }
699
700 $this->userService->moveUserGroup($userGroup, $destinationGroup);
701
702 return new Values\ResourceCreated(
703 $this->router->generate(
704 'ezpublish_rest_loadUserGroup',
705 [
706 'groupPath' => trim($destinationGroupLocation->pathString, '/') . '/' . $userGroupLocation->id,
707 ]
708 )
709 );
710 }
711
719 public function loadSubUserGroups($groupPath, Request $request)
720 {
721 $offset = $request->query->has('offset') ? (int)$request->query->get('offset') : 0;
722 $limit = $request->query->has('limit') ? (int)$request->query->get('limit') : 25;
723
724 $userGroupLocation = $this->locationService->loadLocation(
725 $this->extractLocationIdFromPath($groupPath)
726 );
727
728 $userGroup = $this->userService->loadUserGroup(
729 $userGroupLocation->contentId
730 );
731
732 $subGroups = $this->userService->loadSubUserGroups(
733 $userGroup,
734 $offset >= 0 ? $offset : 0,
735 $limit >= 0 ? $limit : 25,
736 Language::ALL
737 );
738
739 $restUserGroups = [];
740 foreach ($subGroups as $subGroup) {
741 $subGroupContentInfo = $subGroup->getVersionInfo()->getContentInfo();
742 $subGroupLocation = $this->locationService->loadLocation($subGroupContentInfo->mainLocationId);
743 $contentType = $this->contentTypeService->loadContentType($subGroupContentInfo->contentTypeId);
744
745 $restUserGroups[] = new Values\RestUserGroup(
746 $subGroup,
747 $contentType,
748 $subGroupContentInfo,
749 $subGroupLocation,
750 $this->contentService->loadRelations($subGroup->getVersionInfo())
751 );
752 }
753
754 if ($this->getMediaType($request) === 'application/vnd.ez.api.usergrouplist') {
755 return new Values\CachedValue(
756 new Values\UserGroupList($restUserGroups, $request->getPathInfo()),
757 ['locationId' => $userGroupLocation->id]
758 );
759 }
760
761 return new Values\CachedValue(
762 new Values\UserGroupRefList($restUserGroups, $request->getPathInfo()),
763 ['locationId' => $userGroupLocation->id]
764 );
765 }
766
776 public function loadUserGroupsOfUser($userId, Request $request)
777 {
778 $offset = $request->query->has('offset') ? (int)$request->query->get('offset') : 0;
779 $limit = $request->query->has('limit') ? (int)$request->query->get('limit') : 25;
780
781 $user = $this->userService->loadUser($userId);
782 $userGroups = $this->userService->loadUserGroupsOfUser(
783 $user,
784 $offset >= 0 ? $offset : 0,
785 $limit >= 0 ? $limit : 25,
786 Language::ALL
787 );
788
789 $restUserGroups = [];
790 foreach ($userGroups as $userGroup) {
791 $userGroupContentInfo = $userGroup->getVersionInfo()->getContentInfo();
792 $userGroupLocation = $this->locationService->loadLocation($userGroupContentInfo->mainLocationId);
793 $contentType = $this->contentTypeService->loadContentType($userGroupContentInfo->contentTypeId);
794
795 $restUserGroups[] = new Values\RestUserGroup(
796 $userGroup,
797 $contentType,
798 $userGroupContentInfo,
799 $userGroupLocation,
800 $this->contentService->loadRelations($userGroup->getVersionInfo())
801 );
802 }
803
804 return new Values\CachedValue(
805 new Values\UserGroupRefList($restUserGroups, $request->getPathInfo(), $userId),
806 ['locationId' => $user->contentInfo->mainLocationId]
807 );
808 }
809
817 public function loadUsersFromGroup($groupPath, Request $request)
818 {
819 $userGroupLocation = $this->locationService->loadLocation(
820 $this->extractLocationIdFromPath($groupPath)
821 );
822
823 $userGroup = $this->userService->loadUserGroup(
824 $userGroupLocation->contentId
825 );
826
827 $offset = $request->query->has('offset') ? (int)$request->query->get('offset') : 0;
828 $limit = $request->query->has('limit') ? (int)$request->query->get('limit') : 25;
829
830 $users = $this->userService->loadUsersOfUserGroup(
831 $userGroup,
832 $offset >= 0 ? $offset : 0,
833 $limit >= 0 ? $limit : 25,
834 Language::ALL
835 );
836
837 $restUsers = [];
838 foreach ($users as $user) {
839 $userContentInfo = $user->getVersionInfo()->getContentInfo();
840 $userLocation = $this->locationService->loadLocation($userContentInfo->mainLocationId);
841 $contentType = $this->contentTypeService->loadContentType($userContentInfo->contentTypeId);
842
843 $restUsers[] = new Values\RestUser(
844 $user,
845 $contentType,
846 $userContentInfo,
847 $userLocation,
848 $this->contentService->loadRelations($user->getVersionInfo())
849 );
850 }
851
852 if ($this->getMediaType($request) === 'application/vnd.ez.api.userlist') {
853 return new Values\CachedValue(
854 new Values\UserList($restUsers, $request->getPathInfo()),
855 ['locationId' => $userGroupLocation->id]
856 );
857 }
858
859 return new Values\CachedValue(
860 new Values\UserRefList($restUsers, $request->getPathInfo()),
861 ['locationId' => $userGroupLocation->id]
862 );
863 }
864
875 public function unassignUserFromUserGroup($userId, $groupPath)
876 {
877 $user = $this->userService->loadUser($userId);
878 $userGroupLocation = $this->locationService->loadLocation(trim($groupPath, '/'));
879
880 $userGroup = $this->userService->loadUserGroup(
881 $userGroupLocation->contentId
882 );
883
884 try {
885 $this->userService->unAssignUserFromUserGroup($user, $userGroup);
886 } catch (ApiExceptions\InvalidArgumentException $e) {
887 // User is not in the group
888 throw new Exceptions\ForbiddenException($e->getMessage());
889 }
890
891 $userGroups = $this->userService->loadUserGroupsOfUser($user);
892 $restUserGroups = [];
893 foreach ($userGroups as $userGroup) {
894 $userGroupContentInfo = $userGroup->getVersionInfo()->getContentInfo();
895 $userGroupLocation = $this->locationService->loadLocation($userGroupContentInfo->mainLocationId);
896 $contentType = $this->contentTypeService->loadContentType($userGroupContentInfo->contentTypeId);
897
898 $restUserGroups[] = new Values\RestUserGroup(
899 $userGroup,
900 $contentType,
901 $userGroupContentInfo,
902 $userGroupLocation,
903 $this->contentService->loadRelations($userGroup->getVersionInfo())
904 );
905 }
906
907 return new Values\UserGroupRefList(
908 $restUserGroups,
909 $this->router->generate(
910 'ezpublish_rest_loadUserGroupsOfUser',
911 ['userId' => $userId]
912 ),
913 $userId
914 );
915 }
916
926 public function assignUserToUserGroup($userId, Request $request)
927 {
928 $user = $this->userService->loadUser($userId);
929
930 try {
931 $userGroupLocation = $this->locationService->loadLocation(
932 $this->extractLocationIdFromPath($request->query->get('group'))
933 );
934 } catch (ApiExceptions\NotFoundException $e) {
935 throw new Exceptions\ForbiddenException($e->getMessage());
936 }
937
938 try {
939 $userGroup = $this->userService->loadUserGroup(
940 $userGroupLocation->contentId
941 );
942 } catch (ApiExceptions\NotFoundException $e) {
943 throw new Exceptions\ForbiddenException($e->getMessage());
944 }
945
946 try {
947 $this->userService->assignUserToUserGroup($user, $userGroup);
948 } catch (ApiExceptions\NotFoundException $e) {
949 throw new Exceptions\ForbiddenException($e->getMessage());
950 }
951
952 $userGroups = $this->userService->loadUserGroupsOfUser($user);
953 $restUserGroups = [];
954 foreach ($userGroups as $userGroup) {
955 $userGroupContentInfo = $userGroup->getVersionInfo()->getContentInfo();
956 $userGroupLocation = $this->locationService->loadLocation($userGroupContentInfo->mainLocationId);
957 $contentType = $this->contentTypeService->loadContentType($userGroupContentInfo->contentTypeId);
958
959 $restUserGroups[] = new Values\RestUserGroup(
960 $userGroup,
961 $contentType,
962 $userGroupContentInfo,
963 $userGroupLocation,
964 $this->contentService->loadRelations($userGroup->getVersionInfo())
965 );
966 }
967
968 return new Values\UserGroupRefList(
969 $restUserGroups,
970 $this->router->generate(
971 'ezpublish_rest_loadUserGroupsOfUser',
972 ['userId' => $userId]
973 ),
974 $userId
975 );
976 }
977
987 public function createSession(Request $request)
988 {
989 @trigger_error(
990 E_USER_DEPRECATED,
991 'The session actions from the User controller are deprecated since 6.5. Use the SessionController instead.'
992 );
993
994 return $this->sessionController->createSessionAction($request);
995 }
996
1008 public function refreshSession($sessionId, Request $request)
1009 {
1010 @trigger_error(
1011 E_USER_DEPRECATED,
1012 'The session actions from the User controller are deprecated since 6.5. Use the SessionController instead.'
1013 );
1014
1015 return $this->sessionController->refreshSessionAction($sessionId, $request);
1016 }
1017
1030 public function deleteSession($sessionId, Request $request)
1031 {
1032 @trigger_error(
1033 E_USER_DEPRECATED,
1034 'The session actions from the User controller are deprecated since 6.5. Use the SessionController instead.'
1035 );
1036
1037 return $this->sessionController->deleteSessionAction($sessionId, $request);
1038 }
1039
1047 private function extractLocationIdFromPath($path)
1048 {
1049 $pathParts = explode('/', $path);
1050
1051 return array_pop($pathParts);
1052 }
1053
1054 public function setTokenStorage(TokenStorageInterface $csrfTokenStorage)
1055 {
1056 @trigger_error(
1057 E_USER_DEPRECATED,
1058 'setTokenStorage() is deprecated since 6.5 and will be removed in 7.0.'
1059 );
1060
1061 $this->csrfTokenStorage = $csrfTokenStorage;
1062 }
1063
1064 public function setSessionController(SessionController $sessionController)
1065 {
1066 $this->sessionController = $sessionController;
1067 }
1068 }
eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
This exception is thrown if a service method is called with an illegal or non appropriate value.
Definition: API/Repository/Exceptions/InvalidArgumentException.php:13
eZ\Publish\API\Repository\Exceptions\NotFoundException
This Exception is thrown if an object referenced by an id or identifier could not be found in the rep...
Definition: API/Repository/Exceptions/NotFoundException.php:16
eZ\Publish\API\Repository\Values\Content\Language
Definition: API/Repository/Values/Content/Language.php:20
eZ\Publish\API\Repository\Values\User\UserGroupRoleAssignment
Definition: API/Repository/Values/User/UserGroupRoleAssignment.php:15
eZ\Publish\API\Repository\Values\User\UserRoleAssignment
Definition: API/Repository/Values/User/UserRoleAssignment.php:15
eZ\Publish\API\Repository\Values\User\User
Definition: Publish/API/Repository/Values/User/User.php:24
eZ\Publish\Core\Base\Exceptions\ForbiddenException
Forbidden Exception implementation.
Definition: Core/Base/Exceptions/ForbiddenException.php:17
eZ\Publish\Core\Base\Exceptions\UnauthorizedException
UnauthorizedException Exception implementation.
Definition: Core/Base/Exceptions/UnauthorizedException.php:21
eZ\Publish\Core\REST\Common\Exceptions\NotFoundException
Implementation of the \eZ\Publish\API\Repository\Exceptions\NotFoundException interface.
Definition: Core/REST/Common/Exceptions/NotFoundException.php:18
eZ\Publish\Core\REST\Common\Message
Simple response struct.
Definition: Core/REST/Common/Message.php:13
eZ\Publish\Core\REST\Server\Controller\SessionController
Definition: SessionController.php:24
eZ\Publish\Core\REST\Server\Controller\User\loadUserGroupsOfUser
loadUserGroupsOfUser($userId, Request $request)
Returns a list of user groups the user belongs to.
Definition: Publish/Core/REST/Server/Controller/User.php:776
eZ\Publish\Core\REST\Server\Controller\User\$roleService
$roleService
Definition: Publish/Core/REST/Server/Controller/User.php:48
eZ\Publish\Core\REST\Server\Controller\User\loadUser
loadUser($userId)
Loads a user for the given ID.
Definition: Publish/Core/REST/Server/Controller/User.php:185
eZ\Publish\Core\REST\Server\Controller\User\updateUserGroup
updateUserGroup($groupPath, Request $request)
Updates a user group.
Definition: Publish/Core/REST/Server/Controller/User.php:320
eZ\Publish\Core\REST\Server\Controller\User\loadRootUserGroup
loadRootUserGroup()
Redirects to the root user group.
Definition: Publish/Core/REST/Server/Controller/User.php:132
eZ\Publish\Core\REST\Server\Controller\User\$contentTypeService
$contentTypeService
Definition: Publish/Core/REST/Server/Controller/User.php:62
eZ\Publish\Core\REST\Server\Controller\User\unassignUserFromUserGroup
unassignUserFromUserGroup($userId, $groupPath)
Unassigns the user from a user group.
Definition: Publish/Core/REST/Server/Controller/User.php:875
eZ\Publish\Core\REST\Server\Controller\User\assignUserToUserGroup
assignUserToUserGroup($userId, Request $request)
Assigns the user to a user group.
Definition: Publish/Core/REST/Server/Controller/User.php:926
eZ\Publish\Core\REST\Server\Controller\User\loadUsersAssignedToRole
loadUsersAssignedToRole($roleId)
Loads a list of users assigned to role.
Definition: Publish/Core/REST/Server/Controller/User.php:523
eZ\Publish\Core\REST\Server\Controller\User\deleteSession
deleteSession($sessionId, Request $request)
Deletes given session.
Definition: Publish/Core/REST/Server/Controller/User.php:1030
eZ\Publish\Core\REST\Server\Controller\User\extractLocationIdFromPath
extractLocationIdFromPath($path)
Extracts and returns an item id from a path, e.g.
Definition: Publish/Core/REST/Server/Controller/User.php:1047
eZ\Publish\Core\REST\Server\Controller\User\loadUserGroups
loadUserGroups(Request $request)
Loads user groups.
Definition: Publish/Core/REST/Server/Controller/User.php:558
eZ\Publish\Core\REST\Server\Controller\User\refreshSession
refreshSession($sessionId, Request $request)
Refresh given session.
Definition: Publish/Core/REST/Server/Controller/User.php:1008
eZ\Publish\Core\REST\Server\Controller\User\loadUsersFromGroup
loadUsersFromGroup($groupPath, Request $request)
Loads the users of the group with the given path.
Definition: Publish/Core/REST/Server/Controller/User.php:817
eZ\Publish\Core\REST\Server\Controller\User\loadUserDrafts
loadUserDrafts($userId, Request $request)
Loads drafts assigned to user.
Definition: Publish/Core/REST/Server/Controller/User.php:653
eZ\Publish\Core\REST\Server\Controller\User\moveUserGroup
moveUserGroup($groupPath, Request $request)
Moves the user group to another parent.
Definition: Publish/Core/REST/Server/Controller/User.php:671
eZ\Publish\Core\REST\Server\Controller\User\updateUser
updateUser($userId, Request $request)
Updates a user.
Definition: Publish/Core/REST/Server/Controller/User.php:370
eZ\Publish\Core\REST\Server\Controller\User\loadUsers
loadUsers(Request $request)
Loads users.
Definition: Publish/Core/REST/Server/Controller/User.php:464
eZ\Publish\Core\REST\Server\Controller\User\$contentService
$contentService
Definition: Publish/Core/REST/Server/Controller/User.php:55
eZ\Publish\Core\REST\Server\Controller\User\__construct
__construct(UserService $userService, RoleService $roleService, ContentService $contentService, ContentTypeService $contentTypeService, LocationService $locationService, SectionService $sectionService, Repository $repository)
Construct controller.
Definition: Publish/Core/REST/Server/Controller/User.php:109
eZ\Publish\Core\REST\Server\Controller\User\setTokenStorage
setTokenStorage(TokenStorageInterface $csrfTokenStorage)
Definition: Publish/Core/REST/Server/Controller/User.php:1054
eZ\Publish\Core\REST\Server\Controller\User\createSession
createSession(Request $request)
Creates a new session based on the credentials provided as POST parameters.
Definition: Publish/Core/REST/Server/Controller/User.php:987
eZ\Publish\Core\REST\Server\Controller\User\$sectionService
$sectionService
Definition: Publish/Core/REST/Server/Controller/User.php:76
eZ\Publish\Core\REST\Server\Controller\User\$locationService
$locationService
Definition: Publish/Core/REST/Server/Controller/User.php:69
eZ\Publish\Core\REST\Server\Controller\User\$sessionController
$sessionController
Definition: Publish/Core/REST/Server/Controller/User.php:97
eZ\Publish\Core\REST\Server\Controller\User\$repository
$repository
Definition: Publish/Core/REST/Server/Controller/User.php:83
eZ\Publish\Core\REST\Server\Controller\User\buildRestUserObject
buildRestUserObject(RepositoryUser $user)
Definition: Publish/Core/REST/Server/Controller/User.php:542
eZ\Publish\Core\REST\Server\Controller\User\deleteUserGroup
deleteUserGroup($groupPath)
Given user group is deleted.
Definition: Publish/Core/REST/Server/Controller/User.php:416
eZ\Publish\Core\REST\Server\Controller\User\loadUserGroupsAssignedToRole
loadUserGroupsAssignedToRole($roleId)
Loads a list of user groups assigned to role.
Definition: Publish/Core/REST/Server/Controller/User.php:619
eZ\Publish\Core\REST\Server\Controller\User\loadUserGroup
loadUserGroup($groupPath)
Loads a user group for the given path.
Definition: Publish/Core/REST/Server/Controller/User.php:147
eZ\Publish\Core\REST\Server\Controller\User\$userService
$userService
Definition: Publish/Core/REST/Server/Controller/User.php:41
eZ\Publish\Core\REST\Server\Controller\User\verifyUsers
verifyUsers(Request $request)
Definition: Publish/Core/REST/Server/Controller/User.php:508
eZ\Publish\Core\REST\Server\Controller\User\$csrfTokenStorage
$csrfTokenStorage
Definition: Publish/Core/REST/Server/Controller/User.php:90
eZ\Publish\Core\REST\Server\Controller\User\loadUserGroupByRemoteId
loadUserGroupByRemoteId(Request $request)
Loads a user group by its remote ID.
Definition: Publish/Core/REST/Server/Controller/User.php:596
eZ\Publish\Core\REST\Server\Controller\User\createUser
createUser($groupPath, Request $request)
Create a new user group in the given group.
Definition: Publish/Core/REST/Server/Controller/User.php:276
eZ\Publish\Core\REST\Server\Controller\User\setSessionController
setSessionController(SessionController $sessionController)
Definition: Publish/Core/REST/Server/Controller/User.php:1064
eZ\Publish\Core\REST\Server\Controller\User\loadSubUserGroups
loadSubUserGroups($groupPath, Request $request)
Returns a list of the sub groups.
Definition: Publish/Core/REST/Server/Controller/User.php:719
eZ\Publish\Core\REST\Server\Controller\User\createUserGroup
createUserGroup($groupPath, Request $request)
Create a new user group under the given parent To create a top level group use /user/groups/1/5/subgr...
Definition: Publish/Core/REST/Server/Controller/User.php:232
eZ\Publish\Core\REST\Server\Controller\User\deleteUser
deleteUser($userId)
Given user is deleted.
Definition: Publish/Core/REST/Server/Controller/User.php:446
eZ\Publish\Core\REST\Server\Controller\getMediaType
getMediaType(Request $request)
Extracts the requested media type from $request.
Definition: Publish/Core/REST/Server/Controller.php:64
eZ\Publish\Core\REST\Server\Exceptions\ForbiddenException
Exception thrown if the request is forbidden.
Definition: Core/REST/Server/Exceptions/ForbiddenException.php:15
eZ\Publish\Core\REST\Server\Values\CachedValue
Definition: Values/CachedValue.php:13
eZ\Publish\Core\REST\Server\Values\CreatedUserGroup
Struct representing a freshly created UserGroup.
Definition: Values/CreatedUserGroup.php:15
eZ\Publish\Core\REST\Server\Values\CreatedUser
Struct representing a freshly created User.
Definition: Values/CreatedUser.php:15
eZ\Publish\Core\REST\Server\Values\NoContent
Definition: Values/NoContent.php:12
eZ\Publish\Core\REST\Server\Values\OK
Value object for a 200 OK response.
Definition: Values/OK.php:13
eZ\Publish\Core\REST\Server\Values\PermanentRedirect
Definition: Values/PermanentRedirect.php:12
eZ\Publish\Core\REST\Server\Values\ResourceCreated
Definition: Values/ResourceCreated.php:12
eZ\Publish\Core\REST\Server\Values\RestUserGroup
REST UserGroup, as received by /user/groups/<path>.
Definition: Values/RestUserGroup.php:19
eZ\Publish\Core\REST\Server\Values\RestUser
REST User, as received by /user/users/<ID>.
Definition: Values/RestUser.php:19
eZ\Publish\Core\REST\Server\Values\UserGroupList
User group list view model.
Definition: Values/UserGroupList.php:15
eZ\Publish\Core\REST\Server\Values\UserGroupRefList
User group list view model.
Definition: Values/UserGroupRefList.php:15
eZ\Publish\Core\REST\Server\Values\UserList
User list view model.
Definition: Server/Values/UserList.php:15
eZ\Publish\Core\REST\Server\Values\UserRefList
User list view model.
Definition: Server/Values/UserRefList.php:15
eZ\Publish\Core\REST\Server\Values\VersionList
Version list view model.
Definition: Values/VersionList.php:15
eZ\Publish\API\Repository\ContentService
Definition: API/Repository/ContentService.php:27
eZ\Publish\API\Repository\ContentTypeService
Definition: API/Repository/ContentTypeService.php:25
eZ\Publish\API\Repository\LocationService
Definition: API/Repository/LocationService.php:21
eZ\Publish\API\Repository\Repository
Repository interface.
Definition: API/Repository/Repository.php:16
eZ\Publish\API\Repository\RoleService
This service provides methods for managing Roles and Policies.
Definition: API/Repository/RoleService.php:26
eZ\Publish\API\Repository\SectionService
Section service, used for section operations.
Definition: API/Repository/SectionService.php:19
eZ\Publish\API\Repository\UserService
Definition: API/Repository/UserService.php:26
eZ\Publish\API\Repository\Exceptions
Definition: API/Repository/Exceptions/BadStateException.php:7
eZ\Publish\Core\REST\Server\Controller
Definition: BinaryContent.php:7
eZ\Publish\Core\REST\Server\Exceptions
Definition: AuthenticationFailedException.php:7
eZ\Publish\Core\REST\Server\Values
Definition: Core/REST/Server/Values/BookmarkList.php:9
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.