1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* File containing the UserService 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\Client; |
10
|
|
|
|
11
|
|
|
use eZ\Publish\API\Repository\UserService as APIUserService; |
12
|
|
|
use eZ\Publish\API\Repository\Values\Content\Content; |
13
|
|
|
use eZ\Publish\API\Repository\Values\User\PasswordValidationContext; |
14
|
|
|
use eZ\Publish\API\Repository\Values\User\User; |
15
|
|
|
use eZ\Publish\API\Repository\Values\User\UserCreateStruct; |
16
|
|
|
use eZ\Publish\API\Repository\Values\User\UserTokenUpdateStruct; |
17
|
|
|
use eZ\Publish\API\Repository\Values\User\UserUpdateStruct; |
18
|
|
|
use eZ\Publish\API\Repository\Values\User\UserGroup; |
19
|
|
|
use eZ\Publish\API\Repository\Values\User\UserGroupCreateStruct; |
20
|
|
|
use eZ\Publish\API\Repository\Values\User\UserGroupUpdateStruct; |
21
|
|
|
use eZ\Publish\Core\REST\Common\RequestParser; |
22
|
|
|
use eZ\Publish\Core\REST\Common\Input\Dispatcher; |
23
|
|
|
use eZ\Publish\Core\REST\Common\Output\Visitor; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Implementation of the {@link \eZ\Publish\API\Repository\UserService} |
27
|
|
|
* interface. |
28
|
|
|
* |
29
|
|
|
* @see \eZ\Publish\API\Repository\UserService |
30
|
|
|
*/ |
31
|
|
|
class UserService implements APIUserService, Sessionable |
32
|
|
|
{ |
33
|
|
|
/** |
34
|
|
|
* @var \eZ\Publish\Core\REST\Client\HttpClient |
35
|
|
|
*/ |
36
|
|
|
private $client; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var \eZ\Publish\Core\REST\Common\Input\Dispatcher |
40
|
|
|
*/ |
41
|
|
|
private $inputDispatcher; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var \eZ\Publish\Core\REST\Common\Output\Visitor |
45
|
|
|
*/ |
46
|
|
|
private $outputVisitor; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var \eZ\Publish\Core\REST\Common\RequestParser |
50
|
|
|
*/ |
51
|
|
|
private $requestParser; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param \eZ\Publish\Core\REST\Client\HttpClient $client |
55
|
|
|
* @param \eZ\Publish\Core\REST\Common\Input\Dispatcher $inputDispatcher |
56
|
|
|
* @param \eZ\Publish\Core\REST\Common\Output\Visitor $outputVisitor |
57
|
|
|
* @param \eZ\Publish\Core\REST\Common\RequestParser $requestParser |
58
|
|
|
*/ |
59
|
|
View Code Duplication |
public function __construct(HttpClient $client, Dispatcher $inputDispatcher, Visitor $outputVisitor, RequestParser $requestParser) |
60
|
|
|
{ |
61
|
|
|
$this->client = $client; |
62
|
|
|
$this->inputDispatcher = $inputDispatcher; |
63
|
|
|
$this->outputVisitor = $outputVisitor; |
64
|
|
|
$this->requestParser = $requestParser; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Set session ID. |
69
|
|
|
* |
70
|
|
|
* Only for testing |
71
|
|
|
* |
72
|
|
|
* @param mixed tringid |
73
|
|
|
* |
74
|
|
|
* @private |
75
|
|
|
*/ |
76
|
|
|
public function setSession($id) |
77
|
|
|
{ |
78
|
|
|
if ($this->outputVisitor instanceof Sessionable) { |
79
|
|
|
$this->outputVisitor->setSession($id); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Creates a new user group using the data provided in the ContentCreateStruct parameter. |
85
|
|
|
* |
86
|
|
|
* In 4.x in the content type parameter in the profile is ignored |
87
|
|
|
* - the content type is determined via configuration and can be set to null. |
88
|
|
|
* The returned version is published. |
89
|
|
|
* |
90
|
|
|
* @param \eZ\Publish\API\Repository\Values\User\UserGroupCreateStruct $userGroupCreateStruct a structure for setting all necessary data to create this user group |
91
|
|
|
* @param \eZ\Publish\API\Repository\Values\User\UserGroup $parentGroup |
92
|
|
|
* |
93
|
|
|
* @return \eZ\Publish\API\Repository\Values\User\UserGroup |
94
|
|
|
* |
95
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to create a user group |
96
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the input structure has invalid data |
97
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $userGroupCreateStruct is not valid |
98
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if a required field is missing |
99
|
|
|
*/ |
100
|
|
|
public function createUserGroup(UserGroupCreateStruct $userGroupCreateStruct, UserGroup $parentGroup) |
101
|
|
|
{ |
102
|
|
|
throw new \Exception('@todo: Implement.'); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* {@inheritdoc} |
107
|
|
|
*/ |
108
|
|
|
public function loadUserGroup($id, array $prioritizedLanguages = []) |
109
|
|
|
{ |
110
|
|
|
throw new \Exception('@todo: Implement.'); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* {@inheritdoc} |
115
|
|
|
*/ |
116
|
|
|
public function loadSubUserGroups(UserGroup $userGroup, $offset = 0, $limit = 25, array $prioritizedLanguages = []) |
117
|
|
|
{ |
118
|
|
|
throw new \Exception('@todo: Implement.'); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* Removes a user group. |
123
|
|
|
* |
124
|
|
|
* the users which are not assigned to other groups will be deleted. |
125
|
|
|
* |
126
|
|
|
* @param \eZ\Publish\API\Repository\Values\User\UserGroup $userGroup |
127
|
|
|
* |
128
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to create a user group |
129
|
|
|
*/ |
130
|
|
|
public function deleteUserGroup(UserGroup $userGroup) |
131
|
|
|
{ |
132
|
|
|
throw new \Exception('@todo: Implement.'); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Moves the user group to another parent. |
137
|
|
|
* |
138
|
|
|
* @param \eZ\Publish\API\Repository\Values\User\UserGroup $userGroup |
139
|
|
|
* @param \eZ\Publish\API\Repository\Values\User\UserGroup $newParent |
140
|
|
|
* |
141
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to move the user group |
142
|
|
|
*/ |
143
|
|
|
public function moveUserGroup(UserGroup $userGroup, UserGroup $newParent) |
144
|
|
|
{ |
145
|
|
|
throw new \Exception('@todo: Implement.'); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Updates the group profile with fields and meta data. |
150
|
|
|
* |
151
|
|
|
* 4.x: If the versionUpdateStruct is set in $userGroupUpdateStruct, this method internally creates a content draft, updates ts with the provided data |
152
|
|
|
* and publishes the draft. If a draft is explicitly required, the user group can be updated via the content service methods. |
153
|
|
|
* |
154
|
|
|
* @param \eZ\Publish\API\Repository\Values\User\UserGroup $userGroup |
155
|
|
|
* @param \eZ\Publish\API\Repository\Values\User\UserGroupUpdateStruct $userGroupUpdateStruct |
156
|
|
|
* |
157
|
|
|
* @return \eZ\Publish\API\Repository\Values\User\UserGroup |
158
|
|
|
* |
159
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to move the user group |
160
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $userGroupUpdateStruct is not valid |
161
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if a required field is set empty |
162
|
|
|
*/ |
163
|
|
|
public function updateUserGroup(UserGroup $userGroup, UserGroupUpdateStruct $userGroupUpdateStruct) |
164
|
|
|
{ |
165
|
|
|
throw new \Exception('@todo: Implement.'); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* Create a new user. The created user is published by this method. |
170
|
|
|
* |
171
|
|
|
* @param \eZ\Publish\API\Repository\Values\User\UserCreateStruct $userCreateStruct the data used for creating the user |
172
|
|
|
* @param array $parentGroups the groups of type {@link \eZ\Publish\API\Repository\Values\User\UserGroup} which are assigned to the user after creation |
173
|
|
|
* |
174
|
|
|
* @return \eZ\Publish\API\Repository\Values\User\User |
175
|
|
|
* |
176
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to move the user group |
177
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if a user group was not found |
178
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $userCreateStruct is not valid |
179
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if a required field is missing |
180
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if a user with provided login already exists |
181
|
|
|
*/ |
182
|
|
|
public function createUser(UserCreateStruct $userCreateStruct, array $parentGroups) |
183
|
|
|
{ |
184
|
|
|
throw new \Exception('@todo: Implement.'); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* {@inheritdoc} |
189
|
|
|
*/ |
190
|
|
|
public function loadUser($userId, array $prioritizedLanguages = []) |
191
|
|
|
{ |
192
|
|
|
throw new \Exception('@todo: Implement.'); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* Loads anonymous user. |
197
|
|
|
* |
198
|
|
|
* @deprecated since 5.3, use loadUser( $anonymousUserId ) instead |
199
|
|
|
* |
200
|
|
|
* |
201
|
|
|
* @return \eZ\Publish\API\Repository\Values\User\User |
202
|
|
|
*/ |
203
|
|
|
public function loadAnonymousUser() |
204
|
|
|
{ |
205
|
|
|
throw new \Exception('@todo: Implement.'); |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* {@inheritdoc} |
210
|
|
|
*/ |
211
|
|
|
public function loadUserByCredentials($login, $password, array $prioritizedLanguages = []) |
212
|
|
|
{ |
213
|
|
|
throw new \Exception('@todo: Implement.'); |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* {@inheritdoc} |
218
|
|
|
*/ |
219
|
|
|
public function loadUserByLogin($login, array $prioritizedLanguages = []) |
220
|
|
|
{ |
221
|
|
|
throw new \Exception('@todo: Implement.'); |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
/** |
225
|
|
|
* {@inheritdoc} |
226
|
|
|
*/ |
227
|
|
|
public function loadUsersByEmail($email, array $prioritizedLanguages = []) |
228
|
|
|
{ |
229
|
|
|
throw new \Exception('@todo: Implement.'); |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
/** |
233
|
|
|
* Loads a user with user hash key. |
234
|
|
|
* |
235
|
|
|
* @param string $hash |
236
|
|
|
* @param array $prioritizedLanguages |
237
|
|
|
* |
238
|
|
|
* @return \eZ\Publish\API\Repository\Values\User\User |
239
|
|
|
*/ |
240
|
|
|
public function loadUserByToken($hash, array $prioritizedLanguages = []) |
241
|
|
|
{ |
242
|
|
|
throw new \Exception('@todo: Implement.'); |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
/** |
246
|
|
|
* This method deletes a user. |
247
|
|
|
* |
248
|
|
|
* @param \eZ\Publish\API\Repository\Values\User\User $user |
249
|
|
|
* |
250
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to delete the user |
251
|
|
|
*/ |
252
|
|
|
public function deleteUser(User $user) |
253
|
|
|
{ |
254
|
|
|
throw new \Exception('@todo: Implement.'); |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
/** |
258
|
|
|
* Updates a user. |
259
|
|
|
* |
260
|
|
|
* 4.x: If the versionUpdateStruct is set in the user update structure, this method internally creates a content draft, updates ts with the provided data |
261
|
|
|
* and publishes the draft. If a draft is explicitly required, the user group can be updated via the content service methods. |
262
|
|
|
* |
263
|
|
|
* @param \eZ\Publish\API\Repository\Values\User\User $user |
264
|
|
|
* @param \eZ\Publish\API\Repository\Values\User\UserUpdateStruct $userUpdateStruct |
265
|
|
|
* |
266
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to update the user |
267
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $userUpdateStruct is not valid |
268
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if a required field is set empty |
269
|
|
|
* |
270
|
|
|
* @return \eZ\Publish\API\Repository\Values\User\User |
271
|
|
|
*/ |
272
|
|
|
public function updateUser(User $user, UserUpdateStruct $userUpdateStruct) |
273
|
|
|
{ |
274
|
|
|
throw new \Exception('@todo: Implement.'); |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
/** |
278
|
|
|
* Update the user token information specified by the user token struct. |
279
|
|
|
* |
280
|
|
|
* @param \eZ\Publish\API\Repository\Values\User\User $user |
281
|
|
|
* @param \eZ\Publish\API\Repository\Values\User\UserTokenUpdateStruct $userTokenUpdateStruct |
282
|
|
|
* |
283
|
|
|
* @return \eZ\Publish\API\Repository\Values\User\User |
284
|
|
|
*/ |
285
|
|
|
public function updateUserToken(User $user, UserTokenUpdateStruct $userTokenUpdateStruct) |
286
|
|
|
{ |
287
|
|
|
throw new \Exception('@todo: Implement.'); |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
/** |
291
|
|
|
* Expires user token with user hash. |
292
|
|
|
* |
293
|
|
|
* @param string $hash |
294
|
|
|
*/ |
295
|
|
|
public function expireUserToken($hash) |
296
|
|
|
{ |
297
|
|
|
throw new \Exception('@todo: Implement.'); |
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
|
301
|
|
|
/** |
302
|
|
|
* Assigns a new user group to the user. |
303
|
|
|
* |
304
|
|
|
* @param \eZ\Publish\API\Repository\Values\User\User $user |
305
|
|
|
* @param \eZ\Publish\API\Repository\Values\User\UserGroup $userGroup |
306
|
|
|
* |
307
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to assign the user group to the user |
308
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the user is already in the given user group |
309
|
|
|
*/ |
310
|
|
|
public function assignUserToUserGroup(User $user, UserGroup $userGroup) |
311
|
|
|
{ |
312
|
|
|
throw new \Exception('@todo: Implement.'); |
313
|
|
|
} |
314
|
|
|
|
315
|
|
|
/** |
316
|
|
|
* Removes a user group from the user. |
317
|
|
|
* |
318
|
|
|
* @param \eZ\Publish\API\Repository\Values\User\User $user |
319
|
|
|
* @param \eZ\Publish\API\Repository\Values\User\UserGroup $userGroup |
320
|
|
|
* |
321
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to remove the user group from the user |
322
|
|
|
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the user is not in the given user group |
323
|
|
|
*/ |
324
|
|
|
public function unAssignUserFromUserGroup(User $user, UserGroup $userGroup) |
325
|
|
|
{ |
326
|
|
|
throw new \Exception('@todo: Implement.'); |
327
|
|
|
} |
328
|
|
|
|
329
|
|
|
/** |
330
|
|
|
* {@inheritdoc} |
331
|
|
|
*/ |
332
|
|
|
public function loadUserGroupsOfUser(User $user, $offset = 0, $limit = 25, array $prioritizedLanguages = []) |
333
|
|
|
{ |
334
|
|
|
throw new \Exception('@todo: Implement.'); |
335
|
|
|
} |
336
|
|
|
|
337
|
|
|
/** |
338
|
|
|
* {@inheritdoc} |
339
|
|
|
*/ |
340
|
|
|
public function loadUsersOfUserGroup( |
341
|
|
|
UserGroup $userGroup, |
342
|
|
|
$offset = 0, |
343
|
|
|
$limit = 25, |
344
|
|
|
array $prioritizedLanguages = [] |
345
|
|
|
) { |
346
|
|
|
throw new \Exception('@todo: Implement.'); |
347
|
|
|
} |
348
|
|
|
|
349
|
|
|
/** |
350
|
|
|
* {@inheritdoc} |
351
|
|
|
*/ |
352
|
|
|
public function isUser(Content $content): bool |
353
|
|
|
{ |
354
|
|
|
foreach ($content->getFields() as $field) { |
355
|
|
|
if ($field->fieldTypeIdentifier === 'ezuser') { |
356
|
|
|
return true; |
357
|
|
|
} |
358
|
|
|
} |
359
|
|
|
|
360
|
|
|
return false; |
361
|
|
|
} |
362
|
|
|
|
363
|
|
|
/** |
364
|
|
|
* {@inheritdoc} |
365
|
|
|
*/ |
366
|
|
|
public function isUserGroup(Content $content): bool |
367
|
|
|
{ |
368
|
|
|
// TODO: Need a way to identify user groups her. Config is an option, lookup another but not an ideal solution. |
369
|
|
|
return false; |
370
|
|
|
} |
371
|
|
|
|
372
|
|
|
/** |
373
|
|
|
* Instantiate a user create class. |
374
|
|
|
* |
375
|
|
|
* @param string $login the login of the new user |
376
|
|
|
* @param string $email the email of the new user |
377
|
|
|
* @param string $password the plain password of the new user |
378
|
|
|
* @param string $mainLanguageCode the main language for the underlying content object |
379
|
|
|
* @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType 5.x the content type for the underlying content object. In 4.x it is ignored and taken from the configuration |
380
|
|
|
* |
381
|
|
|
* @return \eZ\Publish\API\Repository\Values\User\UserCreateStruct |
382
|
|
|
*/ |
383
|
|
|
public function newUserCreateStruct($login, $email, $password, $mainLanguageCode, $contentType = null) |
384
|
|
|
{ |
385
|
|
|
throw new \Exception('@todo: Implement.'); |
386
|
|
|
} |
387
|
|
|
|
388
|
|
|
/** |
389
|
|
|
* Instantiate a user group create class. |
390
|
|
|
* |
391
|
|
|
* @param string $mainLanguageCode The main language for the underlying content object |
392
|
|
|
* @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType 5.x the content type for the underlying content object. In 4.x it is ignored and taken from the configuration |
393
|
|
|
* |
394
|
|
|
* @return \eZ\Publish\API\Repository\Values\User\UserGroupCreateStruct |
395
|
|
|
*/ |
396
|
|
|
public function newUserGroupCreateStruct($mainLanguageCode, $contentType = null) |
397
|
|
|
{ |
398
|
|
|
throw new \Exception('@todo: Implement.'); |
399
|
|
|
} |
400
|
|
|
|
401
|
|
|
/** |
402
|
|
|
* Instantiate a new user update struct. |
403
|
|
|
* |
404
|
|
|
* @return \eZ\Publish\API\Repository\Values\User\UserUpdateStruct |
405
|
|
|
*/ |
406
|
|
|
public function newUserUpdateStruct() |
407
|
|
|
{ |
408
|
|
|
throw new \Exception('@todo: Implement.'); |
409
|
|
|
} |
410
|
|
|
|
411
|
|
|
/** |
412
|
|
|
* Instantiate a new user group update struct. |
413
|
|
|
* |
414
|
|
|
* @return \eZ\Publish\API\Repository\Values\User\UserGroupUpdateStruct |
415
|
|
|
*/ |
416
|
|
|
public function newUserGroupUpdateStruct() |
417
|
|
|
{ |
418
|
|
|
throw new \Exception('@todo: Implement.'); |
419
|
|
|
} |
420
|
|
|
|
421
|
|
|
/** |
422
|
|
|
* {@inheritdoc} |
423
|
|
|
*/ |
424
|
|
|
public function validatePassword(string $password, PasswordValidationContext $context = null): array |
425
|
|
|
{ |
426
|
|
|
throw new \Exception('@todo: Implement.'); |
427
|
|
|
} |
428
|
|
|
} |
429
|
|
|
|