feat(项目设置): 文件管理重构后补充操作日志

This commit is contained in:
fit2-zhao 2022-08-17 11:30:33 +08:00 committed by fit2-zhao
parent ab6071d12e
commit f26dede034
10 changed files with 38 additions and 41 deletions

View File

@ -3,7 +3,7 @@
<mapper namespace="io.metersphere.base.mapper.ext.ExtFileMetadataMapper"> <mapper namespace="io.metersphere.base.mapper.ext.ExtFileMetadataMapper">
<select id="getProjectFiles" resultType="io.metersphere.base.domain.FileMetadata"> <select id="getProjectFiles" resultType="io.metersphere.base.domain.FileMetadata">
SELECT file_metadata.* FROM file_metadata SELECT file_metadata.* FROM file_metadata
WHERE project_id = #{projectId,jdbcType=VARCHAR} WHERE project_id = #{projectId,jdbcType=VARCHAR} AND type != 'RSA_KEY'
<if test="request.name != null and request.name !=''"> <if test="request.name != null and request.name !=''">
AND ( file_metadata.name LIKE CONCAT('%', #{request.name}, '%') AND ( file_metadata.name LIKE CONCAT('%', #{request.name}, '%')
OR file_metadata.tags LIKE CONCAT('%', #{request.name}, '%') OR file_metadata.tags LIKE CONCAT('%', #{request.name}, '%')
@ -64,7 +64,7 @@
</if> </if>
</select> </select>
<select id="getTypes" resultType="java.lang.String"> <select id="getTypes" resultType="java.lang.String">
SELECT type FROM file_metadata GROUP BY type SELECT type FROM file_metadata GROUP BY type HAVING type != 'RSA_KEY'
</select> </select>
<update id="move"> <update id="move">

View File

@ -42,13 +42,12 @@ public class FileMetadataController {
} }
@PostMapping(value = "/create") @PostMapping(value = "/create")
@MsAuditLog(module = OperLogModule.PROJECT_FILE_MANAGEMENT, type = OperLogConstants.IMPORT, content = "#msClass.getLogDetails(#projectId)", msClass = FileMetadataService.class) @MsAuditLog(module = OperLogModule.PROJECT_FILE_MANAGEMENT, type = OperLogConstants.CREATE, title = "#request.name", content = "#msClass.getLogDetails(#request.id)", msClass = FileMetadataService.class)
public List<FileMetadata> create(@RequestPart("request") FileMetadata request, @RequestPart(value = "file", required = false) List<MultipartFile> files) { public List<FileMetadata> create(@RequestPart("request") FileMetadata request, @RequestPart(value = "file", required = false) List<MultipartFile> files) {
return fileMetadataService.create(request, files); return fileMetadataService.create(request, files);
} }
@PostMapping(value = "/upload") @PostMapping(value = "/upload")
@MsAuditLog(module = OperLogModule.PROJECT_FILE_MANAGEMENT, type = OperLogConstants.IMPORT, content = "#msClass.getLogDetails(#projectId)", msClass = FileMetadataService.class)
public FileMetadata upload(@RequestPart("request") FileMetadata request, @RequestPart(value = "file", required = false) List<MultipartFile> files) { public FileMetadata upload(@RequestPart("request") FileMetadata request, @RequestPart(value = "file", required = false) List<MultipartFile> files) {
return fileMetadataService.reLoad(request, files); return fileMetadataService.reLoad(request, files);
} }
@ -72,13 +71,12 @@ public class FileMetadataController {
} }
@GetMapping(value = "/delete/{fileId}") @GetMapping(value = "/delete/{fileId}")
@MsAuditLog(module = OperLogModule.PROJECT_PROJECT_MANAGER, type = OperLogConstants.DELETE, beforeEvent = "#msClass.getLogDetails(#fileId)", msClass = FileMetadataService.class) @MsAuditLog(module = OperLogModule.PROJECT_FILE_MANAGEMENT, type = OperLogConstants.DELETE, beforeEvent = "#msClass.getLogDetails(#fileId)", msClass = FileMetadataService.class)
public void deleteFile(@PathVariable String fileId) { public void deleteFile(@PathVariable String fileId) {
fileMetadataService.deleteFile(fileId); fileMetadataService.deleteFile(fileId);
} }
@PostMapping(value = "/delete/batch") @PostMapping(value = "/delete/batch")
@MsAuditLog(module = OperLogModule.PROJECT_PROJECT_MANAGER, type = OperLogConstants.BATCH_DEL, beforeEvent = "#msClass.getLogDetails(#fileId)", msClass = FileMetadataService.class)
public void deleteBatch(@RequestBody List<String> ids) { public void deleteBatch(@RequestBody List<String> ids) {
fileMetadataService.deleteBatch(ids); fileMetadataService.deleteBatch(ids);
} }
@ -89,17 +87,19 @@ public class FileMetadataController {
} }
@PostMapping(value = "/move") @PostMapping(value = "/move")
@MsAuditLog(module = OperLogModule.PROJECT_FILE_MANAGEMENT, type = OperLogConstants.UPDATE, beforeEvent = "#msClass.getLogDetails(#request.id)", title = "#request.name", content = "#msClass.getLogDetails(#request.id)", msClass = FileMetadataService.class)
public void move(@RequestBody MoveFIleMetadataRequest request) { public void move(@RequestBody MoveFIleMetadataRequest request) {
fileMetadataService.move(request); fileMetadataService.move(request);
} }
@PostMapping(value = "/update") @PostMapping(value = "/update")
@MsAuditLog(module = OperLogModule.PROJECT_FILE_MANAGEMENT, type = OperLogConstants.UPDATE, beforeEvent = "#msClass.getLogDetails(#request.id)", title = "#request.name", content = "#msClass.getLogDetails(#request.id)", msClass = FileMetadataService.class)
public void update(@RequestBody FileMetadata request) { public void update(@RequestBody FileMetadata request) {
fileMetadataService.update(request); fileMetadataService.update(request);
} }
@PostMapping(value = "/api/upload", consumes = {"multipart/form-data"}) @PostMapping(value = "/dump/file", consumes = {"multipart/form-data"})
public void apiUpload(@RequestPart("request") DumpFileRequest request, @RequestPart(value = "files", required = false) List<MultipartFile> files) { public void dumpFile(@RequestPart("request") DumpFileRequest request, @RequestPart(value = "files", required = false) List<MultipartFile> files) {
fileMetadataService.dumpFile(request, files); fileMetadataService.dumpFile(request, files);
} }

View File

@ -41,7 +41,7 @@ public class FileModuleController {
} }
@PostMapping("/delete") @PostMapping("/delete")
@MsAuditLog(module = OperLogModule.PROJECT_FILE_MANAGEMENT, type = OperLogConstants.DELETE, beforeEvent = "#msClass.getLogDetails(#nodeIds)", msClass = FileModule.class) @MsAuditLog(module = OperLogModule.PROJECT_FILE_MANAGEMENT, type = OperLogConstants.DELETE, beforeEvent = "#msClass.getLogDetails(#nodeIds)", msClass = FileModuleService.class)
public int deleteNode(@RequestBody List<String> nodeIds) { public int deleteNode(@RequestBody List<String> nodeIds) {
return fileModuleService.deleteNode(nodeIds); return fileModuleService.deleteNode(nodeIds);
} }

View File

@ -1,5 +1,6 @@
package io.metersphere.metadata.service; package io.metersphere.metadata.service;
import com.alibaba.fastjson.JSON;
import io.metersphere.base.domain.*; import io.metersphere.base.domain.*;
import io.metersphere.base.mapper.*; import io.metersphere.base.mapper.*;
import io.metersphere.base.mapper.ext.ExtFileMetadataMapper; import io.metersphere.base.mapper.ext.ExtFileMetadataMapper;
@ -9,6 +10,10 @@ import io.metersphere.commons.utils.FileUtils;
import io.metersphere.commons.utils.SessionUtils; import io.metersphere.commons.utils.SessionUtils;
import io.metersphere.controller.request.OrderRequest; import io.metersphere.controller.request.OrderRequest;
import io.metersphere.i18n.Translator; import io.metersphere.i18n.Translator;
import io.metersphere.log.utils.ReflexObjectUtil;
import io.metersphere.log.vo.DetailColumn;
import io.metersphere.log.vo.OperatingLogDetails;
import io.metersphere.log.vo.system.SystemReference;
import io.metersphere.metadata.utils.MetadataUtils; import io.metersphere.metadata.utils.MetadataUtils;
import io.metersphere.metadata.vo.DownloadRequest; import io.metersphere.metadata.vo.DownloadRequest;
import io.metersphere.metadata.vo.DumpFileRequest; import io.metersphere.metadata.vo.DumpFileRequest;
@ -356,4 +361,14 @@ public class FileMetadataService {
fileMetadata.createCriteria().andProjectIdEqualTo(projectId).andCreateUserEqualTo(createUser); fileMetadata.createCriteria().andProjectIdEqualTo(projectId).andCreateUserEqualTo(createUser);
return fileMetadataMapper.countByExample(fileMetadata); return fileMetadataMapper.countByExample(fileMetadata);
} }
public String getLogDetails(String id) {
FileMetadata fileMetadata = this.getFileMetadataById(id);
if (fileMetadata != null) {
List<DetailColumn> columns = ReflexObjectUtil.getColumns(fileMetadata, SystemReference.projectColumns);
OperatingLogDetails details = new OperatingLogDetails(JSON.toJSONString(fileMetadata.getId()), fileMetadata.getProjectId(), fileMetadata.getName(), null, columns);
return JSON.toJSONString(details);
}
return null;
}
} }

View File

@ -10,7 +10,6 @@ import io.metersphere.base.mapper.FileModuleMapper;
import io.metersphere.base.mapper.ext.ExtFileMetadataMapper; import io.metersphere.base.mapper.ext.ExtFileMetadataMapper;
import io.metersphere.base.mapper.ext.ExtFileModuleMapper; import io.metersphere.base.mapper.ext.ExtFileModuleMapper;
import io.metersphere.commons.constants.ApiTestConstants; import io.metersphere.commons.constants.ApiTestConstants;
import io.metersphere.commons.constants.TestCaseConstants;
import io.metersphere.commons.exception.MSException; import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.LogUtil; import io.metersphere.commons.utils.LogUtil;
import io.metersphere.commons.utils.SessionUtils; import io.metersphere.commons.utils.SessionUtils;
@ -170,10 +169,6 @@ public class FileModuleService extends NodeTreeService<FileModuleVo> {
} }
private void validateNode(FileModule node) { private void validateNode(FileModule node) {
if (node.getLevel() > TestCaseConstants.MAX_NODE_DEPTH) {
MSException.throwException(Translator.get("test_case_node_level_tip")
+ TestCaseConstants.MAX_NODE_DEPTH + Translator.get("test_case_node_level"));
}
checkApiModuleExist(node); checkApiModuleExist(node);
} }
@ -275,9 +270,6 @@ public class FileModuleService extends NodeTreeService<FileModuleVo> {
private void buildUpdateDefinition(FileModuleVo rootNode, List<FileModule> updateNodes, String rootPath, String pId, int level) { private void buildUpdateDefinition(FileModuleVo rootNode, List<FileModule> updateNodes, String rootPath, String pId, int level) {
rootPath = rootPath + rootNode.getName(); rootPath = rootPath + rootNode.getName();
if (level > 8) {
MSException.throwException(Translator.get("node_deep_limit"));
}
if ("root".equals(rootNode.getId())) { if ("root".equals(rootNode.getId())) {
rootPath = ""; rootPath = "";
} }

View File

@ -78,13 +78,13 @@ ALTER TABLE `ui_scenario` ADD INDEX index_project_id_status_module_id (`proje
-- V128__2-1-0_feat_file_manage -- V128__2-1-0_feat_file_manage
-- file_metadata 新增字段 -- file_metadata 新增字段
ALTER TABLE `file_metadata` ALTER TABLE `file_metadata`
ADD storage VARCHAR(50) DEFAULT 'LOCAL' COMMENT '文件存储方式'; ADD storage VARCHAR(50) DEFAULT NULL COMMENT '文件存储方式';
ALTER TABLE `file_metadata` ALTER TABLE `file_metadata`
ADD create_user VARCHAR(100) DEFAULT '' COMMENT '创建人'; ADD create_user VARCHAR(100) DEFAULT NULL COMMENT '创建人';
ALTER TABLE `file_metadata` ALTER TABLE `file_metadata`
ADD update_user VARCHAR(100) DEFAULT '' COMMENT '修改人'; ADD update_user VARCHAR(100) DEFAULT NULL COMMENT '修改人';
ALTER TABLE `file_metadata` ALTER TABLE `file_metadata`
ADD tags VARCHAR(2000) DEFAULT NULL COMMENT '标签'; ADD tags VARCHAR(2000) DEFAULT NULL COMMENT '标签';
@ -96,7 +96,7 @@ ALTER TABLE `file_metadata`
ADD module_id VARCHAR(50) DEFAULT NULL COMMENT '文件所属模块'; ADD module_id VARCHAR(50) DEFAULT NULL COMMENT '文件所属模块';
ALTER TABLE `file_metadata` ALTER TABLE `file_metadata`
ADD load_jar TINYINT(1) DEFAULT 1 COMMENT '是否加载jar开启后用于接口测试执行时使用'; ADD load_jar TINYINT(1) DEFAULT 0 COMMENT '是否加载jar开启后用于接口测试执行时使用';
ALTER TABLE `file_metadata` ALTER TABLE `file_metadata`
ADD path VARCHAR(1000) DEFAULT NULL COMMENT '文件存储路径'; ADD path VARCHAR(1000) DEFAULT NULL COMMENT '文件存储路径';
@ -104,6 +104,9 @@ ALTER TABLE `file_metadata`
ALTER TABLE `file_metadata` ALTER TABLE `file_metadata`
ADD resource_type VARCHAR(50) DEFAULT NULL COMMENT '资源作用范围主要兼容2.1版本前的历史数据,后续版本不再产生数据'; ADD resource_type VARCHAR(50) DEFAULT NULL COMMENT '资源作用范围主要兼容2.1版本前的历史数据,后续版本不再产生数据';
ALTER TABLE api_execution_queue_detail
ADD COLUMN project_ids VARCHAR(2000) DEFAULT "[]" COMMENT '项目ID集合';
-- 补充索引 -- 补充索引
ALTER TABLE file_metadata ALTER TABLE file_metadata
ADD INDEX module_id_index (`module_id`), ADD INDEX module_id_index (`module_id`),

View File

@ -90,7 +90,7 @@ export default {
files.push(this.file.file); files.push(this.file.file);
} }
let request = {id: getUUID(), resourceId: this.id, moduleId: moduleId, projectId: getCurrentProjectID(), fileName: this.file.name}; let request = {id: getUUID(), resourceId: this.id, moduleId: moduleId, projectId: getCurrentProjectID(), fileName: this.file.name};
this.$fileUpload("/file/metadata/api/upload", null, files, request, (response) => { this.$fileUpload("/file/metadata/dump/file", null, files, request, (response) => {
this.$success(this.$t("organization.integration.successful_operation")); this.$success(this.$t("organization.integration.successful_operation"));
}); });
}, },

View File

@ -79,7 +79,7 @@ export default {
files.push(this.file.file); files.push(this.file.file);
} }
let request = {id: getUUID(), resourceId: this.id, moduleId: moduleId, projectId: getCurrentProjectID(), fileName: this.file.name}; let request = {id: getUUID(), resourceId: this.id, moduleId: moduleId, projectId: getCurrentProjectID(), fileName: this.file.name};
this.$fileUpload("/file/metadata/api/upload", null, files, request, (response) => { this.$fileUpload("/file/metadata/dump/file", null, files, request, (response) => {
this.$success(this.$t("organization.integration.successful_operation")); this.$success(this.$t("organization.integration.successful_operation"));
}); });
}, },

View File

@ -251,18 +251,12 @@ export default {
add(param) { add(param) {
param.projectId = this.projectId; param.projectId = this.projectId;
param.protocol = this.condition.protocol; param.protocol = this.condition.protocol;
if (param && param.level >= 9) {
this.list();
this.$error(this.$t('commons.warning_module_add'));
return;
} else {
this.$post("/api/module/add", param, () => { this.$post("/api/module/add", param, () => {
this.$success(this.$t('commons.save_success')); this.$success(this.$t('commons.save_success'));
this.list(); this.list();
}, (error) => { }, (error) => {
this.list(); this.list();
}); });
}
}, },
remove(nodeIds) { remove(nodeIds) {
this.$post("/api/module/delete", nodeIds, () => { this.$post("/api/module/delete", nodeIds, () => {

View File

@ -141,19 +141,12 @@ export default {
add(param) { add(param) {
param.projectId = this.projectId; param.projectId = this.projectId;
param.protocol = this.condition.protocol; param.protocol = this.condition.protocol;
if (param && param.level >= 9) { this.$post("/file/module/add", param, () => {
this.$success(this.$t('commons.save_success'));
this.list(); this.list();
this.$error(this.$t('commons.warning_module_add')); }, (error) => {
return; this.list();
} else { });
this.$post("/file/module/add", param, () => {
this.$success(this.$t('commons.save_success'));
this.list();
}, (error) => {
this.list();
});
}
}, },
remove(nodeIds) { remove(nodeIds) {
this.$post("/file/module/delete", nodeIds, () => { this.$post("/file/module/delete", nodeIds, () => {