diff --git a/CHANGELOG.md b/CHANGELOG.md index a8d98b557..be29a12cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ * Fixed media fields excluding newly deleted files before saving the object * Fixed method `$pages->find()` should never redirect [#3266](https://github.com/getgrav/grav/pull/3266) * Fixed `Page::activeChild()` throwing an error [#3276](https://github.com/getgrav/grav/issues/3276) + * Fixed `Flex Page` CRUD ACL when creating a new page (needs Flex Objects plugin update) [grav-plugin-flex-objects#115](https://github.com/trilbymedia/grav-plugin-flex-objects/issues/115) # v1.7.8 ## 03/17/2021 diff --git a/system/src/Grav/Common/Flex/Types/Pages/PageObject.php b/system/src/Grav/Common/Flex/Types/Pages/PageObject.php index 2d45b910b..9ed8b671b 100644 --- a/system/src/Grav/Common/Flex/Types/Pages/PageObject.php +++ b/system/src/Grav/Common/Flex/Types/Pages/PageObject.php @@ -22,6 +22,7 @@ use Grav\Common\Language\Language; use Grav\Common\Page\Interfaces\PageInterface; use Grav\Common\Page\Pages; +use Grav\Common\User\Interfaces\UserInterface; use Grav\Common\Utils; use Grav\Framework\Filesystem\Filesystem; use Grav\Framework\Flex\FlexObject; @@ -321,6 +322,28 @@ public function move(PageInterface $parent) return $this; } + /** + * @param UserInterface $user + * @param string $action + * @param string $scope + * @param bool $isMe + * @return bool|null + */ + protected function isAuthorizedOverride(UserInterface $user, string $action, string $scope, bool $isMe): ?bool + { + // Special case: creating a new page means checking parent for its permissions. + if ($action === 'create' && !$this->exists()) { + $parent = $this->parent(); + if ($parent && method_exists($parent, 'isAuthorized')) { + return $parent->isAuthorized($action, $scope, $user); + } + + return false; + } + + return parent::isAuthorizedOverride($user, $action, $scope, $isMe); + } + /** * @param array $ordering * @return PageCollection|null diff --git a/system/src/Grav/Framework/Flex/Pages/Traits/PageRoutableTrait.php b/system/src/Grav/Framework/Flex/Pages/Traits/PageRoutableTrait.php index 66b39556d..8aa269be1 100644 --- a/system/src/Grav/Framework/Flex/Pages/Traits/PageRoutableTrait.php +++ b/system/src/Grav/Framework/Flex/Pages/Traits/PageRoutableTrait.php @@ -422,7 +422,7 @@ public function parent(PageInterface $var = null) $directory = $this->getFlexDirectory(); $parentKey = ltrim(dirname("/{$this->getKey()}"), '/'); - if ($parentKey) { + if ('' !== $parentKey) { $parent = $directory->getObject($parentKey); $language = $this->getLanguage(); if ($language && $parent && method_exists($parent, 'getTranslation')) { @@ -433,7 +433,7 @@ public function parent(PageInterface $var = null) } else { $index = $directory->getIndex(); - $this->_parentCache = method_exists($index, 'getRoot') ? $index->getRoot() : null; + $this->_parentCache = \is_callable([$index, 'getRoot']) ? $index->getRoot() : null; } return $this->_parentCache;