diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/AuthSourceController.java b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/AuthSourceController.java index 3eb8cd5e37..42247adaa9 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/AuthSourceController.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/AuthSourceController.java @@ -10,6 +10,7 @@ import io.metersphere.sdk.util.PageUtils; import io.metersphere.sdk.util.Pager; import io.metersphere.system.domain.AuthSource; import io.metersphere.system.request.AuthSourceRequest; +import io.metersphere.system.request.AuthSourceStatusRequest; import io.metersphere.system.service.AuthSourceLogService; import io.metersphere.system.service.AuthSourceService; import io.swagger.v3.oas.annotations.Operation; @@ -42,16 +43,16 @@ public class AuthSourceController { @Operation(summary = "新增认证设置") @RequiresPermissions(PermissionConstants.SYSTEM_PARAMETER_SETTING_AUTH_READ_CREAT) @Log(type = OperationLogType.ADD, expression = "#msClass.addLog(#authSource)", msClass = AuthSourceLogService.class) - public void add(@Validated @RequestBody AuthSourceRequest authSource) { - authSourceService.addAuthSource(authSource); + public AuthSource add(@Validated @RequestBody AuthSourceRequest authSource) { + return authSourceService.addAuthSource(authSource); } @PostMapping("/update") @Operation(summary = "更新认证设置") @RequiresPermissions(PermissionConstants.SYSTEM_PARAMETER_SETTING_AUTH_READ_UPDATE) @Log(type = OperationLogType.UPDATE, expression = "#msClass.updateLog(#authSource)", msClass = AuthSourceLogService.class) - public void update(@Validated @RequestBody AuthSourceRequest authSource) { - authSourceService.updateAuthSource(authSource); + public AuthSourceRequest update(@Validated @RequestBody AuthSourceRequest authSource) { + return authSourceService.updateAuthSource(authSource); } @GetMapping("/get/{id}") @@ -70,11 +71,11 @@ public class AuthSourceController { } - @GetMapping("/update/{authId}/status/{status}") + @PostMapping("/update/status") @Operation(summary = "更新状态") @RequiresPermissions(PermissionConstants.SYSTEM_PARAMETER_SETTING_AUTH_READ_UPDATE) - @Log(type = OperationLogType.UPDATE, expression = "#msClass.updateLog(#authId)", msClass = AuthSourceLogService.class) - public void updateStatus(@PathVariable(value = "authId") String authId, @PathVariable("status") String status) { - authSourceService.updateStatus(authId, status); + @Log(type = OperationLogType.UPDATE, expression = "#msClass.updateLog(#request.getId())", msClass = AuthSourceLogService.class) + public void updateStatus(@Validated @RequestBody AuthSourceStatusRequest request ) { + authSourceService.updateStatus(request.getId(), request.getEnable()); } } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/request/AuthSourceStatusRequest.java b/backend/services/system-setting/src/main/java/io/metersphere/system/request/AuthSourceStatusRequest.java new file mode 100644 index 0000000000..0bf7384ce6 --- /dev/null +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/request/AuthSourceStatusRequest.java @@ -0,0 +1,18 @@ +package io.metersphere.system.request; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; + +@Data +@EqualsAndHashCode(callSuper = false) +public class AuthSourceStatusRequest implements Serializable { + private static final long serialVersionUID = 1L; + @Schema(title = "是否禁用") + private Boolean enable; + + @Schema(title = "id") + private String id; +} diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/AuthSourceService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/AuthSourceService.java index 6d6d32c9fe..0acdf43106 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/AuthSourceService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/AuthSourceService.java @@ -26,10 +26,11 @@ public class AuthSourceService { return authSourceMapper.selectByExample(example); } - public void addAuthSource(AuthSourceRequest authSource) { + public AuthSource addAuthSource(AuthSourceRequest authSource) { checkAuthSource(authSource); AuthSource source = delRequestToDB(authSource); authSourceMapper.insertSelective(source); + return source; } private AuthSource delRequestToDB(AuthSourceRequest authSource) { @@ -47,9 +48,6 @@ public class AuthSourceService { public void checkAuthSource(AuthSourceRequest authSource) { String resourcePoolName = authSource.getName(); - if (StringUtils.isBlank(resourcePoolName)) { - throw new MSException(Translator.get("authsource_name_is_null")); - } AuthSourceExample example = new AuthSourceExample(); AuthSourceExample.Criteria criteria = example.createCriteria(); @@ -74,7 +72,7 @@ public class AuthSourceService { return authSourceMapper.selectByPrimaryKey(id); } - public void updateAuthSource(AuthSourceRequest authSource) { + public AuthSourceRequest updateAuthSource(AuthSourceRequest authSource) { checkAuthSource(authSource); AuthSource source = authSourceMapper.selectByPrimaryKey(authSource.getId()); if (source != null) { @@ -84,13 +82,16 @@ public class AuthSourceService { source.setUpdateTime(System.currentTimeMillis()); authSourceMapper.updateByPrimaryKeySelective(source); } + return authSource; } - public void updateStatus(String id, String status) { - AuthSource record = new AuthSource(); - record.setId(id); - record.setEnable(Boolean.parseBoolean(status)); - record.setUpdateTime(System.currentTimeMillis()); - authSourceMapper.updateByPrimaryKeySelective(record); + public void updateStatus(String id, Boolean status) { + if (status != null) { + AuthSource record = new AuthSource(); + record.setId(id); + record.setEnable(status); + record.setUpdateTime(System.currentTimeMillis()); + authSourceMapper.updateByPrimaryKeySelective(record); + } } } diff --git a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/AuthSourceControllerTests.java b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/AuthSourceControllerTests.java index 59bd5f6166..f8951b14f1 100644 --- a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/AuthSourceControllerTests.java +++ b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/AuthSourceControllerTests.java @@ -9,6 +9,7 @@ import io.metersphere.sdk.util.JSON; import io.metersphere.sdk.util.Pager; import io.metersphere.system.domain.AuthSource; import io.metersphere.system.request.AuthSourceRequest; +import io.metersphere.system.request.AuthSourceStatusRequest; import org.junit.jupiter.api.MethodOrderer; import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; @@ -21,6 +22,7 @@ import org.springframework.test.web.servlet.ResultMatcher; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import java.nio.charset.StandardCharsets; +import java.util.HashMap; import java.util.List; import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; @@ -44,13 +46,18 @@ public class AuthSourceControllerTests extends BaseTest { private static final ResultMatcher CLIENT_ERROR_MATCHER = status().is4xxClientError(); + public static final String AUTH_SOURCE_UPDATE_STATUS = "/system/authsource/update/status"; + + private static final ResultMatcher ERROR_REQUEST_MATCHER = status().is5xxServerError(); + @Test @Order(1) public void testAddSource() throws Exception { AuthSourceRequest authSource = new AuthSourceRequest(); - authSource.setConfiguration("123"); authSource.setName("测试CAS"); authSource.setType("CAS"); + this.requestPost(AUTH_SOURCE_ADD, authSource,ERROR_REQUEST_MATCHER); + authSource.setConfiguration("123"); this.requestPost(AUTH_SOURCE_ADD, authSource); // @@校验权限 @@ -64,6 +71,10 @@ public class AuthSourceControllerTests extends BaseTest { basePageRequest.setCurrent(1); basePageRequest.setPageSize(10); this.requestPost(AUTH_SOURCE_LIST, basePageRequest); + basePageRequest.setSort(new HashMap<>() {{ + put("createTime", "desc"); + }}); + this.requestPost(AUTH_SOURCE_LIST, basePageRequest); requestPostPermissionTest(PermissionConstants.SYSTEM_PARAMETER_SETTING_AUTH_READ, AUTH_SOURCE_LIST, basePageRequest); } @@ -74,11 +85,12 @@ public class AuthSourceControllerTests extends BaseTest { public void testUpdateSource() throws Exception { List authSourceList = this.getAuthSourceList(); AuthSourceRequest authSource = new AuthSourceRequest(); - authSource.setId(authSourceList.get(0).getId()); + authSource.setId("authsource_id"); authSource.setConfiguration("123666"); authSource.setName("更新"); authSource.setType("CAS"); this.requestPost(AUTH_SOURCE_UPDATE, authSource); + authSource.setId(authSourceList.get(0).getId()); requestPostPermissionTest(PermissionConstants.SYSTEM_PARAMETER_SETTING_AUTH_READ_UPDATE, AUTH_SOURCE_UPDATE, authSource); } @@ -86,11 +98,14 @@ public class AuthSourceControllerTests extends BaseTest { @Test @Order(4) public void testUpdateStatus() throws Exception { - List authSourceList = this.getAuthSourceList(); - String url = AUTH_SOURCE_UPDATE + "/" + authSourceList.get(0).getId() + "/status/false"; - this.requestGet(url); - requestGetPermissionTest(PermissionConstants.SYSTEM_PARAMETER_SETTING_AUTH_READ_UPDATE, url); + List authSourceList = this.getAuthSourceList(); + AuthSourceStatusRequest request = new AuthSourceStatusRequest(); + request.setId(authSourceList.get(0).getId()); + this.requestPost(AUTH_SOURCE_UPDATE_STATUS, request); + request.setEnable(false); + this.requestPost(AUTH_SOURCE_UPDATE_STATUS, request); + requestPostPermissionTest(PermissionConstants.SYSTEM_PARAMETER_SETTING_AUTH_READ_UPDATE, AUTH_SOURCE_UPDATE_STATUS, request); } diff --git a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/OperationLogControllerTests.java b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/OperationLogControllerTests.java index 1bb29c8140..f6692c9e5b 100644 --- a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/OperationLogControllerTests.java +++ b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/OperationLogControllerTests.java @@ -132,7 +132,7 @@ public class OperationLogControllerTests extends BaseTest { this.requestGetWithOkAndReturn(OPTIONS_LIST); // @@校验权限 - //requestGetPermissionTest(PermissionConstants.SYSTEM_OPERATING_LOG_READ, OPTIONS_LIST); + requestGetPermissionTest(PermissionConstants.SYSTEM_OPERATING_LOG_READ, OPTIONS_LIST); } @Test @@ -141,7 +141,7 @@ public class OperationLogControllerTests extends BaseTest { this.requestGetWithOkAndReturn(USER_LIST); // @@校验权限 - // requestGetPermissionTest(PermissionConstants.SYSTEM_OPERATING_LOG_READ, USER_LIST); + requestGetPermissionTest(PermissionConstants.SYSTEM_OPERATING_LOG_READ, USER_LIST); } @Test