Skip to content

Commit

Permalink
[Data objects] Do not use admin mode when reloading object as admin u…
Browse files Browse the repository at this point in the history
…ser (#10079)

* do not use admin mode when reloading object as admin user

* do not use admin mode when reloading object as admin user

* remove reload split button option "Master" as this is already default behaviour of the main button

* set current layout id on first opening of option

* set current layout id on first opening of option

* set current layout id on first opening of option

* set current layout id on first opening of option

* set current layout id on first opening of option

* set current layout id on first opening of option

* set current layout id on first opening of option

* fix permisson check

* fix permisson check
  • Loading branch information
BlackbitDevs committed Aug 26, 2021
1 parent 2fabb66 commit af229c0
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 45 deletions.
Expand Up @@ -492,27 +492,26 @@ public function getAction(Request $request, EventDispatcherInterface $eventDispa

$this->addAdminStyle($object, ElementAdminStyleEvent::CONTEXT_EDITOR, $objectData['general']);

$currentLayoutId = $request->get('layoutId', null);
$currentLayoutId = $request->get('layoutId', 0);

$validLayouts = DataObject\Service::getValidLayouts($object);

//Fallback if $currentLayoutId is not set or empty string
//Uses first valid layout instead of admin layout when empty
$ok = false;
foreach ($validLayouts as $key => $layout) {
foreach ($validLayouts as $layout) {
if ($currentLayoutId == $layout->getId()) {
$ok = true;
}
}

if (!$ok) {
if (count($validLayouts) > 0) {
$currentLayoutId = reset($validLayouts)->getId();
}
$currentLayoutId = null;
}

//master layout has id 0 so we check for is_null()
if ((is_null($currentLayoutId) || !strlen($currentLayoutId)) && !empty($validLayouts)) {
if (count($validLayouts) == 1) {
if ($currentLayoutId === null && !empty($validLayouts)) {
if (count($validLayouts) === 1) {
$firstLayout = reset($validLayouts);
$currentLayoutId = $firstLayout->getId();
} else {
Expand All @@ -523,35 +522,25 @@ public function getAction(Request $request, EventDispatcherInterface $eventDispa
}
}
}

if ($currentLayoutId === null && count($validLayouts) > 0) {
$currentLayoutId = reset($validLayouts)->getId();
}

if (!empty($validLayouts)) {
$objectData['validLayouts'] = [ ];
$objectData['validLayouts'] = [];

foreach ($validLayouts as $validLayout) {
$objectData['validLayouts'][] = ['id' => $validLayout->getId(), 'name' => $validLayout->getName()];
}

$user = Tool\Admin::getCurrentUser();

if (!is_null($currentLayoutId)) {
if ($currentLayoutId == '0' && !$user->isAdmin()) {
$first = reset($validLayouts);
$currentLayoutId = $first->getId();
}
}

if ($currentLayoutId == -1 && $user->isAdmin()) {
$layout = DataObject\Service::getSuperLayoutDefinition($object);
$objectData['layout'] = $layout;
} elseif (!empty($currentLayoutId)) {
// check if user has sufficient rights
if (is_array($validLayouts) && $validLayouts[$currentLayoutId]) {
$customLayout = DataObject\ClassDefinition\CustomLayout::getById($currentLayoutId);

$customLayoutDefinition = $customLayout->getLayoutDefinitions();
$objectData['layout'] = $customLayoutDefinition;
} else {
$currentLayoutId = 0;
}
$objectData['layout'] = $validLayouts[$currentLayoutId]->getLayoutDefinitions();
}

$objectData['currentLayoutId'] = $currentLayoutId;
Expand Down
Expand Up @@ -459,7 +459,7 @@ pimcore.object.object = Class.create(pimcore.object.abstract, {
})
};

if (this.data["validLayouts"] && this.data.validLayouts.length > 1) {
if (this.data["validLayouts"] && this.data.validLayouts.length >= 1) {
reloadConfig.xtype = "splitbutton";

var menu = [];
Expand Down
Expand Up @@ -84,12 +84,10 @@ pimcore.object.tags.objectbricks = Class.create(pimcore.object.tags.abstract, {
this.layoutDefinitions = bricksData.layoutDefinitions;

this.component.insert(0, this.getControls());
if (this.data.length > 0) {
for (var i = 0; i < this.data.length; i++) {
if (this.data[i] != null) {
this.preventDelete[this.data[i].type] = this.data[i].inherited;
this.addBlockElement(i, this.data[i].type, this.data[i], true, this.data[i].title, false);
}
for (var i = 0; i < this.data.length; i++) {
if (this.data[i] != null) {
this.preventDelete[this.data[i].type] = this.data[i].inherited;
this.addBlockElement(i, this.data[i].type, this.data[i], true, this.data[i].title, false);
}
}

Expand Down
23 changes: 10 additions & 13 deletions bundles/CoreBundle/EventListener/WorkflowManagementListener.php
Expand Up @@ -183,19 +183,16 @@ public function onAdminElementGetPreSendData(GenericEvent $e)
//load the new layout into the object container
$validLayouts = DataObject\Service::getValidLayouts($element);

//check that the layout id is valid before trying to load
if (!empty($validLayouts)) {
// check user permissions again
if ($validLayouts[$workflowLayoutId]) {
$customLayout = ClassDefinition\CustomLayout::getById($workflowLayoutId);
$customLayoutDefinition = $customLayout->getLayoutDefinitions();
DataObject\Service::enrichLayoutDefinition(
$customLayoutDefinition,
$e->getArgument('object')
);
$data['layout'] = $customLayoutDefinition;
$data['currentLayoutId'] = $workflowLayoutId;
}
// check user permissions again
if (isset($validLayouts[$workflowLayoutId])) {
$customLayout = ClassDefinition\CustomLayout::getById($workflowLayoutId);
$customLayoutDefinition = $customLayout->getLayoutDefinitions();
DataObject\Service::enrichLayoutDefinition(
$customLayoutDefinition,
$e->getArgument('object')
);
$data['layout'] = $customLayoutDefinition;
$data['currentLayoutId'] = $workflowLayoutId;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion models/DataObject/Service.php
Expand Up @@ -979,7 +979,7 @@ public static function rewriteIds($object, $rewriteConfig, $params = [])
/**
* @param Concrete $object
*
* @return array
* @return DataObject\ClassDefinition\CustomLayout[]
*/
public static function getValidLayouts(Concrete $object)
{
Expand Down

0 comments on commit af229c0

Please sign in to comment.