Skip to content

Commit 5767ff4

Browse files
committed
fix: update lockCanvas,parameter validation
1 parent 2b97f64 commit 5767ff4

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

base/src/main/java/com/tinyengine/it/service/app/impl/CanvasServiceImpl.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ public class CanvasServiceImpl implements CanvasService {
4545

4646
@Override
4747
public Result<CanvasDto> lockCanvas(Integer id, String state, String type) {
48+
if(id== null){
49+
return Result.failed("id can not be null");
50+
}
51+
if(isNull(state) || isNull(type)){
52+
return Result.failed("invalid parameter");
53+
}
4854
String occupier = null;
4955
// needTODO 先试用mock数据,后续添加登录及权限后从session获取,
5056
User user = userMapper.queryUserById(loginUserContext.getLoginUserId());
@@ -57,6 +63,9 @@ public Result<CanvasDto> lockCanvas(Integer id, String state, String type) {
5763
User occupierValue = state.equals(Enums.CanvasEditorState.OCCUPY.getValue()) ? user : null;
5864
if ("page".equals(type)) {
5965
Page page = pageMapper.queryPageById(id);
66+
if(page == null){
67+
return Result.failed("page not exist");
68+
}
6069
if (page.getOccupier() != null) {
6170
occupier = page.getOccupier().getId();
6271
}
@@ -72,6 +81,9 @@ public Result<CanvasDto> lockCanvas(Integer id, String state, String type) {
7281
}
7382
} else {
7483
Block block = blockMapper.queryBlockById(id);
84+
if(block == null){
85+
return Result.failed("block not exist");
86+
}
7587
occupier = block.getOccupierBy();
7688
Boolean isCaDoIt = isCanDoIt(occupier, user);
7789
if (isCaDoIt) {
@@ -88,7 +100,9 @@ public Result<CanvasDto> lockCanvas(Integer id, String state, String type) {
88100
canvasDto.setOccupier(occupierValue);
89101
return Result.success(canvasDto);
90102
}
91-
103+
public static boolean isNull(String str) {
104+
return str != null && !str.trim().isEmpty();
105+
}
92106
private Boolean isCanDoIt(String occupier, User user) {
93107
return occupier == null || occupier.equals(user.getId());
94108
}

0 commit comments

Comments
 (0)