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" } ] },