feat: refactor super admin to use is_super_admin flag and enhance site deletion logic
- Changed super admin detection from role-based to `is_super_admin` flag in AdminUser model
- Added `requireDefaultAdminSiteId()` method to throw validation error when no integration site exists
- Enhanced site deletion to migrate platform role bindings to fallback site and auto-delete site-specific admin accounts
- Made agent line code optional with auto-generation fallback using `{site_code}-agent-{counter}` format
This commit is contained in:
@@ -50,30 +50,11 @@ expect()->extend('toBeOne', function () {
|
||||
|
|
||||
*/
|
||||
|
||||
/** 为后台测试账号挂上 `super_admin` 角色(细粒度权限校验全放行)。 */
|
||||
/** 为后台测试账号挂上唯一超级管理员(不绑定站点)。 */
|
||||
function grantSuperAdminRole(AdminUser $admin): void
|
||||
{
|
||||
$now = now();
|
||||
DB::table('admin_roles')->updateOrInsert(
|
||||
['slug' => AdminUser::ROLE_SUPER_ADMIN],
|
||||
[
|
||||
'name' => 'Super Admin',
|
||||
'code' => AdminUser::ROLE_SUPER_ADMIN,
|
||||
'created_at' => $now,
|
||||
'updated_at' => $now,
|
||||
],
|
||||
);
|
||||
$rid = (int) DB::table('admin_roles')->where('slug', AdminUser::ROLE_SUPER_ADMIN)->value('id');
|
||||
$siteId = (int) DB::table('admin_sites')->where('is_default', true)->value('id');
|
||||
|
||||
DB::table('admin_user_site_roles')->updateOrInsert(
|
||||
[
|
||||
'admin_user_id' => $admin->id,
|
||||
'site_id' => $siteId,
|
||||
'role_id' => $rid,
|
||||
],
|
||||
['granted_at' => $now],
|
||||
);
|
||||
\App\Support\PlatformSystemRoles::ensureSuperAdminRole();
|
||||
\App\Support\SuperAdminAccount::assign($admin);
|
||||
}
|
||||
|
||||
/** 为后台测试账号挂上代理节点(需已存在 agent_nodes / admin_user_agents 表)。 */
|
||||
|
||||
Reference in New Issue
Block a user