refactor(项目管理): 配置三方平台key校验
This commit is contained in:
parent
cf40902d99
commit
89e3ce9266
|
@ -309,7 +309,7 @@ public class ProjectApplicationController {
|
||||||
@PostMapping("/validate/{pluginId}")
|
@PostMapping("/validate/{pluginId}")
|
||||||
@Operation(summary = "插件key校验")
|
@Operation(summary = "插件key校验")
|
||||||
public void validateProjectConfig(@PathVariable("pluginId") String pluginId, @RequestBody Map configs) {
|
public void validateProjectConfig(@PathVariable("pluginId") String pluginId, @RequestBody Map configs) {
|
||||||
projectApplicationService.validateProjectConfig(pluginId, configs);
|
projectApplicationService.validateProjectConfig(pluginId, configs, SessionUtils.getCurrentOrganizationId());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,6 @@ import io.metersphere.sdk.util.JSON;
|
||||||
import io.metersphere.sdk.util.Translator;
|
import io.metersphere.sdk.util.Translator;
|
||||||
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.User;
|
import io.metersphere.system.domain.User;
|
||||||
import io.metersphere.system.dto.sdk.OptionDTO;
|
import io.metersphere.system.dto.sdk.OptionDTO;
|
||||||
import io.metersphere.system.log.constants.OperationLogModule;
|
import io.metersphere.system.log.constants.OperationLogModule;
|
||||||
|
@ -442,19 +441,29 @@ public class ProjectApplicationService {
|
||||||
* @param pluginId
|
* @param pluginId
|
||||||
* @param configs
|
* @param configs
|
||||||
*/
|
*/
|
||||||
public void validateProjectConfig(String pluginId, Map configs) {
|
public void validateProjectConfig(String pluginId, Map configs, String organizationId) {
|
||||||
Platform platform = this.getPlatform(pluginId);
|
Platform platform = this.getPlatform(pluginId, organizationId);
|
||||||
platform.validateProjectConfig(JSON.toJSONString(configs));
|
platform.validateProjectConfig(JSON.toJSONString(configs));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Platform getPlatform(String pluginId) {
|
private Platform getPlatform(String pluginId, String organizationId) {
|
||||||
ServiceIntegrationExample example = new ServiceIntegrationExample();
|
Set<String> orgPluginIds = platformPluginService.getOrgEnabledPlatformPlugins(organizationId)
|
||||||
example.createCriteria().andPluginIdEqualTo(pluginId);
|
.stream()
|
||||||
List<ServiceIntegration> serviceIntegrations = serviceIntegrationMapper.selectByExampleWithBLOBs(example);
|
.map(Plugin::getId)
|
||||||
if (CollectionUtils.isEmpty(serviceIntegrations)) {
|
.collect(Collectors.toSet());
|
||||||
|
// 查询服务集成中启用并且支持第三方模板的插件
|
||||||
|
ServiceIntegration integration = serviceIntegrationService.getServiceIntegrationByOrgId(organizationId)
|
||||||
|
.stream()
|
||||||
|
.filter(serviceIntegration -> {
|
||||||
|
return serviceIntegration.getEnable() // 服务集成开启
|
||||||
|
&& orgPluginIds.contains(pluginId);
|
||||||
|
})
|
||||||
|
.findFirst()
|
||||||
|
.orElse(null);
|
||||||
|
if (integration == null) {
|
||||||
throw new MSException(NOT_FOUND);
|
throw new MSException(NOT_FOUND);
|
||||||
}
|
}
|
||||||
return platformPluginService.getPlatform(pluginId, serviceIntegrations.get(0).getOrganizationId(), new String(serviceIntegrations.get(0).getConfiguration()));
|
return platformPluginService.getPlatform(pluginId, integration.getOrganizationId(), new String(integration.getConfiguration()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getFakeErrorList(String projectId) {
|
public int getFakeErrorList(String projectId) {
|
||||||
|
|
|
@ -15,6 +15,7 @@ import io.metersphere.system.base.BaseTest;
|
||||||
import io.metersphere.system.controller.handler.ResultHolder;
|
import io.metersphere.system.controller.handler.ResultHolder;
|
||||||
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.dto.request.ServiceIntegrationUpdateRequest;
|
import io.metersphere.system.dto.request.ServiceIntegrationUpdateRequest;
|
||||||
import io.metersphere.system.mapper.ServiceIntegrationMapper;
|
import io.metersphere.system.mapper.ServiceIntegrationMapper;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
|
@ -639,7 +640,7 @@ public class ProjectApplicationControllerTests extends BaseTest {
|
||||||
request.setEnable(true);
|
request.setEnable(true);
|
||||||
request.setPluginId(plugin.getId());
|
request.setPluginId(plugin.getId());
|
||||||
request.setConfiguration(integrationConfigMap);
|
request.setConfiguration(integrationConfigMap);
|
||||||
request.setOrganizationId("100001100001");
|
request.setOrganizationId("100001");
|
||||||
this.requestPostWithOkAndReturn("/service/integration/add", request);
|
this.requestPostWithOkAndReturn("/service/integration/add", request);
|
||||||
mockServerClient
|
mockServerClient
|
||||||
.when(
|
.when(
|
||||||
|
@ -660,6 +661,10 @@ public class ProjectApplicationControllerTests extends BaseTest {
|
||||||
ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class);
|
ResultHolder resultHolder = JSON.parseObject(returnData, ResultHolder.class);
|
||||||
// 返回请求正常
|
// 返回请求正常
|
||||||
Assertions.assertNotNull(resultHolder);
|
Assertions.assertNotNull(resultHolder);
|
||||||
|
//测试完清掉
|
||||||
|
ServiceIntegrationExample example = new ServiceIntegrationExample();
|
||||||
|
example.createCriteria().andPluginIdEqualTo(plugin.getId()).andOrganizationIdEqualTo("100001").andEnableEqualTo(true);
|
||||||
|
serviceIntegrationMapper.deleteByExample(example);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
|
|
Loading…
Reference in New Issue