Skip to content

Commit

Permalink
Fixed Flex Page CRUD ACL when creating a new page (needs Flex Objec…
Browse files Browse the repository at this point in the history
…ts plugin update)
  • Loading branch information
mahagr committed Mar 18, 2021
1 parent 0d1c63f commit 1c24f9f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions system/src/Grav/Common/Flex/Types/Pages/PageObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand All @@ -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;
Expand Down

0 comments on commit 1c24f9f

Please sign in to comment.