feat: 增强管理员权限管理,添加 RBAC 支持,更新 AdminUser 模型以处理角色和权限,更新登录接口返回权限信息,扩展数据库填充器以同步角色权限
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
<?php
|
||||
|
||||
use App\Models\AdminUser;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Tests\TestCase;
|
||||
|
||||
/*
|
||||
@@ -44,7 +46,19 @@ expect()->extend('toBeOne', function () {
|
||||
|
|
||||
*/
|
||||
|
||||
function something()
|
||||
/** 为后台测试账号挂上 `super_admin` 角色(细粒度权限校验全放行)。 */
|
||||
function grantSuperAdminRole(AdminUser $admin): void
|
||||
{
|
||||
// ..
|
||||
$now = now();
|
||||
DB::table('admin_roles')->updateOrInsert(
|
||||
['slug' => AdminUser::ROLE_SUPER_ADMIN],
|
||||
['name' => 'Super Admin', 'created_at' => $now, 'updated_at' => $now],
|
||||
);
|
||||
$rid = (int) DB::table('admin_roles')->where('slug', AdminUser::ROLE_SUPER_ADMIN)->value('id');
|
||||
if (! DB::table('admin_user_roles')->where('admin_user_id', $admin->id)->where('role_id', $rid)->exists()) {
|
||||
DB::table('admin_user_roles')->insert([
|
||||
'admin_user_id' => $admin->id,
|
||||
'role_id' => $rid,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user