폴더단위 권한 제어 기능 추가
This commit is contained in:
@@ -43,11 +43,12 @@ const cloudType = process.env.CLOUD_TYPE;
|
||||
|
||||
//// env의 NODE_ENV에 따라 DB 테이블 이름 설정
|
||||
const env = process.env.NODE_ENV;
|
||||
const tbLog = 'tb_log';
|
||||
const tbLog = env === 'production' ? 'tb_log' : '_test_tb_log';
|
||||
const tbData = env == 'production'? 'tb_data':'_test_tb_data';
|
||||
const tbClickLog = env == 'production'? 'tb_click_log':'_test_tb_click_log';
|
||||
const tbProject = env === 'production' ? 'tb_project' : '_test_tb_project';
|
||||
const tbPermission = env === 'production' ? 'tb_permission' : '_test_tb_permission';
|
||||
const tbFolderPermission = env === 'production' ? 'tb_folder_permission' : '_test_tb_folder_permission';
|
||||
|
||||
// 테스트
|
||||
// const tbLog = env == 'production'? 'tb_log':'tb_log';
|
||||
@@ -281,16 +282,23 @@ async function selectData(projectId, storageType, userInfo, resourcePath) {
|
||||
}
|
||||
|
||||
queryString += `
|
||||
AND ((d.data_permission+32)&`;
|
||||
if (permission) {
|
||||
queryString += `$${paramCounter++}`;
|
||||
values.push(permission);
|
||||
} else {
|
||||
queryString += `(SELECT lev FROM ver4.${tbPermission} WHERE project_id = $${paramCounter++} AND user_id = $${paramCounter++})`;
|
||||
values.push(projectId);
|
||||
values.push(userId);
|
||||
}
|
||||
queryString += `) <> 0`;
|
||||
AND ((d.data_permission+32) & COALESCE(
|
||||
(SELECT lev FROM ver4.${tbFolderPermission}
|
||||
WHERE project_id = d.project_id
|
||||
AND user_id = $${paramCounter++}
|
||||
AND folder_path_key = CASE
|
||||
WHEN d.data_depth = 1 THEN d.path1
|
||||
WHEN d.data_depth = 2 THEN CONCAT(d.path1, '/', d.path2)
|
||||
ELSE CONCAT(d.path1, '/', d.path2, '/', d.path3)
|
||||
END),
|
||||
(SELECT lev FROM ver4.${tbPermission}
|
||||
WHERE project_id = d.project_id
|
||||
AND user_id = $${paramCounter++}),
|
||||
$${paramCounter++}::integer
|
||||
)) <> 0`;
|
||||
values.push(userId);
|
||||
values.push(userId);
|
||||
values.push(parseInt(permission) || 0);
|
||||
|
||||
queryString += `
|
||||
ORDER BY path1, path2, path3, path4, path5, path6, path7, path8;`;
|
||||
@@ -425,16 +433,23 @@ async function selectRemovedData(projectId, storageType, userInfo) {
|
||||
values.push(storageType);
|
||||
|
||||
queryString += `
|
||||
AND ((d.data_permission+32)&`;
|
||||
if (permission) {
|
||||
queryString += `$${paramCounter++}`;
|
||||
values.push(permission);
|
||||
} else {
|
||||
queryString += `(SELECT lev FROM ver4.${tbPermission} WHERE project_id = $${paramCounter++} AND user_id = $${paramCounter++})`;
|
||||
values.push(projectId);
|
||||
values.push(userId);
|
||||
}
|
||||
queryString += `) <> 0`;
|
||||
AND ((d.data_permission+32) & COALESCE(
|
||||
(SELECT lev FROM ver4.${tbFolderPermission}
|
||||
WHERE project_id = d.project_id
|
||||
AND user_id = $${paramCounter++}
|
||||
AND folder_path_key = CASE
|
||||
WHEN d.data_depth = 1 THEN d.path1
|
||||
WHEN d.data_depth = 2 THEN CONCAT(d.path1, '/', d.path2)
|
||||
ELSE CONCAT(d.path1, '/', d.path2, '/', d.path3)
|
||||
END),
|
||||
(SELECT lev FROM ver4.${tbPermission}
|
||||
WHERE project_id = d.project_id
|
||||
AND user_id = $${paramCounter++}),
|
||||
$${paramCounter++}::integer
|
||||
)) <> 0`;
|
||||
values.push(userId);
|
||||
values.push(userId);
|
||||
values.push(parseInt(permission) || 0);
|
||||
|
||||
queryString += `
|
||||
ORDER BY path1, path2, path3, path4, path5, path6, path7, path8;`;
|
||||
@@ -773,6 +788,7 @@ async function insertData(params) {
|
||||
return result;
|
||||
} catch(error) {
|
||||
console.error("insertData err:", error);
|
||||
return { message: 'insertData_failed', error: error };
|
||||
} finally {
|
||||
client.release();
|
||||
}
|
||||
@@ -848,6 +864,7 @@ async function insertLog(params, from) {
|
||||
return result;
|
||||
} catch(error) {
|
||||
console.error("insertLog err:", error);
|
||||
return { message: 'insertLog_failed', error: error };
|
||||
} finally {
|
||||
client.release();
|
||||
}
|
||||
@@ -2328,42 +2345,54 @@ exports.checkTargetExists = async (req, res) => {
|
||||
}
|
||||
|
||||
exports.createFolder = async (req, res) => {
|
||||
const projectId = req.baseUrl.split('/')[1];
|
||||
try {
|
||||
const projectId = req.baseUrl.split('/')[1];
|
||||
|
||||
let { params } = req.body;
|
||||
params.projectId = projectId;
|
||||
let { params } = req.body;
|
||||
params.projectId = projectId;
|
||||
|
||||
let activity = 'createFolder';
|
||||
let folderType = params.folderType;
|
||||
if (folderType) activity = `${activity}-${folderType}`;
|
||||
params.activity = activity;
|
||||
let activity = 'createFolder';
|
||||
let folderType = params.folderType;
|
||||
if (folderType) activity = `${activity}-${folderType}`;
|
||||
params.activity = activity;
|
||||
|
||||
let insertDataResult = await insertData(params);
|
||||
if (insertDataResult.message == 'insertData_success') {
|
||||
let dataIdArr = [];
|
||||
for (let i = 0; i < insertDataResult.rows.length; i++) {
|
||||
let row = insertDataResult.rows[i];
|
||||
dataIdArr.push(row.data_id);
|
||||
}
|
||||
params.dataIdArr = dataIdArr;
|
||||
params.userIp = req.ip;
|
||||
|
||||
let insertLogResult = await insertLog(params);
|
||||
if (insertLogResult.message == 'insertLog_success') {
|
||||
let resultData = {
|
||||
message: 'createFolder_success',
|
||||
projectId: projectId,
|
||||
activity: activity,
|
||||
resourcePath: params.resourcePathArr[0]
|
||||
};
|
||||
|
||||
let io = getIo();
|
||||
io.emit('createFolder_success', resultData);
|
||||
|
||||
res.status(200).json({
|
||||
message: 'createFolder_success',
|
||||
});
|
||||
let insertDataResult = await insertData(params);
|
||||
if (insertDataResult && insertDataResult.message == 'insertData_success') {
|
||||
let dataIdArr = [];
|
||||
for (let i = 0; i < insertDataResult.rows.length; i++) {
|
||||
let row = insertDataResult.rows[i];
|
||||
dataIdArr.push(row.data_id);
|
||||
}
|
||||
params.dataIdArr = dataIdArr;
|
||||
params.userIp = req.ip;
|
||||
|
||||
let insertLogResult = await insertLog(params);
|
||||
if (insertLogResult && insertLogResult.message == 'insertLog_success') {
|
||||
let resultData = {
|
||||
message: 'createFolder_success',
|
||||
projectId: projectId,
|
||||
activity: activity,
|
||||
resourcePath: params.resourcePathArr[0]
|
||||
};
|
||||
|
||||
let io = getIo();
|
||||
io.emit('createFolder_success', resultData);
|
||||
|
||||
return res.status(200).json({
|
||||
message: 'createFolder_success',
|
||||
});
|
||||
}
|
||||
}
|
||||
res.status(500).json({
|
||||
message: 'createFolder_failed',
|
||||
error: '폴더 생성 중 오류가 발생했습니다.'
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("createFolder error:", error);
|
||||
res.status(500).json({
|
||||
message: 'createFolder_failed',
|
||||
error: error.message
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2847,55 +2876,62 @@ exports.relocateTarget = async(req, res) => {
|
||||
}
|
||||
|
||||
exports.removeTarget = async(req, res) => {
|
||||
let { params } = req.body;
|
||||
let permission = JSON.parse(params.userInfoString).permission;
|
||||
let depth = getDepth(params.resourcePathArr[0]);
|
||||
let isRecycleBinModal = params.isRecycleBinModal;
|
||||
try {
|
||||
let { params } = req.body;
|
||||
let permission = JSON.parse(params.userInfoString).permission;
|
||||
let depth = getDepth(params.resourcePathArr[0]);
|
||||
let isRecycleBinModal = params.isRecycleBinModal;
|
||||
|
||||
if (!isRecycleBinModal && (depth == 1 && permission < 191) || (depth >= 2 && permission < 7)) {
|
||||
res.status(200).json({
|
||||
message: 'removeTarget_failed_permission',
|
||||
});
|
||||
} else {
|
||||
const projectId = req.baseUrl.split('/')[1];
|
||||
params.projectId = projectId;
|
||||
if (!isRecycleBinModal && (depth == 1 && permission < 191) || (depth >= 2 && permission < 7)) {
|
||||
return res.status(200).json({
|
||||
message: 'removeTarget_failed_permission',
|
||||
});
|
||||
} else {
|
||||
const projectId = req.baseUrl.split('/')[1];
|
||||
params.projectId = projectId;
|
||||
|
||||
// console.log('!!!!!!!!!!!!!!!!!!!!!! removeTarget');
|
||||
// console.log(params);
|
||||
let activity = `removeTarget_${params.dataType}`;
|
||||
params.activity = activity;
|
||||
|
||||
let activity = `removeTarget_${params.dataType}`;
|
||||
params.activity = activity;
|
||||
let updateDataRemoveResult = await updateDataRemove(params);
|
||||
if (updateDataRemoveResult && updateDataRemoveResult.message == 'updateDataRemove_success') {
|
||||
params.userIp = req.ip;
|
||||
|
||||
let updateDataRemoveResult = await updateDataRemove(params);
|
||||
if (updateDataRemoveResult.message == 'updateDataRemove_success') {
|
||||
params.userIp = req.ip;
|
||||
if (params.dataType == 'file') {
|
||||
let updateLastFolderActDateResult = await updateLastFolderActDate(params.depth3DataIdArr);
|
||||
}
|
||||
|
||||
if (params.dataType == 'file') {
|
||||
let updateLastFolderActDateResult = await updateLastFolderActDate(params.depth3DataIdArr);
|
||||
// if (updateLastFolderActDateResult.message == 'updateLastFolderActDate_success') {
|
||||
// }
|
||||
}
|
||||
|
||||
let insertLogResult = await insertLog(params);
|
||||
if (insertLogResult.message == 'insertLog_success') {
|
||||
|
||||
let resultData = {
|
||||
message: `removeTarget_success`,
|
||||
projectId: projectId,
|
||||
activity: activity,
|
||||
resourcePathArr: params.resourcePathArr,
|
||||
userInfoString: params.userInfoString,
|
||||
isExpiredFolder: params.isExpiredFolder
|
||||
};
|
||||
|
||||
let io = getIo();
|
||||
io.emit('removeTarget_success', resultData);
|
||||
|
||||
res.status(200).json({
|
||||
message: 'removeTarget_success',
|
||||
});
|
||||
let insertLogResult = await insertLog(params);
|
||||
if (insertLogResult && insertLogResult.message == 'insertLog_success') {
|
||||
|
||||
let resultData = {
|
||||
message: `removeTarget_success`,
|
||||
projectId: projectId,
|
||||
activity: activity,
|
||||
resourcePathArr: params.resourcePathArr,
|
||||
userInfoString: params.userInfoString,
|
||||
isExpiredFolder: params.isExpiredFolder
|
||||
};
|
||||
|
||||
let io = getIo();
|
||||
io.emit('removeTarget_success', resultData);
|
||||
|
||||
return res.status(200).json({
|
||||
message: 'removeTarget_success',
|
||||
});
|
||||
}
|
||||
}
|
||||
res.status(500).json({
|
||||
message: 'removeTarget_failed',
|
||||
error: '대상 제거 중 오류가 발생했습니다.'
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("removeTarget error:", error);
|
||||
res.status(500).json({
|
||||
message: 'removeTarget_failed',
|
||||
error: error.message
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user