Fixed FlexUser loosing ACL information (apply only for user)

This commit is contained in:
Matias Griese
2019-02-19 22:39:47 +02:00
parent dd5a10d0e2
commit cf088d00ff
2 changed files with 45 additions and 4 deletions

View File

@@ -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).
*

View File

@@ -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());