fix(个人中心): 修改平台账号校验逻辑

This commit is contained in:
song-cc-rock 2024-01-10 11:19:41 +08:00 committed by f2c-ci-robot[bot]
parent f380c3defc
commit 7edeaa06c4
4 changed files with 20 additions and 17 deletions

View File

@ -1,16 +1,16 @@
package io.metersphere.system.controller; package io.metersphere.system.controller;
import io.metersphere.system.service.*; import io.metersphere.system.service.UserPlatformAccountService;
import io.metersphere.system.utils.SessionUtils; import io.metersphere.system.utils.SessionUtils;
import io.metersphere.validation.groups.Updated;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotEmpty; import jakarta.validation.constraints.NotEmpty;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
@RestController @RestController
@ -26,15 +26,18 @@ public class UserPlatformAccountController {
return userPlatformAccountService.getAccountInfoList(); return userPlatformAccountService.getAccountInfoList();
} }
@PostMapping("/validate/{pluginId}") @PostMapping("/validate/{pluginId}/{orgId}")
@Operation(summary = "系统设置-个人中心-校验服务集成信息") @Operation(summary = "系统设置-个人中心-校验用户集成信息")
public void validate(@PathVariable String pluginId, @Parameters({
@Validated({Updated.class}) @Parameter(name = "pluginId", description = "插件ID", schema = @Schema(requiredMode = Schema.RequiredMode.REQUIRED)),
@Parameter(name = "orgId", description = "组织ID", schema = @Schema(requiredMode = Schema.RequiredMode.REQUIRED))
})
public void validate(@PathVariable String pluginId, @PathVariable String orgId,
@RequestBody @RequestBody
@NotEmpty @NotEmpty
@Schema(description = "配置的表单键值对", requiredMode = Schema.RequiredMode.REQUIRED) @Schema(description = "用户配置集成信息", requiredMode = Schema.RequiredMode.REQUIRED)
HashMap<String, String> serviceIntegrationInfo) { Map<String, String> userPlatformConfig) {
userPlatformAccountService.validate(pluginId, serviceIntegrationInfo); userPlatformAccountService.validate(pluginId, orgId, userPlatformConfig);
} }
@PostMapping("/save") @PostMapping("/save")

View File

@ -15,7 +15,6 @@ import io.metersphere.system.log.dto.LogDTO;
import io.metersphere.system.log.service.OperationLogService; import io.metersphere.system.log.service.OperationLogService;
import io.metersphere.system.mapper.UserExtendMapper; import io.metersphere.system.mapper.UserExtendMapper;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -56,9 +55,10 @@ public class UserPlatformAccountService {
return pluginLoadService.getPluginScriptContent(pluginId, platformPlugin.getAccountScriptId()); return pluginLoadService.getPluginScriptContent(pluginId, platformPlugin.getAccountScriptId());
} }
public void validate(String pluginId, Map<String, String> serviceIntegrationInfo) { public void validate(String pluginId, String orgId, Map<String, String> userPlatformConfig) {
Platform platform = platformPluginService.getPlatform(pluginId, StringUtils.EMPTY, JSON.toJSONString(serviceIntegrationInfo)); // 获取组织服务集成信息
platform.validateIntegrationConfig(); Platform platform = platformPluginService.getPlatform(pluginId, orgId);
platform.validateUserConfig(JSON.toJSONString(userPlatformConfig));
} }
public void save(Map<String, Object> platformInfo, String userId) { public void save(Map<String, Object> platformInfo, String userId) {

View File

@ -34,7 +34,7 @@ public class UserPlatformAccountControllerTests extends BaseTest {
private int mockServerHostPort; private int mockServerHostPort;
@Resource @Resource
private MockServerClient mockServerClient; private MockServerClient mockServerClient;
private static final String VALIDATE_POST = "/user/platform/validate/{0}"; private static final String VALIDATE_POST = "/user/platform/validate/{0}/{1}";
private static final String SAVE_POST = "/user/platform/save"; private static final String SAVE_POST = "/user/platform/save";
public static <T> T parseObjectFromMvcResult(MvcResult mvcResult, Class<T> parseClass) { public static <T> T parseObjectFromMvcResult(MvcResult mvcResult, Class<T> parseClass) {
try { try {
@ -78,7 +78,7 @@ public class UserPlatformAccountControllerTests extends BaseTest {
integrationConfig.setAddress(String.format("http://%s:%s", mockServerHost, mockServerHostPort)); integrationConfig.setAddress(String.format("http://%s:%s", mockServerHost, mockServerHostPort));
Map<String, Object> integrationConfigMap = JSON.parseMap(JSON.toJSONString(integrationConfig)); Map<String, Object> integrationConfigMap = JSON.parseMap(JSON.toJSONString(integrationConfig));
// @@请求成功 // @@请求成功
this.requestPostWithOk(VALIDATE_POST, integrationConfigMap, plugin.getId()); this.requestPostWithOk(VALIDATE_POST, integrationConfigMap, plugin.getId(), "100001");
} }
@Test @Test