From cf088d00ff3792b4701e0d2f0df485037c8a7b7f Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Tue, 19 Feb 2019 22:39:47 +0200 Subject: [PATCH] Fixed FlexUser loosing ACL information (apply only for user) --- system/src/Grav/Common/User/FlexUser/User.php | 44 +++++++++++++++++++ system/src/Grav/Framework/Flex/FlexObject.php | 5 +-- 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/system/src/Grav/Common/User/FlexUser/User.php b/system/src/Grav/Common/User/FlexUser/User.php index 3dd151e76..c2ef855e2 100644 --- a/system/src/Grav/Common/User/FlexUser/User.php +++ b/system/src/Grav/Common/User/FlexUser/User.php @@ -9,6 +9,7 @@ namespace Grav\Common\User\FlexUser; +use Grav\Common\Data\ValidationException; use Grav\Common\Grav; use Grav\Common\Media\Interfaces\MediaCollectionInterface; use Grav\Common\Page\Media; @@ -17,6 +18,7 @@ use Grav\Common\Page\Medium\Medium; use Grav\Common\User\Authentication; use Grav\Common\User\Interfaces\UserInterface; use Grav\Common\User\Traits\UserTrait; +use Grav\Common\Utils; use Grav\Framework\File\Formatter\JsonFormatter; use Grav\Framework\File\Formatter\YamlFormatter; use Grav\Framework\Flex\FlexDirectory; @@ -148,6 +150,48 @@ class User extends FlexObject implements UserInterface, MediaManipulationInterfa return $this; } + /** + * @param array $data + * @param array $files + * @return $this + * @throws ValidationException + */ + public function update(array $data, array $files = []) + { + if ($data) { + // Filter updated data. + $this->filterElements($data); + + // Merge data to the existing object. + $elements = $this->getElements(); + + // Validate and filter the incoming data. + $blueprint = $this->getFlexDirectory()->getBlueprint(); + + // Merge existing object to the data. + $data = $blueprint->mergeData($elements, $data); + + // Validate and filter elements and throw an error if any issues were found. + $blueprint->validate($data + ['storage_key' => $this->getStorageKey(), 'timestamp' => $this->getTimestamp()]); + $data = $blueprint->filter($data); + + // Make sure that we add missing (filtered by ACL) elements back. + $data = $blueprint->mergeData($elements, $data); + + // Store the changes + $this->_changes = Utils::arrayDiffMultidimensional($data, $this->getElements()); + + // Finally update the object. + $this->setElements($data); + } + + if ($files && method_exists($this, 'setUpdatedMedia')) { + $this->setUpdatedMedia($files); + } + + return $this; + } + /** * Get value from a page variable (used mostly for creating edit forms). * diff --git a/system/src/Grav/Framework/Flex/FlexObject.php b/system/src/Grav/Framework/Flex/FlexObject.php index baac648f1..9558bdd76 100644 --- a/system/src/Grav/Framework/Flex/FlexObject.php +++ b/system/src/Grav/Framework/Flex/FlexObject.php @@ -51,7 +51,7 @@ class FlexObject implements FlexObjectInterface, FlexAuthorizeInterface /** @var array */ private $_storage; /** @var array */ - private $_changes; + protected $_changes; /** * @return array @@ -133,9 +133,6 @@ class FlexObject implements FlexObjectInterface, FlexAuthorizeInterface $blueprint->validate($data + ['storage_key' => $this->getStorageKey(), 'timestamp' => $this->getTimestamp()]); $data = $blueprint->filter($data); - // Make sure that we add missing (filtered by ACL) elements back. - $data = $blueprint->mergeData($elements, $data); - // Store the changes $this->_changes = Utils::arrayDiffMultidimensional($data, $this->getElements());