[메뉴 권한 1차 작업]
This commit is contained in:
345
types/permissions.ts
Normal file
345
types/permissions.ts
Normal file
@@ -0,0 +1,345 @@
|
||||
/**
|
||||
* 권한 시스템 타입 정의
|
||||
*
|
||||
* 2자리 계층 코드 시스템을 사용하여 메뉴 > 페이지 > 컴포넌트 계층 구조를 표현합니다.
|
||||
*
|
||||
* 코드 규칙:
|
||||
* - 메뉴: M01, M02, M03, M04...
|
||||
* - 페이지: P0101 (M01 하위), P0201 (M02 하위), P0501 (독립 페이지)...
|
||||
* - 컴포넌트: C010101 (P0101 하위), C010102 (P0101 하위)...
|
||||
*/
|
||||
|
||||
// 리소스 타입 정의 (메뉴, 페이지, 컴포넌트)
|
||||
export type ResourceType = "menu" | "page" | "component";
|
||||
|
||||
// 개별 리소스 객체 (계층 구조 지원)
|
||||
export interface Resource {
|
||||
oid: number; // OID (고유 식별자)
|
||||
code: string; // 2자리 계층 코드 (M01, P0101, C010101)
|
||||
name: string; // 리소스 이름
|
||||
parentCode?: string; // 부모 리소스 코드 (계층 구조)
|
||||
type: ResourceType; // 리소스 타입
|
||||
path?: string; // 페이지 경로 (페이지 타입만)
|
||||
sortOrder: number; // 정렬 순서
|
||||
description?: string; // 리소스 설명
|
||||
componentType?: string; // 컴포넌트 세부 타입 (버튼, 그리드 등)
|
||||
children?: Resource[]; // 자식 리소스들 (계층 구조)
|
||||
}
|
||||
|
||||
// 사용자 권한 구조 (계층적 리소스 관리)
|
||||
export interface UserPermissions {
|
||||
resources: {
|
||||
menus: Resource[]; // 메뉴 리소스들 (M01, M02...)
|
||||
pages: Resource[]; // 페이지 리소스들 (P0101, P0201...)
|
||||
components: Resource[]; // 컴포넌트 리소스들 (C010101, C010102...)
|
||||
};
|
||||
}
|
||||
|
||||
// 권한 체크 결과 타입 (권한 스토어에서 제공하는 함수들)
|
||||
export interface PermissionCheckResult {
|
||||
// 기존 호환성 함수들 (경로/코드 기반)
|
||||
hasPagePermission: (page: string) => boolean; // 페이지 경로로 권한 체크
|
||||
hasMenuPermission: (menu: string) => boolean; // 메뉴 코드로 권한 체크
|
||||
hasComponentPermission: (component: string) => boolean; // 컴포넌트 코드로 권한 체크
|
||||
|
||||
// 계층 구조를 고려한 권한 체크 함수들
|
||||
hasResourcePermission: (resourceCode: string) => boolean; // 리소스 코드로 권한 체크
|
||||
getResourceByCode: (code: string) => Resource | undefined; // 코드로 리소스 조회
|
||||
getResourceByPath: (path: string) => Resource | undefined; // 경로로 리소스 조회
|
||||
getChildResources: (parentCode: string) => Resource[]; // 부모의 자식 리소스들 조회
|
||||
}
|
||||
|
||||
// 권한 종류별 상수 (기존 호환성 유지용)
|
||||
export const PERMISSION_TYPES = {
|
||||
PAGE: "pagePermissions",
|
||||
MENU: "menuPermissions",
|
||||
COMPONENT: "componentPermissions",
|
||||
} as const;
|
||||
|
||||
/**
|
||||
* 가데이터용 권한 목록 (개발/테스트용)
|
||||
*
|
||||
* 2자리 계층 코드 시스템을 사용한 실제 권한 데이터 예시입니다.
|
||||
*
|
||||
* 계층 구조:
|
||||
* - M01 (관리자 메뉴) > P0101~P0105 (관리자 페이지들) > C010101~C010106 (컴포넌트들)
|
||||
* - M02 (사용자 메뉴) > P0201~P0202 (사용자 페이지들)
|
||||
* - P0501~P0504 (독립 페이지들: 홈, 로그인, 회원가입, 소개)
|
||||
* - P0601~P0602 (테스트 페이지들)
|
||||
* - P0701 (팝업 페이지들)
|
||||
*/
|
||||
export const MOCK_PERMISSIONS: UserPermissions = {
|
||||
resources: {
|
||||
// 메뉴 리소스들 (최상위 레벨)
|
||||
menus: [
|
||||
{
|
||||
oid: 1,
|
||||
code: "M01",
|
||||
name: "테스트 메뉴",
|
||||
type: "menu",
|
||||
sortOrder: 1,
|
||||
description: "테스트 관련 메뉴",
|
||||
},
|
||||
{
|
||||
oid: 2,
|
||||
code: "M02",
|
||||
name: "관리자 메뉴",
|
||||
type: "menu",
|
||||
sortOrder: 2,
|
||||
description: "관리자 전용 메뉴",
|
||||
},
|
||||
],
|
||||
|
||||
// 페이지 리소스들 (화면 메뉴 구성에 맞춤)
|
||||
pages: [
|
||||
// 테스트 메뉴 하위 페이지들 (M01 > P0101~P0115)
|
||||
{
|
||||
oid: 5,
|
||||
code: "P0101",
|
||||
name: "테스트",
|
||||
type: "page",
|
||||
path: "/test",
|
||||
parentCode: "M01",
|
||||
sortOrder: 1,
|
||||
description: "기본 테스트 페이지",
|
||||
},
|
||||
{
|
||||
oid: 6,
|
||||
code: "P0102",
|
||||
name: "ivg",
|
||||
type: "page",
|
||||
path: "/test/igv",
|
||||
parentCode: "M01",
|
||||
sortOrder: 2,
|
||||
description: "IGV 테스트 페이지",
|
||||
},
|
||||
{
|
||||
oid: 7,
|
||||
code: "P0103",
|
||||
name: "ivg2",
|
||||
type: "page",
|
||||
path: "/test/igv2",
|
||||
parentCode: "M01",
|
||||
sortOrder: 3,
|
||||
description: "IGV2 테스트 페이지",
|
||||
},
|
||||
{
|
||||
oid: 8,
|
||||
code: "P0104",
|
||||
name: "pathway",
|
||||
type: "page",
|
||||
path: "/test/pathway",
|
||||
parentCode: "M01",
|
||||
sortOrder: 4,
|
||||
description: "경로 분석 페이지",
|
||||
},
|
||||
{
|
||||
oid: 9,
|
||||
code: "P0105",
|
||||
name: "pathway2",
|
||||
type: "page",
|
||||
path: "/test/pathway2",
|
||||
parentCode: "M01",
|
||||
sortOrder: 5,
|
||||
description: "경로 분석 페이지 2",
|
||||
},
|
||||
{
|
||||
oid: 10,
|
||||
code: "P0106",
|
||||
name: "pathway3",
|
||||
type: "page",
|
||||
path: "/test/pathway3",
|
||||
parentCode: "M01",
|
||||
sortOrder: 6,
|
||||
description: "경로 분석 페이지 3",
|
||||
},
|
||||
{
|
||||
oid: 11,
|
||||
code: "P0107",
|
||||
name: "pathway4",
|
||||
type: "page",
|
||||
path: "/test/pathway4",
|
||||
parentCode: "M01",
|
||||
sortOrder: 7,
|
||||
description: "경로 분석 페이지 4",
|
||||
},
|
||||
{
|
||||
oid: 12,
|
||||
code: "P0108",
|
||||
name: "pathwayjson",
|
||||
type: "page",
|
||||
path: "/test/pathwayJson",
|
||||
parentCode: "M01",
|
||||
sortOrder: 8,
|
||||
description: "경로 분석 JSON 페이지",
|
||||
},
|
||||
{
|
||||
oid: 13,
|
||||
code: "P0109",
|
||||
name: "배양그래프",
|
||||
type: "page",
|
||||
path: "/test/culture-graph",
|
||||
parentCode: "M01",
|
||||
sortOrder: 9,
|
||||
description: "배양 그래프 페이지",
|
||||
},
|
||||
{
|
||||
oid: 14,
|
||||
code: "P0110",
|
||||
name: "배양그래프 멀티",
|
||||
type: "page",
|
||||
path: "/test/culture-graph-multi",
|
||||
parentCode: "M01",
|
||||
sortOrder: 10,
|
||||
description: "배양 그래프 멀티 페이지",
|
||||
},
|
||||
{
|
||||
oid: 15,
|
||||
code: "P0111",
|
||||
name: "배양그래프 탭",
|
||||
type: "page",
|
||||
path: "/test/culture-graph-tab",
|
||||
parentCode: "M01",
|
||||
sortOrder: 11,
|
||||
description: "배양 그래프 탭 페이지",
|
||||
},
|
||||
{
|
||||
oid: 16,
|
||||
code: "P0112",
|
||||
name: "tui-grid",
|
||||
type: "page",
|
||||
path: "/tui",
|
||||
parentCode: "M01",
|
||||
sortOrder: 12,
|
||||
description: "TUI 그리드 페이지",
|
||||
},
|
||||
{
|
||||
oid: 17,
|
||||
code: "P0113",
|
||||
name: "리소스",
|
||||
type: "page",
|
||||
path: "/admin/resource",
|
||||
parentCode: "M01",
|
||||
sortOrder: 13,
|
||||
description: "리소스 관리 페이지",
|
||||
},
|
||||
{
|
||||
oid: 18,
|
||||
code: "P0114",
|
||||
name: "sample",
|
||||
type: "page",
|
||||
path: "/sampleList",
|
||||
parentCode: "M01",
|
||||
sortOrder: 14,
|
||||
description: "샘플 목록 페이지",
|
||||
},
|
||||
{
|
||||
oid: 19,
|
||||
code: "P0115",
|
||||
name: "공용 기능 테스트",
|
||||
type: "page",
|
||||
path: "/test/common-test",
|
||||
parentCode: "M01",
|
||||
sortOrder: 15,
|
||||
description: "공용 기능 테스트 페이지",
|
||||
},
|
||||
|
||||
// 관리자 메뉴 하위 페이지들 (M02 > P0201~P0203)
|
||||
{
|
||||
oid: 20,
|
||||
code: "P0201",
|
||||
name: "접속기록",
|
||||
type: "page",
|
||||
path: "/admin/logs",
|
||||
parentCode: "M02",
|
||||
sortOrder: 1,
|
||||
description: "사용자 접속 기록 관리",
|
||||
},
|
||||
{
|
||||
oid: 21,
|
||||
code: "P0202",
|
||||
name: "공통코드",
|
||||
type: "page",
|
||||
path: "/admin/codes",
|
||||
parentCode: "M02",
|
||||
sortOrder: 2,
|
||||
description: "공통 코드 관리",
|
||||
},
|
||||
{
|
||||
oid: 22,
|
||||
code: "P0203",
|
||||
name: "프로그램",
|
||||
type: "page",
|
||||
path: "/admin/programs",
|
||||
parentCode: "M02",
|
||||
sortOrder: 3,
|
||||
description: "프로그램 관리",
|
||||
},
|
||||
],
|
||||
|
||||
// 컴포넌트 리소스들 (페이지 하위)
|
||||
components: [
|
||||
// 테스트 페이지 하위 컴포넌트들 (P0101 > C010101~C010106)
|
||||
{
|
||||
oid: 19,
|
||||
code: "C010101",
|
||||
name: "삭제 버튼",
|
||||
type: "component",
|
||||
componentType: "button",
|
||||
parentCode: "P0101",
|
||||
sortOrder: 1,
|
||||
description: "테스트 삭제 버튼",
|
||||
},
|
||||
{
|
||||
oid: 20,
|
||||
code: "C010102",
|
||||
name: "수정 버튼",
|
||||
type: "component",
|
||||
componentType: "button",
|
||||
parentCode: "P0101",
|
||||
sortOrder: 2,
|
||||
description: "테스트 수정 버튼",
|
||||
},
|
||||
{
|
||||
oid: 21,
|
||||
code: "C010103",
|
||||
name: "내보내기 버튼",
|
||||
type: "component",
|
||||
componentType: "button",
|
||||
parentCode: "P0101",
|
||||
sortOrder: 3,
|
||||
description: "테스트 내보내기 버튼",
|
||||
},
|
||||
{
|
||||
oid: 22,
|
||||
code: "C010104",
|
||||
name: "가져오기 버튼",
|
||||
type: "component",
|
||||
componentType: "button",
|
||||
parentCode: "P0101",
|
||||
sortOrder: 4,
|
||||
description: "테스트 가져오기 버튼",
|
||||
},
|
||||
{
|
||||
oid: 23,
|
||||
code: "C010105",
|
||||
name: "생성 버튼",
|
||||
type: "component",
|
||||
componentType: "button",
|
||||
parentCode: "P0101",
|
||||
sortOrder: 5,
|
||||
description: "테스트 생성 버튼",
|
||||
},
|
||||
{
|
||||
oid: 24,
|
||||
code: "C010106",
|
||||
name: "보기 버튼",
|
||||
type: "component",
|
||||
componentType: "button",
|
||||
parentCode: "P0101",
|
||||
sortOrder: 6,
|
||||
description: "테스트 상세보기 버튼",
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user