fix(项目管理): 删除自定义字段时,没有删除字段和模板的中间表

This commit is contained in:
AgAngle 2023-11-30 18:00:50 +08:00 committed by jianxing
parent 589415ac05
commit fc87410095
3 changed files with 39 additions and 15 deletions

View File

@ -1,19 +1,17 @@
package io.metersphere.project.controller;
import io.metersphere.sdk.constants.*;
import io.metersphere.system.domain.*;
import io.metersphere.system.dto.sdk.CustomFieldDTO;
import io.metersphere.system.dto.sdk.request.CustomFieldOptionRequest;
import io.metersphere.system.dto.sdk.request.CustomFieldUpdateRequest;
import io.metersphere.sdk.util.BeanUtils;
import io.metersphere.system.base.BaseTest;
import io.metersphere.system.controller.param.CustomFieldUpdateRequestDefinition;
import io.metersphere.system.domain.CustomField;
import io.metersphere.system.domain.CustomFieldExample;
import io.metersphere.system.domain.CustomFieldOption;
import io.metersphere.system.domain.OrganizationParameter;
import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.system.mapper.CustomFieldMapper;
import io.metersphere.system.mapper.OrganizationParameterMapper;
import io.metersphere.system.mapper.TemplateCustomFieldMapper;
import io.metersphere.system.service.BaseCustomFieldOptionService;
import io.metersphere.system.service.BaseCustomFieldService;
import io.metersphere.system.service.UserLoginService;
@ -57,6 +55,8 @@ public class ProjectCustomFieldControllerTests extends BaseTest {
private UserLoginService userLoginService;
@Resource
private OrganizationParameterMapper organizationParameterMapper;
@Resource
private TemplateCustomFieldMapper templateCustomFieldMapper;
private static CustomField addCustomField;
private static CustomField anotherAddCustomField;
@ -266,6 +266,7 @@ public class ProjectCustomFieldControllerTests extends BaseTest {
this.requestGetWithOk(DEFAULT_DELETE, addCustomField.getId());
Assertions.assertNull(customFieldMapper.selectByPrimaryKey(addCustomField.getId()));
Assertions.assertTrue(CollectionUtils.isEmpty(baseCustomFieldOptionService.getByFieldId(addCustomField.getId())));
Assertions.assertTrue(CollectionUtils.isEmpty(getTemplateCustomField(addCustomField.getId())));
// @@校验内置字段删除异常
CustomFieldExample example = new CustomFieldExample();
@ -297,4 +298,11 @@ public class ProjectCustomFieldControllerTests extends BaseTest {
}
}
}
private List<TemplateCustomField> getTemplateCustomField(String id) {
TemplateCustomFieldExample example = new TemplateCustomFieldExample();
example.createCriteria()
.andFieldIdEqualTo(id);
return templateCustomFieldMapper.selectByExample(example);
}
}

View File

@ -1,18 +1,20 @@
package io.metersphere.system.service;
import io.metersphere.sdk.constants.CustomFieldType;
import io.metersphere.system.dto.request.DefaultFunctionalCustomField;
import io.metersphere.sdk.constants.TemplateScene;
import io.metersphere.sdk.constants.TemplateScopeType;
import io.metersphere.system.dto.sdk.CustomFieldDTO;
import io.metersphere.system.dto.sdk.request.CustomFieldOptionRequest;
import io.metersphere.sdk.exception.MSException;
import io.metersphere.sdk.util.BeanUtils;
import io.metersphere.sdk.util.Translator;
import io.metersphere.system.domain.CustomField;
import io.metersphere.system.domain.CustomFieldExample;
import io.metersphere.system.domain.CustomFieldOption;
import io.metersphere.system.domain.TemplateCustomFieldExample;
import io.metersphere.system.dto.request.DefaultFunctionalCustomField;
import io.metersphere.system.dto.sdk.CustomFieldDTO;
import io.metersphere.system.dto.sdk.request.CustomFieldOptionRequest;
import io.metersphere.system.mapper.CustomFieldMapper;
import io.metersphere.system.mapper.TemplateCustomFieldMapper;
import io.metersphere.system.uid.IDGenerator;
import io.metersphere.system.utils.ServiceUtils;
import jakarta.annotation.Resource;
@ -45,6 +47,8 @@ public class BaseCustomFieldService {
protected BaseCustomFieldOptionService baseCustomFieldOptionService;
@Resource
protected BaseOrganizationParameterService baseOrganizationParameterService;
@Resource
protected TemplateCustomFieldMapper templateCustomFieldMapper;
public List<CustomFieldDTO> list(String scopeId, String scene) {
checkScene(scene);
@ -165,6 +169,13 @@ public class BaseCustomFieldService {
public void delete(String id) {
customFieldMapper.deleteByPrimaryKey(id);
baseCustomFieldOptionService.deleteByFieldId(id);
deleteTemplateCustomField(id);
}
public void deleteTemplateCustomField(String id) {
TemplateCustomFieldExample example = new TemplateCustomFieldExample();
example.createCriteria().andFieldIdEqualTo(id);
templateCustomFieldMapper.deleteByExample(example);
}
protected void checkInternal(CustomField customField) {

View File

@ -4,19 +4,17 @@ import io.metersphere.project.domain.Project;
import io.metersphere.project.domain.ProjectExample;
import io.metersphere.project.mapper.ProjectMapper;
import io.metersphere.sdk.constants.*;
import io.metersphere.system.domain.*;
import io.metersphere.system.dto.sdk.CustomFieldDTO;
import io.metersphere.system.dto.sdk.request.CustomFieldOptionRequest;
import io.metersphere.system.dto.sdk.request.CustomFieldUpdateRequest;
import io.metersphere.sdk.util.BeanUtils;
import io.metersphere.system.base.BaseTest;
import io.metersphere.system.controller.param.CustomFieldUpdateRequestDefinition;
import io.metersphere.system.domain.CustomField;
import io.metersphere.system.domain.CustomFieldExample;
import io.metersphere.system.domain.CustomFieldOption;
import io.metersphere.system.domain.OrganizationParameter;
import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.system.mapper.CustomFieldMapper;
import io.metersphere.system.mapper.OrganizationParameterMapper;
import io.metersphere.system.mapper.TemplateCustomFieldMapper;
import io.metersphere.system.service.BaseCustomFieldOptionService;
import io.metersphere.system.service.BaseCustomFieldService;
import io.metersphere.system.service.OrganizationCustomFieldService;
@ -29,10 +27,7 @@ import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMock
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.web.servlet.MvcResult;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.*;
import static io.metersphere.sdk.constants.InternalUserRole.ADMIN;
import static io.metersphere.system.controller.handler.result.CommonResultCode.*;
@ -65,6 +60,8 @@ public class OrganizationCustomFieldControllerTests extends BaseTest {
private ProjectMapper projectMapper;
@Resource
private OrganizationCustomFieldService organizationCustomFieldService;
@Resource
private TemplateCustomFieldMapper templateCustomFieldMapper;
private static CustomField addCustomField;
private static CustomField anotherAddCustomField;
@ -274,6 +271,7 @@ public class OrganizationCustomFieldControllerTests extends BaseTest {
this.requestGetWithOk(DEFAULT_DELETE, addCustomField.getId());
Assertions.assertNull(customFieldMapper.selectByPrimaryKey(addCustomField.getId()));
Assertions.assertTrue(CollectionUtils.isEmpty(baseCustomFieldOptionService.getByFieldId(addCustomField.getId())));
Assertions.assertTrue(CollectionUtils.isEmpty(getTemplateCustomField(addCustomField.getId())));
// @@校验内置字段删除异常
CustomFieldExample example = new CustomFieldExample();
@ -291,6 +289,13 @@ public class OrganizationCustomFieldControllerTests extends BaseTest {
requestGetPermissionTest(PermissionConstants.ORGANIZATION_TEMPLATE_DELETE, DEFAULT_DELETE, addCustomField.getId());
}
private List<TemplateCustomField> getTemplateCustomField(String id) {
TemplateCustomFieldExample example = new TemplateCustomFieldExample();
example.createCriteria()
.andFieldIdEqualTo(id);
return templateCustomFieldMapper.selectByExample(example);
}
/**
* 校验变更组织字段时有没有同步变更项目字段
*/