明树Git Lab
Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
J
jt_backend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zengfanpei
jt_backend
Commits
0d859b9a
Commit
0d859b9a
authored
May 15, 2026
by
zfp1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
项目列表用户权限控制
parent
39ef5ff0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
0 deletions
+60
-0
projectController.js
controller/projectController.js
+56
-0
errorMessage.js
utils/errorMessage.js
+4
-0
No files found.
controller/projectController.js
View file @
0d859b9a
...
...
@@ -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
}
//集团用户
}
}
/**
* 当数据量比较大的情况,导出分两步走,一步建任务,二步利用定时任务执行任务
* 当前系统数据量较小,暂考虑使用一步导出
...
...
utils/errorMessage.js
View file @
0d859b9a
...
...
@@ -38,6 +38,10 @@ module.exports = {
code
:
40009
,
message
:
"该角色已绑定用户,不能删除!请联系管理员处理。"
},
noUserDepart
:
{
code
:
40010
,
message
:
"用户部门不存在"
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment