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