Skip to content

Commit

Permalink
Maintain compatibility with old version
Browse files Browse the repository at this point in the history
  • Loading branch information
Steveb-p committed Oct 15, 2020
1 parent 0d367a0 commit 8d1d838
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion eZ/Publish/Core/Repository/UserService.php
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,9 @@ public function updateUser(APIUser $user, UserUpdateStruct $userUpdateStruct): A

$contentService = $this->repository->getContentService();

if (!$this->permissionResolver->canUser('content', 'edit', $loadedUser)) {
$canEditContent = $this->permissionResolver->canUser('content', 'edit', $loadedUser);

if (!$canEditContent && $this->isUserProfileUpdateRequested($userUpdateStruct)) {
throw new UnauthorizedException('content', 'edit');
}

Expand Down Expand Up @@ -681,6 +683,13 @@ public function updateUser(APIUser $user, UserUpdateStruct $userUpdateStruct): A
);
}

if (!empty($userUpdateStruct->password) &&
!$canEditContent &&
!$this->permissionResolver->canUser('user', 'password', $loadedUser)
) {
throw new UnauthorizedException('user', 'password');
}

$this->executeUserUpdate($loadedUser, $userUpdateStruct);

return $this->loadUser($loadedUser->id);
Expand Down Expand Up @@ -1351,6 +1360,23 @@ private function comparePasswordHashes(
return $this->passwordHashService->isValidPassword($plainPassword, $passwordHash, $hashAlgorithm);
}

/**
* Return true if any of the UserUpdateStruct properties refers to User Profile (Content) update.
*
* @param UserUpdateStruct $userUpdateStruct
*
* @return bool
*/
private function isUserProfileUpdateRequested(UserUpdateStruct $userUpdateStruct)
{
return
!empty($userUpdateStruct->contentUpdateStruct) ||
!empty($userUpdateStruct->contentMetadataUpdateStruct) ||
!empty($userUpdateStruct->email) ||
!empty($userUpdateStruct->enabled) ||
!empty($userUpdateStruct->maxLogin);
}

private function getDateTime(?int $timestamp): ?DateTimeInterface
{
if ($timestamp !== null) {
Expand Down

0 comments on commit 8d1d838

Please sign in to comment.