Fixing some issues and probably solving later
This commit is contained in:
parent
c84e76646e
commit
54d2a000c8
|
|
@ -9,6 +9,12 @@
|
||||||
"type": "project",
|
"type": "project",
|
||||||
"require": {
|
"require": {
|
||||||
"php": "^7.1.3",
|
"php": "^7.1.3",
|
||||||
|
"ext-openssl": "*",
|
||||||
|
"ext-pdo": "*",
|
||||||
|
"ext-mbstring": "*",
|
||||||
|
"ext-tokenizer": "*",
|
||||||
|
"ext-pdo_mysql": "*",
|
||||||
|
"ext-curl": "*",
|
||||||
"barryvdh/laravel-dompdf": "^0.8.0@dev",
|
"barryvdh/laravel-dompdf": "^0.8.0@dev",
|
||||||
"dimsav/laravel-translatable": "^9.0",
|
"dimsav/laravel-translatable": "^9.0",
|
||||||
"doctrine/dbal": "^2.9@dev",
|
"doctrine/dbal": "^2.9@dev",
|
||||||
|
|
|
||||||
|
|
@ -71,8 +71,56 @@ class AdminServiceProvider extends ServiceProvider
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$tree->items = core()->sortItems($tree->items);
|
$allowedPermissions = auth()->guard('admin')->user()->role->permissions;
|
||||||
|
$withoutDots = array();
|
||||||
|
|
||||||
|
foreach ($allowedPermissions as $key => $allowedPermission) {
|
||||||
|
if (!str_contains($allowedPermission, '.')) {
|
||||||
|
array_push($withoutDots, $allowedPermission);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$levelThreeKey = function() use($allowedPermissions, $withoutDots) {
|
||||||
|
$collectSimilar = array();
|
||||||
|
|
||||||
|
foreach ($withoutDots as $key => $withoutDot) {
|
||||||
|
$group = array();
|
||||||
|
|
||||||
|
foreach ($allowedPermissions as $key1 => $allowedPermission) {
|
||||||
|
//pluck a level 3 group & match the dots
|
||||||
|
if (str_contains($allowedPermission, $withoutDot.'.')) {
|
||||||
|
array_push($group, $allowedPermission);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$collectSimilar[$key] = $group;
|
||||||
|
unset($group);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($collectSimilar as $collected) {
|
||||||
|
if (count($collected) > 1) {
|
||||||
|
$first = $collected[0];
|
||||||
|
$second = $collected[1];
|
||||||
|
|
||||||
|
|
||||||
|
//confirmed, level three key exists
|
||||||
|
if (str_contains($second, $first.'.')) {
|
||||||
|
//find the missing key
|
||||||
|
foreach (config('menu.admin') as $key => $menuItem) {
|
||||||
|
if ($menuItem['key'] == $first) {
|
||||||
|
if(bouncer()->hasPermission(config('menu.admin')[$key+1]['key'])) {
|
||||||
|
//condition met and now just alter the tree
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
$levelThreeKey();
|
||||||
|
|
||||||
|
$tree->items = core()->sortItems($tree->items);
|
||||||
$view->with('menu', $tree);
|
$view->with('menu', $tree);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ class Bouncer
|
||||||
if (! auth()->guard('admin')->check() || ! auth()->guard('admin')->user()->hasPermission($permission))
|
if (! auth()->guard('admin')->check() || ! auth()->guard('admin')->user()->hasPermission($permission))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -31,6 +31,6 @@ class Bouncer
|
||||||
public static function allow($permission)
|
public static function allow($permission)
|
||||||
{
|
{
|
||||||
if (! auth()->guard('admin')->check() || ! auth()->guard('admin')->user()->hasPermission($permission))
|
if (! auth()->guard('admin')->check() || ! auth()->guard('admin')->user()->hasPermission($permission))
|
||||||
abort(401, 'This action is unauthorized.');
|
abort(401, 'This action is unauthorized');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue