Skip to content

Commit d14849a

Browse files
Merge pull request #1830 from lekoala/patch-6
FIX Don't trigger init if already redirected
2 parents 27a2da7 + 188e45e commit d14849a

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

code/ModelAdmin.php

+17-10
Original file line numberDiff line numberDiff line change
@@ -150,22 +150,29 @@ protected function init()
150150
$models = $this->getManagedModels();
151151
$this->modelTab = $this->getRequest()->param('ModelClass');
152152

153+
// security check for valid models
154+
if ($this->modelTab && !$this->isManagedModel($this->modelTab)) {
155+
// No need to check model tab since we are already redirected
156+
// This happens when there's a permission failure in LeftAndMain
157+
if ($this->redirectedTo()) {
158+
// reset so we use the "landing page"
159+
$this->modelTab = null;
160+
} else {
161+
// if it fails to match the string exactly, try reverse-engineering a classname
162+
$this->modelTab = $this->unsanitiseClassName($this->modelTab);
163+
164+
if (!$this->isManagedModel($this->modelTab)) {
165+
throw new \RuntimeException(sprintf('ModelAdmin::init(): Invalid Model class %s', $this->modelTab));
166+
}
167+
}
168+
}
169+
153170
// if we've hit the "landing" page
154171
if ($this->modelTab === null) {
155172
reset($models);
156173
$this->modelTab = key($models ?? []);
157174
}
158175

159-
// security check for valid models
160-
if (!$this->isManagedModel($this->modelTab)) {
161-
// if it fails to match the string exactly, try reverse-engineering a classname
162-
$this->modelTab = $this->unsanitiseClassName($this->modelTab);
163-
164-
if (!$this->isManagedModel($this->modelTab)) {
165-
throw new \RuntimeException(sprintf('ModelAdmin::init(): Invalid Model class %s', $this->modelTab));
166-
}
167-
}
168-
169176
$this->modelClass = isset($models[$this->modelTab]['dataClass'])
170177
? $models[$this->modelTab]['dataClass']
171178
: $this->modelTab;

0 commit comments

Comments
 (0)