|
@@ -2,15 +2,11 @@ import {IApiProcessor, ICachedData, IMethodParams, IRequest} from "@core/Defined
|
|
import {Resp} from "@util/Resp";
|
|
import {Resp} from "@util/Resp";
|
|
import {Oss} from "@util/Oss";
|
|
import {Oss} from "@util/Oss";
|
|
import {IdGen} from "@util/IdGen";
|
|
import {IdGen} from "@util/IdGen";
|
|
-import {PrjTaskOutcome} from "@core-models/PrjTaskOutcome";
|
|
|
|
import {PrjInfo} from "@core-models/PrjInfo";
|
|
import {PrjInfo} from "@core-models/PrjInfo";
|
|
-import {PrjPlanTask} from "@core-models/PrjPlanTask";
|
|
|
|
-import {QueryTypes} from "sequelize";
|
|
|
|
-import {BizContractInfo} from "@core-models/BizContractInfo";
|
|
|
|
import dayjs from "dayjs";
|
|
import dayjs from "dayjs";
|
|
-import {PrjWeekReport} from "@core-models/PrjWeekReport";
|
|
|
|
import {PrjFile} from "@core-models/PrjFile";
|
|
import {PrjFile} from "@core-models/PrjFile";
|
|
import {PrjFileCategory} from "@core-models/PrjFileCategory";
|
|
import {PrjFileCategory} from "@core-models/PrjFileCategory";
|
|
|
|
+import {is_project_document_uploadable} from "@src/utils/prj_premission_helper";
|
|
|
|
|
|
interface IData {
|
|
interface IData {
|
|
/**
|
|
/**
|
|
@@ -25,17 +21,18 @@ interface IData {
|
|
* 项目id
|
|
* 项目id
|
|
*/
|
|
*/
|
|
prj_id: string;
|
|
prj_id: string;
|
|
- [property: string]: any;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-// TODO: 所有文档都放在一个表中,记录项目id和文档类型
|
|
|
|
-
|
|
|
|
function get_upload_url(json: IRequest, params: IMethodParams, cached_data: ICachedData): Promise<any> {
|
|
function get_upload_url(json: IRequest, params: IMethodParams, cached_data: ICachedData): Promise<any> {
|
|
return new Promise(async (resolve, reject) => {
|
|
return new Promise(async (resolve, reject) => {
|
|
|
|
+ let data = <IData>json.data;
|
|
|
|
+ if (!await is_project_document_uploadable(cached_data.user_id, data.prj_id)) {
|
|
|
|
+ return reject(Resp.gen_err(Resp.Forbidden, "没有权限上传文档"));
|
|
|
|
+ }
|
|
let t = await PrjFile.sequelize!.transaction();
|
|
let t = await PrjFile.sequelize!.transaction();
|
|
try {
|
|
try {
|
|
let id = IdGen.id();
|
|
let id = IdGen.id();
|
|
- let data = <IData>json.data;
|
|
|
|
|
|
+
|
|
let object_name = `project/${data.prj_id}/${data.category_id}/${id}`;
|
|
let object_name = `project/${data.prj_id}/${data.category_id}/${id}`;
|
|
|
|
|
|
await PrjFile.create({
|
|
await PrjFile.create({
|
|
@@ -59,7 +56,7 @@ function get_upload_url(json: IRequest, params: IMethodParams, cached_data: ICac
|
|
}
|
|
}
|
|
|
|
|
|
/// 检查项目是否存在
|
|
/// 检查项目是否存在
|
|
-function existsGuard(json: IRequest, cached_data: ICachedData): Promise<void> {
|
|
|
|
|
|
+function existsGuard(json: IRequest, _cached_data: ICachedData): Promise<void> {
|
|
return new Promise<void>(async (resolve, reject) => {
|
|
return new Promise<void>(async (resolve, reject) => {
|
|
let data = <IData>json.data;
|
|
let data = <IData>json.data;
|
|
let prj = await PrjInfo.findOne({where: {id: data.prj_id}, raw: true});
|
|
let prj = await PrjInfo.findOne({where: {id: data.prj_id}, raw: true});
|
|
@@ -69,12 +66,12 @@ function existsGuard(json: IRequest, cached_data: ICachedData): Promise<void> {
|
|
}
|
|
}
|
|
|
|
|
|
/// 检查文档类型是否允许自由上传
|
|
/// 检查文档类型是否允许自由上传
|
|
-function allowUploadGuard(json: IRequest, cached_data: ICachedData): Promise<void> {
|
|
|
|
|
|
+function allowUploadGuard(json: IRequest, _cached_data: ICachedData): Promise<void> {
|
|
return new Promise<void>(async (resolve, reject) => {
|
|
return new Promise<void>(async (resolve, reject) => {
|
|
let data = <IData>json.data;
|
|
let data = <IData>json.data;
|
|
let category = await PrjFileCategory.findOne({where: {id: data.category_id}, raw: true});
|
|
let category = await PrjFileCategory.findOne({where: {id: data.category_id}, raw: true});
|
|
if (!category) return reject(Resp.gen_err(Resp.ResourceNotFound, "文档类型不存在,id: "+ data.category_id));
|
|
if (!category) return reject(Resp.gen_err(Resp.ResourceNotFound, "文档类型不存在,id: "+ data.category_id));
|
|
- if (category.allow_upload === false) return reject(Resp.gen_err(Resp.Forbidden, '此文档类型不允许自由上传文件。'))
|
|
|
|
|
|
+ if (!category.allow_upload) return reject(Resp.gen_err(Resp.Forbidden, '此文档类型不允许自由上传文件。'))
|
|
resolve();
|
|
resolve();
|
|
});
|
|
});
|
|
}
|
|
}
|