From 8a0b9b06e5b2c033b4f643c16b3c0fd4313c669b Mon Sep 17 00:00:00 2001 From: song-cc-rock Date: Sat, 12 Oct 2024 11:28:29 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92):=20?= =?UTF-8?q?=E8=A1=A5=E5=85=85=E6=8E=A5=E5=8F=A3=E5=88=86=E4=BA=AB=E6=97=A5?= =?UTF-8?q?=E5=BF=97&&=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --story=1016179 --user=宋昌昌 【接口测试】接口文档 https://www.tapd.cn/55049933/s/1589978 --- .../migration/3.4.0/dml/V3.4.0_2_1__data.sql | 3 +- .../definition/ApiDocShareController.java | 6 ++ .../definition/ApiDocShareLogService.java | 64 +++++++++++++++++++ .../src/main/resources/permission.json | 4 ++ 4 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDocShareLogService.java diff --git a/backend/framework/domain/src/main/resources/migration/3.4.0/dml/V3.4.0_2_1__data.sql b/backend/framework/domain/src/main/resources/migration/3.4.0/dml/V3.4.0_2_1__data.sql index 1e32509ed2..33bb870328 100644 --- a/backend/framework/domain/src/main/resources/migration/3.4.0/dml/V3.4.0_2_1__data.sql +++ b/backend/framework/domain/src/main/resources/migration/3.4.0/dml/V3.4.0_2_1__data.sql @@ -98,7 +98,8 @@ WHERE urp.permission_id = 'SYSTEM_TASK_CENTER:READ+STOP' and user_role.type = 'SYSTEM' and user_role.id != 'admin'; - +-- 初始化项目管理员定义分享权限 +INSERT INTO user_role_permission (id, role_id, permission_id) VALUES (UUID_SHORT(), 'project_admin', 'PROJECT_API_DEFINITION:READ+SHARE'); -- set innodb lock wait timeout to default SET SESSION innodb_lock_wait_timeout = DEFAULT; \ No newline at end of file diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiDocShareController.java b/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiDocShareController.java index b35282c8a2..77574cc37b 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiDocShareController.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/controller/definition/ApiDocShareController.java @@ -6,8 +6,11 @@ import io.metersphere.api.domain.ApiDocShare; import io.metersphere.api.dto.definition.ApiDocShareDTO; import io.metersphere.api.dto.definition.request.ApiDocShareEditRequest; import io.metersphere.api.dto.definition.request.ApiDocSharePageRequest; +import io.metersphere.api.service.definition.ApiDocShareLogService; import io.metersphere.api.service.definition.ApiDocShareService; import io.metersphere.sdk.constants.PermissionConstants; +import io.metersphere.system.log.annotation.Log; +import io.metersphere.system.log.constants.OperationLogType; import io.metersphere.system.security.CheckOwner; import io.metersphere.system.utils.PageUtils; import io.metersphere.system.utils.Pager; @@ -51,6 +54,7 @@ public class ApiDocShareController { @Operation(summary = "接口测试-接口管理-新增分享") @RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_DOC_SHARE) @CheckOwner(resourceId = "#request.getProjectId()", resourceType = "project") + @Log(type = OperationLogType.ADD, expression = "#msClass.addLog(#request)", msClass = ApiDocShareLogService.class) public ApiDocShare add(@Validated({Created.class}) @RequestBody ApiDocShareEditRequest request) { return apiDocShareService.create(request, SessionUtils.getUserId()); } @@ -59,6 +63,7 @@ public class ApiDocShareController { @Operation(summary = "接口测试-接口管理-更新分享") @RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_DOC_SHARE) @CheckOwner(resourceId = "#request.getId()", resourceType = "api_doc_share") + @Log(type = OperationLogType.UPDATE, expression = "#msClass.updateLog(#request)", msClass = ApiDocShareLogService.class) public ApiDocShare update(@Validated({Updated.class}) @RequestBody ApiDocShareEditRequest request) { return apiDocShareService.update(request); } @@ -68,6 +73,7 @@ public class ApiDocShareController { @Parameter(name = "id", description = "分享ID", schema = @Schema(requiredMode = Schema.RequiredMode.REQUIRED)) @RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_DOC_SHARE) @CheckOwner(resourceId = "#id", resourceType = "api_doc_share") + @Log(type = OperationLogType.DELETE, expression = "#msClass.deleteLog(#id)", msClass = ApiDocShareLogService.class) public void delete(@PathVariable String id) { apiDocShareService.delete(id); } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDocShareLogService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDocShareLogService.java new file mode 100644 index 0000000000..b62f6ce780 --- /dev/null +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDocShareLogService.java @@ -0,0 +1,64 @@ +package io.metersphere.api.service.definition; + +import io.metersphere.api.domain.ApiDocShare; +import io.metersphere.api.dto.definition.request.ApiDocShareEditRequest; +import io.metersphere.api.mapper.ApiDocShareMapper; +import io.metersphere.sdk.constants.HttpMethodConstants; +import io.metersphere.sdk.util.JSON; +import io.metersphere.system.log.constants.OperationLogModule; +import io.metersphere.system.log.constants.OperationLogType; +import io.metersphere.system.log.dto.LogDTO; +import jakarta.annotation.Resource; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@Transactional(rollbackFor = Exception.class) +public class ApiDocShareLogService { + + @Resource + private ApiDocShareMapper apiDocShareMapper; + + /** + * 添加接口分享日志 + * + * @param request 请求参数 + * @return 日志 + */ + public LogDTO addLog(ApiDocShareEditRequest request) { + LogDTO dto = new LogDTO(request.getProjectId(), null, null, null,OperationLogType.SHARE.name(), OperationLogModule.API_TEST_MANAGEMENT_DEFINITION, request.getName()); + dto.setHistory(true); + dto.setMethod(HttpMethodConstants.POST.name()); + dto.setOriginalValue(JSON.toJSONBytes(request)); + return dto; + } + + /** + * 更新接口分享日志 + * + * @param request 请求参数 + * @return 日志 + */ + public LogDTO updateLog(ApiDocShareEditRequest request) { + LogDTO dto = new LogDTO(request.getProjectId(), null, null, null,OperationLogType.UPDATE.name(), OperationLogModule.API_TEST_MANAGEMENT_DEFINITION, "【分享接口功能】" + request.getName()); + dto.setHistory(true); + dto.setMethod(HttpMethodConstants.POST.name()); + dto.setOriginalValue(JSON.toJSONBytes(request)); + return dto; + } + + /** + * 删除接口分享日志 + * + * @param id 分享ID + * @return 日志 + */ + public LogDTO deleteLog(String id) { + ApiDocShare docShare = apiDocShareMapper.selectByPrimaryKey(id); + LogDTO dto = new LogDTO(docShare.getProjectId(), null, null, null,OperationLogType.DELETE.name(), OperationLogModule.API_TEST_MANAGEMENT_DEFINITION, "【分享接口功能】" + docShare.getName()); + dto.setHistory(true); + dto.setMethod(HttpMethodConstants.POST.name()); + dto.setOriginalValue(JSON.toJSONBytes(docShare)); + return dto; + } +} diff --git a/backend/services/api-test/src/main/resources/permission.json b/backend/services/api-test/src/main/resources/permission.json index f504c55571..ec014f571a 100644 --- a/backend/services/api-test/src/main/resources/permission.json +++ b/backend/services/api-test/src/main/resources/permission.json @@ -50,6 +50,10 @@ }, { "id": "PROJECT_API_DEFINITION:READ+EXPORT" + }, + { + "id": "PROJECT_API_DEFINITION:READ+SHARE", + "name": "permission.api_doc.share" } ] },