guoyuanquan@mail.taiji.com.cn 3 miesięcy temu
rodzic
commit
fe492e25cb

+ 26 - 1
api/controllers/console/datasets/datasets_document.py

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

+ 5 - 0
api/models/dataset.py

@@ -362,6 +362,11 @@ class Document(db.Model):  # type: ignore[name-defined]
     doc_metadata = db.Column(JSONB, nullable=True)
     doc_form = db.Column(db.String(255), nullable=False, server_default=db.text("'text_model'::character varying"))
     doc_language = db.Column(db.String(255), nullable=True)
+    check_status = db.Column(db.Integer, nullable=False)
+    check_by = db.Column(StringUUID, nullable=False)
+    check_at = db.Column(db.DateTime, nullable=True)
+    disable_applicant = db.Column(StringUUID, nullable=False)
+    enable_applicant = db.Column(StringUUID, nullable=False)
 
     DATA_SOURCES = ["upload_file", "notion_import", "website_crawl"]
 

+ 1 - 1
api/services/dataset_service.py

@@ -187,7 +187,7 @@ class DatasetService:
         dataset.tenant_id = tenant_id
         dataset.embedding_model_provider = embedding_model.provider if embedding_model else None
         dataset.embedding_model = embedding_model.model if embedding_model else None
-        dataset.permission = permission or DatasetPermissionEnum.ONLY_ME
+        dataset.permission = DatasetPermissionEnum.ALL_TEAM
         dataset.provider = provider
         db.session.add(dataset)
         db.session.flush()