diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectCustomFieldService.java b/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectCustomFieldService.java index 488de8d27b..235b36127d 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectCustomFieldService.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/service/ProjectCustomFieldService.java @@ -52,7 +52,7 @@ public class ProjectCustomFieldService extends BaseCustomFieldService { CustomField originCustomField = getWithCheck(customField.getId()); if (originCustomField.getInternal()) { // 内置字段不能修改名字 - originCustomField.setName(null); + customField.setName(null); } customField.setScopeId(originCustomField.getScopeId()); Project project = projectService.checkResourceExist(originCustomField.getScopeId()); diff --git a/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectCustomFieldControllerTests.java b/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectCustomFieldControllerTests.java index 8a97c04ff2..d44eae86ee 100644 --- a/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectCustomFieldControllerTests.java +++ b/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectCustomFieldControllerTests.java @@ -177,10 +177,13 @@ public class ProjectCustomFieldControllerTests extends BaseTest { } CustomFieldExample example = new CustomFieldExample(); - example.createCriteria().andScopeIdEqualTo(DEFAULT_PROJECT_ID).andInternalEqualTo(true); - request = BeanUtils.copyBean(request, customFieldMapper.selectByExample(example).get(0)); - this.requestPostWithOk(DEFAULT_UPDATE, request); + example.createCriteria().andScopeIdEqualTo(DEFAULT_PROJECT_ID).andNameEqualTo("functional_priority"); + CustomFieldUpdateRequest internalRequest = BeanUtils.copyBean(new CustomFieldUpdateRequest(), customFieldMapper.selectByExample(example).get(0)); + internalRequest.setName("aaaa"); + this.requestPostWithOk(DEFAULT_UPDATE, internalRequest); Assertions.assertEquals(customFieldMapper.selectByExample(example).get(0).getInternal(), true); + // 内置字段名称不能修改 + Assertions.assertEquals(customFieldMapper.selectByExample(example).get(0).getName(), "functional_priority"); // @校验是否开启项目模板 changeOrgTemplateEnable(true); diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/OrganizationCustomFieldService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/OrganizationCustomFieldService.java index 3d62a198f8..3dcaacb7aa 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/OrganizationCustomFieldService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/OrganizationCustomFieldService.java @@ -83,7 +83,7 @@ public class OrganizationCustomFieldService extends BaseCustomFieldService { CustomField originCustomField = getWithCheck(customField.getId()); if (originCustomField.getInternal()) { // 内置字段不能修改名字 - originCustomField.setName(null); + customField.setName(null); } checkOrganizationTemplateEnable(customField.getScopeId(), originCustomField.getScene()); customField.setScopeId(originCustomField.getScopeId()); diff --git a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/OrganizationCustomFieldControllerTests.java b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/OrganizationCustomFieldControllerTests.java index a0b8e3eeba..d4567a335a 100644 --- a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/OrganizationCustomFieldControllerTests.java +++ b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/OrganizationCustomFieldControllerTests.java @@ -182,10 +182,13 @@ public class OrganizationCustomFieldControllerTests extends BaseTest { assertRefCustomField(customField); CustomFieldExample example = new CustomFieldExample(); - example.createCriteria().andScopeIdEqualTo(DEFAULT_ORGANIZATION_ID).andInternalEqualTo(true); - request = BeanUtils.copyBean(request, customFieldMapper.selectByExample(example).get(0)); - this.requestPostWithOk(DEFAULT_UPDATE, request); + example.createCriteria().andScopeIdEqualTo(DEFAULT_ORGANIZATION_ID).andNameEqualTo("functional_priority"); + CustomFieldUpdateRequest internalRequest = BeanUtils.copyBean(new CustomFieldUpdateRequest(), customFieldMapper.selectByExample(example).get(0)); + internalRequest.setName("aaaa"); + this.requestPostWithOk(DEFAULT_UPDATE, internalRequest); Assertions.assertEquals(customFieldMapper.selectByExample(example).get(0).getInternal(), true); + // 内置字段名称不能修改 + Assertions.assertEquals(customFieldMapper.selectByExample(example).get(0).getName(), "functional_priority"); // @校验是否开启组织模板 changeOrgTemplateEnable(false);