1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* File containing the User controller 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\REST\Server\Controller; |
10
|
|
|
|
11
|
|
|
use eZ\Publish\API\Repository\Values\Content\Language; |
12
|
|
|
use eZ\Publish\Core\REST\Common\Message; |
13
|
|
|
use eZ\Publish\Core\REST\Server\Values; |
14
|
|
|
use eZ\Publish\Core\REST\Server\Exceptions; |
15
|
|
|
use eZ\Publish\Core\REST\Server\Controller as RestController; |
16
|
|
|
use eZ\Publish\API\Repository\UserService; |
17
|
|
|
use eZ\Publish\API\Repository\ContentService; |
18
|
|
|
use eZ\Publish\API\Repository\ContentTypeService; |
19
|
|
|
use eZ\Publish\API\Repository\RoleService; |
20
|
|
|
use eZ\Publish\API\Repository\LocationService; |
21
|
|
|
use eZ\Publish\API\Repository\SectionService; |
22
|
|
|
use eZ\Publish\API\Repository\Repository; |
23
|
|
|
use eZ\Publish\API\Repository\Values\User\UserRoleAssignment; |
24
|
|
|
use eZ\Publish\API\Repository\Values\User\UserGroupRoleAssignment; |
25
|
|
|
use eZ\Publish\API\Repository\Values\User\User as RepositoryUser; |
26
|
|
|
use eZ\Publish\API\Repository\Exceptions as ApiExceptions; |
27
|
|
|
use eZ\Publish\Core\REST\Server\Exceptions\ForbiddenException; |
28
|
|
|
use eZ\Publish\Core\REST\Common\Exceptions\NotFoundException; |
29
|
|
|
use eZ\Publish\Core\Base\Exceptions\UnauthorizedException; |
30
|
|
|
use Symfony\Component\HttpFoundation\Request; |
31
|
|
|
use Symfony\Component\Security\Csrf\TokenStorage\TokenStorageInterface; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* User controller. |
35
|
|
|
*/ |
36
|
|
|
class User extends RestController |
37
|
|
|
{ |
38
|
|
|
/** |
39
|
|
|
* User service. |
40
|
|
|
* |
41
|
|
|
* @var \eZ\Publish\API\Repository\UserService |
42
|
|
|
*/ |
43
|
|
|
protected $userService; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Role service. |
47
|
|
|
* |
48
|
|
|
* @var \eZ\Publish\API\Repository\RoleService |
49
|
|
|
*/ |
50
|
|
|
protected $roleService; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Content service. |
54
|
|
|
* |
55
|
|
|
* @var \eZ\Publish\API\Repository\ContentService |
56
|
|
|
*/ |
57
|
|
|
protected $contentService; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Content service. |
61
|
|
|
* |
62
|
|
|
* @var \eZ\Publish\API\Repository\ContentTypeService |
63
|
|
|
*/ |
64
|
|
|
protected $contentTypeService; |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Location service. |
68
|
|
|
* |
69
|
|
|
* @var \eZ\Publish\API\Repository\LocationService |
70
|
|
|
*/ |
71
|
|
|
protected $locationService; |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Section service. |
75
|
|
|
* |
76
|
|
|
* @var \eZ\Publish\API\Repository\SectionService |
77
|
|
|
*/ |
78
|
|
|
protected $sectionService; |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Repository. |
82
|
|
|
* |
83
|
|
|
* @var \eZ\Publish\API\Repository\Repository |
84
|
|
|
*/ |
85
|
|
|
protected $repository; |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @var \Symfony\Component\Security\Csrf\TokenStorage\TokenStorageInterface |
89
|
|
|
* @deprecated This property is deprecated since 6.5, and will be removed in 7.0. |
90
|
|
|
*/ |
91
|
|
|
private $csrfTokenStorage; |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @var \eZ\Publish\Core\REST\Server\Controller\SessionController |
95
|
|
|
* @deprecated This property is added for backward compatibility. It is deprecated, and will be removed in 7.0. |
96
|
|
|
*/ |
97
|
|
|
private $sessionController; |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Construct controller. |
101
|
|
|
* |
102
|
|
|
* @param \eZ\Publish\API\Repository\UserService $userService |
103
|
|
|
* @param \eZ\Publish\API\Repository\RoleService $roleService |
104
|
|
|
* @param \eZ\Publish\API\Repository\ContentService $contentService |
105
|
|
|
* @param \eZ\Publish\API\Repository\LocationService $locationService |
106
|
|
|
* @param \eZ\Publish\API\Repository\SectionService $sectionService |
107
|
|
|
* @param \eZ\Publish\API\Repository\Repository $repository |
108
|
|
|
*/ |
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
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Redirects to the root user group. |
129
|
|
|
* |
130
|
|
|
* @return \eZ\Publish\Core\REST\Server\Values\PermanentRedirect |
131
|
|
|
*/ |
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
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Loads a user group for the given path. |
142
|
|
|
* |
143
|
|
|
* @param $groupPath |
144
|
|
|
* |
145
|
|
|
* @return \eZ\Publish\Core\REST\Server\Values\RestUserGroup |
146
|
|
|
*/ |
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
|
|
|
|
178
|
|
|
/** |
179
|
|
|
* Loads a user for the given ID. |
180
|
|
|
* |
181
|
|
|
* @param $userId |
182
|
|
|
* |
183
|
|
|
* @return \eZ\Publish\Core\REST\Server\Values\RestUser |
184
|
|
|
*/ |
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
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* Create a new user group under the given parent |
224
|
|
|
* To create a top level group use /user/groups/1/5/subgroups. |
225
|
|
|
* |
226
|
|
|
* @param $groupPath |
227
|
|
|
* |
228
|
|
|
* @throws \eZ\Publish\Core\REST\Server\Exceptions\BadRequestException |
229
|
|
|
* |
230
|
|
|
* @return \eZ\Publish\Core\REST\Server\Values\CreatedUserGroup |
231
|
|
|
*/ |
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
|
|
|
|
267
|
|
|
/** |
268
|
|
|
* Create a new user group in the given group. |
269
|
|
|
* |
270
|
|
|
* @param $groupPath |
271
|
|
|
* |
272
|
|
|
* @throws \eZ\Publish\Core\REST\Server\Exceptions\ForbiddenException |
273
|
|
|
* |
274
|
|
|
* @return \eZ\Publish\Core\REST\Server\Values\CreatedUser |
275
|
|
|
*/ |
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
|
|
|
|
313
|
|
|
/** |
314
|
|
|
* Updates a user group. |
315
|
|
|
* |
316
|
|
|
* @param $groupPath |
317
|
|
|
* |
318
|
|
|
* @return \eZ\Publish\Core\REST\Server\Values\RestUserGroup |
319
|
|
|
*/ |
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
|
|
View Code Duplication |
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
|
|
|
|
363
|
|
|
/** |
364
|
|
|
* Updates a user. |
365
|
|
|
* |
366
|
|
|
* @param $userId |
367
|
|
|
* |
368
|
|
|
* @return \eZ\Publish\Core\REST\Server\Values\RestUser |
369
|
|
|
*/ |
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
|
|
View Code Duplication |
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
|
|
|
|
407
|
|
|
/** |
408
|
|
|
* Given user group is deleted. |
409
|
|
|
* |
410
|
|
|
* @param $groupPath |
411
|
|
|
* |
412
|
|
|
* @throws \eZ\Publish\Core\REST\Server\Exceptions\ForbiddenException |
413
|
|
|
* |
414
|
|
|
* @return \eZ\Publish\Core\REST\Server\Values\NoContent |
415
|
|
|
*/ |
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
|
|
|
|
437
|
|
|
/** |
438
|
|
|
* Given user is deleted. |
439
|
|
|
* |
440
|
|
|
* @param $userId |
441
|
|
|
* |
442
|
|
|
* @throws \eZ\Publish\Core\REST\Server\Exceptions\ForbiddenException |
443
|
|
|
* |
444
|
|
|
* @return \eZ\Publish\Core\REST\Server\Values\NoContent |
445
|
|
|
*/ |
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
|
|
|
|
459
|
|
|
/** |
460
|
|
|
* Loads users. |
461
|
|
|
* |
462
|
|
|
* @return \eZ\Publish\Core\REST\Server\Values\UserList|\eZ\Publish\Core\REST\Server\Values\UserRefList |
463
|
|
|
*/ |
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
|
|
|
|
516
|
|
|
/** |
517
|
|
|
* Loads a list of users assigned to role. |
518
|
|
|
* |
519
|
|
|
* @param mixed $roleId |
520
|
|
|
* |
521
|
|
|
* @return \eZ\Publish\Core\REST\Server\Values\RestUser[] |
522
|
|
|
*/ |
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
|
|
|
|
539
|
|
|
/** |
540
|
|
|
* @return Values\RestUser |
541
|
|
|
*/ |
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
|
|
|
|
553
|
|
|
/** |
554
|
|
|
* Loads user groups. |
555
|
|
|
* |
556
|
|
|
* @return \eZ\Publish\Core\REST\Server\Values\UserGroupList|\eZ\Publish\Core\REST\Server\Values\UserGroupRefList |
557
|
|
|
*/ |
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
|
|
|
|
591
|
|
|
/** |
592
|
|
|
* Loads a user group by its remote ID. |
593
|
|
|
* |
594
|
|
|
* @return \eZ\Publish\Core\REST\Server\Values\RestUserGroup |
595
|
|
|
*/ |
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
|
|
|
|
612
|
|
|
/** |
613
|
|
|
* Loads a list of user groups assigned to role. |
614
|
|
|
* |
615
|
|
|
* @param mixed $roleId |
616
|
|
|
* |
617
|
|
|
* @return \eZ\Publish\Core\REST\Server\Values\RestUserGroup[] |
618
|
|
|
*/ |
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
|
|
|
|
646
|
|
|
/** |
647
|
|
|
* Loads drafts assigned to user. |
648
|
|
|
* |
649
|
|
|
* @param $userId |
650
|
|
|
* |
651
|
|
|
* @return \eZ\Publish\Core\REST\Server\Values\VersionList |
652
|
|
|
*/ |
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
|
|
|
|
662
|
|
|
/** |
663
|
|
|
* Moves the user group to another parent. |
664
|
|
|
* |
665
|
|
|
* @param $groupPath |
666
|
|
|
* |
667
|
|
|
* @throws \eZ\Publish\Core\REST\Server\Exceptions\ForbiddenException |
668
|
|
|
* |
669
|
|
|
* @return \eZ\Publish\Core\REST\Server\Values\ResourceCreated |
670
|
|
|
*/ |
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
|
|
|
|
712
|
|
|
/** |
713
|
|
|
* Returns a list of the sub groups. |
714
|
|
|
* |
715
|
|
|
* @param $groupPath |
716
|
|
|
* |
717
|
|
|
* @return \eZ\Publish\Core\REST\Server\Values\UserGroupList|\eZ\Publish\Core\REST\Server\Values\UserGroupRefList |
718
|
|
|
*/ |
719
|
|
View Code Duplication |
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
|
|
|
|
767
|
|
|
/** |
768
|
|
|
* Returns a list of user groups the user belongs to. |
769
|
|
|
* The returned list includes the resources for unassigning |
770
|
|
|
* a user group if the user is in multiple groups. |
771
|
|
|
* |
772
|
|
|
* @param $userId |
773
|
|
|
* |
774
|
|
|
* @return \eZ\Publish\Core\REST\Server\Values\UserGroupRefList |
775
|
|
|
*/ |
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
|
|
|
|
810
|
|
|
/** |
811
|
|
|
* Loads the users of the group with the given path. |
812
|
|
|
* |
813
|
|
|
* @param $groupPath |
814
|
|
|
* |
815
|
|
|
* @return \eZ\Publish\Core\REST\Server\Values\UserList|\eZ\Publish\Core\REST\Server\Values\UserRefList |
816
|
|
|
*/ |
817
|
|
View Code Duplication |
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
|
|
|
|
865
|
|
|
/** |
866
|
|
|
* Unassigns the user from a user group. |
867
|
|
|
* |
868
|
|
|
* @param $userId |
869
|
|
|
* @param $groupPath |
870
|
|
|
* |
871
|
|
|
* @throws \eZ\Publish\Core\REST\Server\Exceptions\ForbiddenException |
872
|
|
|
* |
873
|
|
|
* @return \eZ\Publish\Core\REST\Server\Values\UserGroupRefList |
874
|
|
|
*/ |
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
|
|
|
|
917
|
|
|
/** |
918
|
|
|
* Assigns the user to a user group. |
919
|
|
|
* |
920
|
|
|
* @param $userId |
921
|
|
|
* |
922
|
|
|
* @throws \eZ\Publish\Core\REST\Server\Exceptions\ForbiddenException |
923
|
|
|
* |
924
|
|
|
* @return \eZ\Publish\Core\REST\Server\Values\UserGroupRefList |
925
|
|
|
*/ |
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
|
|
|
|
978
|
|
|
/** |
979
|
|
|
* Creates a new session based on the credentials provided as POST parameters. |
980
|
|
|
* |
981
|
|
|
* @throws \eZ\Publish\Core\Base\Exceptions\UnauthorizedException If the login or password are incorrect or invalid CSRF |
982
|
|
|
* |
983
|
|
|
* @return Values\UserSession|Values\Conflict |
984
|
|
|
* |
985
|
|
|
* @deprecated Deprecated since 6.5. Use SessionController::refreshSessionAction(). |
986
|
|
|
*/ |
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
|
|
|
|
997
|
|
|
/** |
998
|
|
|
* Refresh given session. |
999
|
|
|
* |
1000
|
|
|
* @param string $sessionId |
1001
|
|
|
* |
1002
|
|
|
* @throws \eZ\Publish\Core\Base\Exceptions\UnauthorizedException If the CSRF token is missing or invalid. |
1003
|
|
|
* |
1004
|
|
|
* @return \eZ\Publish\Core\REST\Server\Values\UserSession |
1005
|
|
|
* |
1006
|
|
|
* @deprecated Deprecated since 6.5. Use SessionController::refreshSessionAction(). |
1007
|
|
|
*/ |
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
|
|
|
|
1018
|
|
|
/** |
1019
|
|
|
* Deletes given session. |
1020
|
|
|
* |
1021
|
|
|
* @param string $sessionId |
1022
|
|
|
* |
1023
|
|
|
* @return Values\DeletedUserSession|\Symfony\Component\HttpFoundation\Response |
1024
|
|
|
* |
1025
|
|
|
* @throws \eZ\Publish\Core\Base\Exceptions\UnauthorizedException If the CSRF token is missing or invalid. |
1026
|
|
|
* @throws RestNotFoundException |
1027
|
|
|
* |
1028
|
|
|
* @deprecated Deprecated since 6.5. Use SessionController::refreshSessionAction(). |
1029
|
|
|
*/ |
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
|
|
|
|
1040
|
|
|
/** |
1041
|
|
|
* Extracts and returns an item id from a path, e.g. /1/2/58 => 58. |
1042
|
|
|
* |
1043
|
|
|
* @param string $path |
1044
|
|
|
* |
1045
|
|
|
* @return mixed |
1046
|
|
|
*/ |
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
|
|
|
} |
1069
|
|
|
|
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.