fix(系统设置): 组织插件开启关闭报错问题

This commit is contained in:
song-cc-rock 2023-12-18 16:52:19 +08:00 committed by 刘瑞斌
parent 9797570922
commit a1c76847aa
3 changed files with 47 additions and 16 deletions

View File

@ -587,14 +587,13 @@ public class ProjectApplicationService {
* @return 项目所属平台 * @return 项目所属平台
*/ */
public String getPlatformName(String projectId) { public String getPlatformName(String projectId) {
ProjectApplicationExample example = new ProjectApplicationExample(); ProjectApplication platformEnableConfig = getByType(projectId, ProjectApplicationType.BUG.BUG_SYNC.name() + "_" + ProjectApplicationType.BUG_SYNC_CONFIG.SYNC_ENABLE.name());
example.createCriteria().andProjectIdEqualTo(projectId).andTypeEqualTo(ProjectApplicationType.BUG.BUG_SYNC.name() + "_PLATFORM_KEY"); ProjectApplication platformKeyConfig = getByType(projectId, ProjectApplicationType.BUG.BUG_SYNC.name() + "_PLATFORM_KEY");
List<ProjectApplication> list = projectApplicationMapper.selectByExample(example); boolean isEnable = platformEnableConfig != null && Boolean.parseBoolean(platformEnableConfig.getTypeValue()) && platformKeyConfig != null;
if (CollectionUtils.isNotEmpty(list)) { if (!isEnable) {
return getPluginName(list.get(0).getTypeValue());
} else {
return "Local"; return "Local";
} }
return getPluginName(platformKeyConfig.getTypeValue());
} }
/** /**

View File

@ -3,6 +3,8 @@ package io.metersphere.project.controller;
import io.metersphere.project.controller.param.ProjectApplicationDefinition; import io.metersphere.project.controller.param.ProjectApplicationDefinition;
import io.metersphere.project.controller.param.ProjectApplicationRequestDefinition; import io.metersphere.project.controller.param.ProjectApplicationRequestDefinition;
import io.metersphere.project.domain.ProjectApplication; import io.metersphere.project.domain.ProjectApplication;
import io.metersphere.project.domain.ProjectApplicationExample;
import io.metersphere.project.mapper.ProjectApplicationMapper;
import io.metersphere.project.request.ProjectApplicationRequest; import io.metersphere.project.request.ProjectApplicationRequest;
import io.metersphere.project.service.ProjectApplicationService; import io.metersphere.project.service.ProjectApplicationService;
import io.metersphere.sdk.constants.ProjectApplicationType; import io.metersphere.sdk.constants.ProjectApplicationType;
@ -15,7 +17,6 @@ import io.metersphere.system.domain.Plugin;
import io.metersphere.system.domain.ServiceIntegration; import io.metersphere.system.domain.ServiceIntegration;
import io.metersphere.system.dto.request.ServiceIntegrationUpdateRequest; import io.metersphere.system.dto.request.ServiceIntegrationUpdateRequest;
import io.metersphere.system.mapper.ServiceIntegrationMapper; import io.metersphere.system.mapper.ServiceIntegrationMapper;
import io.metersphere.system.service.PluginService;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
@ -47,14 +48,13 @@ public class ProjectApplicationControllerTests extends BaseTest {
private static Plugin plugin; private static Plugin plugin;
@Resource @Resource
private PluginService pluginService;
@Resource
private BasePluginTestService basePluginTestService; private BasePluginTestService basePluginTestService;
@Resource @Resource
private ServiceIntegrationMapper serviceIntegrationMapper; private ServiceIntegrationMapper serviceIntegrationMapper;
@Resource @Resource
private ProjectApplicationService projectApplicationService; private ProjectApplicationService projectApplicationService;
@Resource
private ProjectApplicationMapper projectApplicationMapper;
public static final String PROJECT_ID = "project_application_test_id"; public static final String PROJECT_ID = "project_application_test_id";
public static final String TIME_TYPE_VALUE = "3M"; public static final String TIME_TYPE_VALUE = "3M";
@ -685,12 +685,43 @@ public class ProjectApplicationControllerTests extends BaseTest {
@Test @Test
@Order(40) @Order(41)
public void testGetProjectDemandThirdPartConfig() throws Exception { public void testGetProjectDemandThirdPartConfig() {
projectApplicationService.getProjectDemandThirdPartConfig(DEFAULT_PROJECT_ID); projectApplicationService.getProjectDemandThirdPartConfig(DEFAULT_PROJECT_ID);
projectApplicationService.getProjectDemandThirdPartConfig(PROJECT_ID); projectApplicationService.getProjectDemandThirdPartConfig(PROJECT_ID);
projectApplicationService.getPlatformName(DEFAULT_PROJECT_ID); projectApplicationService.getPlatformName(DEFAULT_PROJECT_ID);
projectApplicationService.getPlatformName(PROJECT_ID); projectApplicationService.getPlatformName(PROJECT_ID);
ProjectApplicationExample example = new ProjectApplicationExample();
example.createCriteria().andProjectIdEqualTo("default-project-for-application").andTypeEqualTo("BUG_SYNC_SYNC_ENABLE");
ProjectApplication record = new ProjectApplication();
record.setProjectId("default-project-for-application-tmp");
projectApplicationMapper.updateByExampleSelective(record, example);
projectApplicationService.getPlatformName("default-project-for-application");
projectApplicationService.getPlatformServiceIntegrationWithSyncOrDemand("default-project-for-application", true);
ProjectApplicationExample example1 = new ProjectApplicationExample();
example1.createCriteria().andProjectIdEqualTo("default-project-for-application-tmp").andTypeEqualTo("BUG_SYNC_SYNC_ENABLE");
record.setProjectId("default-project-for-application");
record.setTypeValue("false");
projectApplicationMapper.updateByExampleSelective(record, example1);
projectApplicationService.getPlatformName("default-project-for-application");
projectApplicationService.getPlatformServiceIntegrationWithSyncOrDemand("default-project-for-application", true);
ProjectApplicationExample example2 = new ProjectApplicationExample();
example2.createCriteria().andProjectIdEqualTo("default-project-for-application").andTypeEqualTo("BUG_SYNC_SYNC_ENABLE");
record.setTypeValue("true");
projectApplicationMapper.updateByExampleSelective(record, example2);
projectApplicationService.getPlatformName("default-project-for-application");
projectApplicationService.getPlatformServiceIntegrationWithSyncOrDemand("default-project-for-application", true);
ProjectApplicationExample example3 = new ProjectApplicationExample();
example3.createCriteria().andProjectIdEqualTo("default-project-for-application").andTypeEqualTo("BUG_SYNC_PLATFORM_KEY");
record.setProjectId("default-project-for-application-tmp");
projectApplicationMapper.updateByExampleSelective(record, example3);
projectApplicationService.getPlatformName("default-project-for-application");
projectApplicationService.getPlatformServiceIntegrationWithSyncOrDemand("default-project-for-application", true);
ProjectApplicationExample example4 = new ProjectApplicationExample();
example4.createCriteria().andProjectIdEqualTo("default-project-for-application-tmp").andTypeEqualTo("BUG_SYNC_PLATFORM_KEY");
record.setProjectId("default-project-for-application");
record.setTypeValue("jira");
projectApplicationMapper.updateByExampleSelective(record, example4);
} }

View File

@ -3,16 +3,16 @@ package io.metersphere.system.service;
import io.metersphere.plugin.platform.spi.AbstractPlatformPlugin; import io.metersphere.plugin.platform.spi.AbstractPlatformPlugin;
import io.metersphere.plugin.platform.spi.Platform; import io.metersphere.plugin.platform.spi.Platform;
import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.exception.MSException;
import io.metersphere.system.uid.IDGenerator;
import io.metersphere.sdk.util.BeanUtils; import io.metersphere.sdk.util.BeanUtils;
import io.metersphere.sdk.util.JSON; import io.metersphere.sdk.util.JSON;
import io.metersphere.system.utils.ServiceUtils;
import io.metersphere.system.domain.Plugin; import io.metersphere.system.domain.Plugin;
import io.metersphere.system.domain.ServiceIntegration; import io.metersphere.system.domain.ServiceIntegration;
import io.metersphere.system.domain.ServiceIntegrationExample; import io.metersphere.system.domain.ServiceIntegrationExample;
import io.metersphere.system.dto.ServiceIntegrationDTO; import io.metersphere.system.dto.ServiceIntegrationDTO;
import io.metersphere.system.mapper.ServiceIntegrationMapper;
import io.metersphere.system.dto.request.ServiceIntegrationUpdateRequest; import io.metersphere.system.dto.request.ServiceIntegrationUpdateRequest;
import io.metersphere.system.mapper.ServiceIntegrationMapper;
import io.metersphere.system.uid.IDGenerator;
import io.metersphere.system.utils.ServiceUtils;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -92,8 +92,9 @@ public class ServiceIntegrationService {
} }
public ServiceIntegration update(ServiceIntegrationUpdateRequest request) { public ServiceIntegration update(ServiceIntegrationUpdateRequest request) {
basePluginService.checkPluginEnableAndPermission(request.getPluginId(), request.getOrganizationId());
checkResourceExist(request.getId()); checkResourceExist(request.getId());
ServiceIntegration originServiceIntegration = serviceIntegrationMapper.selectByPrimaryKey(request.getId());
basePluginService.checkPluginEnableAndPermission(originServiceIntegration.getPluginId(), originServiceIntegration.getOrganizationId());
ServiceIntegration serviceIntegration = new ServiceIntegration(); ServiceIntegration serviceIntegration = new ServiceIntegration();
// 组织不能修改 // 组织不能修改
serviceIntegration.setOrganizationId(null); serviceIntegration.setOrganizationId(null);