fix(项目设置): 成员类型的字段添加默认选项

This commit is contained in:
AgAngle 2024-02-27 10:06:40 +08:00 committed by jianxing
parent f71b4b4b49
commit 31854f01cd
6 changed files with 43 additions and 8 deletions

View File

@ -21,7 +21,6 @@ import io.metersphere.system.mapper.CustomFieldOptionMapper;
import io.metersphere.system.service.BaseTemplateService;
import io.metersphere.system.service.PlatformPluginService;
import io.metersphere.system.service.PluginLoadService;
import io.metersphere.system.service.ServiceIntegrationService;
import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
@ -47,8 +46,6 @@ public class ProjectTemplateService extends BaseTemplateService {
@Resource
private ProjectService projectService;
@Resource
private ServiceIntegrationService serviceIntegrationService;
@Resource
private PluginLoadService pluginLoadService;
@Resource
private PlatformPluginService platformPluginService;

View File

@ -20,6 +20,7 @@ import io.metersphere.system.service.UserLoginService;
import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.*;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
@ -131,10 +132,16 @@ public class ProjectCustomFieldControllerTests extends BaseTest {
assertErrorCode(this.requestPost(DEFAULT_ADD, request), NOT_FOUND);
// 插入另一条数据用户更新时重名校验
request.setType(CustomFieldType.MEMBER.name());
request.setScopeId(DEFAULT_PROJECT_ID);
MvcResult anotherMvcResult = this.requestPostWithOkAndReturn(DEFAULT_ADD, request);
this.anotherAddCustomField = customFieldMapper.selectByPrimaryKey(getResultData(anotherMvcResult, CustomField.class).getId());
request.setType(CustomFieldType.MULTIPLE_MEMBER.name());
request.setScopeId(DEFAULT_PROJECT_ID);
request.setName("testAAA");
this.requestPostWithOkAndReturn(DEFAULT_ADD, request);
// @@校验日志
checkLog(this.addCustomField.getId(), OperationLogType.ADD);
// @@异常参数校验
@ -224,7 +231,7 @@ public class ProjectCustomFieldControllerTests extends BaseTest {
List<String> userIds = customFields.stream().map(CustomField::getCreateUser).toList();
Map<String, String> userNameMap = userLoginService.getUserNameMap(userIds);
for (int i = 0; i < resultList.size(); i++) {
CustomField resultItem = BeanUtils.copyBean(new CustomField(), resultList.get(i));;
CustomField resultItem = BeanUtils.copyBean(new CustomField(), resultList.get(i));
CustomField customField = customFields.get(i);
customField.setCreateUser(userNameMap.get(customField.getCreateUser()));
if (customField.getInternal()) {
@ -233,8 +240,14 @@ public class ProjectCustomFieldControllerTests extends BaseTest {
}
Assertions.assertEquals(customField, resultItem);
Assertions.assertEquals(resultItem.getScene(), scene);
// 有下拉框选项的校验选项
if (CustomFieldType.getHasOptionValueSet().contains(resultItem.getType())) {
if (StringUtils.equalsAny(resultItem.getType(), CustomFieldType.MEMBER.name(), CustomFieldType.MULTIPLE_MEMBER.name())) {
List<CustomFieldOption> options = resultList.get(i).getOptions();
Assertions.assertEquals(options.size(), 1);
Assertions.assertEquals(options.get(0).getValue(), "CREATE_USER");
Assertions.assertEquals(options.get(0).getText(), "创建人");
} else if (CustomFieldType.getHasOptionValueSet().contains(resultItem.getType())) {
// 有下拉框选项的校验选项
Assertions.assertEquals(resultList.get(i).getOptions().stream().sorted(Comparator.comparing(CustomFieldOption::getValue)).toList(),
baseCustomFieldOptionService.getByFieldId(customField.getId()).stream().sorted(Comparator.comparing(CustomFieldOption::getValue)).toList());
}

View File

@ -34,6 +34,7 @@ public class StatusItemAddRequest implements Serializable {
private String scene;
@Schema(description = "状态说明")
@Size(max = 500)
private String remark;
@Schema(description = "所有状态都可以流转到该状态")

View File

@ -22,5 +22,6 @@ public class StatusItemUpdateRequest implements Serializable {
private String name;
@Schema(description = "状态说明")
@Size(max = 500)
private String remark;
}

View File

@ -51,6 +51,8 @@ public class BaseCustomFieldService {
@Resource
protected TemplateCustomFieldMapper templateCustomFieldMapper;
private static final String CREATE_USER = "CREATE_USER";
public List<CustomFieldDTO> list(String scopeId, String scene) {
checkScene(scene);
List<CustomField> customFields = getByScopeIdAndScene(scopeId, scene);
@ -69,6 +71,15 @@ public class BaseCustomFieldService {
if (CustomFieldType.getHasOptionValueSet().contains(customFieldDTO.getType()) && customFieldDTO.getOptions() == null) {
customFieldDTO.setOptions(List.of());
}
if (StringUtils.equalsAny(item.getType(), CustomFieldType.MEMBER.name(), CustomFieldType.MULTIPLE_MEMBER.name())) {
// 成员选项添加默认的选项
CustomFieldOption createUserOption = new CustomFieldOption();
createUserOption.setFieldId(item.getId());
createUserOption.setText(Translator.get("message.domain.create_user"));
createUserOption.setValue(CREATE_USER);
createUserOption.setInternal(false);
customFieldDTO.setOptions(List.of(createUserOption));
}
return customFieldDTO;
}).toList();
}

View File

@ -20,6 +20,7 @@ import io.metersphere.system.service.*;
import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.*;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
@ -137,9 +138,14 @@ public class OrganizationCustomFieldControllerTests extends BaseTest {
// 插入另一条数据用户更新时重名校验
request.setScopeId(DEFAULT_ORGANIZATION_ID);
request.setType(CustomFieldType.MEMBER.name());
MvcResult anotherMvcResult = this.requestPostWithOkAndReturn(DEFAULT_ADD, request);
this.anotherAddCustomField = customFieldMapper.selectByPrimaryKey(getResultData(anotherMvcResult, CustomField.class).getId());
request.setType(CustomFieldType.MULTIPLE_MEMBER.name());
request.setName("testAAA");
this.requestPostWithOkAndReturn(DEFAULT_ADD, request);
// @@校验日志
checkLog(this.addCustomField.getId(), OperationLogType.ADD);
// @@异常参数校验
@ -239,8 +245,14 @@ public class OrganizationCustomFieldControllerTests extends BaseTest {
}
Assertions.assertEquals(customField, resultItem);
Assertions.assertEquals(resultItem.getScene(), scene);
// 有下拉框选项的校验选项
if (CustomFieldType.getHasOptionValueSet().contains(resultItem.getType())) {
if (StringUtils.equalsAny(resultItem.getType(), CustomFieldType.MEMBER.name(), CustomFieldType.MULTIPLE_MEMBER.name())) {
List<CustomFieldOption> options = resultList.get(i).getOptions();
Assertions.assertEquals(options.size(), 1);
Assertions.assertEquals(options.get(0).getValue(), "CREATE_USER");
Assertions.assertEquals(options.get(0).getText(), "创建人");
} else if (CustomFieldType.getHasOptionValueSet().contains(resultItem.getType())) {
// 有下拉框选项的校验选项
Assertions.assertEquals(resultList.get(i).getOptions().stream().sorted(Comparator.comparing(CustomFieldOption::getValue)).toList(),
baseCustomFieldOptionService.getByFieldId(customField.getId()).stream().sorted(Comparator.comparing(CustomFieldOption::getValue)).toList());
}