File tree Expand file tree Collapse file tree 2 files changed +37
-6
lines changed
Admin/src/Http/Controllers/User Expand file tree Collapse file tree 2 files changed +37
-6
lines changed Original file line number Diff line number Diff line change @@ -40,20 +40,26 @@ public function store()
40
40
'password ' => 'required ' ,
41
41
]);
42
42
43
- if (! auth ()->guard ('user ' )->attempt (request (['email ' , 'password ' ]), request ('remember ' ))) {
43
+ $ user = auth ()->guard ('user ' );
44
+
45
+ if (! $ user ->attempt (request (['email ' , 'password ' ]), request ('remember ' ))) {
44
46
session ()->flash ('error ' , trans ('admin::app.users.login-error ' ));
45
47
46
48
return redirect ()->back ();
47
49
}
48
50
49
- if (auth ()-> guard ( ' user ' ) ->user ()->status == 0 ) {
51
+ if ($ user ->user ()->status == 0 ) {
50
52
session ()->flash ('warning ' , trans ('admin::app.users.activate-warning ' ));
51
53
52
- auth ()-> guard ( ' user ' ) ->logout ();
54
+ $ user ->logout ();
53
55
54
56
return redirect ()->route ('admin.session.create ' );
55
57
}
56
58
59
+ if ($ user ->user ()->role ->permission_type !== 'all ' ) {
60
+ return redirect ()->route (menu ()->getItems ('admin ' )->first ()->getRoute ());
61
+ }
62
+
57
63
return redirect ()->intended (route ('admin.dashboard.index ' ));
58
64
}
59
65
Original file line number Diff line number Diff line change @@ -80,9 +80,8 @@ public function getItems(?string $area = null, string $key = ''): Collection
80
80
$ this ->prepareMenuItems ();
81
81
}
82
82
83
- $ items = collect ($ this ->items )->sortBy (fn ($ item ) => $ item ->getPosition ());
84
-
85
- return $ items ;
83
+ return collect ($ this ->removeUnauthorizedMenuItem ())
84
+ ->sortBy (fn ($ item ) => $ item ->getPosition ());
86
85
}
87
86
88
87
/**
@@ -185,4 +184,30 @@ private function findMatchingItem($items, $currentKey): ?MenuItem
185
184
186
185
return null ;
187
186
}
187
+
188
+ /**
189
+ * Remove unauthorized menu item.
190
+ */
191
+ private function removeUnauthorizedMenuItem (): array
192
+ {
193
+ return collect ($ this ->items )->map (function ($ item ) {
194
+ $ this ->removeChildrenUnauthorizedMenuItem ($ item );
195
+
196
+ return $ item ;
197
+ })->toArray ();
198
+ }
199
+
200
+ /**
201
+ * Remove unauthorized menuItem's children. This will handle all levels.
202
+ */
203
+ private function removeChildrenUnauthorizedMenuItem (MenuItem &$ menuItem ): void
204
+ {
205
+ if ($ menuItem ->haveChildren ()) {
206
+ $ firstChildrenItem = $ menuItem ->getChildren ()->first ();
207
+
208
+ $ menuItem ->setRoute ($ firstChildrenItem ->getRoute ());
209
+
210
+ $ this ->removeChildrenUnauthorizedMenuItem ($ firstChildrenItem );
211
+ }
212
+ }
188
213
}
You can’t perform that action at this time.
0 commit comments