유저 권한레벨 처리

This commit is contained in:
2025-03-26 15:28:26 +09:00
parent cddd8e6333
commit 894eb17fd8
5 changed files with 118 additions and 87 deletions

View File

@@ -1,4 +1,4 @@
import { authType } from './types';
import { adminAuthLevel, authType } from './types';
export const menuConfig = {
usermanage: {
@@ -11,13 +11,17 @@ export const menuConfig = {
confirm: authType.adminSearchConfirm,
update: authType.adminSearchUpdate,
delete: authType.adminSearchDelete
}
},
view: true,
authLevel: adminAuthLevel.NONE
},
logview: {
title: '사용 이력 조회',
permissions: {
read: authType.adminLogSearchRead
}
},
view: true,
authLevel: adminAuthLevel.NONE
},
authsetting: {
title: '권한 설정',
@@ -25,14 +29,25 @@ export const menuConfig = {
read: authType.authoritySettingRead,
update: authType.authoritySettingUpdate,
delete: authType.authoritySettingDelete
}
},
view: true,
authLevel: adminAuthLevel.NONE
},
caliumrequest: {
title: '칼리움 요청',
permissions: {
read: authType.caliumRequestRead,
update: authType.caliumRequestUpdate
}
},
view: true,
authLevel: adminAuthLevel.NONE
},
datainit: {
title: '데이터 초기화',
permissions: {},
view: false,
test: true,
authLevel: adminAuthLevel.MASTER
}
}
},
@@ -43,13 +58,17 @@ export const menuConfig = {
title: '유저 지표',
permissions: {
read: authType.userIndicatorsRead
}
},
view: true,
authLevel: adminAuthLevel.NONE
},
economicindex: {
title: '경제 지표',
permissions: {
read: authType.economicIndicatorsRead
}
},
view: true,
authLevel: adminAuthLevel.NONE
}
}
},
@@ -62,7 +81,9 @@ export const menuConfig = {
read: authType.userSearchRead,
update: authType.userSearchUpdate,
delete: authType.userSearchDelete
}
},
view: true,
authLevel: adminAuthLevel.NONE
},
landview: {
title: '랜드 정보 조회',
@@ -70,25 +91,33 @@ export const menuConfig = {
read: authType.landRead,
update: authType.landUpdate,
delete: authType.landDelete
}
},
view: true,
authLevel: adminAuthLevel.NONE
},
gamelogview: {
title: '게임 로그 조회',
permissions: {
read: authType.gameLogRead
}
},
view: true,
authLevel: adminAuthLevel.NONE
},
cryptview: {
title: '크립토 조회',
permissions: {
read: authType.cryptoRead
}
},
view: true,
authLevel: adminAuthLevel.NONE
},
businesslogview: {
title: '비즈니스 로그 조회',
permissions: {
read: authType.businessLogRead
}
},
view: true,
authLevel: adminAuthLevel.NONE
}
}
},
@@ -101,7 +130,9 @@ export const menuConfig = {
read: authType.inGameRead,
update: authType.inGameUpdate,
delete: authType.inGameDelete
}
},
view: true,
authLevel: adminAuthLevel.NONE
},
mail: {
title: '우편',
@@ -109,7 +140,9 @@ export const menuConfig = {
read: authType.mailRead,
update: authType.mailUpdate,
delete: authType.mailDelete
}
},
view: true,
authLevel: adminAuthLevel.NONE
},
userblock: {
title: '이용자 제재',
@@ -117,7 +150,9 @@ export const menuConfig = {
read: authType.blackListRead,
update: authType.blackListUpdate,
delete: authType.blackListDelete
}
},
view: true,
authLevel: adminAuthLevel.NONE
},
reportlist: {
title: '신고내역',
@@ -125,7 +160,9 @@ export const menuConfig = {
read: authType.reportRead,
update: authType.reportUpdate,
delete: authType.reportDelete
}
},
view: true,
authLevel: adminAuthLevel.NONE
},
event: {
title: '보상 이벤트 관리',
@@ -133,7 +170,9 @@ export const menuConfig = {
read: authType.eventRead,
update: authType.eventUpdate,
delete: authType.eventDelete
}
},
view: true,
authLevel: adminAuthLevel.NONE
},
landauction: {
title: '랜드 경매 관리',
@@ -141,7 +180,9 @@ export const menuConfig = {
read: authType.landAuctionRead,
update: authType.landAuctionUpdate,
delete: authType.landAuctionDelete
}
},
view: true,
authLevel: adminAuthLevel.NONE
},
battleevent: {
title: '전투시스템 타입 스케줄러',
@@ -149,7 +190,9 @@ export const menuConfig = {
read: authType.battleEventRead,
update: authType.battleEventUpdate,
delete: authType.battleEventDelete
}
},
view: true,
authLevel: adminAuthLevel.NONE
},
}
}

View File

@@ -9,9 +9,8 @@ import { useEffect, useState } from 'react';
import Button from '../button/Button';
import { useLocation } from 'react-router-dom';
import { AuthInfo } from '../../../apis';
import { authType } from '../../../assets/data';
import { menuConfig } from '../../../assets/data/menuConfig';
import { getMenuConfig } from '../../../utils';
import { adminAuthLevel } from '../../../assets/data/types';
const Navi = () => {
const token = sessionStorage.getItem('token');
@@ -71,54 +70,16 @@ const Navi = () => {
}
};
// const menu = [
// {
// title: '운영자 관리',
// link: '/usermanage',
// access: userInfo.auth_list && userInfo.auth_list.some(auth => auth.id === authType.adminSearchRead || auth.id === authType.adminLogSearchRead || auth.id === authType.authoritySettingRead || auth.id === authType.caliumRequestRead),
// submenu: [
// { title: '운영자 조회', link: '/usermanage/adminview', id: authType.adminSearchRead },
// { title: '사용 이력 조회', link: '/usermanage/logview', id: authType.adminLogSearchRead },
// { title: '권한 설정', link: '/usermanage/authsetting', id: authType.authoritySettingRead },
// { title: '칼리움 요청', link: '/usermanage/caliumrequest', id: authType.caliumRequestRead },
// ],
// },
// {
// title: '지표 관리',
// link: '/indexmanage',
// access: userInfo.auth_list && userInfo.auth_list.some(auth => auth.id === authType.userIndicatorsRead || auth.id === authType.economicIndicatorsRead),
// submenu: [
// { title: '유저 지표', link: '/indexmanage/userindex', id: authType.userIndicatorsRead },
// { title: '경제 지표', link: '/indexmanage/economicindex', id: authType.economicIndicatorsRead },
// ],
// },
// {
// title: '운영 정보 관리',
// link: '/datamanage',
// access: userInfo.auth_list && userInfo.auth_list.some(auth => auth.id === authType.userSearchRead || auth.id === authType.contentSearchRead || auth.id === authType.gameLogRead || auth.id === authType.cryptoRead),
// submenu: [
// { title: '유저 조회', link: '/datamanage/userview', id: authType.userIndicatorsRead },
// { title: '컨텐츠 조회', link: '/datamanage/contentsview', id: authType.contentSearchRead },
// { title: '게임 로그 조회', link: '/datamanage/gamelogview', id: authType.gameLogRead },
// { title: '크립토 조회', link: '/datamanage/cryptview', id: authType.cryptoRead },
// ],
// },
// {
// title: '운영 서비스 관리',
// link: '/servicemanage',
// access: userInfo.auth_list && userInfo.auth_list.some(auth => auth.id === authType.inGameRead || auth.id === authType.whiteListRead || auth.id === authType.mailRead
// || auth.id === authType.blackListRead || auth.id === authType.reportRead || auth.id === authType.itemRead || auth.id === authType.eventRead ),
// submenu: [
// { title: '인게임 메시지', link: '/servicemanage/board', id: authType.inGameRead },
// // { title: '화이트리스트', link: '/servicemanage/whitelist', id: authType.whiteListRead },
// { title: '우편', link: '/servicemanage/mail', id: authType.mailRead },
// { title: '이용자 제재', link: '/servicemanage/userblock', id: authType.blackListRead },
// { title: '신고내역', link: '/servicemanage/reportlist', id: authType.reportRead },
// // { title: '아이템 복구 및 삭제', link: '/servicemanage/items', id: authType.itemRead },
// { title: '보상 이벤트 관리', link: '/servicemanage/event', id: authType.eventRead },
// ],
// },
// ];
const isClickable = (submenu) => {
switch (userInfo.auth_level_type) {
case adminAuthLevel.DEVELOPER:
case adminAuthLevel.READER:
case adminAuthLevel.MASTER:
return true;
default:
return submenu.authLevel === adminAuthLevel.NONE && userInfo.auth_list && userInfo.auth_list.some(auth => auth.id === submenu.id);
}
}
return (
<>
@@ -133,14 +94,14 @@ const Navi = () => {
</TopMenu>
)}
<SubMenu>
{item.submenu &&
{item.submenu && userInfo &&
item.submenu.map((submenu, idx) => {
return (
<SubMenuItem key={idx} $isclickable={userInfo.auth_list && userInfo.auth_list.some(auth => auth.id === submenu.id) ? 'true' : 'false'}>
<SubMenuItem key={idx} $isclickable={isClickable(submenu) ? 'true' : 'false'}>
<NavLink
to={userInfo.auth_list && userInfo.auth_list.some(auth => auth.id === submenu.id) ? submenu.link : location.pathname}
to={isClickable(submenu) ? submenu.link : location.pathname}
onClick={e => {
userInfo.auth_list && userInfo.auth_list.some(auth => auth.id === submenu.id) ? handleLink(e) : handleModalClose();
isClickable(submenu) ? handleLink(e) : handleModalClose();
}}>
{submenu.title}
</NavLink>

View File

@@ -29,7 +29,9 @@ const Profile = () => {
const fetchData = async () => {
const token = sessionStorage.getItem('token');
setInfoData(await AuthInfo(token));
await AuthInfo(token).then(data => {
setInfoData(data);
});
};
useEffect(() => {

View File

@@ -1,16 +1,28 @@
import { menuConfig } from '../assets/data/menuConfig';
export const getMenuConfig = (userInfo) => {
return Object.entries(menuConfig).map(([key, group]) => ({
title: group.title,
link: `/${key}`,
access: hasGroupAccess(userInfo, group),
submenu: Object.entries(group.items).map(([itemKey, item]) => ({
title: item.title,
link: `/${key}/${itemKey}`,
id: item.permissions.read
}))
}));
const isLiveEnv = process.env.REACT_APP_ENV === 'live';
return Object.entries(menuConfig)
.map(([key, group]) => {
return {
title: group.title,
link: `/${key}`,
access: hasGroupAccess(userInfo, group),
submenu: Object.entries(group.items)
.filter(([itemKey, item]) => {
if(isLiveEnv) {
if(item.test && item.test === true) return false;
}
return true;
})
.map(([itemKey, item]) => ({
title: item.title,
link: `/${key}/${itemKey}`,
id: item.permissions.read,
authLevel: item.authLevel
}))
}
});
};
// 권한 체크 유틸리티 함수들

View File

@@ -4,6 +4,7 @@ import { AuthModal } from '../components/common';
import { authList } from '../store/authList';
import { INITIAL_CURRENT_PAGE, INITIAL_PAGE_SIZE } from '../assets/data/adminConstants';
import { PageSkeleton } from '../components/Skeleton/PageSkeleton';
import { adminAuthLevel, authType } from '../assets/data/types';
export const useDateTimeState = (initialDate = '') => {
const [date, setDate] = useState(initialDate);
@@ -67,10 +68,22 @@ export const withAuth = (requiredAuth) => (WrappedComponent) => {
);
}
const hasRequiredAuth = userInfo.auth_list &&
userInfo.auth_list.some(auth => auth.id === requiredAuth);
const authLevelPermissions = {
[adminAuthLevel.DEVELOPER]: [authType.levelReader, authType.levelMaster, authType.levelDeveloper],
[adminAuthLevel.MASTER]: [authType.levelReader, authType.levelMaster],
[adminAuthLevel.READER]: [authType.levelReader]
};
if (!hasRequiredAuth) {
const allowedAuthTypes = authLevelPermissions[userInfo.auth_level_type] || [];
const adminAuth = allowedAuthTypes.includes(requiredAuth);
if (adminAuth) {
return <WrappedComponent {...props} />;
}
const hasRequiredAuth = userInfo.auth_list.some(auth => auth.id === requiredAuth);
if (!hasRequiredAuth && !adminAuth) {
return <AuthModal />;
}