Completed
Push — EZP-26342-validation-improvmen... ( 9c5a9c...57b308 )
by André
56:51 queued 36:58
created

User::createSession()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 1
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
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
 * @version //autogentag//
10
 */
11
namespace eZ\Publish\Core\REST\Server\Controller;
12
13
use eZ\Publish\Core\REST\Common\Message;
14
use eZ\Publish\Core\REST\Server\Values;
15
use eZ\Publish\Core\REST\Server\Exceptions;
16
use eZ\Publish\Core\REST\Server\Controller as RestController;
17
use eZ\Publish\API\Repository\UserService;
18
use eZ\Publish\API\Repository\ContentService;
19
use eZ\Publish\API\Repository\ContentTypeService;
20
use eZ\Publish\API\Repository\RoleService;
21
use eZ\Publish\API\Repository\LocationService;
22
use eZ\Publish\API\Repository\SectionService;
23
use eZ\Publish\API\Repository\Repository;
24
use eZ\Publish\API\Repository\Values\User\UserRoleAssignment;
25
use eZ\Publish\API\Repository\Values\User\UserGroupRoleAssignment;
26
use eZ\Publish\API\Repository\Values\User\User as RepositoryUser;
27
use eZ\Publish\API\Repository\Exceptions as ApiExceptions;
28
use eZ\Publish\Core\REST\Server\Exceptions\ForbiddenException;
29
use eZ\Publish\Core\REST\Common\Exceptions\NotFoundException;
30
use eZ\Publish\Core\Base\Exceptions\UnauthorizedException;
31
use Symfony\Component\HttpFoundation\Request;
32
use Symfony\Component\Security\Csrf\TokenStorage\TokenStorageInterface;
33
34
/**
35
 * User controller.
36
 */
37
class User extends RestController
38
{
39
    /**
40
     * User service.
41
     *
42
     * @var \eZ\Publish\API\Repository\UserService
43
     */
44
    protected $userService;
45
46
    /**
47
     * Role service.
48
     *
49
     * @var \eZ\Publish\API\Repository\RoleService
50
     */
51
    protected $roleService;
52
53
    /**
54
     * Content service.
55
     *
56
     * @var \eZ\Publish\API\Repository\ContentService
57
     */
58
    protected $contentService;
59
60
    /**
61
     * Content service.
62
     *
63
     * @var \eZ\Publish\API\Repository\ContentTypeService
64
     */
65
    protected $contentTypeService;
66
67
    /**
68
     * Location service.
69
     *
70
     * @var \eZ\Publish\API\Repository\LocationService
71
     */
72
    protected $locationService;
73
74
    /**
75
     * Section service.
76
     *
77
     * @var \eZ\Publish\API\Repository\SectionService
78
     */
79
    protected $sectionService;
80
81
    /**
82
     * Repository.
83
     *
84
     * @var \eZ\Publish\API\Repository\Repository
85
     */
86
    protected $repository;
87
88
    /**
89
     * @var \Symfony\Component\Security\Csrf\TokenStorage\TokenStorageInterface
90
     * @deprecated This property is deprecated since 6.5, and will be removed in 7.0.
91
     */
92
    private $csrfTokenStorage;
93
94
    /**
95
     * @var \eZ\Publish\Core\REST\Server\Controller\SessionController
96
     * @deprecated This property is added for backward compatibility. It is deprecated, and will be removed in 7.0.
97
     */
98
    private $sessionController;
99
100
    /**
101
     * Construct controller.
102
     *
103
     * @param \eZ\Publish\API\Repository\UserService $userService
104
     * @param \eZ\Publish\API\Repository\RoleService $roleService
105
     * @param \eZ\Publish\API\Repository\ContentService $contentService
106
     * @param \eZ\Publish\API\Repository\LocationService $locationService
107
     * @param \eZ\Publish\API\Repository\SectionService $sectionService
108
     * @param \eZ\Publish\API\Repository\Repository $repository
109
     */
110
    public function __construct(
111
        UserService $userService,
112
        RoleService $roleService,
113
        ContentService $contentService,
114
        ContentTypeService $contentTypeService,
115
        LocationService $locationService,
116
        SectionService $sectionService,
117
        Repository $repository
118
    ) {
119
        $this->userService = $userService;
120
        $this->roleService = $roleService;
121
        $this->contentService = $contentService;
122
        $this->contentTypeService = $contentTypeService;
123
        $this->locationService = $locationService;
124
        $this->sectionService = $sectionService;
125
        $this->repository = $repository;
126
    }
127
128
    /**
129
     * Redirects to the root user group.
130
     *
131
     * @return \eZ\Publish\Core\REST\Server\Values\PermanentRedirect
132
     */
133
    public function loadRootUserGroup()
134
    {
135
        //@todo Replace hardcoded value with one loaded from settings
136
        return new Values\PermanentRedirect(
137
            $this->router->generate('ezpublish_rest_loadUserGroup', array('groupPath' => '/1/5'))
138
        );
139
    }
140
141
    /**
142
     * Loads a user group for the given path.
143
     *
144
     * @param $groupPath
145
     *
146
     * @return \eZ\Publish\Core\REST\Server\Values\RestUserGroup
147
     */
148
    public function loadUserGroup($groupPath)
149
    {
150
        $userGroupLocation = $this->locationService->loadLocation(
151
            $this->extractLocationIdFromPath($groupPath)
152
        );
153
154
        if (trim($userGroupLocation->pathString, '/') != $groupPath) {
155
            throw new NotFoundException(
156
                "Could not find location with path string $groupPath"
157
            );
158
        }
159
160
        $userGroup = $this->userService->loadUserGroup(
161
            $userGroupLocation->contentId
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
            array('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);
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) {
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\API\Repositor...itory::getCurrentUser() has been deprecated with message: since 6.6, to be removed. Use PermissionResolver::getCurrentUserReference() instead. Get current user. Loads the full user object if not already loaded, if you only need to know user id use {@see getCurrentUserReference()}

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.

Loading history...
198
                $userMainLocation = $this->repository->sudo(
0 ignored issues
show
Bug introduced by
It seems like you code against a concrete implementation and not the interface eZ\Publish\API\Repository\Repository as the method sudo() does only exist in the following implementations of said interface: eZ\Publish\Core\Repository\Repository, eZ\Publish\Core\SignalSlot\Repository.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
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 = array();
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
            array('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(
0 ignored issues
show
Compatibility introduced by
$this->inputDispatcher->...request->getContent())) of type object<eZ\Publish\API\Re...ory\Values\ValueObject> is not a sub-type of object<eZ\Publish\API\Re...\UserGroupCreateStruct>. It seems like you assume a child class of the class eZ\Publish\API\Repository\Values\ValueObject to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
240
                new Message(
241
                    array('Content-Type' => $request->headers->get('Content-Type')),
242
                    $request->getContent()
0 ignored issues
show
Bug introduced by
It seems like $request->getContent() targeting Symfony\Component\HttpFo...n\Request::getContent() can also be of type resource; however, eZ\Publish\Core\REST\Common\Message::__construct() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
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
            array(
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
                array('Content-Type' => $request->headers->get('Content-Type')),
286
                $request->getContent()
0 ignored issues
show
Bug introduced by
It seems like $request->getContent() targeting Symfony\Component\HttpFo...n\Request::getContent() can also be of type resource; however, eZ\Publish\Core\REST\Common\Message::__construct() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
287
            )
288
        );
289
290
        try {
291
            $createdUser = $this->userService->createUser($userCreateStruct, array($userGroup));
0 ignored issues
show
Compatibility introduced by
$userCreateStruct of type object<eZ\Publish\API\Re...ory\Values\ValueObject> is not a sub-type of object<eZ\Publish\API\Re...\User\UserCreateStruct>. It seems like you assume a child class of the class eZ\Publish\API\Repository\Values\ValueObject to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
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
            array(
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
                array(
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()
0 ignored issues
show
Bug introduced by
It seems like $request->getContent() targeting Symfony\Component\HttpFo...n\Request::getContent() can also be of type resource; however, eZ\Publish\Core\REST\Common\Message::__construct() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
338
            )
339
        );
340
341 View Code Duplication
        if ($updateStruct->sectionId !== null) {
0 ignored issues
show
Documentation introduced by
The property sectionId does not exist on object<eZ\Publish\API\Re...ory\Values\ValueObject>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
342
            $section = $this->sectionService->loadSection($updateStruct->sectionId);
0 ignored issues
show
Documentation introduced by
The property sectionId does not exist on object<eZ\Publish\API\Re...ory\Values\ValueObject>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
343
            $this->sectionService->assignSection(
344
                $userGroup->getVersionInfo()->getContentInfo(),
345
                $section
346
            );
347
        }
348
349
        $updatedGroup = $this->userService->updateUserGroup($userGroup, $updateStruct->userGroupUpdateStruct);
0 ignored issues
show
Documentation introduced by
The property userGroupUpdateStruct does not exist on object<eZ\Publish\API\Re...ory\Values\ValueObject>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
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
                array(
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()
0 ignored issues
show
Bug introduced by
It seems like $request->getContent() targeting Symfony\Component\HttpFo...n\Request::getContent() can also be of type resource; however, eZ\Publish\Core\REST\Common\Message::__construct() does only seem to accept string, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
382
            )
383
        );
384
385 View Code Duplication
        if ($updateStruct->sectionId !== null) {
0 ignored issues
show
Documentation introduced by
The property sectionId does not exist on object<eZ\Publish\API\Re...ory\Values\ValueObject>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
386
            $section = $this->sectionService->loadSection($updateStruct->sectionId);
0 ignored issues
show
Documentation introduced by
The property sectionId does not exist on object<eZ\Publish\API\Re...ory\Values\ValueObject>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
387
            $this->sectionService->assignSection(
388
                $user->getVersionInfo()->getContentInfo(),
389
                $section
390
            );
391
        }
392
393
        $updatedUser = $this->userService->updateUser($user, $updateStruct->userUpdateStruct);
0 ignored issues
show
Documentation introduced by
The property userUpdateStruct does not exist on object<eZ\Publish\API\Re...ory\Values\ValueObject>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
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) {
0 ignored issues
show
Deprecated Code introduced by
The method eZ\Publish\API\Repositor...itory::getCurrentUser() has been deprecated with message: since 6.6, to be removed. Use PermissionResolver::getCurrentUserReference() instead. Get current user. Loads the full user object if not already loaded, if you only need to know user id use {@see getCurrentUserReference()}

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.

Loading history...
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 = array();
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 = array(
475
                    $this->buildRestUserObject(
476
                        $this->userService->loadUser(
477
                            $this->contentService->loadContentInfoByRemoteId($request->query->get('remoteId'))->id
478
                        )
479
                    ),
480
                );
481
            } elseif ($request->query->has('login')) {
482
                $restUsers = array(
483
                    $this->buildRestUserObject(
484
                        $this->userService->loadUserByLogin($request->query->get('login'))
485
                    ),
486
                );
487
            } elseif ($request->query->has('email')) {
488
                foreach ($this->userService->loadUsersByEmail($request->query->get('email')) as $user) {
489
                    $restUsers[] = $this->buildRestUserObject($user);
490
                }
491
            }
492
        } catch (ApiExceptions\UnauthorizedException $e) {
493
            $restUsers = [];
494
        }
495
496
        if (empty($restUsers)) {
497
            throw new NotFoundException('No users were found with the given filter');
498
        }
499
500
        if ($this->getMediaType($request) === 'application/vnd.ez.api.userlist') {
501
            return new Values\UserList($restUsers, $request->getPathInfo());
502
        }
503
504
        return new Values\UserRefList($restUsers, $request->getPathInfo());
505
    }
506
507
    public function verifyUsers(Request $request)
508
    {
509
        // We let the NotFoundException loadUsers throws if there are no results pass.
510
        $this->loadUsers($request)->users;
511
512
        return new Values\OK();
513
    }
514
515
    /**
516
     * Loads a list of users assigned to role.
517
     *
518
     * @param mixed $roleId
519
     *
520
     * @return \eZ\Publish\Core\REST\Server\Values\RestUser[]
521
     */
522
    public function loadUsersAssignedToRole($roleId)
523
    {
524
        $role = $this->roleService->loadRole($roleId);
525
        $roleAssignments = $this->roleService->getRoleAssignments($role);
526
527
        $restUsers = array();
528
529
        foreach ($roleAssignments as $roleAssignment) {
530
            if ($roleAssignment instanceof UserRoleAssignment) {
531
                $restUsers[] = $this->buildRestUserObject($roleAssignment->getUser());
532
            }
533
        }
534
535
        return $restUsers;
536
    }
537
538
    /**
539
     * @return Values\RestUser
540
     */
541
    private function buildRestUserObject(RepositoryUser $user)
542
    {
543
        return new Values\RestUser(
544
            $user,
545
            $this->contentTypeService->loadContentType($user->contentInfo->contentTypeId),
546
            $user->contentInfo,
547
            $this->locationService->loadLocation($user->contentInfo->mainLocationId),
548
            $this->contentService->loadRelations($user->getVersionInfo())
549
        );
550
    }
551
552
    /**
553
     * Loads user groups.
554
     *
555
     * @return \eZ\Publish\Core\REST\Server\Values\UserGroupList|\eZ\Publish\Core\REST\Server\Values\UserGroupRefList
556
     */
557
    public function loadUserGroups(Request $request)
558
    {
559
        $restUserGroups = array();
560
        if ($request->query->has('id')) {
561
            $userGroup = $this->userService->loadUserGroup($request->query->get('id'));
562
            $userGroupContentInfo = $userGroup->getVersionInfo()->getContentInfo();
563
            $userGroupMainLocation = $this->locationService->loadLocation($userGroupContentInfo->mainLocationId);
564
            $contentType = $this->contentTypeService->loadContentType($userGroupContentInfo->contentTypeId);
565
566
            $restUserGroups = array(
567
                new Values\RestUserGroup(
568
                    $userGroup,
569
                    $contentType,
570
                    $userGroupContentInfo,
571
                    $userGroupMainLocation,
572
                    $this->contentService->loadRelations($userGroup->getVersionInfo())
573
                ),
574
            );
575
        } elseif ($request->query->has('roleId')) {
576
            $restUserGroups = $this->loadUserGroupsAssignedToRole($request->query->get('roleId'));
577
        } elseif ($request->query->has('remoteId')) {
578
            $restUserGroups = array(
579
                $this->loadUserGroupByRemoteId($request),
580
            );
581
        }
582
583
        if ($this->getMediaType($request) === 'application/vnd.ez.api.usergrouplist') {
584
            return new Values\UserGroupList($restUserGroups, $request->getPathInfo());
585
        }
586
587
        return new Values\UserGroupRefList($restUserGroups, $request->getPathInfo());
588
    }
589
590
    /**
591
     * Loads a user group by its remote ID.
592
     *
593
     * @return \eZ\Publish\Core\REST\Server\Values\RestUserGroup
594
     */
595
    public function loadUserGroupByRemoteId(Request $request)
596
    {
597
        $contentInfo = $this->contentService->loadContentInfoByRemoteId($request->query->get('remoteId'));
598
        $userGroup = $this->userService->loadUserGroup($contentInfo->id);
599
        $userGroupLocation = $this->locationService->loadLocation($contentInfo->mainLocationId);
600
        $contentType = $this->contentTypeService->loadContentType($contentInfo->contentTypeId);
601
602
        return new Values\RestUserGroup(
603
            $userGroup,
604
            $contentType,
605
            $contentInfo,
606
            $userGroupLocation,
607
            $this->contentService->loadRelations($userGroup->getVersionInfo())
608
        );
609
    }
610
611
    /**
612
     * Loads a list of user groups assigned to role.
613
     *
614
     * @param mixed $roleId
615
     *
616
     * @return \eZ\Publish\Core\REST\Server\Values\RestUserGroup[]
617
     */
618
    public function loadUserGroupsAssignedToRole($roleId)
619
    {
620
        $role = $this->roleService->loadRole($roleId);
621
        $roleAssignments = $this->roleService->getRoleAssignments($role);
622
623
        $restUserGroups = array();
624
625
        foreach ($roleAssignments as $roleAssignment) {
626
            if ($roleAssignment instanceof UserGroupRoleAssignment) {
627
                $userGroup = $roleAssignment->getUserGroup();
628
                $userGroupContentInfo = $userGroup->getVersionInfo()->getContentInfo();
629
                $userGroupLocation = $this->locationService->loadLocation($userGroupContentInfo->mainLocationId);
630
                $contentType = $this->contentTypeService->loadContentType($userGroupContentInfo->contentTypeId);
631
632
                $restUserGroups[] = new Values\RestUserGroup(
633
                    $userGroup,
634
                    $contentType,
635
                    $userGroupContentInfo,
636
                    $userGroupLocation,
637
                    $this->contentService->loadRelations($userGroup->getVersionInfo())
638
                );
639
            }
640
        }
641
642
        return $restUserGroups;
643
    }
644
645
    /**
646
     * Loads drafts assigned to user.
647
     *
648
     * @param $userId
649
     *
650
     * @return \eZ\Publish\Core\REST\Server\Values\VersionList
651
     */
652
    public function loadUserDrafts($userId, Request $request)
653
    {
654
        $contentDrafts = $this->contentService->loadContentDrafts(
655
            $this->userService->loadUser($userId)
656
        );
657
658
        return new Values\VersionList($contentDrafts, $request->getPathInfo());
659
    }
660
661
    /**
662
     * Moves the user group to another parent.
663
     *
664
     * @param $groupPath
665
     *
666
     * @throws \eZ\Publish\Core\REST\Server\Exceptions\ForbiddenException
667
     *
668
     * @return \eZ\Publish\Core\REST\Server\Values\ResourceCreated
669
     */
670
    public function moveUserGroup($groupPath, Request $request)
671
    {
672
        $userGroupLocation = $this->locationService->loadLocation(
673
            $this->extractLocationIdFromPath($groupPath)
674
        );
675
676
        $userGroup = $this->userService->loadUserGroup(
677
            $userGroupLocation->contentId
678
        );
679
680
        $locationPath = $this->requestParser->parseHref(
681
            $request->headers->get('Destination'),
682
            'groupPath'
683
        );
684
685
        try {
686
            $destinationGroupLocation = $this->locationService->loadLocation(
687
                $this->extractLocationIdFromPath($locationPath)
688
            );
689
        } catch (ApiExceptions\NotFoundException $e) {
690
            throw new Exceptions\ForbiddenException($e->getMessage());
691
        }
692
693
        try {
694
            $destinationGroup = $this->userService->loadUserGroup($destinationGroupLocation->contentId);
695
        } catch (ApiExceptions\NotFoundException $e) {
696
            throw new Exceptions\ForbiddenException($e->getMessage());
697
        }
698
699
        $this->userService->moveUserGroup($userGroup, $destinationGroup);
700
701
        return new Values\ResourceCreated(
702
            $this->router->generate(
703
                'ezpublish_rest_loadUserGroup',
704
                array(
705
                    'groupPath' => trim($destinationGroupLocation->pathString, '/') . '/' . $userGroupLocation->id,
706
                )
707
            )
708
        );
709
    }
710
711
    /**
712
     * Returns a list of the sub groups.
713
     *
714
     * @param $groupPath
715
     *
716
     * @return \eZ\Publish\Core\REST\Server\Values\UserGroupList|\eZ\Publish\Core\REST\Server\Values\UserGroupRefList
717
     */
718 View Code Duplication
    public function loadSubUserGroups($groupPath, Request $request)
719
    {
720
        $offset = $request->query->has('offset') ? (int)$request->query->get('offset') : 0;
721
        $limit = $request->query->has('limit') ? (int)$request->query->get('limit') : 25;
722
723
        $userGroupLocation = $this->locationService->loadLocation(
724
            $this->extractLocationIdFromPath($groupPath)
725
        );
726
727
        $userGroup = $this->userService->loadUserGroup(
728
            $userGroupLocation->contentId
729
        );
730
731
        $subGroups = $this->userService->loadSubUserGroups(
732
            $userGroup,
733
            $offset >= 0 ? $offset : 0,
734
            $limit >= 0 ? $limit : 25
735
        );
736
737
        $restUserGroups = array();
738
        foreach ($subGroups as $subGroup) {
739
            $subGroupContentInfo = $subGroup->getVersionInfo()->getContentInfo();
740
            $subGroupLocation = $this->locationService->loadLocation($subGroupContentInfo->mainLocationId);
741
            $contentType = $this->contentTypeService->loadContentType($subGroupContentInfo->contentTypeId);
742
743
            $restUserGroups[] = new Values\RestUserGroup(
744
                $subGroup,
745
                $contentType,
746
                $subGroupContentInfo,
747
                $subGroupLocation,
748
                $this->contentService->loadRelations($subGroup->getVersionInfo())
749
            );
750
        }
751
752
        if ($this->getMediaType($request) === 'application/vnd.ez.api.usergrouplist') {
753
            return new Values\CachedValue(
754
                new Values\UserGroupList($restUserGroups, $request->getPathInfo()),
755
                array('locationId' => $userGroupLocation->id)
756
            );
757
        }
758
759
        return new Values\CachedValue(
760
            new Values\UserGroupRefList($restUserGroups, $request->getPathInfo()),
761
            array('locationId' => $userGroupLocation->id)
762
        );
763
    }
764
765
    /**
766
     * Returns a list of user groups the user belongs to.
767
     * The returned list includes the resources for unassigning
768
     * a user group if the user is in multiple groups.
769
     *
770
     * @param $userId
771
     *
772
     * @return \eZ\Publish\Core\REST\Server\Values\UserGroupRefList
773
     */
774
    public function loadUserGroupsOfUser($userId, Request $request)
775
    {
776
        $offset = $request->query->has('offset') ? (int)$request->query->get('offset') : 0;
777
        $limit = $request->query->has('limit') ? (int)$request->query->get('limit') : 25;
778
779
        $user = $this->userService->loadUser($userId);
780
        $userGroups = $this->userService->loadUserGroupsOfUser(
781
            $user,
782
            $offset >= 0 ? $offset : 0,
783
            $limit >= 0 ? $limit : 25
784
        );
785
786
        $restUserGroups = array();
787
        foreach ($userGroups as $userGroup) {
788
            $userGroupContentInfo = $userGroup->getVersionInfo()->getContentInfo();
789
            $userGroupLocation = $this->locationService->loadLocation($userGroupContentInfo->mainLocationId);
790
            $contentType = $this->contentTypeService->loadContentType($userGroupContentInfo->contentTypeId);
791
792
            $restUserGroups[] = new Values\RestUserGroup(
793
                $userGroup,
794
                $contentType,
795
                $userGroupContentInfo,
796
                $userGroupLocation,
797
                $this->contentService->loadRelations($userGroup->getVersionInfo())
798
            );
799
        }
800
801
        return new Values\CachedValue(
802
            new Values\UserGroupRefList($restUserGroups, $request->getPathInfo(), $userId),
803
            array('locationId' => $user->contentInfo->mainLocationId)
804
        );
805
    }
806
807
    /**
808
     * Loads the users of the group with the given path.
809
     *
810
     * @param $groupPath
811
     *
812
     * @return \eZ\Publish\Core\REST\Server\Values\UserList|\eZ\Publish\Core\REST\Server\Values\UserRefList
813
     */
814 View Code Duplication
    public function loadUsersFromGroup($groupPath, Request $request)
815
    {
816
        $userGroupLocation = $this->locationService->loadLocation(
817
            $this->extractLocationIdFromPath($groupPath)
818
        );
819
820
        $userGroup = $this->userService->loadUserGroup(
821
            $userGroupLocation->contentId
822
        );
823
824
        $offset = $request->query->has('offset') ? (int)$request->query->get('offset') : 0;
825
        $limit = $request->query->has('limit') ? (int)$request->query->get('limit') : 25;
826
827
        $users = $this->userService->loadUsersOfUserGroup(
828
            $userGroup,
829
            $offset >= 0 ? $offset : 0,
830
            $limit >= 0 ? $limit : 25
831
        );
832
833
        $restUsers = array();
834
        foreach ($users as $user) {
835
            $userContentInfo = $user->getVersionInfo()->getContentInfo();
836
            $userLocation = $this->locationService->loadLocation($userContentInfo->mainLocationId);
837
            $contentType = $this->contentTypeService->loadContentType($userContentInfo->contentTypeId);
838
839
            $restUsers[] = new Values\RestUser(
840
                $user,
841
                $contentType,
842
                $userContentInfo,
843
                $userLocation,
844
                $this->contentService->loadRelations($user->getVersionInfo())
845
            );
846
        }
847
848
        if ($this->getMediaType($request) === 'application/vnd.ez.api.userlist') {
849
            return new Values\CachedValue(
850
                new Values\UserList($restUsers, $request->getPathInfo()),
851
                array('locationId' => $userGroupLocation->id)
852
            );
853
        }
854
855
        return new Values\CachedValue(
856
            new Values\UserRefList($restUsers, $request->getPathInfo()),
857
            array('locationId' => $userGroupLocation->id)
858
        );
859
    }
860
861
    /**
862
     * Unassigns the user from a user group.
863
     *
864
     * @param $userId
865
     * @param $groupPath
866
     *
867
     * @throws \eZ\Publish\Core\REST\Server\Exceptions\ForbiddenException
868
     *
869
     * @return \eZ\Publish\Core\REST\Server\Values\UserGroupRefList
870
     */
871
    public function unassignUserFromUserGroup($userId, $groupPath)
872
    {
873
        $user = $this->userService->loadUser($userId);
874
        $userGroupLocation = $this->locationService->loadLocation(trim($groupPath, '/'));
875
876
        $userGroup = $this->userService->loadUserGroup(
877
            $userGroupLocation->contentId
878
        );
879
880
        try {
881
            $this->userService->unAssignUserFromUserGroup($user, $userGroup);
882
        } catch (ApiExceptions\InvalidArgumentException $e) {
883
            // User is not in the group
884
            throw new Exceptions\ForbiddenException($e->getMessage());
885
        }
886
887
        $userGroups = $this->userService->loadUserGroupsOfUser($user);
888
        $restUserGroups = array();
889
        foreach ($userGroups as $userGroup) {
890
            $userGroupContentInfo = $userGroup->getVersionInfo()->getContentInfo();
891
            $userGroupLocation = $this->locationService->loadLocation($userGroupContentInfo->mainLocationId);
892
            $contentType = $this->contentTypeService->loadContentType($userGroupContentInfo->contentTypeId);
893
894
            $restUserGroups[] = new Values\RestUserGroup(
895
                $userGroup,
896
                $contentType,
897
                $userGroupContentInfo,
898
                $userGroupLocation,
899
                $this->contentService->loadRelations($userGroup->getVersionInfo())
900
            );
901
        }
902
903
        return new Values\UserGroupRefList(
904
            $restUserGroups,
905
            $this->router->generate(
906
                'ezpublish_rest_loadUserGroupsOfUser',
907
                array('userId' => $userId)
908
            ),
909
            $userId
910
        );
911
    }
912
913
    /**
914
     * Assigns the user to a user group.
915
     *
916
     * @param $userId
917
     *
918
     * @throws \eZ\Publish\Core\REST\Server\Exceptions\ForbiddenException
919
     *
920
     * @return \eZ\Publish\Core\REST\Server\Values\UserGroupRefList
921
     */
922
    public function assignUserToUserGroup($userId, Request $request)
923
    {
924
        $user = $this->userService->loadUser($userId);
925
926
        try {
927
            $userGroupLocation = $this->locationService->loadLocation(
928
                $this->extractLocationIdFromPath($request->query->get('group'))
929
            );
930
        } catch (ApiExceptions\NotFoundException $e) {
931
            throw new Exceptions\ForbiddenException($e->getMessage());
932
        }
933
934
        try {
935
            $userGroup = $this->userService->loadUserGroup(
936
                $userGroupLocation->contentId
937
            );
938
        } catch (ApiExceptions\NotFoundException $e) {
939
            throw new Exceptions\ForbiddenException($e->getMessage());
940
        }
941
942
        try {
943
            $this->userService->assignUserToUserGroup($user, $userGroup);
944
        } catch (ApiExceptions\NotFoundException $e) {
945
            throw new Exceptions\ForbiddenException($e->getMessage());
946
        }
947
948
        $userGroups = $this->userService->loadUserGroupsOfUser($user);
949
        $restUserGroups = array();
950
        foreach ($userGroups as $userGroup) {
951
            $userGroupContentInfo = $userGroup->getVersionInfo()->getContentInfo();
952
            $userGroupLocation = $this->locationService->loadLocation($userGroupContentInfo->mainLocationId);
953
            $contentType = $this->contentTypeService->loadContentType($userGroupContentInfo->contentTypeId);
954
955
            $restUserGroups[] = new Values\RestUserGroup(
956
                $userGroup,
957
                $contentType,
958
                $userGroupContentInfo,
959
                $userGroupLocation,
960
                $this->contentService->loadRelations($userGroup->getVersionInfo())
961
            );
962
        }
963
964
        return new Values\UserGroupRefList(
965
            $restUserGroups,
966
            $this->router->generate(
967
                'ezpublish_rest_loadUserGroupsOfUser',
968
                array('userId' => $userId)
969
            ),
970
            $userId
971
        );
972
    }
973
974
    /**
975
     * Creates a new session based on the credentials provided as POST parameters.
976
     *
977
     * @throws \eZ\Publish\Core\Base\Exceptions\UnauthorizedException If the login or password are incorrect or invalid CSRF
978
     *
979
     * @return Values\UserSession|Values\Conflict
980
     *
981
     * @deprecated Deprecated since 6.5. Use SessionController::refreshSessionAction().
982
     */
983
    public function createSession(Request $request)
984
    {
985
        @trigger_error(
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
986
            E_USER_DEPRECATED,
987
            'The session actions from the User controller are deprecated since 6.5. Use the SessionController instead.'
988
        );
989
990
        return $this->sessionController->createSessionAction($request);
0 ignored issues
show
Deprecated Code introduced by
The property eZ\Publish\Core\REST\Ser...ser::$sessionController has been deprecated with message: This property is added for backward compatibility. It is deprecated, and will be removed in 7.0.

This property 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 property will be removed from the class and what other property to use instead.

Loading history...
991
    }
992
993
    /**
994
     * Refresh given session.
995
     *
996
     * @param string $sessionId
997
     *
998
     * @throws \eZ\Publish\Core\Base\Exceptions\UnauthorizedException If the CSRF token is missing or invalid.
999
     *
1000
     * @return \eZ\Publish\Core\REST\Server\Values\UserSession
1001
     *
1002
     * @deprecated Deprecated since 6.5. Use SessionController::refreshSessionAction().
1003
     */
1004
    public function refreshSession($sessionId, Request $request)
1005
    {
1006
        @trigger_error(
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
1007
            E_USER_DEPRECATED,
1008
            'The session actions from the User controller are deprecated since 6.5. Use the SessionController instead.'
1009
        );
1010
1011
        return $this->sessionController->refreshSessionAction($sessionId, $request);
0 ignored issues
show
Deprecated Code introduced by
The property eZ\Publish\Core\REST\Ser...ser::$sessionController has been deprecated with message: This property is added for backward compatibility. It is deprecated, and will be removed in 7.0.

This property 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 property will be removed from the class and what other property to use instead.

Loading history...
1012
    }
1013
1014
    /**
1015
     * Deletes given session.
1016
     *
1017
     * @param string $sessionId
1018
     *
1019
     * @return Values\DeletedUserSession|\Symfony\Component\HttpFoundation\Response
1020
     *
1021
     * @throws \eZ\Publish\Core\Base\Exceptions\UnauthorizedException If the CSRF token is missing or invalid.
1022
     * @throws RestNotFoundException
1023
     *
1024
     * @deprecated Deprecated since 6.5. Use SessionController::refreshSessionAction().
1025
     */
1026
    public function deleteSession($sessionId, Request $request)
1027
    {
1028
        @trigger_error(
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
1029
            E_USER_DEPRECATED,
1030
            'The session actions from the User controller are deprecated since 6.5. Use the SessionController instead.'
1031
        );
1032
1033
        return $this->sessionController->deleteSessionAction($sessionId, $request);
0 ignored issues
show
Deprecated Code introduced by
The property eZ\Publish\Core\REST\Ser...ser::$sessionController has been deprecated with message: This property is added for backward compatibility. It is deprecated, and will be removed in 7.0.

This property 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 property will be removed from the class and what other property to use instead.

Loading history...
1034
    }
1035
1036
    /**
1037
     * Extracts and returns an item id from a path, e.g. /1/2/58 => 58.
1038
     *
1039
     * @param string $path
1040
     *
1041
     * @return mixed
1042
     */
1043
    private function extractLocationIdFromPath($path)
1044
    {
1045
        $pathParts = explode('/', $path);
1046
1047
        return array_pop($pathParts);
1048
    }
1049
1050
    public function setTokenStorage(TokenStorageInterface $csrfTokenStorage)
1051
    {
1052
        @trigger_error(
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
1053
            E_USER_DEPRECATED,
1054
            'setTokenStorage() is deprecated since 6.5 and will be removed in 7.0.'
1055
        );
1056
1057
        $this->csrfTokenStorage = $csrfTokenStorage;
0 ignored issues
show
Deprecated Code introduced by
The property eZ\Publish\Core\REST\Ser...User::$csrfTokenStorage has been deprecated with message: This property is deprecated since 6.5, and will be removed in 7.0.

This property 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 property will be removed from the class and what other property to use instead.

Loading history...
1058
    }
1059
1060
    public function setSessionController(SessionController $sessionController)
1061
    {
1062
        $this->sessionController = $sessionController;
0 ignored issues
show
Deprecated Code introduced by
The property eZ\Publish\Core\REST\Ser...ser::$sessionController has been deprecated with message: This property is added for backward compatibility. It is deprecated, and will be removed in 7.0.

This property 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 property will be removed from the class and what other property to use instead.

Loading history...
1063
    }
1064
}
1065