Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
T
ts-api-demo
Project
Project
Details
Activity
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
wmvm
ts-api-demo
Commits
84f83c6c
Commit
84f83c6c
authored
Sep 06, 2024
by
ml
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改
parent
1a4f0695
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
44 deletions
+43
-44
aclRoleAuth.control.ts
src/functional/mvc/control/aclRoleAuth.control.ts
+1
-1
aclRoleAuth.service.ts
src/functional/mvc/service/aclRoleAuth.service.ts
+27
-2
userOpt.service.ts
src/functional/mvc/service/userOpt.service.ts
+15
-41
No files found.
src/functional/mvc/control/aclRoleAuth.control.ts
View file @
84f83c6c
...
@@ -33,7 +33,7 @@ export const getAuthTree = async (req: any, aclAuthPageVO: AclAuthPageVO) => {
...
@@ -33,7 +33,7 @@ export const getAuthTree = async (req: any, aclAuthPageVO: AclAuthPageVO) => {
let
func_name
=
"aclRoleAuthCtrl.getAuthTree"
;
let
func_name
=
"aclRoleAuthCtrl.getAuthTree"
;
let
cmd
=
req
.
path
;
let
cmd
=
req
.
path
;
try
{
try
{
let
res
=
await
aclRoleAuthService
.
getAuthTree
();
let
res
=
await
aclRoleAuthService
.
getAuthTree
(
[]
);
return
Res3Utils
.
result
(
res
);
return
Res3Utils
.
result
(
res
);
}
}
catch
(
e
)
{
catch
(
e
)
{
...
...
src/functional/mvc/service/aclRoleAuth.service.ts
View file @
84f83c6c
...
@@ -87,10 +87,11 @@ export const authList = async (aclAuthPageVO: AclAuthPageVO) => {
...
@@ -87,10 +87,11 @@ export const authList = async (aclAuthPageVO: AclAuthPageVO) => {
return
resList
;
return
resList
;
};
};
export
const
getAuthTree
=
async
()
=>
{
export
const
getAuthTree
=
async
(
dbAuthList
:
any
[]
)
=>
{
let
authM
=
{};
let
authM
=
{};
let
authList
:
any
=
[]
// 需要返回给前端tree 数组
let
authList
:
any
=
[]
// 需要返回给前端tree 数组
let
tmp
=
await
getAllAuthListSorted
();
//存在就用入参的权限构造树 不存在则查询
let
tmp
=
dbAuthList
.
length
?
dbAuthList
:
await
getAllAuthListSorted
();
for
(
let
auth
of
tmp
)
{
for
(
let
auth
of
tmp
)
{
authM
[
auth
.
id
]
=
auth
;
authM
[
auth
.
id
]
=
auth
;
let
pid
=
auth
.
pid
;
let
pid
=
auth
.
pid
;
...
@@ -755,3 +756,27 @@ export const getUserRoleListByUids = async function (uids: number[]) {
...
@@ -755,3 +756,27 @@ export const getUserRoleListByUids = async function (uids: number[]) {
}
}
/**
* 获取用户权限、权限树
* @param userId
*/
export
async
function
getUserAclAndTree
(
userId
:
number
)
{
let
roleIDArr
=
await
getRoleIDArr
(
userId
);
let
roleSet
=
await
getRole
(
roleIDArr
);
let
authArr
;
if
(
await
_hashSuper
(
roleIDArr
))
{
authArr
=
await
getAllAuthListSorted
()
}
else
{
let
authIDArr
=
await
getAuthIDArr
(
roleIDArr
);
authArr
=
await
getAuth
(
authIDArr
);
}
let
authSet
=
authArr
.
map
(
item
=>
item
.
url
);
let
authTree
=
authArr
.
length
?
await
getAuthTree
(
authArr
)
:
[];
authSet
=
Array
.
from
(
new
Set
(
authSet
))
return
{
roleSet
,
authSet
,
role_ids
:
roleIDArr
.
toString
(),
authTree
}
}
src/functional/mvc/service/userOpt.service.ts
View file @
84f83c6c
...
@@ -10,7 +10,7 @@ import { getDepartmentPositionByUid, getOneAclUserByAccount, getOneAclUserByUid
...
@@ -10,7 +10,7 @@ import { getDepartmentPositionByUid, getOneAclUserByAccount, getOneAclUserByUid
import
{
RedisVal
}
from
"../../../constant/redis-val"
;
import
{
RedisVal
}
from
"../../../constant/redis-val"
;
import
Config
from
"../../../../config"
;
import
Config
from
"../../../../config"
;
import
*
as
userOptLogService
from
"./userOptLog.service"
;
import
*
as
userOptLogService
from
"./userOptLog.service"
;
import
{
getRoleByUser
}
from
"../service/aclRoleAuth.service"
;
import
{
getRoleByUser
,
getUserAclAndTree
}
from
"../service/aclRoleAuth.service"
;
const
Otplib
=
require
(
'otplib'
);
const
Otplib
=
require
(
'otplib'
);
...
@@ -29,7 +29,7 @@ export const getInfo = async (currentUserId: number | any, sessionId: string) =>
...
@@ -29,7 +29,7 @@ export const getInfo = async (currentUserId: number | any, sessionId: string) =>
ApiAssert
.
isFalse
(
ErrorCode
.
ACCOUNT_LOCK
,
dbUserInfo
.
user_status
===
AclUserInfoConst
.
USER_STATUS
.
LOCK
);
ApiAssert
.
isFalse
(
ErrorCode
.
ACCOUNT_LOCK
,
dbUserInfo
.
user_status
===
AclUserInfoConst
.
USER_STATUS
.
LOCK
);
ApiAssert
.
isFalse
(
ErrorCode
.
ACCOUNT_STOP
,
dbUserInfo
.
user_status
===
AclUserInfoConst
.
USER_STATUS
.
STOP
);
ApiAssert
.
isFalse
(
ErrorCode
.
ACCOUNT_STOP
,
dbUserInfo
.
user_status
===
AclUserInfoConst
.
USER_STATUS
.
STOP
);
let
{
roleSet
,
authSet
}
=
await
aclRoleAuthService
.
getUserAcl
(
dbUserInfo
.
user_id
);
let
{
roleSet
,
authSet
,
role_ids
,
authTree
}
=
await
aclRoleAuthService
.
getUserAclAndTree
(
dbUserInfo
.
user_id
);
let
data
=
{
let
data
=
{
...
@@ -44,6 +44,8 @@ export const getInfo = async (currentUserId: number | any, sessionId: string) =>
...
@@ -44,6 +44,8 @@ export const getInfo = async (currentUserId: number | any, sessionId: string) =>
roleSet
:
roleSet
,
roleSet
:
roleSet
,
authSet
:
authSet
,
authSet
:
authSet
,
hasTotp
:
dbUserInfo
&&
dbUserInfo
.
totp_encrypt
?
1
:
0
,
hasTotp
:
dbUserInfo
&&
dbUserInfo
.
totp_encrypt
?
1
:
0
,
authTree
:
authTree
,
role_ids
:
role_ids
?
role_ids
:
""
}
}
await
dealDepartmentAndPosition
(
data
);
await
dealDepartmentAndPosition
(
data
);
return
data
return
data
...
@@ -55,7 +57,7 @@ export const getInfoByUserId = async (user_id: number | any) => {
...
@@ -55,7 +57,7 @@ export const getInfoByUserId = async (user_id: number | any) => {
ApiAssert
.
isNotEmpty
(
ErrorCode
.
USER_NOT_EXIST
,
dbUserInfo
);
ApiAssert
.
isNotEmpty
(
ErrorCode
.
USER_NOT_EXIST
,
dbUserInfo
);
let
{
roleSet
,
authSet
}
=
await
aclRoleAuthService
.
getUserAcl
(
dbUserInfo
.
user_id
);
let
{
roleSet
,
authSet
,
role_ids
,
authTree
}
=
await
aclRoleAuthService
.
getUserAclAndTree
(
dbUserInfo
.
user_id
);
let
data
=
{
let
data
=
{
...
@@ -66,7 +68,9 @@ export const getInfoByUserId = async (user_id: number | any) => {
...
@@ -66,7 +68,9 @@ export const getInfoByUserId = async (user_id: number | any) => {
remark
:
dbUserInfo
.
remark
,
remark
:
dbUserInfo
.
remark
,
user_status
:
dbUserInfo
.
user_status
,
user_status
:
dbUserInfo
.
user_status
,
roleSet
:
roleSet
,
roleSet
:
roleSet
,
authSet
:
authSet
authSet
:
authSet
,
authTree
:
authTree
,
role_ids
:
role_ids
?
role_ids
:
""
}
}
await
dealDepartmentAndPosition
(
data
);
await
dealDepartmentAndPosition
(
data
);
return
data
return
data
...
@@ -79,7 +83,7 @@ export const getInfoDetailByUserId = async (user_id: number | any) => {
...
@@ -79,7 +83,7 @@ export const getInfoDetailByUserId = async (user_id: number | any) => {
ApiAssert
.
isNotEmpty
(
ErrorCode
.
USER_NOT_EXIST
,
dbUserInfo
);
ApiAssert
.
isNotEmpty
(
ErrorCode
.
USER_NOT_EXIST
,
dbUserInfo
);
let
{
roleSet
,
authSet
}
=
await
aclRoleAuthService
.
getUserAcl
(
dbUserInfo
.
user_id
);
let
{
roleSet
,
authSet
,
role_ids
,
authTree
}
=
await
aclRoleAuthService
.
getUserAclAndTree
(
dbUserInfo
.
user_id
);
let
data
=
{
let
data
=
{
remark
:
dbUserInfo
.
remark
,
remark
:
dbUserInfo
.
remark
,
...
@@ -94,6 +98,8 @@ export const getInfoDetailByUserId = async (user_id: number | any) => {
...
@@ -94,6 +98,8 @@ export const getInfoDetailByUserId = async (user_id: number | any) => {
authSet
:
authSet
,
authSet
:
authSet
,
hasTotp
:
dbUserInfo
&&
dbUserInfo
.
totp_encrypt
?
1
:
0
,
hasTotp
:
dbUserInfo
&&
dbUserInfo
.
totp_encrypt
?
1
:
0
,
totp_encrypt
:
dbUserInfo
?
dbUserInfo
.
totp_encrypt
:
""
,
totp_encrypt
:
dbUserInfo
?
dbUserInfo
.
totp_encrypt
:
""
,
authTree
:
authTree
,
role_ids
:
role_ids
?
role_ids
:
""
}
}
await
dealDepartmentAndPosition
(
data
);
await
dealDepartmentAndPosition
(
data
);
return
data
return
data
...
@@ -306,40 +312,8 @@ async function _updateTotpConfig(userId: number, totpEncrypt: any) {
...
@@ -306,40 +312,8 @@ async function _updateTotpConfig(userId: number, totpEncrypt: any) {
}
}
async
function
dealDepartmentAndPosition
(
data
:
any
)
{
/*
async
function
dealDepartmentAndPosition
(
data
:
any
)
{
let [departmentList,positionList,dp] =
let
dp
=
await
getDepartmentPositionByUid
(
data
.
userId
);
await Promise.all([getAllDepartment(),getAllPosition(),getDepartmentPositionByUid(data.user_id)]);
data
.
department_id
=
dp
.
department_id
;
let departmentMap = {};
data
.
position_id
=
dp
.
position_id
;
let positionMap = {};
for (let item of departmentList) {
departmentMap[item.id] = item.name;
}
for (let item of positionList) {
positionMap[item.id] = item.name;
}
let departmentIds = dp.department_id.split(",");
let positionIds = dp.position_id.split(",");
let departmentNameList:any = [];
let positionNameList:any = [];
if (departmentIds.length){
for (let departmentId of departmentIds) {
departmentNameList.push(departmentMap[departmentId])
}
}
if (positionIds.length){
for (let positionId of positionIds) {
positionNameList.push(positionMap[positionId])
}
}*/
let
[
aclRoleList
,
db
]
=
await
Promise
.
all
([
getRoleByUser
(
data
.
userId
),
getDepartmentPositionByUid
(
data
.
userId
)]);
let
role_ids
=
aclRoleList
.
map
(
item
=>
item
.
id
);
data
.
role_ids
=
role_ids
&&
role_ids
.
length
?
role_ids
.
join
(
","
)
:
""
;
data
.
department_id
=
db
.
department_id
;
data
.
position_id
=
db
.
position_id
;
}
}
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