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

Issue #1654 fixed. #1656

Open
wants to merge 1 commit into
base: 2.0
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,26 @@ public function store()
'password' => 'required',
]);

if (! auth()->guard('user')->attempt(request(['email', 'password']), request('remember'))) {
$user = auth()->guard('user');

if (! $user->attempt(request(['email', 'password']), request('remember'))) {
session()->flash('error', trans('admin::app.users.login-error'));

return redirect()->back();
}

if (auth()->guard('user')->user()->status == 0) {
if ($user->user()->status == 0) {
session()->flash('warning', trans('admin::app.users.activate-warning'));

auth()->guard('user')->logout();
$user->logout();

return redirect()->route('admin.session.create');
}

if ($user->user()->role->permission_type !== 'all') {
return redirect()->route(menu()->getItems('admin')->first()->getRoute());
}

return redirect()->intended(route('admin.dashboard.index'));
}

Expand Down
31 changes: 28 additions & 3 deletions packages/Webkul/Core/src/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,8 @@ public function getItems(?string $area = null, string $key = ''): Collection
$this->prepareMenuItems();
}

$items = collect($this->items)->sortBy(fn ($item) => $item->getPosition());

return $items;
return collect($this->removeUnauthorizedMenuItem())
->sortBy(fn ($item) => $item->getPosition());
}

/**
Expand Down Expand Up @@ -185,4 +184,30 @@ private function findMatchingItem($items, $currentKey): ?MenuItem

return null;
}

/**
* Remove unauthorized menu item.
*/
private function removeUnauthorizedMenuItem(): array
{
return collect($this->items)->map(function ($item) {
$this->removeChildrenUnauthorizedMenuItem($item);

return $item;
})->toArray();
}

/**
* Remove unauthorized menuItem's children. This will handle all levels.
*/
private function removeChildrenUnauthorizedMenuItem(MenuItem &$menuItem): void
{
if ($menuItem->haveChildren()) {
$firstChildrenItem = $menuItem->getChildren()->first();

$menuItem->setRoute($firstChildrenItem->getRoute());

$this->removeChildrenUnauthorizedMenuItem($firstChildrenItem);
}
}
}
Loading