forked from baron/baron-sso
권한부여 및 정합성 검사 추가
This commit is contained in:
@@ -5,6 +5,7 @@ import { Badge } from "../../../components/ui/badge";
|
||||
import { Button } from "../../../components/ui/button";
|
||||
import { fetchMe, fetchTenant } from "../../../lib/adminApi";
|
||||
import { t } from "../../../lib/i18n";
|
||||
import { normalizeAdminRole } from "../../../lib/roles";
|
||||
|
||||
export function canShowWorksmobileEntry(tenant?: {
|
||||
id?: string;
|
||||
@@ -30,8 +31,9 @@ function TenantDetailPage() {
|
||||
queryFn: fetchMe,
|
||||
});
|
||||
|
||||
const profileRole = normalizeAdminRole(profile?.role);
|
||||
const canAccessSchema =
|
||||
profile?.role === "super_admin" || profile?.role === "tenant_admin";
|
||||
profileRole === "super_admin" || profileRole === "tenant_admin";
|
||||
const showWorksmobileEntry = canShowWorksmobileEntry(tenantQuery.data);
|
||||
|
||||
const isPermissionsTab = location.pathname.includes("/permissions");
|
||||
|
||||
@@ -74,6 +74,7 @@ import {
|
||||
importTenantsCSV,
|
||||
} from "../../../lib/adminApi";
|
||||
import { t } from "../../../lib/i18n";
|
||||
import { normalizeAdminRole } from "../../../lib/roles";
|
||||
import { type TenantNode, buildTenantFullTree } from "../../../lib/tenantTree";
|
||||
import {
|
||||
filterNonHanmacFamilyTenants,
|
||||
@@ -262,10 +263,11 @@ function TenantListPage() {
|
||||
queryKey: ["me"],
|
||||
queryFn: fetchMe,
|
||||
});
|
||||
const profileRole = normalizeAdminRole(profile?.role);
|
||||
|
||||
// Redirect tenant_admin ONLY if they have one or fewer manageable tenants in the list
|
||||
React.useEffect(() => {
|
||||
if (profile?.role === "tenant_admin") {
|
||||
if (profile && profileRole === "tenant_admin") {
|
||||
const manageableCount = profile.manageableTenants?.length ?? 0;
|
||||
if (
|
||||
(manageableCount === 1 || manageableCount === 0) &&
|
||||
@@ -274,7 +276,7 @@ function TenantListPage() {
|
||||
navigate(`/tenants/${profile.tenantId}`, { replace: true });
|
||||
}
|
||||
}
|
||||
}, [profile, navigate]);
|
||||
}, [profile, profileRole, navigate]);
|
||||
|
||||
const query = useInfiniteQuery({
|
||||
queryKey: ["tenants", "lazy"],
|
||||
@@ -289,9 +291,9 @@ function TenantListPage() {
|
||||
getNextPageParam: (lastPage) =>
|
||||
lastPage.nextCursor || lastPage.next_cursor || undefined,
|
||||
enabled:
|
||||
profile?.role === "super_admin" ||
|
||||
(profile?.role === "tenant_admin" &&
|
||||
(profile.manageableTenants?.length ?? 0) > 1),
|
||||
profileRole === "super_admin" ||
|
||||
(profileRole === "tenant_admin" &&
|
||||
(profile?.manageableTenants?.length ?? 0) > 1),
|
||||
});
|
||||
|
||||
const deleteMutation = useMutation({
|
||||
@@ -356,8 +358,8 @@ function TenantListPage() {
|
||||
|
||||
if (
|
||||
profile &&
|
||||
profile.role !== "super_admin" &&
|
||||
profile.role !== "tenant_admin"
|
||||
profileRole !== "super_admin" &&
|
||||
profileRole !== "tenant_admin"
|
||||
) {
|
||||
return (
|
||||
<div className="flex h-[50vh] flex-col items-center justify-center space-y-4">
|
||||
@@ -372,7 +374,8 @@ function TenantListPage() {
|
||||
}
|
||||
|
||||
if (
|
||||
profile?.role === "tenant_admin" &&
|
||||
profile &&
|
||||
profileRole === "tenant_admin" &&
|
||||
(profile.manageableTenants?.length ?? 0) <= 1
|
||||
) {
|
||||
return null;
|
||||
@@ -396,7 +399,7 @@ function TenantListPage() {
|
||||
return rawTenants.find((tenant) => tenant.slug === "hanmac-family")?.id;
|
||||
}, [rawTenants]);
|
||||
const allTenants = React.useMemo(() => {
|
||||
if (profile?.role === "super_admin") {
|
||||
if (profileRole === "super_admin") {
|
||||
return rawTenants;
|
||||
}
|
||||
if (
|
||||
@@ -406,7 +409,7 @@ function TenantListPage() {
|
||||
return rawTenants;
|
||||
}
|
||||
return filterNonHanmacFamilyTenants(rawTenants, hanmacFamilyTenantId);
|
||||
}, [hanmacFamilyTenantId, profile, rawTenants]);
|
||||
}, [hanmacFamilyTenantId, profile, profileRole, rawTenants]);
|
||||
const importParentOptionGroups =
|
||||
buildTenantImportParentOptionGroups(allTenants);
|
||||
const tenantSortResolvers = React.useMemo<
|
||||
|
||||
@@ -16,6 +16,7 @@ import { Label } from "../../../components/ui/label";
|
||||
import { toast } from "../../../components/ui/use-toast";
|
||||
import { fetchMe, fetchTenant, updateTenant } from "../../../lib/adminApi";
|
||||
import { t } from "../../../lib/i18n";
|
||||
import { normalizeAdminRole } from "../../../lib/roles";
|
||||
|
||||
export type SchemaFieldType =
|
||||
| "text"
|
||||
@@ -101,8 +102,9 @@ export function TenantSchemaPage() {
|
||||
queryFn: fetchMe,
|
||||
});
|
||||
|
||||
const profileRole = normalizeAdminRole(profile?.role);
|
||||
const canAccess =
|
||||
profile?.role === "super_admin" || profile?.role === "tenant_admin";
|
||||
profileRole === "super_admin" || profileRole === "tenant_admin";
|
||||
|
||||
const tenantQuery = useQuery({
|
||||
queryKey: ["tenant", tenantId],
|
||||
|
||||
Reference in New Issue
Block a user