Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX Don't trigger init if already redirected #1830

Merged
merged 5 commits into from
Oct 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading