action permissions
parent
2d25f38d12
commit
39c40820e0
|
|
@ -20,6 +20,8 @@ class KeywordController extends AdminController
|
|||
$user = Admin::user();
|
||||
$crud = $this->baseCRUD()
|
||||
->filterTogglable(false)
|
||||
->bulkActions([])
|
||||
->columnsTogglable(false)
|
||||
->headerToolbar([
|
||||
$this->createButton()->visible($user->can('keywords.create')),
|
||||
...$this->baseHeaderToolBar(),
|
||||
|
|
|
|||
|
|
@ -1,66 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Slowlyo\OwlAdmin\Admin;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class AdminPermission
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
|
||||
*/
|
||||
public function handle(Request $request, Closure $next, ...$args): Response
|
||||
{
|
||||
$name = Route::currentRouteName();
|
||||
if (!$name) {
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
if (Admin::config('admin.auth.permission') === false) {
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
if ($request->path() == Admin::config('admin.route.prefix')) {
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
$excepted = collect(Admin::config('admin.auth.except', []))
|
||||
->merge(Admin::config('admin.show_development_tools') ? ['/dev_tools*'] : [])
|
||||
->map(fn($path) => $this->pathFormatting($path))
|
||||
->contains(fn($except) => $request->is($except == '/' ? $except : trim($except, '/')));
|
||||
|
||||
if ($excepted) {
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
$user = Admin::user();
|
||||
if (!$user) {
|
||||
return $next($request);
|
||||
}
|
||||
if ($user->isAdministrator() || $user->can($name)) {
|
||||
return $next($request);
|
||||
}
|
||||
|
||||
return Admin::response()->fail(admin_trans('admin.unauthorized'));
|
||||
}
|
||||
|
||||
private function pathFormatting($path)
|
||||
{
|
||||
$prefix = '/' . trim(Admin::config('admin.route.prefix'), '/');
|
||||
|
||||
$prefix = ($prefix === '/') ? '' : $prefix;
|
||||
|
||||
$path = trim($path, '/');
|
||||
|
||||
if (is_null($path) || $path === '') {
|
||||
return $prefix ?: '/';
|
||||
}
|
||||
return $prefix . '/' . $path;
|
||||
}
|
||||
}
|
||||
|
|
@ -24,12 +24,13 @@ return [
|
|||
'domain' => null,
|
||||
'namespace' => 'App\\Admin\\Controllers',
|
||||
'middleware' => [
|
||||
'admin.autoSetLocale',
|
||||
'admin.auth',
|
||||
'admin.bootstrap',
|
||||
AdminPermission::class,
|
||||
'sanctum',
|
||||
'substitute',
|
||||
// 'admin.autoSetLocale',
|
||||
// 'admin.auth',
|
||||
// 'admin.bootstrap',
|
||||
// AdminPermission::class,
|
||||
// 'sanctum',
|
||||
// 'substitute',
|
||||
'admin'
|
||||
],
|
||||
// 不包含额外路由, 配置后, 不会追加新增/详情/编辑页面路由
|
||||
'without_extra_routes' => [
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class AdminPermissionSeeder extends Seeder
|
|||
['name' => '权限', 'icon' => 'mdi:key-variant', 'slug' => 'permissions', 'url' => '/system/admin_permissions'],
|
||||
['name' => '菜单', 'icon' => 'mdi:menu-open', 'slug' => 'menus', 'url' => '/system/admin_menus'],
|
||||
['name' => '设置', 'icon' => 'mdi:application-cog-outline', 'slug' => 'settings', 'url' => '/system/settings'],
|
||||
['name' => '字典管理', 'icon' => 'mdi:folder-key-network', 'slug' => 'keywords', 'url' => '/system/keywords', 'resource' => true],
|
||||
['name' => '字典管理', 'icon' => 'mdi:folder-key-network', 'slug' => 'keywords', 'url' => '/system/keywords', 'resource' => true, 'permissions' => ['export' => '导出']],
|
||||
]],
|
||||
];
|
||||
$this->createByTree($list);
|
||||
|
|
@ -47,9 +47,9 @@ class AdminPermissionSeeder extends Seeder
|
|||
if (isset($item['children'])) {
|
||||
$this->createByTree($item['children'], ['permission' => $permission->id, 'menu' => $menu->id]);
|
||||
}
|
||||
$resource_permissions = data_get($item, 'permissions', []);
|
||||
if (isset($item['resource'])) {
|
||||
$resource_permissions = array_merge($resource_permissions, $this->getResourcePermissions($item['resource']));
|
||||
$resource_permissions = $this->getResourcePermissions(data_get($item, 'resource'));
|
||||
if (isset($item['permissions'])) {
|
||||
$resource_permissions = array_merge($resource_permissions, $item['permissions']);
|
||||
}
|
||||
foreach($resource_permissions as $key => $name) {
|
||||
$this->createPermission([
|
||||
|
|
@ -82,7 +82,7 @@ class AdminPermissionSeeder extends Seeder
|
|||
'custom_order' => data_get($item, 'custom_order', 0),
|
||||
'name' => data_get($item, 'name'),
|
||||
'slug' => $slug,
|
||||
'http_path' => $slug,
|
||||
'http_path' => $url ? [$url] : null,
|
||||
]);
|
||||
if ($menu) {
|
||||
$menu_has_permissions = [
|
||||
|
|
|
|||
Loading…
Reference in New Issue