feat(测试计划): 补充接口分享日志&&权限

--story=1016179 --user=宋昌昌 【接口测试】接口文档 https://www.tapd.cn/55049933/s/1589978
This commit is contained in:
song-cc-rock 2024-10-12 11:28:29 +08:00 committed by Craftsman
parent 7c4e964e74
commit 8a0b9b06e5
4 changed files with 76 additions and 1 deletions

View File

@ -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;

View File

@ -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);
}

View File

@ -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;
}
}

View File

@ -50,6 +50,10 @@
},
{
"id": "PROJECT_API_DEFINITION:READ+EXPORT"
},
{
"id": "PROJECT_API_DEFINITION:READ+SHARE",
"name": "permission.api_doc.share"
}
]
},