Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
brandkbs2
Overview
Overview
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
shenjunjie
brandkbs2
Commits
12128651
Commit
12128651
authored
Jun 05, 2024
by
shenjunjie
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'release' into 'master'
Release See merge request
!530
parents
f14b1626
267902ed
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
38 additions
and
11 deletions
+38
-11
src/main/java/com/zhiwei/brandkbs2/exception/CustomException.java
+4
-0
src/main/java/com/zhiwei/brandkbs2/exception/ExceptionCatch.java
+2
-2
src/main/java/com/zhiwei/brandkbs2/model/ResponseResult.java
+12
-1
src/main/java/com/zhiwei/brandkbs2/service/impl/UserServiceImpl.java
+20
-8
No files found.
src/main/java/com/zhiwei/brandkbs2/exception/CustomException.java
View file @
12128651
...
@@ -39,4 +39,8 @@ public class CustomException extends RuntimeException {
...
@@ -39,4 +39,8 @@ public class CustomException extends RuntimeException {
return
exception
;
return
exception
;
}
}
public
String
getErrorMessage
(){
return
errorMessage
;
}
}
}
src/main/java/com/zhiwei/brandkbs2/exception/ExceptionCatch.java
View file @
12128651
...
@@ -34,9 +34,9 @@ public class ExceptionCatch {
...
@@ -34,9 +34,9 @@ public class ExceptionCatch {
Exception
exception
=
customException
.
getException
();
Exception
exception
=
customException
.
getException
();
//记录日志
//记录日志
if
(
null
==
exception
)
{
if
(
null
==
exception
)
{
log
.
info
(
"catch exception-custom:{}"
,
resultCode
.
m
essage
());
log
.
info
(
"catch exception-custom:{}"
,
customException
.
getErrorM
essage
());
}
else
{
}
else
{
log
.
error
(
"catch exception-custom:{}"
,
resultCode
.
m
essage
(),
exception
);
log
.
error
(
"catch exception-custom:{}"
,
customException
.
getErrorM
essage
(),
exception
);
}
}
return
new
ResponseResult
(
resultCode
,
Collections
.
EMPTY_LIST
);
return
new
ResponseResult
(
resultCode
,
Collections
.
EMPTY_LIST
);
}
}
...
...
src/main/java/com/zhiwei/brandkbs2/model/ResponseResult.java
View file @
12128651
...
@@ -89,7 +89,18 @@ public class ResponseResult {
...
@@ -89,7 +89,18 @@ public class ResponseResult {
* @return 操作失败带返回数据
* @return 操作失败带返回数据
*/
*/
public
static
ResponseResult
failure
(
String
message
)
{
public
static
ResponseResult
failure
(
String
message
)
{
ResponseResult
responseResult
=
new
ResponseResult
(
CommonCodeEnum
.
FAIL
,
null
);
return
failure
(
message
,
CommonCodeEnum
.
FAIL
);
}
/**
* 操作失败带返回数据
*
* @param message 失败信息
* @param commonCodeEnum 失败类型
* @return 操作失败带返回数据
*/
public
static
ResponseResult
failure
(
String
message
,
CommonCodeEnum
commonCodeEnum
)
{
ResponseResult
responseResult
=
new
ResponseResult
(
commonCodeEnum
,
null
);
responseResult
.
setMessage
(
message
);
responseResult
.
setMessage
(
message
);
return
responseResult
;
return
responseResult
;
}
}
...
...
src/main/java/com/zhiwei/brandkbs2/service/impl/UserServiceImpl.java
View file @
12128651
...
@@ -146,16 +146,11 @@ public class UserServiceImpl implements UserService {
...
@@ -146,16 +146,11 @@ public class UserServiceImpl implements UserService {
@Override
@Override
public
ResponseResult
addUser
(
UserDTO
userDTO
)
{
public
ResponseResult
addUser
(
UserDTO
userDTO
)
{
if
(
Objects
.
isNull
(
userDTO
.
getRoleId
())
||
userDTO
.
getRoleId
()
<
RoleEnum
.
ADMIN
.
getState
(
))
{
if
(
!
checkPermissionExceptSuperAdmin
(
userDTO
.
getRoleId
()
))
{
// 抛出用户权限设置错误异常
// 抛出用户权限设置错误异常
ExceptionCast
.
cast
(
CommonCodeEnum
.
UN_AUTHORISE
);
return
ResponseResult
.
failure
(
"权限不足,无权操作"
,
CommonCodeEnum
.
UN_AUTHORISE
);
}
}
int
roleId
=
UserThreadLocal
.
getRoleId
();
String
nickname
=
UserThreadLocal
.
getNickname
();
String
nickname
=
UserThreadLocal
.
getNickname
();
// 只有超管能设置管理员
if
(
roleId
!=
RoleEnum
.
SUPER_ADMIN
.
getState
()
&&
userDTO
.
getRoleId
()
<=
RoleEnum
.
ADMIN
.
getState
())
{
ExceptionCast
.
cast
(
CommonCodeEnum
.
UN_AUTHORISE
);
}
// 有密码则通过用户中心注册
// 有密码则通过用户中心注册
CenterUser
centerUser
=
null
;
CenterUser
centerUser
=
null
;
if
(
null
!=
userDTO
.
getPassword
())
{
if
(
null
!=
userDTO
.
getPassword
())
{
...
@@ -192,7 +187,7 @@ public class UserServiceImpl implements UserService {
...
@@ -192,7 +187,7 @@ public class UserServiceImpl implements UserService {
}
else
{
}
else
{
if
(
roles
.
stream
().
map
(
UserRole:
:
getProjectId
).
collect
(
Collectors
.
toList
()).
contains
(
userDTO
.
getProjectId
()))
{
if
(
roles
.
stream
().
map
(
UserRole:
:
getProjectId
).
collect
(
Collectors
.
toList
()).
contains
(
userDTO
.
getProjectId
()))
{
// 抛出用户权限设置错误异常
// 抛出用户权限设置错误异常
ExceptionCast
.
cast
(
CommonCodeEnum
.
INVALID_PARAM
,
"用户权限设置重复"
);
return
ResponseResult
.
failure
(
"用户权限设置重复"
,
CommonCodeEnum
.
INVALID_PARAM
);
}
}
}
}
roles
.
add
(
UserRole
.
createFromUserDto
(
userDTO
));
roles
.
add
(
UserRole
.
createFromUserDto
(
userDTO
));
...
@@ -222,6 +217,10 @@ public class UserServiceImpl implements UserService {
...
@@ -222,6 +217,10 @@ public class UserServiceImpl implements UserService {
if
(
null
==
user
)
{
if
(
null
==
user
)
{
ExceptionCast
.
cast
(
CommonCodeEnum
.
INVALID_PARAM
);
ExceptionCast
.
cast
(
CommonCodeEnum
.
INVALID_PARAM
);
}
}
if
(!
checkPermissionExceptSuperAdmin
(
userDTO
.
getRoleId
()))
{
// 抛出用户权限设置错误异常
ExceptionCast
.
cast
(
CommonCodeEnum
.
UN_AUTHORISE
);
}
List
<
UserRole
>
roles
=
user
.
getRoles
();
List
<
UserRole
>
roles
=
user
.
getRoles
();
user
.
getRoles
().
stream
().
filter
(
userRoles
->
userRoles
.
getProjectId
().
equals
(
userDTO
.
getProjectId
())).
findAny
().
ifPresent
(
userRole
->
{
user
.
getRoles
().
stream
().
filter
(
userRoles
->
userRoles
.
getProjectId
().
equals
(
userDTO
.
getProjectId
())).
findAny
().
ifPresent
(
userRole
->
{
// 更新原userRole
// 更新原userRole
...
@@ -485,4 +484,17 @@ public class UserServiceImpl implements UserService {
...
@@ -485,4 +484,17 @@ public class UserServiceImpl implements UserService {
UserThreadLocal
.
set
(
userInfo
);
UserThreadLocal
.
set
(
userInfo
);
}
}
/**
* 添加超管以外的用户权限校验
*
* @param roleId
*/
private
boolean
checkPermissionExceptSuperAdmin
(
Integer
roleId
)
{
if
(
Objects
.
isNull
(
roleId
))
{
return
false
;
}
// 不能设置超级管理员以及比自身权限大的用户
return
roleId
!=
RoleEnum
.
SUPER_ADMIN
.
getState
()
&&
UserThreadLocal
.
getRoleId
()
<=
roleId
;
}
}
}
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