Skip to content

Commit

Permalink
IBX-6592: Allowed Location to be a part of permission check for Obj…
Browse files Browse the repository at this point in the history
…ect State assignment
  • Loading branch information
barw4 committed Nov 7, 2023
1 parent affa252 commit 6e3f37f
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 23 deletions.
12 changes: 7 additions & 5 deletions eZ/Publish/API/Repository/ObjectStateService.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
namespace eZ\Publish\API\Repository;

use eZ\Publish\API\Repository\Values\Content\ContentInfo;
use eZ\Publish\API\Repository\Values\Content\Location;
use eZ\Publish\API\Repository\Values\ObjectState\ObjectState;
use eZ\Publish\API\Repository\Values\ObjectState\ObjectStateCreateStruct;
use eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup;
Expand Down Expand Up @@ -172,12 +173,13 @@ public function deleteObjectState(ObjectState $objectState): void;
*
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the object state does not belong to the given group
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to change the object state
*
* @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
* @param \eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup $objectStateGroup
* @param \eZ\Publish\API\Repository\Values\ObjectState\ObjectState $objectState
*/
public function setContentState(ContentInfo $contentInfo, ObjectStateGroup $objectStateGroup, ObjectState $objectState): void;
public function setContentState(
ContentInfo $contentInfo,
ObjectStateGroup $objectStateGroup,
ObjectState $objectState,
?Location $location = null
): void;

/**
* Gets the object-state of object identified by $contentId.
Expand Down
6 changes: 4 additions & 2 deletions eZ/Publish/Core/Event/ObjectStateService.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use eZ\Publish\API\Repository\Events\ObjectState\UpdateObjectStateGroupEvent;
use eZ\Publish\API\Repository\ObjectStateService as ObjectStateServiceInterface;
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
use eZ\Publish\API\Repository\Values\Content\Location;
use eZ\Publish\API\Repository\Values\ObjectState\ObjectState;
use eZ\Publish\API\Repository\Values\ObjectState\ObjectStateCreateStruct;
use eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup;
Expand Down Expand Up @@ -214,7 +215,8 @@ public function deleteObjectState(ObjectState $objectState): void
public function setContentState(
ContentInfo $contentInfo,
ObjectStateGroup $objectStateGroup,
ObjectState $objectState
ObjectState $objectState,
?Location $location = null
): void {
$eventData = [
$contentInfo,
Expand All @@ -229,7 +231,7 @@ public function setContentState(
return;
}

$this->innerService->setContentState($contentInfo, $objectStateGroup, $objectState);
$this->innerService->setContentState($contentInfo, $objectStateGroup, $objectState, $location);

$this->eventDispatcher->dispatch(
new SetContentStateEvent(...$eventData)
Expand Down
8 changes: 4 additions & 4 deletions eZ/Publish/Core/Limitation/NewObjectStateLimitationType.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,11 @@ public function evaluate(APILimitationValue $value, APIUserReference $currentUse
return false;
}

foreach ($targets as $target) {
if (!$target instanceof ObjectState && !$target instanceof SPIObjectState) {
throw new InvalidArgumentException('$targets', 'Must contain ObjectState objects');
}
$targets = array_filter($targets, static function ($target) {
return $target instanceof ObjectState || $target instanceof SPIObjectState;
});

foreach ($targets as $target) {
if (!in_array($target->id, $value->limitationValues)) {
return false;
}
Expand Down
16 changes: 9 additions & 7 deletions eZ/Publish/Core/Repository/ObjectStateService.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use eZ\Publish\API\Repository\PermissionResolver;
use eZ\Publish\API\Repository\Repository as RepositoryInterface;
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
use eZ\Publish\API\Repository\Values\Content\Location;
use eZ\Publish\API\Repository\Values\ObjectState\ObjectState as APIObjectState;
use eZ\Publish\API\Repository\Values\ObjectState\ObjectStateCreateStruct;
use eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup as APIObjectStateGroup;
Expand Down Expand Up @@ -463,14 +464,15 @@ public function deleteObjectState(APIObjectState $objectState): void
*
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the object state does not belong to the given group
* @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to change the object state
*
* @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
* @param \eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup $objectStateGroup
* @param \eZ\Publish\API\Repository\Values\ObjectState\ObjectState $objectState
*/
public function setContentState(ContentInfo $contentInfo, APIObjectStateGroup $objectStateGroup, APIObjectState $objectState): void
{
if (!$this->permissionResolver->canUser('state', 'assign', $contentInfo, [$objectState])) {
public function setContentState(
ContentInfo $contentInfo,
APIObjectStateGroup $objectStateGroup,
APIObjectState $objectState,
?Location $location = null
): void {
$targets = $location !== null ? [$location, $objectState] : [$objectState];
if (!$this->permissionResolver->canUser('state', 'assign', $contentInfo, $targets)) {
throw new UnauthorizedException('state', 'assign', ['contentId' => $contentInfo->id]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use eZ\Publish\API\Repository\LanguageResolver;
use eZ\Publish\API\Repository\ObjectStateService as ObjectStateServiceInterface;
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
use eZ\Publish\API\Repository\Values\Content\Location;
use eZ\Publish\API\Repository\Values\ObjectState\ObjectState;
use eZ\Publish\API\Repository\Values\ObjectState\ObjectStateCreateStruct;
use eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup;
Expand Down Expand Up @@ -127,9 +128,13 @@ public function deleteObjectState(ObjectState $objectState): void
$this->service->deleteObjectState($objectState);
}

public function setContentState(ContentInfo $contentInfo, ObjectStateGroup $objectStateGroup, ObjectState $objectState): void
{
$this->service->setContentState($contentInfo, $objectStateGroup, $objectState);
public function setContentState(
ContentInfo $contentInfo,
ObjectStateGroup $objectStateGroup,
ObjectState $objectState,
?Location $location = null
): void {
$this->service->setContentState($contentInfo, $objectStateGroup, $objectState, $location);
}

public function getContentState(ContentInfo $contentInfo, ObjectStateGroup $objectStateGroup): ObjectState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use eZ\Publish\API\Repository\ObjectStateService;
use eZ\Publish\API\Repository\Values\Content\ContentInfo;
use eZ\Publish\API\Repository\Values\Content\Location;
use eZ\Publish\API\Repository\Values\ObjectState\ObjectState;
use eZ\Publish\API\Repository\Values\ObjectState\ObjectStateCreateStruct;
use eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup;
Expand Down Expand Up @@ -121,9 +122,10 @@ public function deleteObjectState(ObjectState $objectState): void
public function setContentState(
ContentInfo $contentInfo,
ObjectStateGroup $objectStateGroup,
ObjectState $objectState
ObjectState $objectState,
?Location $location = null
): void {
$this->innerService->setContentState($contentInfo, $objectStateGroup, $objectState);
$this->innerService->setContentState($contentInfo, $objectStateGroup, $objectState, $location);
}

public function getContentState(
Expand Down

0 comments on commit 6e3f37f

Please sign in to comment.