fix(文件管理): 修复文件管理统计相关问题

--bug=1015977 --user=赵勇 【项目设置】文件管理-我的文件-上传文件后所有模块未更新统计数量 https://www.tapd.cn/55049933/s/1227221
This commit is contained in:
fit2-zhao 2022-08-18 18:37:08 +08:00 committed by fit2-zhao
parent 09acd152f5
commit 5e60ea6260
9 changed files with 67 additions and 14 deletions

View File

@ -3,4 +3,5 @@ package io.metersphere.commons.constants;
public class ApiTestConstants {
public static final String JAR_PATH = "JAR_PATH";
public static final String DEF_MODULE = "DEF_MODULE";
public static final String ROOT = "root";
}

View File

@ -5,6 +5,7 @@ import com.alibaba.nacos.common.utils.ByteUtils;
import io.metersphere.base.domain.*;
import io.metersphere.base.mapper.*;
import io.metersphere.base.mapper.ext.ExtFileMetadataMapper;
import io.metersphere.commons.constants.ApiTestConstants;
import io.metersphere.commons.constants.StorageConstants;
import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.FileUtils;
@ -412,7 +413,7 @@ public class FileMetadataService {
if (StringUtils.isEmpty(fileMetadata.getProjectId())) {
fileMetadata.setProjectId(SessionUtils.getCurrentProjectId());
}
if (StringUtils.isEmpty(fileMetadata.getModuleId())) {
if (StringUtils.isEmpty(fileMetadata.getModuleId()) || StringUtils.equals(ApiTestConstants.ROOT, fileMetadata.getModuleId())) {
fileMetadata.setModuleId(fileModuleService.getDefaultNodeId(fileMetadata.getProjectId()));
}
fileMetadata.setCreateTime(System.currentTimeMillis());

View File

@ -178,6 +178,9 @@ FROM jar_config j
-- 初始化权限
INSERT INTO user_group_permission (id, group_id, permission_id, module_id)
VALUES (UUID(), 'project_admin', 'PROJECT_FILE:READ', 'PROJECT_FILE');
INSERT INTO user_group_permission (id, group_id, permission_id, module_id)
VALUES (UUID(), 'project_admin', 'PROJECT_FILE:READ+DOWNLOAD+JAR', 'PROJECT_FILE');

View File

@ -373,7 +373,7 @@
"resourceId": "PROJECT_OPERATING_LOG"
},
{
"id": "PROJECT_FILE:READ+JAR",
"id": "PROJECT_FILE:READ",
"name": "permission.project_file.jar",
"resourceId": "PROJECT_FILE"
},

View File

@ -19,7 +19,7 @@
{{ $t('project.env') }}
</el-menu-item>
<el-menu-item :index="'/project/file/manage'"
v-permission="['PROJECT_FILE:READ+JAR', 'PROJECT_FILE:READ+FILE']"
v-permission="['PROJECT_FILE:READ', 'PROJECT_FILE:READ+FILE']"
popper-class="submenu">
{{ $t('project.file_manage') }}
</el-menu-item>

View File

@ -79,7 +79,7 @@
<div class="div-item">
<div style="float: left">
<i class="el-icon-s-cooperation icon-color"
@click="click('/project/file/manage', ['PROJECT_FILE:READ+JAR', 'PROJECT_FILE:READ+FILE'])">
@click="click('/project/file/manage', ['PROJECT_FILE:READ', 'PROJECT_FILE:READ+FILE'])">
</i>
</div>
<div style="float: left">

View File

@ -31,7 +31,7 @@
</el-col>
<el-col :span="13">
<el-form :model="data" label-position="right" label-width="80px" size="small">
<el-form :model="data" :rules="rules" label-position="right" label-width="80px" size="small" ref="form">
<!-- 基础信息 -->
<el-form-item :label="$t('commons.description')" prop="description">
<el-input class="ms-http-textarea"
@ -53,14 +53,14 @@
</el-form-item>
<el-form-item :label="$t('load_test.file_size')" prop="size">
<span>{{ data.size }} KB</span>
<span>{{ formatFileSize(data.size) }}</span>
</el-form-item>
<el-form-item :label="$t('api_test.automation.tag')" prop="tags">
<ms-input-tag :currentScenario="data" ref="tag" @onblur="save"/>
</el-form-item>
<el-form-item :label="$t('test_track.case.module')" prop="name">
<el-form-item :label="$t('test_track.case.module')" prop="moduleId">
<ms-select-tree size="small" :data="moduleOptions" :defaultKey="data.moduleId"
@getValue="setModule" :obj="moduleObj" clearable checkStrictly/>
@ -78,10 +78,11 @@
<el-switch v-model="data.loadJar" :active-text="$t('project.file_jar_message')" @change="save"/>
</el-form-item>
<el-form-item :label="$t('project.upload_file_again')" prop="name">
<el-form-item :label="$t('project.upload_file_again')" prop="files">
<el-upload
style="width: 38px; float: left;"
action="#"
:before-upload="beforeUploadFile"
:http-request="handleUpload"
:show-file-list="false">
<el-button icon="el-icon-plus" size="mini"/>
@ -114,11 +115,19 @@ export default {
id: 'id',
label: 'name',
},
rules: {
name: [
{min: 1, max: 200, message: this.$t('commons.input_limit', [1, 200]), trigger: 'blur'}
],
description: [
{max: 3000, message: this.$t('commons.input_limit', [0, 3000]), trigger: 'blur'}
]
},
total: 0,
pageSize: 10,
loading: false,
currentPage: 1,
images: ["bmp", "jpg", "png", "tif", "gif", "pcx", "tga", "exif", "fpx", "svg", "psd", "cdr", "pcd", "dxf", "ufo", "eps", "ai", "raw", "WMF", "webp", "avif", "apng"]
images: ["bmp", "jpg", "png", "tif", "gif", "pcx", "tga", "exif", "fpx", "svg", "psd", "cdr", "pcd", "dxf", "ufo", "eps", "ai", "raw", "WMF", "webp", "avif", "apng", "jpeg"]
};
},
props: {
@ -137,6 +146,19 @@ export default {
},
},
methods: {
beforeUploadFile(file) {
if (!this.fileValidator(file)) {
return false;
}
if (file.size / 1024 / 1024 > 500) {
this.$warning(this.$t('api_test.request.body_upload_limit_size'));
return false;
}
return true;
},
fileValidator(file) {
return file.size > 0;
},
setModule(id, data) {
if (this.data.moduleId !== id) {
this.data.moduleId = id;
@ -160,9 +182,19 @@ export default {
this.visible = true;
},
save() {
let request = JSON.parse(JSON.stringify(this.data));
request.tags = JSON.stringify(request.tags);
this.$post('/file/metadata/update', request, () => {
this.$refs['form'].validate((valid) => {
if (valid) {
let request = JSON.parse(JSON.stringify(this.data));
request.tags = JSON.stringify(request.tags);
if (request.tags && request.tags.length > 1000) {
this.$warning(this.$t('api_test.automation.tag') + this.$t('commons.input_limit', [0, 1000]));
return;
}
this.$post('/file/metadata/update', request, () => {
}, err => {
this.$emit("reload");
});
}
});
},
getType(type) {
@ -241,6 +273,22 @@ export default {
}
}
},
formatFileSize(val) {
if (isNaN(val)) {
return "";
}
let list = ["bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
let temp = Math.floor(Math.log(val) / Math.log(2));
if (temp < 1) {
temp = 0;
}
let num = Math.floor(temp / 10);
val = val / Math.pow(2, 10 * num);
if (val.toString().length > val.toFixed(2).toString().length) {
val = val.toFixed(2);
}
return val + " " + list[num];
},
nextData() {
const index = this.results.findIndex(e => e.id === this.data.id);
this.isLast = (this.results.length - 1) === index;

View File

@ -103,7 +103,7 @@
icon="el-icon-view"
type="primary"
:tip="$t('permission.project_report_analysis.read')"
v-permission="['PROJECT_FILE:READ+JAR']"
v-permission="['PROJECT_FILE:READ']"
@exec="handleView(scope.row)">
</ms-table-operator-button>

View File

@ -44,7 +44,7 @@ export default {
currentPage: 1,
pageSize: 10,
total: 0,
images: ["bmp", "jpg", "png", "tif", "gif", "pcx", "tga", "exif", "fpx", "svg", "psd", "cdr", "pcd", "dxf", "ufo", "eps", "ai", "raw", "WMF", "webp", "avif", "apng"]
images: ["bmp", "jpg", "png", "tif", "gif", "pcx", "tga", "exif", "fpx", "svg", "psd", "cdr", "pcd", "dxf", "ufo", "eps", "ai", "raw", "WMF", "webp", "avif", "apng","jpeg"]
};
},
props: {