This site has been archived. To learn more about our current products Ibexa Content, Ibexa Experience, Ibexa Commerce head over to the Ibexa Developer Portal
Tuesday 29 May 2018 10:19:10 am - 3 replies
Bonjour,
I have a problem with auto editing user account.
In a service, I have this piece of code that changes the current user's account.
$user = $this->repository->getCurrentUser();
$userContent = $contentService->loadContentByContentInfo($user->contentInfo);
$draft = $contentService->createContentDraft($userContent->contentInfo);
$struct = $contentService->newContentUpdateStruct();
$struct->setField('my_field', $my_new_value);
$contentService->updateContent($draft->versionInfo, $struct);
$contentService->publishVersion($draft->versionInfo);
And in response I have the following error 500:
> User does not have access to 'edit' 'content' with: contentId '11290'
500 Internal Server Error - UnauthorizedException
However, my user has the right to "user/selfedit".
On the other hand I do not see how to give him the right of edition on the contents of type user but only himself.
By the way, I would like to skip the rights management at the service level..
Note. My service is called from a legacy BO
Modified on Tuesday 29 May 2018 10:20:24 am by Rémy PHP
Tuesday 29 May 2018 10:44:40 am
I tried to handle it at the legacy module level.
$popinService = $container->get('mybundle.popin_service');
$curent_user = eZUser::currentUser();
$admin_user = eZUser::fetch(14);
eZUser::setCurrentlyLoggedInUser($admin_user, $admin_user->id());
try {
$data = $popinService->accept($contentObjectID, $curent_user->id());
} catch (Exception $e) {
echo $e->getMessage();
$data = false;
}
eZUser::setCurrentlyLoggedInUser($curent_user, $curent_user->id());
But without success
Tuesday 29 May 2018 11:24:08 am
Got it !
$adminUser = $this->repository->getUserService()->loadUser(14);
$currentUser = $this->repository->getUserService()->loadUser($userContent->id);
$this->repository->setCurrentUser($adminUser);
$draft = $contentService->createContentDraft($userContent->contentInfo);
$struct = $contentService->newContentUpdateStruct();
$struct->setField('popin_accepted', $value);
$contentService->updateContent($draft->versionInfo, $struct);
/*$userContent =*/ $contentService->publishVersion($draft->versionInfo);
$this->repository->setCurrentUser($currentUser);
You must be logged in to post messages in this topic!