Skip to content

Commit 245c155

Browse files
committed
fix: 修复多租户权限系统接口问题 - 新增 /tenant/active 路由 - ByTenant 接口支持 tenantId=0 返回全局角色 - 修复数据库缺少 t_role.tenant_id / t_tenant.expired_at|menu_keys / t_audit_log.action_type 等字段
1 parent cd49e0d commit 245c155

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

Juggle.Api/Controllers/Api/RoleController.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,17 @@ public async Task<ApiResult> All()
7272
[HttpGet("byTenant/{tenantId}"), Authorize]
7373
public async Task<ApiResult> ByTenant(long tenantId)
7474
{
75+
// tenantId=0 时返回全局角色(无租户绑定)
76+
if (tenantId == 0)
77+
{
78+
var globalList = await _db.Roles
79+
.Where(r => r.Deleted == 0 && r.TenantId == null)
80+
.OrderBy(r => r.Id)
81+
.Select(r => new { r.Id, r.RoleName, r.RoleCode, r.TenantId })
82+
.ToListAsync();
83+
return ApiResult.Success(globalList);
84+
}
85+
7586
// 超管可获取指定租户下所有角色
7687
// 非超管只能获取本租户的角色
7788
if (!_tenant.IsSuperAdmin && tenantId != _tenant.TenantId)

Juggle.Api/Controllers/Api/TenantController.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,18 @@ public async Task<ApiResult> All()
7878
return ApiResult.Success(list);
7979
}
8080

81+
/// <summary>所有启用租户(下拉选择用,兼容前端 /active 路由)</summary>
82+
[HttpGet("active"), Authorize]
83+
public async Task<ApiResult> Active()
84+
{
85+
var list = await _db.Tenants
86+
.Where(t => t.Deleted == 0 && t.Status == 1)
87+
.OrderBy(t => t.Id)
88+
.Select(t => new { t.Id, t.TenantName, t.TenantCode })
89+
.ToListAsync();
90+
return ApiResult.Success(list);
91+
}
92+
8193
/// <summary>租户详情(含菜单权限和关联用户)</summary>
8294
[HttpGet("detail/{id}"), Authorize]
8395
public async Task<ApiResult> Detail(long id)

0 commit comments

Comments
 (0)