1
0
forked from baron/baron-sso

feat: handle multiple manageable tenants for tenant admin

This commit is contained in:
2026-03-04 13:45:54 +09:00
parent d9ed46f4b9
commit 88720b48c4
2 changed files with 25 additions and 14 deletions

View File

@@ -50,25 +50,33 @@ function AppLayout() {
const items = [...staticNavItems]; const items = [...staticNavItems];
const isSuperAdmin = profile?.role === "super_admin"; const isSuperAdmin = profile?.role === "super_admin";
const isTenantAdmin = profile?.role === "tenant_admin"; const isTenantAdmin = profile?.role === "tenant_admin";
const manageableCount = profile?.manageableTenants?.length ?? 0;
if (isSuperAdmin) { if (isSuperAdmin) {
// Insert Tenants at index 1 for Super Admin // Super Admin sees everything
items.splice(1, 0, { items.splice(1, 0, {
label: "ui.admin.nav.tenants", label: "ui.admin.nav.tenants",
to: "/tenants", to: "/tenants",
icon: Building2, icon: Building2,
}); });
} else if (isTenantAdmin && profile?.tenantId) { } else if (isTenantAdmin) {
// Insert My Tenant link for Tenant Admin if (manageableCount === 1 && profile?.tenantId) {
items.splice(1, 0, { // Direct link if only one tenant
label: "ui.admin.nav.my_tenant", items.splice(1, 0, {
to: `/tenants/${profile.tenantId}`, label: "ui.admin.nav.my_tenant",
icon: Building2, to: `/tenants/${profile.tenantId}`,
}); icon: Building2,
});
} else if (manageableCount > 1) {
// Show list menu if multiple tenants
items.splice(1, 0, {
label: "ui.admin.nav.tenants",
to: "/tenants",
icon: Building2,
});
}
} }
// Tenant Admin should not see global API keys or global audit logs (unless allowed)
// For now, let's keep them but they might return 403
return items; return items;
}, [profile]); }, [profile]);

View File

@@ -36,17 +36,20 @@ function TenantListPage() {
queryFn: fetchMe, queryFn: fetchMe,
}); });
// Redirect tenant_admin to their own tenant // Redirect tenant_admin ONLY if they have exactly one manageable tenant
React.useEffect(() => { React.useEffect(() => {
if (profile?.role === "tenant_admin" && profile?.tenantId) { if (profile?.role === "tenant_admin") {
navigate(`/tenants/${profile.tenantId}`, { replace: true }); const manageableCount = profile.manageableTenants?.length ?? 0;
if (manageableCount === 1 && profile.tenantId) {
navigate(`/tenants/${profile.tenantId}`, { replace: true });
}
} }
}, [profile, navigate]); }, [profile, navigate]);
const query = useQuery({ const query = useQuery({
queryKey: ["tenants", { limit: 1000, offset: 0 }], queryKey: ["tenants", { limit: 1000, offset: 0 }],
queryFn: () => fetchTenants(1000, 0), queryFn: () => fetchTenants(1000, 0),
enabled: profile?.role === "super_admin", enabled: profile?.role === "super_admin" || (profile?.role === "tenant_admin" && (profile.manageableTenants?.length ?? 0) > 1),
}); });
const deleteMutation = useMutation({ const deleteMutation = useMutation({