明树Git Lab

Commit 0d859b9a authored by zfp1's avatar zfp1

项目列表用户权限控制

parent 39ef5ff0
......@@ -1208,6 +1208,11 @@ async function deleteProject(req, res, next) {
}
}
/**
*
* 如果用户是项目公司,则只看见自己公司的项目
* 如果用户是非项目公司,则看见所有项目
*/
async function listProject(req, res, next) {
try {
let page = req.body.page || 1;
......@@ -1275,6 +1280,13 @@ async function listProject(req, res, next) {
if (req.body.projectId) {
search.where.id = req.body.projectId;
}
/**
* 用户权限控制
*/
let xmCompanyUser = await getXmCompanyUser(req, res, next);
if (xmCompanyUser.type == 2) {
search.where.projectCreator = { [Op.in]: xmCompanyUser.userIds };
}
console.log(search)
search.raw = true
let ret = await DB.Project.findAndCountAll(search);
......@@ -1286,6 +1298,50 @@ async function listProject(req, res, next) {
}
async function getXmCompanyUser(req, res, next) {
let userDepart = await DB.UserDepart.findOne({ where: { userId: req.user.id }, raw: true });
if (!(userDepart && userDepart.departId)) {
return res.sendError(errorMessage.noUserDepart);
}
let curentDepart = await DB.Depart.findOne({ where: { id: userDepart.departId }, raw: true });
if (!(curentDepart && curentDepart.id)) {
return res.sendError(errorMessage.noUserDepart);
}
let parentIds = curentDepart.parentIds ? curentDepart.parentIds.split(",") : [];
if (parentIds.includes(86) || parentIds.includes('86') || curentDepart.id == 86) {
let pidStr = "";
if (curentDepart.id == 86) {
pidStr = curentDepart.parentIds + curentDepart.id;
} else
if (curentDepart.parentId == 86) { //项目公司
pidStr = curentDepart.parentIds + curentDepart.id;// 为了查询currentDepart.id所有部门
} else {
// 项目公司下属部门
const index = parentIds.indexOf(86);
const result = index !== -1
? parentIds.slice(0, index + 1)
: parentIds;
pidStr = result.join(",");
}
console.log("pidStr", pidStr) //项目公司部门id字符串
let departs = await DB.Depart.findAll({
where: {
parentIds: { [Op.like]: `%${pidStr}%` }
}, raw: true
});
departs.push(curentDepart); //加上当前部门
console.log("departs", departs) //项目公司下属部门信息
let departIds = departs.map(o => { return o.id });
let userDeparts = await DB.UserDepart.findAll({ where: { departId: { [Op.in]: departIds } }, raw: true });
let userIds = userDeparts.map(o => { return o.userId });
return { type: 2, userIds };
} else if (parentIds.includes(40) || parentIds.includes('40')) {
//在集团下,非项目公司,目前因为部门没有处理,暂时止如此处理
return { type: 1 } //集团用户
}
}
/**
* 当数据量比较大的情况,导出分两步走,一步建任务,二步利用定时任务执行任务
* 当前系统数据量较小,暂考虑使用一步导出
......
......@@ -38,6 +38,10 @@ module.exports = {
code: 40009,
message: "该角色已绑定用户,不能删除!请联系管理员处理。"
},
noUserDepart : {
code: 40010,
message: "用户部门不存在"
},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment