feat(系统设置): 补充系统视图
--task=1016128 --user=陈建星 高级搜索-视图增删改查-后端 https://www.tapd.cn/55049933/s/1573254
This commit is contained in:
parent
7d48b46e71
commit
141d5304bb
|
@ -557,3 +557,5 @@ internal_user_view_permission_error=系统视图无法删除!
|
|||
user_view.all_data=全部数据
|
||||
user_view.my_follow=我关注的
|
||||
user_view.my_create=我创建的
|
||||
user_view.my_review=我评审的
|
||||
user_view_exist=视图已存在
|
|
@ -595,3 +595,5 @@ internal_user_view_permission_error=System views cannot be deleted!
|
|||
user_view.all_data=All data
|
||||
user_view.my_follow=I followed
|
||||
user_view.my_create=I created
|
||||
user_view.my_review=I review
|
||||
user_view_exist=The view already exists
|
|
@ -590,3 +590,5 @@ internal_user_view_permission_error=系统视图无法删除!
|
|||
user_view.all_data=全部数据
|
||||
user_view.my_follow=我关注的
|
||||
user_view.my_create=我创建的
|
||||
user_view.my_review=我评审的
|
||||
user_view_exist=视图已存在
|
|
@ -590,3 +590,5 @@ internal_user_view_permission_error=系統視圖無法刪除!
|
|||
user_view.all_data=全部數據
|
||||
user_view.my_follow=我關注的
|
||||
user_view.my_create=我創建的
|
||||
user_view.my_review=我評審的
|
||||
user_view_exist=視圖已存在
|
|
@ -22,7 +22,7 @@ public enum InternalUserView {
|
|||
CombineCondition condition = new CombineCondition();
|
||||
condition.setName("follower");
|
||||
condition.setValue(getCurrentUserValue());
|
||||
condition.setOperator(CombineCondition.CombineConditionOperator.EQUALS.name());
|
||||
condition.setOperator(CombineCondition.CombineConditionOperator.IN.name());
|
||||
userViewDTO.setConditions(List.of(condition));
|
||||
return userViewDTO;
|
||||
}),
|
||||
|
@ -31,7 +31,16 @@ public enum InternalUserView {
|
|||
CombineCondition condition = new CombineCondition();
|
||||
condition.setName("create_user");
|
||||
condition.setValue(getCurrentUserValue());
|
||||
condition.setOperator(CombineCondition.CombineConditionOperator.EQUALS.name());
|
||||
condition.setOperator(CombineCondition.CombineConditionOperator.IN.name());
|
||||
userViewDTO.setConditions(List.of(condition));
|
||||
return userViewDTO;
|
||||
}),
|
||||
MY_REVIEW(() -> {
|
||||
UserViewDTO userViewDTO = getUserViewDTO("my_review");
|
||||
CombineCondition condition = new CombineCondition();
|
||||
condition.setName("review_user");
|
||||
condition.setValue(getCurrentUserValue());
|
||||
condition.setOperator(CombineCondition.CombineConditionOperator.IN.name());
|
||||
userViewDTO.setConditions(List.of(condition));
|
||||
return userViewDTO;
|
||||
});
|
||||
|
|
|
@ -8,11 +8,19 @@ import java.util.List;
|
|||
/**
|
||||
* @Author: jianxing
|
||||
* @CreateTime: 2024-09-02 10:47
|
||||
*
|
||||
* 视图的类型
|
||||
* 例如:功能用例视图
|
||||
*
|
||||
*/
|
||||
public enum UserViewType implements ValueEnum {
|
||||
|
||||
FUNCTIONAL_CASE("functional-case",
|
||||
List.of(InternalUserView.ALL_DATA, InternalUserView.MY_FOLLOW, InternalUserView.MY_CREATE)),
|
||||
REVIEW_FUNCTIONAL_CASE("review-functional-case",
|
||||
List.of(InternalUserView.ALL_DATA, InternalUserView.MY_REVIEW, InternalUserView.MY_CREATE)),
|
||||
API_DEFINITION("api-definition",
|
||||
List.of(InternalUserView.ALL_DATA, InternalUserView.MY_FOLLOW, InternalUserView.MY_CREATE)),
|
||||
;
|
||||
|
||||
private String value;
|
||||
|
|
|
@ -32,7 +32,8 @@ public enum SystemResultCode implements IResultCode {
|
|||
PLUGIN_SCRIPT_FORMAT(101011, "plugin.script.format"),
|
||||
NO_PROJECT_USER_ROLE_PERMISSION(101012, "project_user_role_permission_error"),
|
||||
NO_GLOBAL_USER_ROLE_PERMISSION(101013, "no_global_user_role_permission_error"),
|
||||
PLUGIN_PARSE_ERROR(101014, "plugin.parse.error");
|
||||
PLUGIN_PARSE_ERROR(101014, "plugin.parse.error"),
|
||||
USER_VIEW_EXIST(101015, "user_view_exist"),;
|
||||
|
||||
private final int code;
|
||||
private final String message;
|
||||
|
|
|
@ -23,6 +23,7 @@ import io.metersphere.system.mapper.UserViewConditionMapper;
|
|||
import io.metersphere.system.mapper.UserViewMapper;
|
||||
import io.metersphere.system.uid.IDGenerator;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
@ -31,6 +32,8 @@ import java.util.Comparator;
|
|||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static io.metersphere.system.controller.result.SystemResultCode.USER_VIEW_EXIST;
|
||||
|
||||
/**
|
||||
* @Author: jianxing
|
||||
* @CreateTime: 2024-08-30 14:30
|
||||
|
@ -90,6 +93,7 @@ public class UserViewService {
|
|||
}
|
||||
|
||||
public UserViewDTO add(UserViewAddRequest request, String viewType, String userId) {
|
||||
checkAddExist(request, viewType, userId);
|
||||
Long nextPos = getNextPos(request.getScopeId(), userId, viewType);
|
||||
UserView userView = BeanUtils.copyBean(new UserView(), request);
|
||||
userView.setCreateTime(System.currentTimeMillis());
|
||||
|
@ -113,6 +117,33 @@ public class UserViewService {
|
|||
return userViewDTO;
|
||||
}
|
||||
|
||||
private void checkAddExist(UserViewAddRequest request, String viewType, String userId) {
|
||||
UserViewExample example = new UserViewExample();
|
||||
example.createCriteria()
|
||||
.andUserIdEqualTo(userId)
|
||||
.andScopeIdEqualTo(request.getScopeId())
|
||||
.andViewTypeEqualTo(viewType)
|
||||
.andNameEqualTo(request.getName());
|
||||
if (userViewMapper.countByExample(example) > 0) {
|
||||
throw new MSException(USER_VIEW_EXIST);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkUpdateExist(String name, String scopeId, String viewType, String userId) {
|
||||
if (StringUtils.isBlank(name)) {
|
||||
return;
|
||||
}
|
||||
UserViewExample example = new UserViewExample();
|
||||
example.createCriteria()
|
||||
.andUserIdEqualTo(userId)
|
||||
.andScopeIdEqualTo(scopeId)
|
||||
.andViewTypeEqualTo(viewType)
|
||||
.andNameEqualTo(name);
|
||||
if (userViewMapper.countByExample(example) > 0) {
|
||||
throw new MSException(USER_VIEW_EXIST);
|
||||
}
|
||||
}
|
||||
|
||||
public Long getNextPos(String scopeId, String userId, String viewType) {
|
||||
Long pos = extUserViewMapper.getLastPos(scopeId, userId, viewType, null);
|
||||
return (pos == null ? 0 : pos) + POS_STEP;
|
||||
|
@ -133,6 +164,9 @@ public class UserViewService {
|
|||
}
|
||||
|
||||
private void addUserViewConditions(List<CombineCondition> conditions, UserView userView) {
|
||||
if (CollectionUtils.isEmpty(conditions)) {
|
||||
return;
|
||||
}
|
||||
List<UserViewCondition> insertConditions = conditions.stream().map(condition -> {
|
||||
UserViewCondition userViewCondition = BeanUtils.copyBean(new UserViewCondition(), condition);
|
||||
userViewCondition.setId(IDGenerator.nextStr());
|
||||
|
@ -187,16 +221,19 @@ public class UserViewService {
|
|||
UserView originUserView = userViewMapper.selectByPrimaryKey(request.getId());
|
||||
// 校验权限,只能修改自己的视图
|
||||
checkOwner(userId, originUserView);
|
||||
checkUpdateExist(request.getName(), originUserView.getScopeId(), viewType, userId);
|
||||
|
||||
UserView userView = BeanUtils.copyBean(new UserView(), request);
|
||||
userView.setViewType(viewType);
|
||||
userView.setUpdateTime(System.currentTimeMillis());
|
||||
userViewMapper.updateByPrimaryKeySelective(userView);
|
||||
|
||||
if (request.getConditions() != null) {
|
||||
// 先删除
|
||||
deleteConditionsByViewId(originUserView.getId());
|
||||
// 再新增
|
||||
addUserViewConditions(request.getConditions(), userView);
|
||||
}
|
||||
|
||||
UserViewDTO userViewDTO = BeanUtils.copyBean(new UserViewDTO(), request);
|
||||
userViewDTO.setId(originUserView.getId());
|
||||
|
|
|
@ -23,6 +23,8 @@ import org.springframework.test.web.servlet.MvcResult;
|
|||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static io.metersphere.system.controller.result.SystemResultCode.USER_VIEW_EXIST;
|
||||
|
||||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
||||
@AutoConfigureMockMvc
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
|
@ -33,6 +35,7 @@ public class UserViewControllerTests extends BaseTest {
|
|||
private final String GROUPED_LIST = "grouped/list?scopeId={0}";
|
||||
|
||||
private static UserViewDTO addUserViewDTO;
|
||||
private static UserViewDTO anotherAddUserViewDTO;
|
||||
|
||||
@Resource
|
||||
private UserViewService userViewService;
|
||||
|
@ -117,6 +120,14 @@ public class UserViewControllerTests extends BaseTest {
|
|||
UserViewDTO userViewDTO = userViewService.get(addUserViewDTO.getId(), UserViewType.FUNCTIONAL_CASE, InternalUser.ADMIN.getValue());
|
||||
Assertions.assertEquals(request, BeanUtils.copyBean(new UserViewAddRequest(), userViewDTO));
|
||||
Assertions.assertEquals(request.getConditions(), userViewDTO.getConditions());
|
||||
|
||||
// @@重名校验异常
|
||||
assertErrorCode(this.requestPost(DEFAULT_ADD, request), USER_VIEW_EXIST);
|
||||
|
||||
request.setName(UUID.randomUUID().toString());
|
||||
request.setConditions(null);
|
||||
mvcResult = this.requestPostWithOkAndReturn(DEFAULT_ADD, request);
|
||||
anotherAddUserViewDTO = getResultData(mvcResult, UserViewDTO.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -134,6 +145,13 @@ public class UserViewControllerTests extends BaseTest {
|
|||
UserViewDTO userViewDTO = userViewService.get(addUserViewDTO.getId(), UserViewType.FUNCTIONAL_CASE, InternalUser.ADMIN.getValue());
|
||||
Assertions.assertEquals(request, BeanUtils.copyBean(new UserViewUpdateRequest(), userViewDTO));
|
||||
Assertions.assertEquals(request.getConditions(), userViewDTO.getConditions());
|
||||
|
||||
// @@ Conditions 为 null
|
||||
request.setId(anotherAddUserViewDTO.getId());
|
||||
assertErrorCode(this.requestPost(DEFAULT_UPDATE, request), USER_VIEW_EXIST);
|
||||
request.setName(UUID.randomUUID().toString());
|
||||
request.setConditions(null);
|
||||
this.requestPostWithOkAndReturn(DEFAULT_UPDATE, request);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -160,7 +178,7 @@ public class UserViewControllerTests extends BaseTest {
|
|||
MvcResult mvcResult = this.requestGetWithOkAndReturn(GROUPED_LIST, DEFAULT_PROJECT_ID);
|
||||
UserViewListGroupedDTO result = getResultData(mvcResult, UserViewListGroupedDTO.class);
|
||||
Assertions.assertEquals(result.getInternalViews().size(), 3);
|
||||
Assertions.assertEquals(result.getCustomViews().size(), 1);
|
||||
Assertions.assertEquals(result.getCustomViews().size(), 2);
|
||||
Assertions.assertEquals(result.getCustomViews().get(0), BeanUtils.copyBean(new UserViewListDTO(), addUserViewDTO));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue