Skip to content

Commit

Permalink
Merge branch '2.2' into 2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Oct 3, 2024
2 parents c21cf6d + d14849a commit 6e4b18a
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions code/ModelAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,22 +150,29 @@ protected function init()
$models = $this->getManagedModels();
$this->modelTab = $this->getRequest()->param('ModelClass');

// security check for valid models
if ($this->modelTab && !$this->isManagedModel($this->modelTab)) {
// No need to check model tab since we are already redirected
// This happens when there's a permission failure in LeftAndMain
if ($this->redirectedTo()) {
// reset so we use the "landing page"
$this->modelTab = null;
} else {
// if it fails to match the string exactly, try reverse-engineering a classname
$this->modelTab = $this->unsanitiseClassName($this->modelTab);

if (!$this->isManagedModel($this->modelTab)) {
throw new \RuntimeException(sprintf('ModelAdmin::init(): Invalid Model class %s', $this->modelTab));
}
}
}

// if we've hit the "landing" page
if ($this->modelTab === null) {
reset($models);
$this->modelTab = key($models ?? []);
}

// security check for valid models
if (!$this->isManagedModel($this->modelTab)) {
// if it fails to match the string exactly, try reverse-engineering a classname
$this->modelTab = $this->unsanitiseClassName($this->modelTab);

if (!$this->isManagedModel($this->modelTab)) {
throw new \RuntimeException(sprintf('ModelAdmin::init(): Invalid Model class %s', $this->modelTab));
}
}

$this->modelClass = isset($models[$this->modelTab]['dataClass'])
? $models[$this->modelTab]['dataClass']
: $this->modelTab;
Expand Down

0 comments on commit 6e4b18a

Please sign in to comment.