1 | <?php |
||
33 | class UserService implements APIUserService, Sessionable |
||
34 | { |
||
35 | /** @var \eZ\Publish\Core\REST\Client\HttpClient */ |
||
36 | private $client; |
||
37 | |||
38 | /** @var \eZ\Publish\Core\REST\Common\Input\Dispatcher */ |
||
39 | private $inputDispatcher; |
||
40 | |||
41 | /** @var \eZ\Publish\Core\REST\Common\Output\Visitor */ |
||
42 | private $outputVisitor; |
||
43 | |||
44 | /** @var \eZ\Publish\Core\REST\Common\RequestParser */ |
||
45 | private $requestParser; |
||
46 | |||
47 | /** |
||
48 | * @param \eZ\Publish\Core\REST\Client\HttpClient $client |
||
49 | * @param \eZ\Publish\Core\REST\Common\Input\Dispatcher $inputDispatcher |
||
50 | * @param \eZ\Publish\Core\REST\Common\Output\Visitor $outputVisitor |
||
51 | * @param \eZ\Publish\Core\REST\Common\RequestParser $requestParser |
||
52 | */ |
||
53 | public function __construct(HttpClient $client, Dispatcher $inputDispatcher, Visitor $outputVisitor, RequestParser $requestParser) |
||
60 | |||
61 | /** |
||
62 | * Set session ID. |
||
63 | * |
||
64 | * Only for testing |
||
65 | * |
||
66 | * @param mixed tringid |
||
67 | * |
||
68 | * @private |
||
69 | */ |
||
70 | public function setSession($id) |
||
76 | |||
77 | /** |
||
78 | * Creates a new user group using the data provided in the ContentCreateStruct parameter. |
||
79 | * |
||
80 | * In 4.x in the content type parameter in the profile is ignored |
||
81 | * - the content type is determined via configuration and can be set to null. |
||
82 | * The returned version is published. |
||
83 | * |
||
84 | * @param \eZ\Publish\API\Repository\Values\User\UserGroupCreateStruct $userGroupCreateStruct a structure for setting all necessary data to create this user group |
||
85 | * @param \eZ\Publish\API\Repository\Values\User\UserGroup $parentGroup |
||
86 | * |
||
87 | * @return \eZ\Publish\API\Repository\Values\User\UserGroup |
||
88 | * |
||
89 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to create a user group |
||
90 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the input structure has invalid data |
||
91 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $userGroupCreateStruct is not valid |
||
92 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if a required field is missing |
||
93 | */ |
||
94 | public function createUserGroup(UserGroupCreateStruct $userGroupCreateStruct, UserGroup $parentGroup) |
||
98 | |||
99 | /** |
||
100 | * {@inheritdoc} |
||
101 | */ |
||
102 | public function loadUserGroup($id, array $prioritizedLanguages = []) |
||
106 | |||
107 | /** |
||
108 | * {@inheritdoc} |
||
109 | */ |
||
110 | public function loadSubUserGroups(UserGroup $userGroup, $offset = 0, $limit = 25, array $prioritizedLanguages = []) |
||
114 | |||
115 | /** |
||
116 | * Removes a user group. |
||
117 | * |
||
118 | * the users which are not assigned to other groups will be deleted. |
||
119 | * |
||
120 | * @param \eZ\Publish\API\Repository\Values\User\UserGroup $userGroup |
||
121 | * |
||
122 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to create a user group |
||
123 | */ |
||
124 | public function deleteUserGroup(UserGroup $userGroup) |
||
128 | |||
129 | /** |
||
130 | * Moves the user group to another parent. |
||
131 | * |
||
132 | * @param \eZ\Publish\API\Repository\Values\User\UserGroup $userGroup |
||
133 | * @param \eZ\Publish\API\Repository\Values\User\UserGroup $newParent |
||
134 | * |
||
135 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to move the user group |
||
136 | */ |
||
137 | public function moveUserGroup(UserGroup $userGroup, UserGroup $newParent) |
||
141 | |||
142 | /** |
||
143 | * Updates the group profile with fields and meta data. |
||
144 | * |
||
145 | * 4.x: If the versionUpdateStruct is set in $userGroupUpdateStruct, this method internally creates a content draft, updates ts with the provided data |
||
146 | * and publishes the draft. If a draft is explicitly required, the user group can be updated via the content service methods. |
||
147 | * |
||
148 | * @param \eZ\Publish\API\Repository\Values\User\UserGroup $userGroup |
||
149 | * @param \eZ\Publish\API\Repository\Values\User\UserGroupUpdateStruct $userGroupUpdateStruct |
||
150 | * |
||
151 | * @return \eZ\Publish\API\Repository\Values\User\UserGroup |
||
152 | * |
||
153 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to move the user group |
||
154 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $userGroupUpdateStruct is not valid |
||
155 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if a required field is set empty |
||
156 | */ |
||
157 | public function updateUserGroup(UserGroup $userGroup, UserGroupUpdateStruct $userGroupUpdateStruct) |
||
161 | |||
162 | /** |
||
163 | * Create a new user. The created user is published by this method. |
||
164 | * |
||
165 | * @param \eZ\Publish\API\Repository\Values\User\UserCreateStruct $userCreateStruct the data used for creating the user |
||
166 | * @param array $parentGroups the groups of type {@link \eZ\Publish\API\Repository\Values\User\UserGroup} which are assigned to the user after creation |
||
167 | * |
||
168 | * @return \eZ\Publish\API\Repository\Values\User\User |
||
169 | * |
||
170 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to move the user group |
||
171 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if a user group was not found |
||
172 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $userCreateStruct is not valid |
||
173 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if a required field is missing |
||
174 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if a user with provided login already exists |
||
175 | */ |
||
176 | public function createUser(UserCreateStruct $userCreateStruct, array $parentGroups) |
||
180 | |||
181 | /** |
||
182 | * {@inheritdoc} |
||
183 | */ |
||
184 | public function loadUser($userId, array $prioritizedLanguages = []) |
||
188 | |||
189 | /** |
||
190 | * Loads anonymous user. |
||
191 | * |
||
192 | * @deprecated since 5.3, use loadUser( $anonymousUserId ) instead |
||
193 | * |
||
194 | * |
||
195 | * @return \eZ\Publish\API\Repository\Values\User\User |
||
196 | */ |
||
197 | public function loadAnonymousUser() |
||
201 | |||
202 | /** |
||
203 | * {@inheritdoc} |
||
204 | */ |
||
205 | public function loadUserByCredentials($login, $password, array $prioritizedLanguages = []) |
||
209 | |||
210 | /** |
||
211 | * {@inheritdoc} |
||
212 | */ |
||
213 | public function checkUserCredentials(User $user, string $credentials): bool |
||
217 | |||
218 | /** |
||
219 | * {@inheritdoc} |
||
220 | */ |
||
221 | public function loadUserByLogin($login, array $prioritizedLanguages = []) |
||
225 | |||
226 | /** |
||
227 | * {@inheritdoc} |
||
228 | */ |
||
229 | public function loadUsersByEmail($email, array $prioritizedLanguages = []) |
||
233 | |||
234 | /** |
||
235 | * Loads a user with user hash key. |
||
236 | * |
||
237 | * @param string $hash |
||
238 | * @param array $prioritizedLanguages |
||
239 | * |
||
240 | * @return \eZ\Publish\API\Repository\Values\User\User |
||
241 | */ |
||
242 | public function loadUserByToken($hash, array $prioritizedLanguages = []) |
||
246 | |||
247 | /** |
||
248 | * This method deletes a user. |
||
249 | * |
||
250 | * @param \eZ\Publish\API\Repository\Values\User\User $user |
||
251 | * |
||
252 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to delete the user |
||
253 | */ |
||
254 | public function deleteUser(User $user) |
||
258 | |||
259 | /** |
||
260 | * Updates a user. |
||
261 | * |
||
262 | * 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 |
||
263 | * and publishes the draft. If a draft is explicitly required, the user group can be updated via the content service methods. |
||
264 | * |
||
265 | * @param \eZ\Publish\API\Repository\Values\User\User $user |
||
266 | * @param \eZ\Publish\API\Repository\Values\User\UserUpdateStruct $userUpdateStruct |
||
267 | * |
||
268 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to update the user |
||
269 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $userUpdateStruct is not valid |
||
270 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if a required field is set empty |
||
271 | * |
||
272 | * @return \eZ\Publish\API\Repository\Values\User\User |
||
273 | */ |
||
274 | public function updateUser(User $user, UserUpdateStruct $userUpdateStruct) |
||
278 | |||
279 | /** |
||
280 | * Update the user token information specified by the user token struct. |
||
281 | * |
||
282 | * @param \eZ\Publish\API\Repository\Values\User\User $user |
||
283 | * @param \eZ\Publish\API\Repository\Values\User\UserTokenUpdateStruct $userTokenUpdateStruct |
||
284 | * |
||
285 | * @return \eZ\Publish\API\Repository\Values\User\User |
||
286 | */ |
||
287 | public function updateUserToken(User $user, UserTokenUpdateStruct $userTokenUpdateStruct) |
||
291 | |||
292 | /** |
||
293 | * Expires user token with user hash. |
||
294 | * |
||
295 | * @param string $hash |
||
296 | */ |
||
297 | public function expireUserToken($hash) |
||
301 | |||
302 | |||
303 | /** |
||
304 | * Assigns a new user group to the user. |
||
305 | * |
||
306 | * @param \eZ\Publish\API\Repository\Values\User\User $user |
||
307 | * @param \eZ\Publish\API\Repository\Values\User\UserGroup $userGroup |
||
308 | * |
||
309 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to assign the user group to the user |
||
310 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the user is already in the given user group |
||
311 | */ |
||
312 | public function assignUserToUserGroup(User $user, UserGroup $userGroup) |
||
316 | |||
317 | /** |
||
318 | * Removes a user group from the user. |
||
319 | * |
||
320 | * @param \eZ\Publish\API\Repository\Values\User\User $user |
||
321 | * @param \eZ\Publish\API\Repository\Values\User\UserGroup $userGroup |
||
322 | * |
||
323 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to remove the user group from the user |
||
324 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the user is not in the given user group |
||
325 | */ |
||
326 | public function unAssignUserFromUserGroup(User $user, UserGroup $userGroup) |
||
330 | |||
331 | /** |
||
332 | * {@inheritdoc} |
||
333 | */ |
||
334 | public function loadUserGroupsOfUser(User $user, $offset = 0, $limit = 25, array $prioritizedLanguages = []) |
||
338 | |||
339 | /** |
||
340 | * {@inheritdoc} |
||
341 | */ |
||
342 | public function loadUsersOfUserGroup( |
||
350 | |||
351 | /** |
||
352 | * {@inheritdoc} |
||
353 | */ |
||
354 | public function isUser(Content $content): bool |
||
364 | |||
365 | /** |
||
366 | * {@inheritdoc} |
||
367 | */ |
||
368 | public function isUserGroup(Content $content): bool |
||
373 | |||
374 | /** |
||
375 | * Instantiate a user create class. |
||
376 | * |
||
377 | * @param string $login the login of the new user |
||
378 | * @param string $email the email of the new user |
||
379 | * @param string $password the plain password of the new user |
||
380 | * @param string $mainLanguageCode the main language for the underlying content object |
||
381 | * @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 |
||
382 | * |
||
383 | * @return \eZ\Publish\API\Repository\Values\User\UserCreateStruct |
||
384 | */ |
||
385 | public function newUserCreateStruct($login, $email, $password, $mainLanguageCode, $contentType = null) |
||
389 | |||
390 | /** |
||
391 | * Instantiate a user group create class. |
||
392 | * |
||
393 | * @param string $mainLanguageCode The main language for the underlying content object |
||
394 | * @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 |
||
395 | * |
||
396 | * @return \eZ\Publish\API\Repository\Values\User\UserGroupCreateStruct |
||
397 | */ |
||
398 | public function newUserGroupCreateStruct($mainLanguageCode, $contentType = null) |
||
402 | |||
403 | /** |
||
404 | * Instantiate a new user update struct. |
||
405 | * |
||
406 | * @return \eZ\Publish\API\Repository\Values\User\UserUpdateStruct |
||
407 | */ |
||
408 | public function newUserUpdateStruct() |
||
412 | |||
413 | /** |
||
414 | * Instantiate a new user group update struct. |
||
415 | * |
||
416 | * @return \eZ\Publish\API\Repository\Values\User\UserGroupUpdateStruct |
||
417 | */ |
||
418 | public function newUserGroupUpdateStruct() |
||
422 | |||
423 | /** |
||
424 | * {@inheritdoc} |
||
425 | */ |
||
426 | public function validatePassword(string $password, PasswordValidationContext $context = null): array |
||
430 | |||
431 | public function getPasswordInfo(User $user): PasswordInfo |
||
435 | } |
||
436 |