Details
-
Bug
-
Resolution: Fixed
-
Medium
-
5.1
-
N/A
Description
Assume User A, for which the content object was created by the Administrator User. Now, for a policy with an Owner(Self) to be taken into account, it's necessary to perform a "chowning" operation - setting the user object for User A as its own Owner:
$repository->setCurrentUser( $adminUser ); $contentMetadataUpdateStruct = $contentService->newContentMetadataUpdateStruct(); $contentMetadataUpdateStruct->ownerId = $user->id; $contentService->updateContentMetadata( $user->getVersionInfo()>getContentInfo(), $contentMetadataUpdateStruct ); $repository->setCurrentUser( $user );
Now, if one wishes to have the user object (User A) edit itself, it's expected that (given that the user has the correct policies setup), it would work, but instead an error is triggered:
User does not have access to 'edit' 'content'
Clearing the cache (ezpublish/console cache:clear) and running the code once again works as expected.
Full code:
/** @var $repository \eZ\Publish\API\Repository\Repository */ $repository = $this->getContainer()->get( 'ezpublish.api.repository' ); $contentService = $repository->getContentService(); $userService = $repository->getUserService(); $locationService = $repository->getLocationService(); $contentTypeService = $repository->getContentTypeService(); $userId = $input->getArgument( "contentId" ); $adminUser = $userService->loadUser( 14); $user = $userService->loadUser( $userId ); // "chown" the user $repository->setCurrentUser( $adminUser ); $contentMetadataUpdateStruct = $contentService->newContentMetadataUpdateStruct(); $contentMetadataUpdateStruct->ownerId = $user->id; $contentService->updateContentMetadata( $user->getVersionInfo()->getContentInfo(), $contentMetadataUpdateStruct ); $repository->setCurrentUser( $user ); try { $userUpdateStruct = $userService->newUserUpdateStruct(); $userUpdateStruct->contentUpdateStruct = $contentService->newContentUpdateStruct(); $userUpdateStruct->contentUpdateStruct->setField( 'first_name', 'test' ); $userUpdateStruct->contentUpdateStruct->setField( 'last_name', 'test' ); $user = $userService->updateUser( $user, $userUpdateStruct ); } catch ( \Exception $e ) { $output->writeln( $e->getMessage() ); }
Attachments
Issue Links
- testing discovered
-
EZP-21575 Missing Legacy signal slot cache clearing on UpdateMetaData while updating user
- Closed