Enhance SUPER_ADMIN middleware and permission utility for improved access control

- Updated the `requireSuperAdmin` middleware to allow users with `userType` as 'SUPER_ADMIN' to access management functionalities, even if their `companyCode` is not '*'.
- Modified the `isSuperAdmin` utility function to recognize users as SUPER_ADMIN based solely on their `userType`, simplifying the access validation logic.
- These changes ensure that SUPER_ADMIN users maintain their management capabilities across company transitions, enhancing the flexibility and security of the application.
This commit is contained in:
kjs
2026-04-02 10:05:38 +09:00
parent 775d698d06
commit d8aaacb8f7
2 changed files with 7 additions and 4 deletions

View File

@@ -15,6 +15,7 @@ export interface AuthenticatedRequest extends Request {
userId: string;
userName: string;
companyCode: string;
userType?: string;
userLang?: string;
};
}
@@ -47,8 +48,9 @@ export const requireSuperAdmin = (
return;
}
// 슈퍼관리자 권한 확인 (회사코드가 '*'인 사용자)
if (req.user.companyCode !== "*") {
// 슈퍼관리자 권한 확인 (회사코드가 '*'이거나 userType이 'SUPER_ADMIN'인 사용자)
// 회사전환 후에도 SUPER_ADMIN은 관리 기능에 접근 가능해야 함
if (req.user.companyCode !== "*" && req.user.userType !== "SUPER_ADMIN") {
logger.warn("DDL 실행 시도 - 권한 부족", {
userId: req.user.userId,
companyCode: req.user.companyCode,
@@ -167,7 +169,7 @@ export const validateDDLPermission = (
* 사용자가 슈퍼관리자인지 확인하는 유틸리티 함수
*/
export const isSuperAdmin = (user: AuthenticatedRequest["user"]): boolean => {
return user?.companyCode === "*";
return user?.companyCode === "*" || user?.userType === "SUPER_ADMIN";
};
/**

View File

@@ -21,7 +21,8 @@ export enum PermissionLevel {
*/
export function isSuperAdmin(user?: PersonBean | null): boolean {
if (!user) return false;
return user.companyCode === "*" && user.userType === "SUPER_ADMIN";
// 회사전환 후에도 userType이 SUPER_ADMIN이면 최고관리자로 인정
return user.userType === "SUPER_ADMIN";
}
/**