refactor(接口测试): 优化接口定义删除接口
This commit is contained in:
parent
1d0ef9a28a
commit
f424fd1a4b
|
@ -82,22 +82,22 @@ public class ApiDefinitionController {
|
||||||
apiDefinitionService.batchUpdate(request, SessionUtils.getUserId());
|
apiDefinitionService.batchUpdate(request, SessionUtils.getUserId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping(value = "/delete")
|
@GetMapping("/delete-to-gc/{id}")
|
||||||
@Operation(summary = "接口测试-接口管理-删除接口定义到回收站")
|
@Operation(summary = "接口测试-接口管理-删除接口定义到回收站")
|
||||||
@RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_DELETE)
|
@RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_DELETE)
|
||||||
@Log(type = OperationLogType.DELETE, expression = "#msClass.delLog(#request)", msClass = ApiDefinitionLogService.class)
|
@Log(type = OperationLogType.DELETE, expression = "#msClass.moveToGcLog(#id)", msClass = ApiDefinitionLogService.class)
|
||||||
@CheckOwner(resourceId = "#request.getId()", resourceType = "api_definition")
|
@CheckOwner(resourceId = "#id", resourceType = "api_definition")
|
||||||
public void delete(@Validated @RequestBody ApiDefinitionDeleteRequest request) {
|
public void deleteToGc(@PathVariable String id, @RequestParam(required = false) boolean deleteAllVersion) {
|
||||||
apiDefinitionService.delete(request, SessionUtils.getUserId());
|
apiDefinitionService.deleteToGc(id, deleteAllVersion, SessionUtils.getUserId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping(value = "/batch-del")
|
@PostMapping(value = "/batch/delete-to-gc")
|
||||||
@Operation(summary = "接口测试-接口管理-批量删除接口定义到回收站")
|
@Operation(summary = "接口测试-接口管理-批量删除接口定义到回收站")
|
||||||
@RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_DELETE)
|
@RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_DELETE)
|
||||||
@CheckOwner(resourceId = "#request.getSelectIds()", resourceType = "api_definition")
|
@CheckOwner(resourceId = "#request.getSelectIds()", resourceType = "api_definition")
|
||||||
@SendNotice(taskType = NoticeConstants.TaskType.API_DEFINITION_TASK, event = NoticeConstants.Event.DELETE, target = "#targetClass.getBatchEditApiDTO(#request)", targetClass = ApiDefinitionNoticeService.class)
|
@SendNotice(taskType = NoticeConstants.TaskType.API_DEFINITION_TASK, event = NoticeConstants.Event.DELETE, target = "#targetClass.getBatchEditApiDTO(#request)", targetClass = ApiDefinitionNoticeService.class)
|
||||||
public void batchDelete(@Validated @RequestBody ApiDefinitionBatchRequest request) {
|
public void batchDeleteToGc(@Validated @RequestBody ApiDefinitionBatchRequest request) {
|
||||||
apiDefinitionService.batchDelete(request, SessionUtils.getUserId());
|
apiDefinitionService.batchDeleteToGc(request, SessionUtils.getUserId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping(value = "/copy")
|
@PostMapping(value = "/copy")
|
||||||
|
@ -161,13 +161,21 @@ public class ApiDefinitionController {
|
||||||
apiDefinitionService.recover(request, SessionUtils.getUserId());
|
apiDefinitionService.recover(request, SessionUtils.getUserId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping(value = "/trash-del")
|
@GetMapping("/delete/{id}")
|
||||||
@Operation(summary = "接口测试-接口管理-删除回收站接口定义")
|
@Operation(summary = "接口测试-接口管理-删除回收站接口定义")
|
||||||
@RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_DELETE)
|
@RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_DELETE)
|
||||||
@Log(type = OperationLogType.DELETE, expression = "#msClass.trashDelLog(#request)", msClass = ApiDefinitionLogService.class)
|
@Log(type = OperationLogType.DELETE, expression = "#msClass.deleteLog(#id)", msClass = ApiDefinitionLogService.class)
|
||||||
@CheckOwner(resourceId = "#request.getId()", resourceType = "api_definition")
|
@CheckOwner(resourceId = "#id", resourceType = "api_definition")
|
||||||
public void trashDel(@Validated @RequestBody ApiDefinitionDeleteRequest request) {
|
public void delete(@PathVariable String id) {
|
||||||
apiDefinitionService.trashDel(request, SessionUtils.getUserId());
|
apiDefinitionService.delete(id, SessionUtils.getUserId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/batch/delete")
|
||||||
|
@Operation(summary = "接口测试-接口管理-批量从回收站删除接口定义")
|
||||||
|
@RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_DELETE)
|
||||||
|
@CheckOwner(resourceId = "#request.getSelectIds()", resourceType = "api_definition")
|
||||||
|
public void batchDelete(@Validated @RequestBody ApiDefinitionBatchRequest request) {
|
||||||
|
apiDefinitionService.batchDelete(request, SessionUtils.getUserId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping(value = "/batch-recover")
|
@PostMapping(value = "/batch-recover")
|
||||||
|
@ -178,14 +186,6 @@ public class ApiDefinitionController {
|
||||||
apiDefinitionService.batchRecover(request, SessionUtils.getUserId());
|
apiDefinitionService.batchRecover(request, SessionUtils.getUserId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping(value = "/batch-trash-del")
|
|
||||||
@Operation(summary = "接口测试-接口管理-批量从回收站删除接口定义")
|
|
||||||
@RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_DELETE)
|
|
||||||
@CheckOwner(resourceId = "#request.getSelectIds()", resourceType = "api_definition")
|
|
||||||
public void batchTrashDel(@Validated @RequestBody ApiDefinitionBatchRequest request) {
|
|
||||||
apiDefinitionService.batchTrashDel(request, SessionUtils.getUserId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("/page-doc")
|
@PostMapping("/page-doc")
|
||||||
@Operation(summary = "接口测试-接口管理-接口文档列表")
|
@Operation(summary = "接口测试-接口管理-接口文档列表")
|
||||||
@RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_DOC_READ)
|
@RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_DOC_READ)
|
||||||
|
|
|
@ -65,7 +65,7 @@ public class ApiTestCaseController {
|
||||||
return apiTestCaseService.get(id, SessionUtils.getUserId());
|
return apiTestCaseService.get(id, SessionUtils.getUserId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/move-gc/{id}")
|
@GetMapping("/delete-to-gc/{id}")
|
||||||
@Operation(summary = "接口测试-接口管理-接口用例-移动到回收站")
|
@Operation(summary = "接口测试-接口管理-接口用例-移动到回收站")
|
||||||
@RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_CASE_DELETE)
|
@RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_CASE_DELETE)
|
||||||
@Log(type = OperationLogType.DELETE, expression = "#msClass.moveToGcLog(#id)", msClass = ApiTestCaseLogService.class)
|
@Log(type = OperationLogType.DELETE, expression = "#msClass.moveToGcLog(#id)", msClass = ApiTestCaseLogService.class)
|
||||||
|
@ -159,7 +159,7 @@ public class ApiTestCaseController {
|
||||||
apiTestCaseService.batchDelete(request, SessionUtils.getUserId());
|
apiTestCaseService.batchDelete(request, SessionUtils.getUserId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/batch/move-gc")
|
@PostMapping("/batch/delete-to-gc")
|
||||||
@Operation(summary = "接口测试-接口管理-接口用例-批量移动到回收站")
|
@Operation(summary = "接口测试-接口管理-接口用例-批量移动到回收站")
|
||||||
@RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_CASE_DELETE)
|
@RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_CASE_DELETE)
|
||||||
@CheckOwner(resourceId = "#request.getSelectIds()", resourceType = "api_test_case")
|
@CheckOwner(resourceId = "#request.getSelectIds()", resourceType = "api_test_case")
|
||||||
|
|
|
@ -33,7 +33,7 @@ public class ApiDebugAddRequest implements Serializable {
|
||||||
private String method;
|
private String method;
|
||||||
|
|
||||||
@Schema(description = "http协议url/其它协议则为空")
|
@Schema(description = "http协议url/其它协议则为空")
|
||||||
@Size(max = 500, message = "{api_debug.protocol.length_range}")
|
@Size(max = 500, message = "{api_debug.path.length_range}")
|
||||||
private String path;
|
private String path;
|
||||||
|
|
||||||
@Schema(description = "项目fk", requiredMode = Schema.RequiredMode.REQUIRED)
|
@Schema(description = "项目fk", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
|
|
@ -31,7 +31,7 @@ public class ApiDebugUpdateRequest implements Serializable {
|
||||||
private String method;
|
private String method;
|
||||||
|
|
||||||
@Schema(description = "http协议路径/其它协议则为空")
|
@Schema(description = "http协议路径/其它协议则为空")
|
||||||
@Size(max = 500, message = "{api_debug.protocol.length_range}")
|
@Size(max = 500, message = "{api_debug.path.length_range}")
|
||||||
private String path;
|
private String path;
|
||||||
|
|
||||||
@Schema(description = "模块fk", requiredMode = Schema.RequiredMode.REQUIRED)
|
@Schema(description = "模块fk", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
|
|
@ -47,7 +47,7 @@ public class ApiDefinitionAddRequest implements Serializable {
|
||||||
private String method;
|
private String method;
|
||||||
|
|
||||||
@Schema(description = "http协议路径/其它协议则为空")
|
@Schema(description = "http协议路径/其它协议则为空")
|
||||||
@Size(max = 500, message = "{api_debug.protocol.length_range}")
|
@Size(max = 500, message = "{api_debug.path.length_range}")
|
||||||
private String path;
|
private String path;
|
||||||
|
|
||||||
@Schema(description = "接口状态/进行中/已完成", requiredMode = Schema.RequiredMode.REQUIRED)
|
@Schema(description = "接口状态/进行中/已完成", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
|
|
|
@ -11,6 +11,7 @@ import io.metersphere.sdk.util.BeanUtils;
|
||||||
import io.metersphere.sdk.util.CommonBeanFactory;
|
import io.metersphere.sdk.util.CommonBeanFactory;
|
||||||
import io.metersphere.sdk.util.JSON;
|
import io.metersphere.sdk.util.JSON;
|
||||||
import io.metersphere.sdk.util.Translator;
|
import io.metersphere.sdk.util.Translator;
|
||||||
|
import io.metersphere.system.log.aspect.OperationLogAspect;
|
||||||
import io.metersphere.system.log.constants.OperationLogModule;
|
import io.metersphere.system.log.constants.OperationLogModule;
|
||||||
import io.metersphere.system.log.constants.OperationLogType;
|
import io.metersphere.system.log.constants.OperationLogType;
|
||||||
import io.metersphere.system.log.dto.LogDTO;
|
import io.metersphere.system.log.dto.LogDTO;
|
||||||
|
@ -52,8 +53,8 @@ public class ApiDefinitionLogService {
|
||||||
OperationLogType.ADD.name(),
|
OperationLogType.ADD.name(),
|
||||||
OperationLogModule.API_TEST_MANAGEMENT_DEFINITION,
|
OperationLogModule.API_TEST_MANAGEMENT_DEFINITION,
|
||||||
request.getName());
|
request.getName());
|
||||||
|
|
||||||
dto.setHistory(false);
|
dto.setHistory(false);
|
||||||
dto.setPath("/api/definition/add");
|
|
||||||
dto.setMethod(HttpMethodConstants.POST.name());
|
dto.setMethod(HttpMethodConstants.POST.name());
|
||||||
dto.setOriginalValue(JSON.toJSONBytes(request));
|
dto.setOriginalValue(JSON.toJSONBytes(request));
|
||||||
return dto;
|
return dto;
|
||||||
|
@ -77,7 +78,6 @@ public class ApiDefinitionLogService {
|
||||||
OperationLogModule.API_TEST_MANAGEMENT_DEFINITION,
|
OperationLogModule.API_TEST_MANAGEMENT_DEFINITION,
|
||||||
request.getName());
|
request.getName());
|
||||||
dto.setHistory(true);
|
dto.setHistory(true);
|
||||||
dto.setPath("/api/definition/update");
|
|
||||||
dto.setMethod(HttpMethodConstants.POST.name());
|
dto.setMethod(HttpMethodConstants.POST.name());
|
||||||
dto.setOriginalValue(JSON.toJSONBytes(apiDefinition));
|
dto.setOriginalValue(JSON.toJSONBytes(apiDefinition));
|
||||||
return dto;
|
return dto;
|
||||||
|
@ -85,40 +85,50 @@ public class ApiDefinitionLogService {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public LogDTO moveToGcLog(String id) {
|
||||||
* 删除接口日志
|
ApiDefinition apiDefinition = apiDefinitionMapper.selectByPrimaryKey(id);
|
||||||
*
|
Project project = projectMapper.selectByPrimaryKey(apiDefinition.getProjectId());
|
||||||
* @param request
|
LogDTO dto = new LogDTO(
|
||||||
* @return
|
apiDefinition.getProjectId(),
|
||||||
*/
|
project.getOrganizationId(),
|
||||||
public LogDTO delLog(ApiDefinitionDeleteRequest request) {
|
id,
|
||||||
ApiDefinitionDTO apiDefinition = getOriginalValue(request.getId());
|
null,
|
||||||
if (apiDefinition.getId() != null) {
|
OperationLogType.DELETE.name(),
|
||||||
LogDTO dto = new LogDTO(
|
OperationLogModule.API_TEST_MANAGEMENT_DEFINITION,
|
||||||
request.getProjectId(),
|
apiDefinition.getName());
|
||||||
null,
|
|
||||||
request.getId(),
|
|
||||||
null,
|
|
||||||
OperationLogType.DELETE.name(),
|
|
||||||
OperationLogModule.API_TEST_MANAGEMENT_DEFINITION,
|
|
||||||
apiDefinition.getName());
|
|
||||||
dto.setHistory(false);
|
|
||||||
dto.setPath("/api/definition/delete");
|
|
||||||
dto.setMethod(HttpMethodConstants.POST.name());
|
|
||||||
dto.setOriginalValue(JSON.toJSONBytes(apiDefinition));
|
|
||||||
return dto;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
dto.setMethod(HttpMethodConstants.GET.name());
|
||||||
|
dto.setOriginalValue(JSON.toJSONBytes(apiDefinition));
|
||||||
|
return dto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public LogDTO deleteLog(String id) {
|
||||||
|
ApiDefinition apiDefinition = apiDefinitionMapper.selectByPrimaryKey(id);
|
||||||
|
Project project = projectMapper.selectByPrimaryKey(apiDefinition.getProjectId());
|
||||||
|
LogDTO dto = new LogDTO(
|
||||||
|
apiDefinition.getProjectId(),
|
||||||
|
project.getOrganizationId(),
|
||||||
|
id,
|
||||||
|
null,
|
||||||
|
OperationLogType.DELETE.name(),
|
||||||
|
OperationLogModule.API_TEST_MANAGEMENT_DEFINITION,
|
||||||
|
apiDefinition.getName());
|
||||||
|
|
||||||
|
dto.setMethod(HttpMethodConstants.GET.name());
|
||||||
|
dto.setOriginalValue(JSON.toJSONBytes(apiDefinition));
|
||||||
|
operationLogService.deleteBySourceIds(List.of(id));
|
||||||
|
return dto;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 批量删除接口日志
|
* 批量删除接口日志
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public void batchDelLog(List<String> ids, String userId, String projectId) {
|
public void batchDelLog(List<String> ids, String userId, String projectId) {
|
||||||
saveBatchLog(projectId, ids, "/api/definition/batch-del", userId, OperationLogType.DELETE.name(), false);
|
saveBatchLog(projectId, ids, userId, OperationLogType.DELETE.name(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -127,7 +137,7 @@ public class ApiDefinitionLogService {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public void batchUpdateLog(List<String> ids, String userId, String projectId) {
|
public void batchUpdateLog(List<String> ids, String userId, String projectId) {
|
||||||
saveBatchLog(projectId, ids, "/api/definition/batch-update", userId, OperationLogType.UPDATE.name(), true);
|
saveBatchLog(projectId, ids, userId, OperationLogType.UPDATE.name(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public LogDTO copyLog(ApiDefinitionCopyRequest request) {
|
public LogDTO copyLog(ApiDefinitionCopyRequest request) {
|
||||||
|
@ -142,7 +152,6 @@ public class ApiDefinitionLogService {
|
||||||
OperationLogModule.API_TEST_MANAGEMENT_DEFINITION,
|
OperationLogModule.API_TEST_MANAGEMENT_DEFINITION,
|
||||||
apiDefinition.getName());
|
apiDefinition.getName());
|
||||||
dto.setHistory(false);
|
dto.setHistory(false);
|
||||||
dto.setPath("/api/definition/copy");
|
|
||||||
dto.setMethod(HttpMethodConstants.POST.name());
|
dto.setMethod(HttpMethodConstants.POST.name());
|
||||||
dto.setOriginalValue(JSON.toJSONBytes(apiDefinition));
|
dto.setOriginalValue(JSON.toJSONBytes(apiDefinition));
|
||||||
return dto;
|
return dto;
|
||||||
|
@ -151,7 +160,7 @@ public class ApiDefinitionLogService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void batchMoveLog(List<String> ids, String userId, String projectId) {
|
public void batchMoveLog(List<String> ids, String userId, String projectId) {
|
||||||
saveBatchLog(projectId, ids, "/api/definition/batch-move", userId, OperationLogType.UPDATE.name(), false);
|
saveBatchLog(projectId, ids, userId, OperationLogType.UPDATE.name(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public LogDTO followLog(String id) {
|
public LogDTO followLog(String id) {
|
||||||
|
@ -167,7 +176,6 @@ public class ApiDefinitionLogService {
|
||||||
OperationLogModule.API_TEST_MANAGEMENT_DEFINITION,
|
OperationLogModule.API_TEST_MANAGEMENT_DEFINITION,
|
||||||
Translator.get("follow") + apiDefinition.getName());
|
Translator.get("follow") + apiDefinition.getName());
|
||||||
|
|
||||||
dto.setPath("/api/definition/follow/" + id);
|
|
||||||
dto.setMethod(HttpMethodConstants.GET.name());
|
dto.setMethod(HttpMethodConstants.GET.name());
|
||||||
dto.setOriginalValue(JSON.toJSONBytes(apiDefinition));
|
dto.setOriginalValue(JSON.toJSONBytes(apiDefinition));
|
||||||
return dto;
|
return dto;
|
||||||
|
@ -193,7 +201,6 @@ public class ApiDefinitionLogService {
|
||||||
OperationLogModule.API_TEST_MANAGEMENT_DEFINITION,
|
OperationLogModule.API_TEST_MANAGEMENT_DEFINITION,
|
||||||
apiDefinition.getName());
|
apiDefinition.getName());
|
||||||
dto.setHistory(false);
|
dto.setHistory(false);
|
||||||
dto.setPath("/api/definition/recover");
|
|
||||||
dto.setMethod(HttpMethodConstants.POST.name());
|
dto.setMethod(HttpMethodConstants.POST.name());
|
||||||
dto.setOriginalValue(JSON.toJSONBytes(apiDefinition));
|
dto.setOriginalValue(JSON.toJSONBytes(apiDefinition));
|
||||||
return dto;
|
return dto;
|
||||||
|
@ -209,39 +216,14 @@ public class ApiDefinitionLogService {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public void batchRecoverLog(List<String> ids, String userId, String projectId) {
|
public void batchRecoverLog(List<String> ids, String userId, String projectId) {
|
||||||
saveBatchLog(projectId, ids, "/api/definition/batch-recover", userId, OperationLogType.RECOVER.name(), false);
|
saveBatchLog(projectId, ids, userId, OperationLogType.RECOVER.name(), false);
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除回收站接口定义接口日志
|
|
||||||
*/
|
|
||||||
public LogDTO trashDelLog(ApiDefinitionDeleteRequest request) {
|
|
||||||
ApiDefinitionDTO apiDefinition = getOriginalValue(request.getId());
|
|
||||||
if (apiDefinition.getId() != null) {
|
|
||||||
LogDTO dto = new LogDTO(
|
|
||||||
request.getProjectId(),
|
|
||||||
null,
|
|
||||||
request.getId(),
|
|
||||||
null,
|
|
||||||
OperationLogType.DELETE.name(),
|
|
||||||
OperationLogModule.API_TEST_MANAGEMENT_DEFINITION,
|
|
||||||
apiDefinition.getName());
|
|
||||||
|
|
||||||
dto.setPath("/api/definition/trash-del");
|
|
||||||
dto.setMethod(HttpMethodConstants.POST.name());
|
|
||||||
dto.setOriginalValue(JSON.toJSONBytes(apiDefinition));
|
|
||||||
return dto;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除回收站接口定义接口日志
|
* 删除回收站接口定义接口日志
|
||||||
*/
|
*/
|
||||||
public void batchTrashDelLog(List<String> ids, String userId, String projectId) {
|
public void batchTrashDelLog(List<String> ids, String userId, String projectId) {
|
||||||
saveBatchLog(projectId, ids, "/api/definition/batch-trash-del", userId, OperationLogType.DELETE.name(), false);
|
saveBatchLog(projectId, ids, userId, OperationLogType.DELETE.name(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ApiDefinitionDTO getOriginalValue(String id) {
|
private ApiDefinitionDTO getOriginalValue(String id) {
|
||||||
|
@ -257,7 +239,7 @@ public class ApiDefinitionLogService {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void saveBatchLog(String projectId, List<String> ids, String path, String userId, String operationType, boolean isHistory) {
|
private void saveBatchLog(String projectId, List<String> ids, String userId, String operationType, boolean isHistory) {
|
||||||
List<LogDTO> dtoList = new ArrayList<>();
|
List<LogDTO> dtoList = new ArrayList<>();
|
||||||
if (CollectionUtils.isNotEmpty(ids)) {
|
if (CollectionUtils.isNotEmpty(ids)) {
|
||||||
Project project = projectMapper.selectByPrimaryKey(projectId);
|
Project project = projectMapper.selectByPrimaryKey(projectId);
|
||||||
|
@ -278,7 +260,7 @@ public class ApiDefinitionLogService {
|
||||||
item.getName());
|
item.getName());
|
||||||
|
|
||||||
dto.setHistory(isHistory);
|
dto.setHistory(isHistory);
|
||||||
dto.setPath(path);
|
dto.setPath(OperationLogAspect.getPath());
|
||||||
dto.setMethod(HttpMethodConstants.POST.name());
|
dto.setMethod(HttpMethodConstants.POST.name());
|
||||||
dto.setOriginalValue(JSON.toJSONBytes(apiDefinitionDTO));
|
dto.setOriginalValue(JSON.toJSONBytes(apiDefinitionDTO));
|
||||||
dtoList.add(dto);
|
dtoList.add(dto);
|
||||||
|
|
|
@ -422,12 +422,12 @@ public class ApiDefinitionService {
|
||||||
return apiDefinition;
|
return apiDefinition;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void delete(ApiDefinitionDeleteRequest request, String userId) {
|
public void deleteToGc(String id, boolean deleteAllVersion, String userId) {
|
||||||
checkApiDefinition(request.getId());
|
ApiDefinition apiDefinition = checkApiDefinition(id);
|
||||||
handleDeleteApiDefinition(Collections.singletonList(request.getId()), request.getDeleteAll(), request.getProjectId(), userId, false);
|
handleDeleteApiDefinition(Collections.singletonList(id), deleteAllVersion, apiDefinition.getProjectId(), userId, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void batchDelete(ApiDefinitionBatchRequest request, String userId) {
|
public void batchDeleteToGc(ApiDefinitionBatchRequest request, String userId) {
|
||||||
List<String> ids = getBatchApiIds(request, request.getProjectId(), request.getProtocol(), false, userId);
|
List<String> ids = getBatchApiIds(request, request.getProjectId(), request.getProtocol(), false, userId);
|
||||||
if (CollectionUtils.isNotEmpty(ids)) {
|
if (CollectionUtils.isNotEmpty(ids)) {
|
||||||
handleDeleteApiDefinition(ids, request.getDeleteAll(), request.getProjectId(), userId, true);
|
handleDeleteApiDefinition(ids, request.getDeleteAll(), request.getProjectId(), userId, true);
|
||||||
|
@ -797,8 +797,9 @@ public class ApiDefinitionService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void trashDel(ApiDefinitionDeleteRequest request, String userId) {
|
public void delete(String id, String userId) {
|
||||||
handleTrashDelApiDefinition(Collections.singletonList(request.getId()), userId, request.getProjectId(), false);
|
ApiDefinition apiDefinition = checkApiDefinition(id);
|
||||||
|
handleTrashDelApiDefinition(Collections.singletonList(id), userId, apiDefinition.getProjectId(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void batchRecover(ApiDefinitionBatchRequest request, String userId) {
|
public void batchRecover(ApiDefinitionBatchRequest request, String userId) {
|
||||||
|
@ -808,7 +809,7 @@ public class ApiDefinitionService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void batchTrashDel(ApiDefinitionBatchRequest request, String userId) {
|
public void batchDelete(ApiDefinitionBatchRequest request, String userId) {
|
||||||
List<String> ids = getBatchApiIds(request, request.getProjectId(), request.getProtocol(), true, userId);
|
List<String> ids = getBatchApiIds(request, request.getProjectId(), request.getProtocol(), true, userId);
|
||||||
if (CollectionUtils.isNotEmpty(ids)) {
|
if (CollectionUtils.isNotEmpty(ids)) {
|
||||||
handleTrashDelApiDefinition(ids, userId, request.getProjectId(), true);
|
handleTrashDelApiDefinition(ids, userId, request.getProjectId(), true);
|
||||||
|
|
|
@ -18,6 +18,7 @@ import io.metersphere.sdk.util.BeanUtils;
|
||||||
import io.metersphere.sdk.util.JSON;
|
import io.metersphere.sdk.util.JSON;
|
||||||
import io.metersphere.sdk.util.Translator;
|
import io.metersphere.sdk.util.Translator;
|
||||||
import io.metersphere.system.dto.builder.LogDTOBuilder;
|
import io.metersphere.system.dto.builder.LogDTOBuilder;
|
||||||
|
import io.metersphere.system.log.aspect.OperationLogAspect;
|
||||||
import io.metersphere.system.log.constants.OperationLogModule;
|
import io.metersphere.system.log.constants.OperationLogModule;
|
||||||
import io.metersphere.system.log.constants.OperationLogType;
|
import io.metersphere.system.log.constants.OperationLogType;
|
||||||
import io.metersphere.system.log.dto.LogDTO;
|
import io.metersphere.system.log.dto.LogDTO;
|
||||||
|
@ -58,8 +59,6 @@ public class ApiTestCaseLogService {
|
||||||
OperationLogType.ADD.name(),
|
OperationLogType.ADD.name(),
|
||||||
OperationLogModule.API_TEST_MANAGEMENT_CASE,
|
OperationLogModule.API_TEST_MANAGEMENT_CASE,
|
||||||
request.getName());
|
request.getName());
|
||||||
|
|
||||||
dto.setPath("/api/case/add");
|
|
||||||
dto.setMethod(HttpMethodConstants.POST.name());
|
dto.setMethod(HttpMethodConstants.POST.name());
|
||||||
dto.setOriginalValue(JSON.toJSONBytes(request));
|
dto.setOriginalValue(JSON.toJSONBytes(request));
|
||||||
return dto;
|
return dto;
|
||||||
|
@ -76,8 +75,6 @@ public class ApiTestCaseLogService {
|
||||||
OperationLogType.DELETE.name(),
|
OperationLogType.DELETE.name(),
|
||||||
OperationLogModule.API_TEST_MANAGEMENT_CASE,
|
OperationLogModule.API_TEST_MANAGEMENT_CASE,
|
||||||
apiTestCase.getName());
|
apiTestCase.getName());
|
||||||
|
|
||||||
dto.setPath("/api/case/delete/" + id);
|
|
||||||
dto.setMethod(HttpMethodConstants.GET.name());
|
dto.setMethod(HttpMethodConstants.GET.name());
|
||||||
dto.setOriginalValue(JSON.toJSONBytes(apiTestCase));
|
dto.setOriginalValue(JSON.toJSONBytes(apiTestCase));
|
||||||
operationLogService.deleteBySourceIds(List.of(id));
|
operationLogService.deleteBySourceIds(List.of(id));
|
||||||
|
@ -95,8 +92,6 @@ public class ApiTestCaseLogService {
|
||||||
OperationLogType.DELETE.name(),
|
OperationLogType.DELETE.name(),
|
||||||
OperationLogModule.API_TEST_MANAGEMENT_CASE,
|
OperationLogModule.API_TEST_MANAGEMENT_CASE,
|
||||||
apiTestCase.getName());
|
apiTestCase.getName());
|
||||||
|
|
||||||
dto.setPath("/api/case/move-gc/" + id);
|
|
||||||
dto.setMethod(HttpMethodConstants.GET.name());
|
dto.setMethod(HttpMethodConstants.GET.name());
|
||||||
dto.setOriginalValue(JSON.toJSONBytes(apiTestCase));
|
dto.setOriginalValue(JSON.toJSONBytes(apiTestCase));
|
||||||
return dto;
|
return dto;
|
||||||
|
@ -114,7 +109,6 @@ public class ApiTestCaseLogService {
|
||||||
OperationLogModule.API_TEST_MANAGEMENT_CASE,
|
OperationLogModule.API_TEST_MANAGEMENT_CASE,
|
||||||
apiTestCase.getName());
|
apiTestCase.getName());
|
||||||
dto.setHistory(false);
|
dto.setHistory(false);
|
||||||
dto.setPath("/api/case/recover/" + id);
|
|
||||||
dto.setMethod(HttpMethodConstants.GET.name());
|
dto.setMethod(HttpMethodConstants.GET.name());
|
||||||
dto.setOriginalValue(JSON.toJSONBytes(apiTestCase));
|
dto.setOriginalValue(JSON.toJSONBytes(apiTestCase));
|
||||||
return dto;
|
return dto;
|
||||||
|
@ -131,8 +125,6 @@ public class ApiTestCaseLogService {
|
||||||
OperationLogType.UPDATE.name(),
|
OperationLogType.UPDATE.name(),
|
||||||
OperationLogModule.API_TEST_MANAGEMENT_CASE,
|
OperationLogModule.API_TEST_MANAGEMENT_CASE,
|
||||||
Translator.get("follow") + apiTestCase.getName());
|
Translator.get("follow") + apiTestCase.getName());
|
||||||
|
|
||||||
dto.setPath("/api/case/follow/" + id);
|
|
||||||
dto.setMethod(HttpMethodConstants.GET.name());
|
dto.setMethod(HttpMethodConstants.GET.name());
|
||||||
dto.setOriginalValue(JSON.toJSONBytes(apiTestCase));
|
dto.setOriginalValue(JSON.toJSONBytes(apiTestCase));
|
||||||
return dto;
|
return dto;
|
||||||
|
@ -149,8 +141,6 @@ public class ApiTestCaseLogService {
|
||||||
OperationLogType.UPDATE.name(),
|
OperationLogType.UPDATE.name(),
|
||||||
OperationLogModule.API_TEST_MANAGEMENT_CASE,
|
OperationLogModule.API_TEST_MANAGEMENT_CASE,
|
||||||
Translator.get("unfollow") + apiTestCase.getName());
|
Translator.get("unfollow") + apiTestCase.getName());
|
||||||
|
|
||||||
dto.setPath("/api/case/unfollow/" + id);
|
|
||||||
dto.setMethod(HttpMethodConstants.GET.name());
|
dto.setMethod(HttpMethodConstants.GET.name());
|
||||||
dto.setOriginalValue(JSON.toJSONBytes(apiTestCase));
|
dto.setOriginalValue(JSON.toJSONBytes(apiTestCase));
|
||||||
return dto;
|
return dto;
|
||||||
|
@ -168,8 +158,6 @@ public class ApiTestCaseLogService {
|
||||||
OperationLogType.UPDATE.name(),
|
OperationLogType.UPDATE.name(),
|
||||||
OperationLogModule.API_TEST_MANAGEMENT_CASE,
|
OperationLogModule.API_TEST_MANAGEMENT_CASE,
|
||||||
request.getName());
|
request.getName());
|
||||||
|
|
||||||
dto.setPath("/api/case/update");
|
|
||||||
dto.setHistory(true);
|
dto.setHistory(true);
|
||||||
dto.setMethod(HttpMethodConstants.POST.name());
|
dto.setMethod(HttpMethodConstants.POST.name());
|
||||||
ApiTestCaseLogDTO apiTestCaseDTO = new ApiTestCaseLogDTO();
|
ApiTestCaseLogDTO apiTestCaseDTO = new ApiTestCaseLogDTO();
|
||||||
|
@ -191,8 +179,6 @@ public class ApiTestCaseLogService {
|
||||||
OperationLogType.UPDATE.name(),
|
OperationLogType.UPDATE.name(),
|
||||||
OperationLogModule.API_TEST_MANAGEMENT_CASE,
|
OperationLogModule.API_TEST_MANAGEMENT_CASE,
|
||||||
apiTestCase.getName());
|
apiTestCase.getName());
|
||||||
|
|
||||||
dto.setPath("/api/case/update");
|
|
||||||
dto.setHistory(true);
|
dto.setHistory(true);
|
||||||
dto.setMethod(HttpMethodConstants.POST.name());
|
dto.setMethod(HttpMethodConstants.POST.name());
|
||||||
ApiTestCaseLogDTO apiTestCaseDTO = new ApiTestCaseLogDTO();
|
ApiTestCaseLogDTO apiTestCaseDTO = new ApiTestCaseLogDTO();
|
||||||
|
@ -212,7 +198,6 @@ public class ApiTestCaseLogService {
|
||||||
.type(OperationLogType.DELETE.name())
|
.type(OperationLogType.DELETE.name())
|
||||||
.module(OperationLogModule.API_TEST_MANAGEMENT_CASE)
|
.module(OperationLogModule.API_TEST_MANAGEMENT_CASE)
|
||||||
.method(HttpMethodConstants.POST.name())
|
.method(HttpMethodConstants.POST.name())
|
||||||
.path("/api/case/batch/delete")
|
|
||||||
.sourceId(item.getId())
|
.sourceId(item.getId())
|
||||||
.content(item.getName())
|
.content(item.getName())
|
||||||
.createUser(operator)
|
.createUser(operator)
|
||||||
|
@ -225,18 +210,18 @@ public class ApiTestCaseLogService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void batchToGcLog(List<ApiTestCase> apiTestCases, String operator, String projectId) {
|
public void batchToGcLog(List<ApiTestCase> apiTestCases, String operator, String projectId) {
|
||||||
saveBatchLog(projectId, apiTestCases, "/api/case/batch/move-gc", operator, OperationLogType.DELETE.name(), false);
|
saveBatchLog(projectId, apiTestCases, operator, OperationLogType.DELETE.name(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void batchEditLog(List<ApiTestCase> apiTestCases, String operator, String projectId) {
|
public void batchEditLog(List<ApiTestCase> apiTestCases, String operator, String projectId) {
|
||||||
saveBatchLog(projectId, apiTestCases, "/api/case/batch/edit", operator, OperationLogType.UPDATE.name(), true);
|
saveBatchLog(projectId, apiTestCases, operator, OperationLogType.UPDATE.name(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void batchRecoverLog(List<ApiTestCase> apiTestCases, String operator, String projectId) {
|
public void batchRecoverLog(List<ApiTestCase> apiTestCases, String operator, String projectId) {
|
||||||
saveBatchLog(projectId, apiTestCases, "/api/case/recover", operator, OperationLogType.RECOVER.name(), false);
|
saveBatchLog(projectId, apiTestCases, operator, OperationLogType.RECOVER.name(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveBatchLog(String projectId, List<ApiTestCase> apiTestCases, String path, String operator, String operationType, boolean isHistory) {
|
private void saveBatchLog(String projectId, List<ApiTestCase> apiTestCases, String operator, String operationType, boolean isHistory) {
|
||||||
Project project = projectMapper.selectByPrimaryKey(projectId);
|
Project project = projectMapper.selectByPrimaryKey(projectId);
|
||||||
//取出apiTestCases所有的id为新的list
|
//取出apiTestCases所有的id为新的list
|
||||||
List<String> caseId = apiTestCases.stream().map(ApiTestCase::getId).distinct().toList();
|
List<String> caseId = apiTestCases.stream().map(ApiTestCase::getId).distinct().toList();
|
||||||
|
@ -263,7 +248,7 @@ public class ApiTestCaseLogService {
|
||||||
.type(operationType)
|
.type(operationType)
|
||||||
.module(OperationLogModule.API_TEST_MANAGEMENT_CASE)
|
.module(OperationLogModule.API_TEST_MANAGEMENT_CASE)
|
||||||
.method(HttpMethodConstants.POST.name())
|
.method(HttpMethodConstants.POST.name())
|
||||||
.path(path)
|
.path(OperationLogAspect.getPath())
|
||||||
.sourceId(item.getId())
|
.sourceId(item.getId())
|
||||||
.content(item.getName())
|
.content(item.getName())
|
||||||
.createUser(operator)
|
.createUser(operator)
|
||||||
|
|
|
@ -80,16 +80,16 @@ public class ApiDefinitionControllerTests extends BaseTest {
|
||||||
private final static String ADD = "add";
|
private final static String ADD = "add";
|
||||||
private final static String UPDATE = "update";
|
private final static String UPDATE = "update";
|
||||||
private final static String BATCH_UPDATE = "batch-update";
|
private final static String BATCH_UPDATE = "batch-update";
|
||||||
private final static String DELETE = "delete";
|
private final static String DELETE_TO_GC = "delete-to-gc/{0}?deleteAllVersion={1}";
|
||||||
private final static String BATCH_DELETE = "batch-del";
|
private final static String BATCH_DELETE_TO_GC = "batch/delete-to-gc";
|
||||||
private final static String COPY = "copy";
|
private final static String COPY = "copy";
|
||||||
private final static String BATCH_MOVE = "batch-move";
|
private final static String BATCH_MOVE = "batch-move";
|
||||||
|
|
||||||
private final static String RESTORE = "recover";
|
private final static String RESTORE = "recover";
|
||||||
private final static String BATCH_RESTORE = "batch-recover";
|
private final static String BATCH_RESTORE = "batch-recover";
|
||||||
|
|
||||||
private final static String TRASH_DEL = "trash-del";
|
private final static String DELETE = "delete/{0}";
|
||||||
private final static String BATCH_TRASH_DEL = "batch-trash-del";
|
private final static String BATCH_DELETE = "batch/delete";
|
||||||
|
|
||||||
private final static String PAGE = "page";
|
private final static String PAGE = "page";
|
||||||
private final static String PAGE_DOC = "page-doc";
|
private final static String PAGE_DOC = "page-doc";
|
||||||
|
@ -1210,27 +1210,22 @@ public class ApiDefinitionControllerTests extends BaseTest {
|
||||||
LogUtils.info("delete api test");
|
LogUtils.info("delete api test");
|
||||||
apiDefinition = apiDefinitionMapper.selectByPrimaryKey("1001");
|
apiDefinition = apiDefinitionMapper.selectByPrimaryKey("1001");
|
||||||
// @只存在一个版本
|
// @只存在一个版本
|
||||||
ApiDefinitionDeleteRequest apiDefinitionDeleteRequest = new ApiDefinitionDeleteRequest();
|
|
||||||
apiDefinitionDeleteRequest.setId(apiDefinition.getId());
|
|
||||||
apiDefinitionDeleteRequest.setProjectId(DEFAULT_PROJECT_ID);
|
|
||||||
apiDefinitionDeleteRequest.setDeleteAll(false);
|
|
||||||
// @@请求成功
|
// @@请求成功
|
||||||
this.requestPostWithOkAndReturn(DELETE, apiDefinitionDeleteRequest);
|
this.requestGetWithOkAndReturn(DELETE_TO_GC, apiDefinition.getId(), false);
|
||||||
checkLogModelList.add(new CheckLogModel(apiDefinition.getId(), OperationLogType.DELETE, DELETE));
|
checkLogModelList.add(new CheckLogModel(apiDefinition.getId(), OperationLogType.DELETE, DELETE_TO_GC.replace("{0}", apiDefinition.getId()).replace("{1}", "false")));
|
||||||
ApiDefinition apiDefinitionInfo = apiDefinitionMapper.selectByPrimaryKey(apiDefinition.getId());
|
ApiDefinition apiDefinitionInfo = apiDefinitionMapper.selectByPrimaryKey(apiDefinition.getId());
|
||||||
Assertions.assertTrue(apiDefinitionInfo.getDeleted());
|
Assertions.assertTrue(apiDefinitionInfo.getDeleted());
|
||||||
Assertions.assertEquals("admin", apiDefinitionInfo.getDeleteUser());
|
Assertions.assertEquals("admin", apiDefinitionInfo.getDeleteUser());
|
||||||
Assertions.assertNotNull(apiDefinitionInfo.getDeleteTime());
|
Assertions.assertNotNull(apiDefinitionInfo.getDeleteTime());
|
||||||
|
|
||||||
// @存在多个版本
|
// @存在多个版本
|
||||||
|
String id = "1004";
|
||||||
// 列表删除
|
// 列表删除
|
||||||
apiDefinitionDeleteRequest.setDeleteAll(false);
|
ApiDefinition delApiDefinition = apiDefinitionMapper.selectByPrimaryKey(id);
|
||||||
apiDefinitionDeleteRequest.setId("1004");
|
MvcResult mvcResult = this.requestGetWithOk(VERSION + id).andReturn();
|
||||||
ApiDefinition delApiDefinition = apiDefinitionMapper.selectByPrimaryKey(apiDefinitionDeleteRequest.getId());
|
|
||||||
MvcResult mvcResult = this.requestGetWithOk(VERSION + apiDefinitionDeleteRequest.getId()).andReturn();
|
|
||||||
List<ApiDefinitionVersionDTO> apiDefinitionVersionDTO = getResultDataArray(mvcResult, ApiDefinitionVersionDTO.class);
|
List<ApiDefinitionVersionDTO> apiDefinitionVersionDTO = getResultDataArray(mvcResult, ApiDefinitionVersionDTO.class);
|
||||||
if (!apiDefinitionVersionDTO.isEmpty()) {
|
if (!apiDefinitionVersionDTO.isEmpty()) {
|
||||||
this.requestPostWithOkAndReturn(DELETE, apiDefinitionDeleteRequest);
|
this.requestGetWithOkAndReturn(DELETE_TO_GC, id, false);
|
||||||
// 效验数据
|
// 效验数据
|
||||||
// 删除的数据为最新版本需要更新最近一条数据为最新数据
|
// 删除的数据为最新版本需要更新最近一条数据为最新数据
|
||||||
if (delApiDefinition.getLatest()) {
|
if (delApiDefinition.getLatest()) {
|
||||||
|
@ -1243,21 +1238,20 @@ public class ApiDefinitionControllerTests extends BaseTest {
|
||||||
Assertions.assertFalse(updateApiDefinition.getDeleted());
|
Assertions.assertFalse(updateApiDefinition.getDeleted());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ApiDefinition delApiDefinitionInfo = apiDefinitionMapper.selectByPrimaryKey(apiDefinitionDeleteRequest.getId());
|
ApiDefinition delApiDefinitionInfo = apiDefinitionMapper.selectByPrimaryKey(id);
|
||||||
if (delApiDefinitionInfo != null) {
|
if (delApiDefinitionInfo != null) {
|
||||||
Assertions.assertTrue(delApiDefinitionInfo.getDeleted());
|
Assertions.assertTrue(delApiDefinitionInfo.getDeleted());
|
||||||
Assertions.assertEquals("admin", delApiDefinitionInfo.getDeleteUser());
|
Assertions.assertEquals("admin", delApiDefinitionInfo.getDeleteUser());
|
||||||
Assertions.assertNotNull(delApiDefinitionInfo.getDeleteTime());
|
Assertions.assertNotNull(delApiDefinitionInfo.getDeleteTime());
|
||||||
}
|
}
|
||||||
checkLogModelList.add(new CheckLogModel(apiDefinitionDeleteRequest.getId(), OperationLogType.DELETE, DELETE));
|
checkLogModelList.add(new CheckLogModel(id, OperationLogType.DELETE, DELETE_TO_GC.replace("{0}", id).replace("{1}", "false")));
|
||||||
}
|
}
|
||||||
// 全部删除
|
// 全部删除
|
||||||
apiDefinitionDeleteRequest.setDeleteAll(true);
|
id = "1002";
|
||||||
apiDefinitionDeleteRequest.setId("1002");
|
|
||||||
// @@请求成功
|
// @@请求成功
|
||||||
this.requestPostWithOkAndReturn(DELETE, apiDefinitionDeleteRequest);
|
this.requestGetWithOkAndReturn(DELETE_TO_GC, id, true);
|
||||||
|
|
||||||
List<String> ids = extApiDefinitionMapper.getApiDefinitionByRefId(apiDefinitionDeleteRequest.getId()).stream().map(ApiDefinitionVersionDTO::getId).toList();
|
List<String> ids = extApiDefinitionMapper.getApiDefinitionByRefId(id).stream().map(ApiDefinitionVersionDTO::getId).toList();
|
||||||
ApiDefinitionExample apiDefinitionExample = new ApiDefinitionExample();
|
ApiDefinitionExample apiDefinitionExample = new ApiDefinitionExample();
|
||||||
apiDefinitionExample.createCriteria().andIdIn(ids);
|
apiDefinitionExample.createCriteria().andIdIn(ids);
|
||||||
List<ApiDefinition> apiDefinitions = apiDefinitionMapper.selectByExample(apiDefinitionExample);
|
List<ApiDefinition> apiDefinitions = apiDefinitionMapper.selectByExample(apiDefinitionExample);
|
||||||
|
@ -1268,13 +1262,11 @@ public class ApiDefinitionControllerTests extends BaseTest {
|
||||||
Assertions.assertNotNull(item.getDeleteTime());
|
Assertions.assertNotNull(item.getDeleteTime());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
checkLogModelList.add(new CheckLogModel(apiDefinitionDeleteRequest.getId(), OperationLogType.DELETE, DELETE));
|
checkLogModelList.add(new CheckLogModel(id, OperationLogType.DELETE, DELETE_TO_GC.replace("{0}", id).replace("{1}", "true")));
|
||||||
apiDefinitionDeleteRequest.setId("121");
|
id = "121";
|
||||||
apiDefinitionDeleteRequest.setDeleteAll(false);
|
assertErrorCode(this.requestGet(DELETE_TO_GC, id, false), ApiResultCode.API_DEFINITION_NOT_EXIST);
|
||||||
assertErrorCode(this.requestPost(DELETE, apiDefinitionDeleteRequest), ApiResultCode.API_DEFINITION_NOT_EXIST);
|
|
||||||
// @@校验权限
|
// @@校验权限
|
||||||
apiDefinitionDeleteRequest.setId(apiDefinition.getId());
|
requestGetPermissionTest(PermissionConstants.PROJECT_API_DEFINITION_DELETE, DELETE_TO_GC, apiDefinition.getId(), false);
|
||||||
requestPostPermissionTest(PermissionConstants.PROJECT_API_DEFINITION_DELETE, DELETE, apiDefinitionDeleteRequest);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1288,14 +1280,14 @@ public class ApiDefinitionControllerTests extends BaseTest {
|
||||||
request.setSelectIds(List.of("1004"));
|
request.setSelectIds(List.of("1004"));
|
||||||
request.setDeleteAll(false);
|
request.setDeleteAll(false);
|
||||||
request.setSelectAll(false);
|
request.setSelectAll(false);
|
||||||
this.requestPostWithOkAndReturn(BATCH_DELETE, request);
|
this.requestPostWithOkAndReturn(BATCH_DELETE_TO_GC, request);
|
||||||
// @@校验日志
|
// @@校验日志
|
||||||
checkLogModelList.add(new CheckLogModel("1004", OperationLogType.DELETE, BATCH_DELETE));
|
checkLogModelList.add(new CheckLogModel("1004", OperationLogType.DELETE, BATCH_DELETE_TO_GC));
|
||||||
|
|
||||||
request.setSelectIds(List.of("1002"));
|
request.setSelectIds(List.of("1002"));
|
||||||
request.setDeleteAll(false);
|
request.setDeleteAll(false);
|
||||||
request.setSelectAll(false);
|
request.setSelectAll(false);
|
||||||
assertErrorCode(this.requestPost(BATCH_DELETE, request), ApiResultCode.API_DEFINITION_NOT_EXIST);
|
assertErrorCode(this.requestPost(BATCH_DELETE_TO_GC, request), ApiResultCode.API_DEFINITION_NOT_EXIST);
|
||||||
// 删除全部 条件为关键字为st-6的数据
|
// 删除全部 条件为关键字为st-6的数据
|
||||||
request.setDeleteAll(true);
|
request.setDeleteAll(true);
|
||||||
request.setExcludeIds(List.of("1005"));
|
request.setExcludeIds(List.of("1005"));
|
||||||
|
@ -1303,11 +1295,11 @@ public class ApiDefinitionControllerTests extends BaseTest {
|
||||||
BaseCondition baseCondition = new BaseCondition();
|
BaseCondition baseCondition = new BaseCondition();
|
||||||
baseCondition.setKeyword("st-6");
|
baseCondition.setKeyword("st-6");
|
||||||
request.setCondition(baseCondition);
|
request.setCondition(baseCondition);
|
||||||
this.requestPostWithOkAndReturn(BATCH_DELETE, request);
|
this.requestPostWithOkAndReturn(BATCH_DELETE_TO_GC, request);
|
||||||
// @@校验日志
|
// @@校验日志
|
||||||
checkLogModelList.add(new CheckLogModel("1006", OperationLogType.DELETE, BATCH_DELETE));
|
checkLogModelList.add(new CheckLogModel("1006", OperationLogType.DELETE, BATCH_DELETE_TO_GC));
|
||||||
// @@校验权限
|
// @@校验权限
|
||||||
requestPostPermissionTest(PermissionConstants.PROJECT_API_DEFINITION_DELETE, BATCH_DELETE, request);
|
requestPostPermissionTest(PermissionConstants.PROJECT_API_DEFINITION_DELETE, BATCH_DELETE_TO_GC, request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1410,26 +1402,17 @@ public class ApiDefinitionControllerTests extends BaseTest {
|
||||||
LogUtils.info("trashDel api test");
|
LogUtils.info("trashDel api test");
|
||||||
apiDefinition = apiDefinitionMapper.selectByPrimaryKey("1001");
|
apiDefinition = apiDefinitionMapper.selectByPrimaryKey("1001");
|
||||||
if (!apiDefinition.getDeleted()) {
|
if (!apiDefinition.getDeleted()) {
|
||||||
ApiDefinitionDeleteRequest apiDefinitionDeleteRequest = new ApiDefinitionDeleteRequest();
|
|
||||||
apiDefinitionDeleteRequest.setId(apiDefinition.getId());
|
|
||||||
apiDefinitionDeleteRequest.setProjectId(DEFAULT_PROJECT_ID);
|
|
||||||
apiDefinitionDeleteRequest.setDeleteAll(false);
|
|
||||||
// @@请求成功
|
// @@请求成功
|
||||||
this.requestPostWithOkAndReturn(DELETE, apiDefinitionDeleteRequest);
|
this.requestGetWithOkAndReturn(DELETE_TO_GC, apiDefinition.getId(), false);
|
||||||
checkLogModelList.add(new CheckLogModel(apiDefinition.getId(), OperationLogType.DELETE, DELETE));
|
|
||||||
apiDefinition = apiDefinitionMapper.selectByPrimaryKey(apiDefinition.getId());
|
apiDefinition = apiDefinitionMapper.selectByPrimaryKey(apiDefinition.getId());
|
||||||
Assertions.assertTrue(apiDefinition.getDeleted());
|
Assertions.assertTrue(apiDefinition.getDeleted());
|
||||||
Assertions.assertEquals("admin", apiDefinition.getDeleteUser());
|
Assertions.assertEquals("admin", apiDefinition.getDeleteUser());
|
||||||
Assertions.assertNotNull(apiDefinition.getDeleteTime());
|
Assertions.assertNotNull(apiDefinition.getDeleteTime());
|
||||||
}
|
}
|
||||||
// @只存在一个版本
|
// @只存在一个版本
|
||||||
ApiDefinitionDeleteRequest apiDefinitionDeleteRequest = new ApiDefinitionDeleteRequest();
|
|
||||||
apiDefinitionDeleteRequest.setId(apiDefinition.getId());
|
|
||||||
apiDefinitionDeleteRequest.setProjectId(DEFAULT_PROJECT_ID);
|
|
||||||
apiDefinitionDeleteRequest.setDeleteAll(false);
|
|
||||||
// @@请求成功
|
// @@请求成功
|
||||||
this.requestPostWithOk(TRASH_DEL, apiDefinitionDeleteRequest);
|
this.requestGetWithOk(DELETE, apiDefinition.getId());
|
||||||
checkLogModelList.add(new CheckLogModel(apiDefinition.getId(), OperationLogType.DELETE, TRASH_DEL));
|
checkLogModelList.add(new CheckLogModel(apiDefinition.getId(), OperationLogType.DELETE, DELETE.replace("{0}", apiDefinition.getId())));
|
||||||
// 验证数据
|
// 验证数据
|
||||||
ApiDefinition apiDefinitionInfo = apiDefinitionMapper.selectByPrimaryKey(apiDefinition.getId());
|
ApiDefinition apiDefinitionInfo = apiDefinitionMapper.selectByPrimaryKey(apiDefinition.getId());
|
||||||
Assertions.assertNull(apiDefinitionInfo);
|
Assertions.assertNull(apiDefinitionInfo);
|
||||||
|
@ -1443,7 +1426,7 @@ public class ApiDefinitionControllerTests extends BaseTest {
|
||||||
Assertions.assertEquals(0, caseLists.size());
|
Assertions.assertEquals(0, caseLists.size());
|
||||||
|
|
||||||
// @@校验权限
|
// @@校验权限
|
||||||
requestPostPermissionTest(PermissionConstants.PROJECT_API_DEFINITION_DELETE, TRASH_DEL, apiDefinitionDeleteRequest);
|
requestGetPermissionTest(PermissionConstants.PROJECT_API_DEFINITION_DELETE, DELETE, apiDefinition.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1456,7 +1439,7 @@ public class ApiDefinitionControllerTests extends BaseTest {
|
||||||
// 删除选中
|
// 删除选中
|
||||||
request.setSelectIds(List.of("1003"));
|
request.setSelectIds(List.of("1003"));
|
||||||
request.setSelectAll(false);
|
request.setSelectAll(false);
|
||||||
this.requestPostWithOk(BATCH_TRASH_DEL, request);
|
this.requestPostWithOk(BATCH_DELETE, request);
|
||||||
// 效验数据结果
|
// 效验数据结果
|
||||||
ApiDefinitionExample apiDefinitionExample = new ApiDefinitionExample();
|
ApiDefinitionExample apiDefinitionExample = new ApiDefinitionExample();
|
||||||
apiDefinitionExample.createCriteria().andIdIn(request.getSelectIds());
|
apiDefinitionExample.createCriteria().andIdIn(request.getSelectIds());
|
||||||
|
@ -1475,13 +1458,8 @@ public class ApiDefinitionControllerTests extends BaseTest {
|
||||||
// @@校验日志
|
// @@校验日志
|
||||||
apiDefinition = apiDefinitionMapper.selectByPrimaryKey("1006");
|
apiDefinition = apiDefinitionMapper.selectByPrimaryKey("1006");
|
||||||
if (!apiDefinition.getDeleted()) {
|
if (!apiDefinition.getDeleted()) {
|
||||||
ApiDefinitionDeleteRequest apiDefinitionDeleteRequest = new ApiDefinitionDeleteRequest();
|
|
||||||
apiDefinitionDeleteRequest.setId(apiDefinition.getId());
|
|
||||||
apiDefinitionDeleteRequest.setProjectId(DEFAULT_PROJECT_ID);
|
|
||||||
apiDefinitionDeleteRequest.setDeleteAll(false);
|
|
||||||
// @@请求成功
|
// @@请求成功
|
||||||
this.requestPostWithOkAndReturn(DELETE, apiDefinitionDeleteRequest);
|
this.requestGetWithOkAndReturn(DELETE_TO_GC, apiDefinition.getId(), false);
|
||||||
checkLogModelList.add(new CheckLogModel(apiDefinition.getId(), OperationLogType.DELETE, DELETE));
|
|
||||||
apiDefinition = apiDefinitionMapper.selectByPrimaryKey(apiDefinition.getId());
|
apiDefinition = apiDefinitionMapper.selectByPrimaryKey(apiDefinition.getId());
|
||||||
Assertions.assertTrue(apiDefinition.getDeleted());
|
Assertions.assertTrue(apiDefinition.getDeleted());
|
||||||
Assertions.assertEquals("admin", apiDefinition.getDeleteUser());
|
Assertions.assertEquals("admin", apiDefinition.getDeleteUser());
|
||||||
|
@ -1493,14 +1471,14 @@ public class ApiDefinitionControllerTests extends BaseTest {
|
||||||
BaseCondition baseCondition = new BaseCondition();
|
BaseCondition baseCondition = new BaseCondition();
|
||||||
baseCondition.setKeyword("st-6");
|
baseCondition.setKeyword("st-6");
|
||||||
request.setCondition(baseCondition);
|
request.setCondition(baseCondition);
|
||||||
this.requestPostWithOk(BATCH_TRASH_DEL, request);
|
this.requestPostWithOk(BATCH_DELETE, request);
|
||||||
// @@校验日志
|
// @@校验日志
|
||||||
String[] ids = {"1003", "1006"};
|
String[] ids = {"1003", "1006"};
|
||||||
for (String id : ids) {
|
for (String id : ids) {
|
||||||
checkLogModelList.add(new CheckLogModel(id, OperationLogType.DELETE, BATCH_TRASH_DEL));
|
checkLogModelList.add(new CheckLogModel(id, OperationLogType.DELETE, BATCH_DELETE));
|
||||||
}
|
}
|
||||||
// @@校验权限
|
// @@校验权限
|
||||||
requestPostPermissionTest(PermissionConstants.PROJECT_API_DEFINITION_DELETE, BATCH_TRASH_DEL, request);
|
requestPostPermissionTest(PermissionConstants.PROJECT_API_DEFINITION_DELETE, BATCH_DELETE, request);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -75,7 +75,7 @@ public class ApiTestCaseControllerTests extends BaseTest {
|
||||||
private static final String BASE_PATH = "/api/case/";
|
private static final String BASE_PATH = "/api/case/";
|
||||||
private static final String ADD = "add";
|
private static final String ADD = "add";
|
||||||
private static final String GET = "get-detail/";
|
private static final String GET = "get-detail/";
|
||||||
private static final String MOVE_TO_GC = "move-gc/";
|
private static final String DELETE_TO_GC = "delete-to-gc/{0}";
|
||||||
private static final String RECOVER = "recover/";
|
private static final String RECOVER = "recover/";
|
||||||
private static final String FOLLOW = "follow/";
|
private static final String FOLLOW = "follow/";
|
||||||
private static final String UNFOLLOW = "unfollow/";
|
private static final String UNFOLLOW = "unfollow/";
|
||||||
|
@ -87,7 +87,7 @@ public class ApiTestCaseControllerTests extends BaseTest {
|
||||||
private static final String UPDATE_PRIORITY = "update-priority";
|
private static final String UPDATE_PRIORITY = "update-priority";
|
||||||
private static final String BATCH_EDIT = "batch/edit";
|
private static final String BATCH_EDIT = "batch/edit";
|
||||||
private static final String BATCH_DELETE = "batch/delete";
|
private static final String BATCH_DELETE = "batch/delete";
|
||||||
private static final String BATCH_MOVE_GC = "batch/move-gc";
|
private static final String BATCH_DELETE_TO_GC = "batch/delete-to-gc";
|
||||||
private static final String BATCH_RECOVER = "batch/recover";
|
private static final String BATCH_RECOVER = "batch/recover";
|
||||||
private static final String POS_URL = "edit/pos";
|
private static final String POS_URL = "edit/pos";
|
||||||
private static final String UPLOAD_TEMP_FILE = "upload/temp/file";
|
private static final String UPLOAD_TEMP_FILE = "upload/temp/file";
|
||||||
|
@ -465,16 +465,16 @@ public class ApiTestCaseControllerTests extends BaseTest {
|
||||||
@Order(4)
|
@Order(4)
|
||||||
public void moveToGC() throws Exception {
|
public void moveToGC() throws Exception {
|
||||||
// @@请求成功
|
// @@请求成功
|
||||||
this.requestGetWithOk(MOVE_TO_GC + apiTestCase.getId());
|
this.requestGetWithOk(DELETE_TO_GC, apiTestCase.getId());
|
||||||
ApiTestCase apiCase = apiTestCaseMapper.selectByPrimaryKey(apiTestCase.getId());
|
ApiTestCase apiCase = apiTestCaseMapper.selectByPrimaryKey(apiTestCase.getId());
|
||||||
Assertions.assertTrue(apiCase.getDeleted());
|
Assertions.assertTrue(apiCase.getDeleted());
|
||||||
Assertions.assertEquals(apiCase.getDeleteUser(), "admin");
|
Assertions.assertEquals(apiCase.getDeleteUser(), "admin");
|
||||||
Assertions.assertNotNull(apiCase.getDeleteTime());
|
Assertions.assertNotNull(apiCase.getDeleteTime());
|
||||||
// @@校验日志
|
// @@校验日志
|
||||||
checkLog(apiTestCase.getId(), OperationLogType.DELETE);
|
checkLog(apiTestCase.getId(), OperationLogType.DELETE);
|
||||||
this.requestGet(MOVE_TO_GC + "111").andExpect(ERROR_REQUEST_MATCHER);
|
this.requestGet(DELETE_TO_GC, "111").andExpect(ERROR_REQUEST_MATCHER);
|
||||||
// @@校验权限
|
// @@校验权限
|
||||||
requestGetPermissionTest(PermissionConstants.PROJECT_API_DEFINITION_CASE_DELETE, MOVE_TO_GC + apiTestCase.getId());
|
requestGetPermissionTest(PermissionConstants.PROJECT_API_DEFINITION_CASE_DELETE, DELETE_TO_GC, apiTestCase.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -942,13 +942,13 @@ public class ApiTestCaseControllerTests extends BaseTest {
|
||||||
request.setSelectAll(false);
|
request.setSelectAll(false);
|
||||||
request.setSelectIds(List.of(apiTestCase.getId()));
|
request.setSelectIds(List.of(apiTestCase.getId()));
|
||||||
request.setExcludeIds(List.of(apiTestCase.getId()));
|
request.setExcludeIds(List.of(apiTestCase.getId()));
|
||||||
requestPostWithOkAndReturn(BATCH_MOVE_GC, request);
|
requestPostWithOkAndReturn(BATCH_DELETE_TO_GC, request);
|
||||||
|
|
||||||
request.setSelectAll(true);
|
request.setSelectAll(true);
|
||||||
request.setExcludeIds(new ArrayList<>());
|
request.setExcludeIds(new ArrayList<>());
|
||||||
request.setApiDefinitionId("apiDefinitionId");
|
request.setApiDefinitionId("apiDefinitionId");
|
||||||
request.setModuleIds(List.of("case-moduleId"));
|
request.setModuleIds(List.of("case-moduleId"));
|
||||||
requestPostWithOkAndReturn(BATCH_MOVE_GC, request);
|
requestPostWithOkAndReturn(BATCH_DELETE_TO_GC, request);
|
||||||
ApiTestCaseExample example = new ApiTestCaseExample();
|
ApiTestCaseExample example = new ApiTestCaseExample();
|
||||||
example.createCriteria().andProjectIdEqualTo(DEFAULT_PROJECT_ID).andApiDefinitionIdEqualTo("apiDefinitionId").andDeletedEqualTo(true);
|
example.createCriteria().andProjectIdEqualTo(DEFAULT_PROJECT_ID).andApiDefinitionIdEqualTo("apiDefinitionId").andDeletedEqualTo(true);
|
||||||
List<ApiTestCase> caseList = apiTestCaseMapper.selectByExample(example);
|
List<ApiTestCase> caseList = apiTestCaseMapper.selectByExample(example);
|
||||||
|
@ -957,11 +957,11 @@ public class ApiTestCaseControllerTests extends BaseTest {
|
||||||
request.setSelectAll(true);
|
request.setSelectAll(true);
|
||||||
request.setExcludeIds(new ArrayList<>());
|
request.setExcludeIds(new ArrayList<>());
|
||||||
request.setModuleIds(List.of("case-moduleId"));
|
request.setModuleIds(List.of("case-moduleId"));
|
||||||
requestPostWithOkAndReturn(BATCH_MOVE_GC, request);
|
requestPostWithOkAndReturn(BATCH_DELETE_TO_GC, request);
|
||||||
//校验日志
|
//校验日志
|
||||||
checkLog(apiTestCase.getId(), OperationLogType.DELETE);
|
checkLog(apiTestCase.getId(), OperationLogType.DELETE);
|
||||||
//校验权限
|
//校验权限
|
||||||
requestPostPermissionTest(PermissionConstants.PROJECT_API_DEFINITION_CASE_DELETE, BATCH_MOVE_GC, request);
|
requestPostPermissionTest(PermissionConstants.PROJECT_API_DEFINITION_CASE_DELETE, BATCH_DELETE_TO_GC, request);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -1053,7 +1053,7 @@ public class ApiTestCaseControllerTests extends BaseTest {
|
||||||
gcRequest.setSelectAll(true);
|
gcRequest.setSelectAll(true);
|
||||||
gcRequest.setExcludeIds(new ArrayList<>());
|
gcRequest.setExcludeIds(new ArrayList<>());
|
||||||
gcRequest.setApiDefinitionId("apiDefinitionId");
|
gcRequest.setApiDefinitionId("apiDefinitionId");
|
||||||
requestPostWithOkAndReturn(BATCH_MOVE_GC, gcRequest);
|
requestPostWithOkAndReturn(BATCH_DELETE_TO_GC, gcRequest);
|
||||||
ApiTestCaseExample example1 = new ApiTestCaseExample();
|
ApiTestCaseExample example1 = new ApiTestCaseExample();
|
||||||
example1.createCriteria().andProjectIdEqualTo(DEFAULT_PROJECT_ID).andApiDefinitionIdEqualTo("apiDefinitionId").andDeletedEqualTo(true);
|
example1.createCriteria().andProjectIdEqualTo(DEFAULT_PROJECT_ID).andApiDefinitionIdEqualTo("apiDefinitionId").andDeletedEqualTo(true);
|
||||||
List<ApiTestCase> caseList1 = apiTestCaseMapper.selectByExample(example1);
|
List<ApiTestCase> caseList1 = apiTestCaseMapper.selectByExample(example1);
|
||||||
|
|
|
@ -280,7 +280,13 @@ public class OperationLogAspect {
|
||||||
|
|
||||||
public static String getPath() {
|
public static String getPath() {
|
||||||
HttpServletRequest httpRequest = getHttpRequest();
|
HttpServletRequest httpRequest = getHttpRequest();
|
||||||
String path = httpRequest == null ? StringUtils.EMPTY : httpRequest.getRequestURI();
|
String path = StringUtils.EMPTY;
|
||||||
|
if (httpRequest != null) {
|
||||||
|
path = httpRequest.getRequestURI();
|
||||||
|
if (StringUtils.isNotBlank(httpRequest.getQueryString())) {
|
||||||
|
path += "?" + httpRequest.getQueryString();
|
||||||
|
}
|
||||||
|
}
|
||||||
return path.length() > 255 ? path.substring(0, 255) : path;
|
return path.length() > 255 ? path.substring(0, 255) : path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue