Skip to content

Commit

Permalink
EZP-29833 : fixes permission check for content create action
Browse files Browse the repository at this point in the history
  • Loading branch information
pawbuj committed Jan 3, 2019
1 parent 5b24cb7 commit 69cd8e2
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/lib/Menu/ContentCreateRightSidebarBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
use eZ\Publish\API\Repository\ContentTypeService;
use eZ\Publish\API\Repository\LocationService;
use eZ\Publish\API\Repository\PermissionResolver;
use eZ\Publish\API\Repository\Values\Content\Language;
use eZ\Publish\API\Repository\Values\Content\Location;
use eZ\Publish\API\Repository\Values\ContentType\ContentType;
use EzSystems\EzPlatformAdminUi\Menu\Event\ConfigureMenuEvent;
use JMS\TranslationBundle\Model\Message;
use JMS\TranslationBundle\Translation\TranslationContainerInterface;
Expand Down Expand Up @@ -97,12 +100,13 @@ public function createStructure(array $options): ItemInterface
/** @var \Knp\Menu\ItemInterface|\Knp\Menu\ItemInterface[] $menu */
$menu = $this->factory->createItem('root');

$contentCreateStruct = $this->contentService->newContentCreateStruct($contentType, $language->languageCode);
$contentCreateStruct = $this->createContentCreateStruct($parentLocation, $contentType, $language);
$locationCreateStruct = $this->locationService->newLocationCreateStruct($parentLocation->id);

$canPublish = $this->permissionResolver->canUser('content', 'publish', $contentCreateStruct, [$locationCreateStruct]);
$canCreate = $this->permissionResolver->canUser('content', 'create', $contentCreateStruct, [$locationCreateStruct]) && $parentContentType->isContainer;
$canPreview = $this->permissionResolver->canUser('content', 'versionread', $contentCreateStruct, [$locationCreateStruct]);

$publishAttributes = [
'class' => self::BTN_TRIGGER_CLASS,
'data-click' => '#ezrepoforms_content_edit_publish',
Expand Down Expand Up @@ -171,4 +175,19 @@ public static function getTranslationMessages(): array
(new Message(self::ITEM__CANCEL, 'menu'))->setDesc('Cancel'),
];
}

/**
* @param \eZ\Publish\API\Repository\Values\Content\Location $location
* @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType
* @param \eZ\Publish\API\Repository\Values\Content\Language $language
*
* @return \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct
*/
private function createContentCreateStruct(Location $location, ContentType $contentType, Language $language)
{
$contentCreateStruct = $this->contentService->newContentCreateStruct($contentType, $language->languageCode);
$contentCreateStruct->sectionId = $location->contentInfo->sectionId;

return $contentCreateStruct;
}
}

0 comments on commit 69cd8e2

Please sign in to comment.