|
@@ -3,7 +3,8 @@ from argparse import ArgumentTypeError
|
|
|
from datetime import UTC, datetime
|
|
|
from typing import cast
|
|
|
|
|
|
-from flask import request
|
|
|
+import json
|
|
|
+from flask import request,jsonify
|
|
|
from flask_login import current_user # type: ignore
|
|
|
from flask_restful import Resource, fields, marshal, marshal_with, reqparse # type: ignore
|
|
|
from sqlalchemy import asc, desc
|
|
@@ -56,6 +57,7 @@ from services.dataset_service import DatasetService, DocumentService
|
|
|
from services.entities.knowledge_entities.knowledge_entities import KnowledgeConfig
|
|
|
from tasks.add_document_to_index_task import add_document_to_index_task
|
|
|
from tasks.remove_document_from_index_task import remove_document_from_index_task
|
|
|
+from models.account import Account, TenantAccountRole
|
|
|
|
|
|
|
|
|
class DocumentResource(Resource):
|
|
@@ -833,9 +835,16 @@ class DocumentStatusApi(DocumentResource):
|
|
|
if action == "enable":
|
|
|
if document.enabled:
|
|
|
continue
|
|
|
+ if current_user.current_role != TenantAccountRole.ADMIN:
|
|
|
+ document.enable_applicant = current_user.id
|
|
|
+ document.check_status=1
|
|
|
+ db.session.commit()
|
|
|
+ return {"result": "该操作需要提交管理员审核后生效,请确认是否提交"}, 200
|
|
|
document.enabled = True
|
|
|
document.disabled_at = None
|
|
|
document.disabled_by = None
|
|
|
+ document.check_by = current_user.id
|
|
|
+ document.check_at = datetime.now(UTC).replace(tzinfo=None)
|
|
|
document.updated_at = datetime.now(UTC).replace(tzinfo=None)
|
|
|
db.session.commit()
|
|
|
|
|
@@ -844,16 +853,32 @@ class DocumentStatusApi(DocumentResource):
|
|
|
|
|
|
add_document_to_index_task.delay(document_id)
|
|
|
|
|
|
+ # 审核不通过
|
|
|
+ elif action == "check_fail":
|
|
|
+ document.enabled = False
|
|
|
+ document.check_by = current_user.id
|
|
|
+ document.updated_at = datetime.now(UTC).replace(tzinfo=None)
|
|
|
+ document.check_status = 4
|
|
|
+ db.session.commit()
|
|
|
+
|
|
|
elif action == "disable":
|
|
|
if not document.completed_at or document.indexing_status != "completed":
|
|
|
raise InvalidActionError(f"Document: {document.name} is not completed.")
|
|
|
if not document.enabled:
|
|
|
continue
|
|
|
+ # 下线判断,非管理员无法提交
|
|
|
+ if current_user.current_role != TenantAccountRole.ADMIN:
|
|
|
+ document.disable_applicant = current_user.id
|
|
|
+ db.session.commit()
|
|
|
+ # data = {"result": "该操作需要提交管理员审核后生效,请确认是否提交"}
|
|
|
+ return {"result": "该操作需要提交管理员审核后生效,请确认是否提交"}, 200
|
|
|
+ # return json.dumps(data, ensure_ascii=False), 200
|
|
|
|
|
|
document.enabled = False
|
|
|
document.disabled_at = datetime.now(UTC).replace(tzinfo=None)
|
|
|
document.disabled_by = current_user.id
|
|
|
document.updated_at = datetime.now(UTC).replace(tzinfo=None)
|
|
|
+ document.check_status = 3
|
|
|
db.session.commit()
|
|
|
|
|
|
# Set cache to prevent indexing the same document multiple times
|