mirror of
https://gitee.com/fit2cloud-feizhiyun/MeterSphere.git
synced 2024-11-29 18:48:13 +08:00
fix(系统设置): 插件更新接口不传name字段报错
This commit is contained in:
parent
2974d1196b
commit
35c697674c
@ -22,10 +22,10 @@ public class PluginUpdateRequest {
|
||||
private String name;
|
||||
|
||||
@Schema(title = "是否启用插件, 默认启用")
|
||||
private Boolean enable = true;
|
||||
private Boolean enable;
|
||||
|
||||
@Schema(title = "是否是全局插件, 默认全局")
|
||||
private Boolean global = true;
|
||||
private Boolean global;
|
||||
|
||||
@Schema(title = "插件描述")
|
||||
@Size(min = 1, max = 500, message = "{plugin.scenario.length_range}", groups = {Created.class, Updated.class})
|
||||
|
@ -16,6 +16,8 @@ import io.metersphere.system.mapper.PluginMapper;
|
||||
import io.metersphere.system.request.PluginUpdateRequest;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.kafka.core.KafkaTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@ -74,6 +76,9 @@ public class PluginService {
|
||||
plugin.setFileName(file.getOriginalFilename());
|
||||
plugin.setCreateTime(System.currentTimeMillis());
|
||||
plugin.setUpdateTime(System.currentTimeMillis());
|
||||
// 如果没有,默认设置为 true
|
||||
request.setEnable(!BooleanUtils.isFalse(request.getEnable()));
|
||||
request.setEnable(!BooleanUtils.isFalse(request.getEnable()));
|
||||
|
||||
// 校验重名
|
||||
checkPluginAddExist(plugin);
|
||||
@ -161,7 +166,7 @@ public class PluginService {
|
||||
// 校验重名
|
||||
checkPluginUpdateExist(plugin);
|
||||
pluginMapper.updateByPrimaryKeySelective(plugin);
|
||||
if (request.getGlobal()) {
|
||||
if (BooleanUtils.isTrue(request.getGlobal())) {
|
||||
// 全局插件,删除和组织的关联关系
|
||||
request.setOrganizationIds(new ArrayList<>(0));
|
||||
}
|
||||
@ -170,6 +175,9 @@ public class PluginService {
|
||||
}
|
||||
|
||||
private void checkPluginUpdateExist(Plugin plugin) {
|
||||
if (StringUtils.isBlank(plugin.getName())) {
|
||||
return;
|
||||
}
|
||||
PluginExample example = new PluginExample();
|
||||
example.createCriteria()
|
||||
.andIdNotEqualTo(plugin.getId())
|
||||
|
@ -78,7 +78,7 @@ public class PluginControllerTests extends BaseTest {
|
||||
|
||||
request.setName("test");
|
||||
request.setDescription("test desc");
|
||||
request.setGlobal(false);
|
||||
request.setGlobal(true);
|
||||
request.setEnable(false);
|
||||
request.setOrganizationIds(Arrays.asList(org.getId()));
|
||||
MultiValueMap<String, Object> multiValueMap = getDefaultMultiPartParam(request, jarFile);
|
||||
@ -94,10 +94,27 @@ public class PluginControllerTests extends BaseTest {
|
||||
Assertions.assertEquals(plugin.getXpack(), false);
|
||||
Assertions.assertEquals(plugin.getFileName(), jarFile.getName());
|
||||
Assertions.assertEquals(plugin.getScenario(), PluginScenarioType.API.name());
|
||||
Assertions.assertEquals(Arrays.asList(org.getId()), getOrgIdsByPlugId(plugin.getId()));
|
||||
Assertions.assertEquals(new ArrayList<>(0), getOrgIdsByPlugId(plugin.getId()));
|
||||
Assertions.assertEquals(Arrays.asList("connect", "disconnect", "pub", "sub"), getScriptIdsByPlugId(plugin.getId()));
|
||||
addPlugin = plugin;
|
||||
|
||||
// 增加覆盖率
|
||||
this.requestGetWithOkAndReturn(DEFAULT_LIST);
|
||||
|
||||
// 校验 global 为 tru e时,organizationIds 为空
|
||||
request.setGlobal(false);
|
||||
request.setEnable(true);
|
||||
request.setName("test2");
|
||||
request.setOrganizationIds(Arrays.asList(org.getId()));
|
||||
MvcResult antoherMvcResult = this.requestMultipartWithOkAndReturn(DEFAULT_ADD,
|
||||
getDefaultMultiPartParam(request, anotherJarFile));
|
||||
Plugin antoherPlugin = pluginMapper.selectByPrimaryKey(getResultData(antoherMvcResult, Plugin.class).getId());
|
||||
Assertions.assertEquals(antoherPlugin.getEnable(), request.getEnable());
|
||||
Assertions.assertEquals(antoherPlugin.getGlobal(), request.getGlobal());
|
||||
Assertions.assertEquals(Arrays.asList(org.getId()), getOrgIdsByPlugId(antoherPlugin.getId()));
|
||||
anotherAddPlugin = antoherPlugin;
|
||||
addPlugin = plugin;
|
||||
|
||||
// @@重名校验异常
|
||||
// 校验插件名称重名
|
||||
assertErrorCode(this.requestMultipart(DEFAULT_ADD,
|
||||
@ -132,20 +149,6 @@ public class PluginControllerTests extends BaseTest {
|
||||
assertErrorCode(this.requestMultipart(DEFAULT_ADD,
|
||||
getDefaultMultiPartParam(request, scriptIdRepeatFile)), PLUGIN_SCRIPT_EXIST);
|
||||
|
||||
request.setGlobal(true);
|
||||
request.setEnable(true);
|
||||
request.setName("test2");
|
||||
MvcResult antoherMvcResult = this.requestMultipartWithOkAndReturn(DEFAULT_ADD,
|
||||
getDefaultMultiPartParam(request, anotherJarFile));
|
||||
// 校验 global 为 tru e时,organizationIds 为空
|
||||
Plugin antoherPlugin = pluginMapper.selectByPrimaryKey(getResultData(antoherMvcResult, Plugin.class).getId());
|
||||
Assertions.assertEquals(antoherPlugin.getEnable(), request.getEnable());
|
||||
Assertions.assertEquals(antoherPlugin.getGlobal(), request.getGlobal());
|
||||
Assertions.assertEquals(new ArrayList<>(0), getOrgIdsByPlugId(antoherPlugin.getId()));
|
||||
anotherAddPlugin = antoherPlugin;
|
||||
|
||||
this.addPlugin = plugin;
|
||||
|
||||
// @@校验日志
|
||||
checkLog(this.addPlugin.getId(), OperationLogType.ADD);
|
||||
// @@校验权限
|
||||
@ -185,12 +188,18 @@ public class PluginControllerTests extends BaseTest {
|
||||
// 校验 global 为 false 时,organizationIds 数据
|
||||
request.setGlobal(false);
|
||||
this.requestPostWithOk(DEFAULT_UPDATE, request);
|
||||
Assertions.assertEquals(Arrays.asList(org.getId()), getOrgIdsByPlugId(plugin.getId()));
|
||||
Assertions.assertEquals(Arrays.asList(org.getId()), getOrgIdsByPlugId(request.getId()));
|
||||
|
||||
// 只修改启用禁用
|
||||
PluginUpdateRequest activeRequest = new PluginUpdateRequest();
|
||||
activeRequest.setId(request.getId());
|
||||
activeRequest.setEnable(true);
|
||||
this.requestPostWithOk(DEFAULT_UPDATE, activeRequest);
|
||||
|
||||
// 校验组织为null,不修改关联关系
|
||||
request.setOrganizationIds(null);
|
||||
this.requestPostWithOk(DEFAULT_UPDATE, request);
|
||||
Assertions.assertEquals(Arrays.asList(org.getId()), getOrgIdsByPlugId(plugin.getId()));
|
||||
Assertions.assertEquals(Arrays.asList(org.getId()), getOrgIdsByPlugId(request.getId()));
|
||||
|
||||
// @@重名校验异常
|
||||
request.setName(anotherAddPlugin.getName());
|
||||
|
Loading…
Reference in New Issue
Block a user