@@ -150,22 +150,29 @@ protected function init()
150
150
$ models = $ this ->getManagedModels ();
151
151
$ this ->modelTab = $ this ->getRequest ()->param ('ModelClass ' );
152
152
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
+
153
170
// if we've hit the "landing" page
154
171
if ($ this ->modelTab === null ) {
155
172
reset ($ models );
156
173
$ this ->modelTab = key ($ models ?? []);
157
174
}
158
175
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
-
169
176
$ this ->modelClass = isset ($ models [$ this ->modelTab ]['dataClass ' ])
170
177
? $ models [$ this ->modelTab ]['dataClass ' ]
171
178
: $ this ->modelTab ;
0 commit comments