260714_01_ENH: 테스트 서버에서 기동 후 중간 테스트를 위한 커밋
This commit is contained in:
80
src/utils/listAccess.ts
Normal file
80
src/utils/listAccess.ts
Normal file
@@ -0,0 +1,80 @@
|
||||
import { ListHeaderAssignConst, ListHeaderConst } from "@/const/listConst";
|
||||
import { CONTACT_INTERVIEWER_ROLE, FIELD_INTERVIEWER_ROLE } from "@/const/userConst";
|
||||
import { ListIsUse, type ListFilter, type listHeader } from "@/types/list";
|
||||
import { isExternalManager, isFieldWorkUser, isInternalManager } from "@/utils/userRole";
|
||||
|
||||
type ListAccessUser = {
|
||||
userRole?: number | null;
|
||||
userId?: string | null;
|
||||
userCmpn?: string | null;
|
||||
};
|
||||
|
||||
const toForcedValue = (value?: string | null) => {
|
||||
const trimmed = value?.trim();
|
||||
return trimmed ? [trimmed] : [""];
|
||||
};
|
||||
|
||||
export const isListHeaderVisibleByAccess = (header: listHeader, userRole?: number | null) =>
|
||||
isFieldWorkUser(userRole) ? header.useColView && header.useIntrvwerView : header.useColView;
|
||||
|
||||
export const isListFilterVisibleByAccess = (header: listHeader, userRole?: number | null) =>
|
||||
isFieldWorkUser(userRole) ? header.useFilter && header.useIntrvwerView : header.useFilter;
|
||||
|
||||
// 컨택 진행 화면(/list/contact)은 역할과 무관하게 면접원 노출 항목만 보여준다.
|
||||
export const isListFieldVisibleForContact = (header: listHeader) => header.useIntrvwerView;
|
||||
|
||||
// SID는 항상 읽기 전용. internal 권한은 그 외 전부 수정 가능, 그 외 역할은 헤더별 면접원 수정가능 여부를 따른다.
|
||||
export const isListFieldEditableForContact = (header: listHeader, userRole?: number | null) =>
|
||||
header.listHderTy !== ListHeaderConst.SID && (isInternalManager(userRole) || header.useIntrvwerEdit);
|
||||
|
||||
export const getLockedListFilterHeaderTypes = (userRole?: number | null) => {
|
||||
const lockedTypes = new Set<number>();
|
||||
|
||||
if (isFieldWorkUser(userRole)) {
|
||||
lockedTypes.add(ListHeaderConst.IS_USE);
|
||||
}
|
||||
|
||||
if (userRole === CONTACT_INTERVIEWER_ROLE) {
|
||||
lockedTypes.add(ListHeaderConst.CONTACT_INTERVIEWER);
|
||||
}
|
||||
|
||||
if (userRole === FIELD_INTERVIEWER_ROLE) {
|
||||
lockedTypes.add(ListHeaderConst.FIELD_INTERVIEWER);
|
||||
}
|
||||
|
||||
if (isExternalManager(userRole)) {
|
||||
lockedTypes.add(ListHeaderConst.OUTSOURCE);
|
||||
}
|
||||
|
||||
return lockedTypes;
|
||||
};
|
||||
|
||||
export const applyListAccessFilter = (listFilter: ListFilter, user: ListAccessUser): ListFilter => {
|
||||
const assignUserMap = {
|
||||
[ListHeaderAssignConst.OUTSOURCE]: listFilter.assignUserMap?.[ListHeaderAssignConst.OUTSOURCE] ?? [],
|
||||
[ListHeaderAssignConst.CONTACT_INTERVIEWER]:
|
||||
listFilter.assignUserMap?.[ListHeaderAssignConst.CONTACT_INTERVIEWER] ?? [],
|
||||
[ListHeaderAssignConst.FIELD_INTERVIEWER]:
|
||||
listFilter.assignUserMap?.[ListHeaderAssignConst.FIELD_INTERVIEWER] ?? [],
|
||||
};
|
||||
|
||||
const listUseSet = isFieldWorkUser(user.userRole) ? [ListIsUse.USABLE] : listFilter.listUseSet;
|
||||
|
||||
if (isExternalManager(user.userRole)) {
|
||||
assignUserMap[ListHeaderAssignConst.OUTSOURCE] = toForcedValue(user.userCmpn);
|
||||
}
|
||||
|
||||
if (user.userRole === CONTACT_INTERVIEWER_ROLE) {
|
||||
assignUserMap[ListHeaderAssignConst.CONTACT_INTERVIEWER] = toForcedValue(user.userId);
|
||||
}
|
||||
|
||||
if (user.userRole === FIELD_INTERVIEWER_ROLE) {
|
||||
assignUserMap[ListHeaderAssignConst.FIELD_INTERVIEWER] = toForcedValue(user.userId);
|
||||
}
|
||||
|
||||
return {
|
||||
...listFilter,
|
||||
listUseSet,
|
||||
assignUserMap,
|
||||
};
|
||||
};
|
||||
20
src/utils/userRole.ts
Normal file
20
src/utils/userRole.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { EXTERNAL_USER_ROLE_GROUP, FW_USER_ROLE_GROUP } from "@/const/userConst";
|
||||
|
||||
const getUserRoleGroup = (userRole?: number | null) => {
|
||||
if (userRole == null) return undefined;
|
||||
return Math.floor(userRole / 1000);
|
||||
};
|
||||
|
||||
export const isFieldWorkUser = (userRole?: number | null) =>
|
||||
getUserRoleGroup(userRole) === FW_USER_ROLE_GROUP;
|
||||
|
||||
export const isExternalManager = (userRole?: number | null) =>
|
||||
getUserRoleGroup(userRole) === EXTERNAL_USER_ROLE_GROUP;
|
||||
|
||||
export const isInternalManager = (userRole?: number | null) => {
|
||||
const userRoleGroup = getUserRoleGroup(userRole);
|
||||
return userRoleGroup != null && userRoleGroup < EXTERNAL_USER_ROLE_GROUP;
|
||||
};
|
||||
|
||||
export const isManager = (userRole?: number | null) =>
|
||||
isInternalManager(userRole) || isExternalManager(userRole);
|
||||
Reference in New Issue
Block a user