유저 권한레벨 처리

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 = { export const menuConfig = {
usermanage: { usermanage: {
@@ -11,13 +11,17 @@ export const menuConfig = {
confirm: authType.adminSearchConfirm, confirm: authType.adminSearchConfirm,
update: authType.adminSearchUpdate, update: authType.adminSearchUpdate,
delete: authType.adminSearchDelete delete: authType.adminSearchDelete
} },
view: true,
authLevel: adminAuthLevel.NONE
}, },
logview: { logview: {
title: '사용 이력 조회', title: '사용 이력 조회',
permissions: { permissions: {
read: authType.adminLogSearchRead read: authType.adminLogSearchRead
} },
view: true,
authLevel: adminAuthLevel.NONE
}, },
authsetting: { authsetting: {
title: '권한 설정', title: '권한 설정',
@@ -25,14 +29,25 @@ export const menuConfig = {
read: authType.authoritySettingRead, read: authType.authoritySettingRead,
update: authType.authoritySettingUpdate, update: authType.authoritySettingUpdate,
delete: authType.authoritySettingDelete delete: authType.authoritySettingDelete
} },
view: true,
authLevel: adminAuthLevel.NONE
}, },
caliumrequest: { caliumrequest: {
title: '칼리움 요청', title: '칼리움 요청',
permissions: { permissions: {
read: authType.caliumRequestRead, read: authType.caliumRequestRead,
update: authType.caliumRequestUpdate 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: '유저 지표', title: '유저 지표',
permissions: { permissions: {
read: authType.userIndicatorsRead read: authType.userIndicatorsRead
} },
view: true,
authLevel: adminAuthLevel.NONE
}, },
economicindex: { economicindex: {
title: '경제 지표', title: '경제 지표',
permissions: { permissions: {
read: authType.economicIndicatorsRead read: authType.economicIndicatorsRead
} },
view: true,
authLevel: adminAuthLevel.NONE
} }
} }
}, },
@@ -62,7 +81,9 @@ export const menuConfig = {
read: authType.userSearchRead, read: authType.userSearchRead,
update: authType.userSearchUpdate, update: authType.userSearchUpdate,
delete: authType.userSearchDelete delete: authType.userSearchDelete
} },
view: true,
authLevel: adminAuthLevel.NONE
}, },
landview: { landview: {
title: '랜드 정보 조회', title: '랜드 정보 조회',
@@ -70,25 +91,33 @@ export const menuConfig = {
read: authType.landRead, read: authType.landRead,
update: authType.landUpdate, update: authType.landUpdate,
delete: authType.landDelete delete: authType.landDelete
} },
view: true,
authLevel: adminAuthLevel.NONE
}, },
gamelogview: { gamelogview: {
title: '게임 로그 조회', title: '게임 로그 조회',
permissions: { permissions: {
read: authType.gameLogRead read: authType.gameLogRead
} },
view: true,
authLevel: adminAuthLevel.NONE
}, },
cryptview: { cryptview: {
title: '크립토 조회', title: '크립토 조회',
permissions: { permissions: {
read: authType.cryptoRead read: authType.cryptoRead
} },
view: true,
authLevel: adminAuthLevel.NONE
}, },
businesslogview: { businesslogview: {
title: '비즈니스 로그 조회', title: '비즈니스 로그 조회',
permissions: { permissions: {
read: authType.businessLogRead read: authType.businessLogRead
} },
view: true,
authLevel: adminAuthLevel.NONE
} }
} }
}, },
@@ -101,7 +130,9 @@ export const menuConfig = {
read: authType.inGameRead, read: authType.inGameRead,
update: authType.inGameUpdate, update: authType.inGameUpdate,
delete: authType.inGameDelete delete: authType.inGameDelete
} },
view: true,
authLevel: adminAuthLevel.NONE
}, },
mail: { mail: {
title: '우편', title: '우편',
@@ -109,7 +140,9 @@ export const menuConfig = {
read: authType.mailRead, read: authType.mailRead,
update: authType.mailUpdate, update: authType.mailUpdate,
delete: authType.mailDelete delete: authType.mailDelete
} },
view: true,
authLevel: adminAuthLevel.NONE
}, },
userblock: { userblock: {
title: '이용자 제재', title: '이용자 제재',
@@ -117,7 +150,9 @@ export const menuConfig = {
read: authType.blackListRead, read: authType.blackListRead,
update: authType.blackListUpdate, update: authType.blackListUpdate,
delete: authType.blackListDelete delete: authType.blackListDelete
} },
view: true,
authLevel: adminAuthLevel.NONE
}, },
reportlist: { reportlist: {
title: '신고내역', title: '신고내역',
@@ -125,7 +160,9 @@ export const menuConfig = {
read: authType.reportRead, read: authType.reportRead,
update: authType.reportUpdate, update: authType.reportUpdate,
delete: authType.reportDelete delete: authType.reportDelete
} },
view: true,
authLevel: adminAuthLevel.NONE
}, },
event: { event: {
title: '보상 이벤트 관리', title: '보상 이벤트 관리',
@@ -133,7 +170,9 @@ export const menuConfig = {
read: authType.eventRead, read: authType.eventRead,
update: authType.eventUpdate, update: authType.eventUpdate,
delete: authType.eventDelete delete: authType.eventDelete
} },
view: true,
authLevel: adminAuthLevel.NONE
}, },
landauction: { landauction: {
title: '랜드 경매 관리', title: '랜드 경매 관리',
@@ -141,7 +180,9 @@ export const menuConfig = {
read: authType.landAuctionRead, read: authType.landAuctionRead,
update: authType.landAuctionUpdate, update: authType.landAuctionUpdate,
delete: authType.landAuctionDelete delete: authType.landAuctionDelete
} },
view: true,
authLevel: adminAuthLevel.NONE
}, },
battleevent: { battleevent: {
title: '전투시스템 타입 스케줄러', title: '전투시스템 타입 스케줄러',
@@ -149,7 +190,9 @@ export const menuConfig = {
read: authType.battleEventRead, read: authType.battleEventRead,
update: authType.battleEventUpdate, update: authType.battleEventUpdate,
delete: authType.battleEventDelete 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 Button from '../button/Button';
import { useLocation } from 'react-router-dom'; import { useLocation } from 'react-router-dom';
import { AuthInfo } from '../../../apis'; import { AuthInfo } from '../../../apis';
import { authType } from '../../../assets/data';
import { menuConfig } from '../../../assets/data/menuConfig';
import { getMenuConfig } from '../../../utils'; import { getMenuConfig } from '../../../utils';
import { adminAuthLevel } from '../../../assets/data/types';
const Navi = () => { const Navi = () => {
const token = sessionStorage.getItem('token'); const token = sessionStorage.getItem('token');
@@ -71,54 +70,16 @@ const Navi = () => {
} }
}; };
// const menu = [ const isClickable = (submenu) => {
// { switch (userInfo.auth_level_type) {
// title: '운영자 관리', case adminAuthLevel.DEVELOPER:
// link: '/usermanage', case adminAuthLevel.READER:
// 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), case adminAuthLevel.MASTER:
// submenu: [ return true;
// { title: '운영자 조회', link: '/usermanage/adminview', id: authType.adminSearchRead }, default:
// { title: '사용 이력 조회', link: '/usermanage/logview', id: authType.adminLogSearchRead }, return submenu.authLevel === adminAuthLevel.NONE && userInfo.auth_list && userInfo.auth_list.some(auth => auth.id === submenu.id);
// { 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 },
// ],
// },
// ];
return ( return (
<> <>
@@ -133,14 +94,14 @@ const Navi = () => {
</TopMenu> </TopMenu>
)} )}
<SubMenu> <SubMenu>
{item.submenu && {item.submenu && userInfo &&
item.submenu.map((submenu, idx) => { item.submenu.map((submenu, idx) => {
return ( 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 <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 => { onClick={e => {
userInfo.auth_list && userInfo.auth_list.some(auth => auth.id === submenu.id) ? handleLink(e) : handleModalClose(); isClickable(submenu) ? handleLink(e) : handleModalClose();
}}> }}>
{submenu.title} {submenu.title}
</NavLink> </NavLink>

View File

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

View File

@@ -1,16 +1,28 @@
import { menuConfig } from '../assets/data/menuConfig'; import { menuConfig } from '../assets/data/menuConfig';
export const getMenuConfig = (userInfo) => { export const getMenuConfig = (userInfo) => {
return Object.entries(menuConfig).map(([key, group]) => ({ const isLiveEnv = process.env.REACT_APP_ENV === 'live';
title: group.title, return Object.entries(menuConfig)
link: `/${key}`, .map(([key, group]) => {
access: hasGroupAccess(userInfo, group), return {
submenu: Object.entries(group.items).map(([itemKey, item]) => ({ title: group.title,
title: item.title, link: `/${key}`,
link: `/${key}/${itemKey}`, access: hasGroupAccess(userInfo, group),
id: item.permissions.read 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 { authList } from '../store/authList';
import { INITIAL_CURRENT_PAGE, INITIAL_PAGE_SIZE } from '../assets/data/adminConstants'; import { INITIAL_CURRENT_PAGE, INITIAL_PAGE_SIZE } from '../assets/data/adminConstants';
import { PageSkeleton } from '../components/Skeleton/PageSkeleton'; import { PageSkeleton } from '../components/Skeleton/PageSkeleton';
import { adminAuthLevel, authType } from '../assets/data/types';
export const useDateTimeState = (initialDate = '') => { export const useDateTimeState = (initialDate = '') => {
const [date, setDate] = useState(initialDate); const [date, setDate] = useState(initialDate);
@@ -67,10 +68,22 @@ export const withAuth = (requiredAuth) => (WrappedComponent) => {
); );
} }
const hasRequiredAuth = userInfo.auth_list && const authLevelPermissions = {
userInfo.auth_list.some(auth => auth.id === requiredAuth); [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 />; return <AuthModal />;
} }