Explorar o código

审批流程,添加返回审核人和提交人

guoyuanquan@mail.taiji.com.cn hai 3 meses
pai
achega
66cc5bf2f1

+ 28 - 7
api/controllers/console/datasets/datasets_document.py

@@ -53,6 +53,7 @@ from fields.document_fields import (
 from libs.login import login_required
 from models import Dataset, DatasetProcessRule, Document, DocumentSegment, UploadFile
 from models.account import TenantAccountRole
+from services.account_service import AccountService
 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
@@ -224,8 +225,22 @@ class DatasetDocumentListApi(Resource):
                 ).count()
                 document.completed_segments = completed_segments
                 document.total_segments = total_segments
+                if document.check_by is not None:
+                    check_account = AccountService.get_user_through_id(document.check_by)
+                    document.check_by = check_account.name
+                if document.enable_applicant is not None:
+                    applicant_account = (AccountService.get_user_through_id(document.enable_applicant),)
+                    document.enable_applicant = applicant_account.name
             data = marshal(documents, document_with_segments_fields)
         else:
+            for document in documents:
+                if document.check_by is not None:
+                    check_account = AccountService.get_user_through_id(document.check_by)
+                    document.check_by = check_account.name
+                if document.enable_applicant is not None:
+                    applicant_account = AccountService.get_user_through_id(document.enable_applicant)
+                    document.enable_applicant = applicant_account.name
+
             data = marshal(documents, document_fields)
         response = {
             "data": data,
@@ -655,6 +670,10 @@ class DocumentDetailApi(DocumentResource):
                 "display_status": document.display_status,
                 "doc_form": document.doc_form,
                 "doc_language": document.doc_language,
+                "check_status": document.check_status,
+                "check_at": document.check_at,
+                "disable_application": document.disable_applicant,
+                "enable_application": document.enable_applicant,
             }
         else:
             dataset_process_rules = DatasetService.get_process_rules(dataset_id)
@@ -690,6 +709,10 @@ class DocumentDetailApi(DocumentResource):
                 "display_status": document.display_status,
                 "doc_form": document.doc_form,
                 "doc_language": document.doc_language,
+                "check_status": document.check_status,
+                "check_at": document.check_at,
+                "disable_application": document.disable_applicant,
+                "enable_application": document.enable_applicant,
             }
 
         return response, 200
@@ -834,9 +857,9 @@ class DocumentStatusApi(DocumentResource):
             if action == "enable":
                 if document.enabled:
                     continue
-                if current_user.current_role != TenantAccountRole.ADMIN:
+                if current_user not in (TenantAccountRole.ADMIN, TenantAccountRole.OWNER):
                     document.enable_applicant = current_user.id
-                    document.check_status=1
+                    document.check_status = 1
                     db.session.commit()
                     return {"result": "该操作需要提交管理员审核后生效,请确认是否提交"}, 200
                 document.enabled = True
@@ -857,7 +880,7 @@ class DocumentStatusApi(DocumentResource):
                 document.enabled = False
                 document.check_by = current_user.id
                 document.updated_at = datetime.now(UTC).replace(tzinfo=None)
-                document.check_status = 4
+                document.check_status = 2
                 db.session.commit()
 
             elif action == "disable":
@@ -866,12 +889,10 @@ class DocumentStatusApi(DocumentResource):
                 if not document.enabled:
                     continue
                 #     下线判断,非管理员无法提交
-                if current_user.current_role != TenantAccountRole.ADMIN:
-                    document.disable_applicant = current_user.id
+                if current_user.current_role not in (TenantAccountRole.ADMIN, TenantAccountRole.OWNER):
+                    document.enable_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)

+ 10 - 0
api/fields/document_fields.py

@@ -33,6 +33,11 @@ document_fields = {
     "hit_count": fields.Integer,
     "doc_form": fields.String,
     "doc_metadata": fields.List(fields.Nested(document_metadata_fields), attribute="doc_metadata_details"),
+    "check_status": fields.Integer,
+    "check_by": fields.String,
+    "check_at": TimestampField,
+    "disable_application": fields.String,
+    "enable_application": fields.String,
 }
 
 document_with_segments_fields = {
@@ -60,6 +65,11 @@ document_with_segments_fields = {
     "completed_segments": fields.Integer,
     "total_segments": fields.Integer,
     "doc_metadata": fields.List(fields.Nested(document_metadata_fields), attribute="doc_metadata_details"),
+    "check_status": fields.Integer,
+    "check_by": fields.String,
+    "check_at": TimestampField,
+    "disable_application": fields.String,
+    "enable_application": fields.String,
 }
 
 dataset_and_document_fields = {

+ 3 - 3
api/models/dataset.py

@@ -363,10 +363,10 @@ class Document(db.Model):  # type: ignore[name-defined]
     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_by = db.Column(db.String(40), nullable=True)
     check_at = db.Column(db.DateTime, nullable=True)
-    disable_applicant = db.Column(StringUUID, nullable=False)
-    enable_applicant = db.Column(StringUUID, nullable=False)
+    disable_applicant = db.Column(StringUUID, nullable=True)
+    enable_applicant = db.Column(db.String(40), nullable=False)
 
     DATA_SOURCES = ["upload_file", "notion_import", "website_crawl"]
 

+ 7 - 0
api/services/account_service.py

@@ -479,6 +479,13 @@ class AccountService:
         return account
 
     @staticmethod
+    def get_user_through_id(id: str) -> Optional[Account]:
+        account: Optional[Account] = db.session.query(Account).filter(Account.id == id).first()
+        if not account:
+            return None
+        return account
+
+    @staticmethod
     def add_login_error_rate_limit(email: str) -> None:
         key = f"login_error_rate_limit:{email}"
         count = redis_client.get(key)

+ 35 - 14
api/services/dataset_service.py

@@ -1149,20 +1149,41 @@ class DocumentService:
         name: str,
         batch: str,
     ):
-        document = Document(
-            tenant_id=dataset.tenant_id,
-            dataset_id=dataset.id,
-            position=position,
-            data_source_type=data_source_type,
-            data_source_info=json.dumps(data_source_info),
-            dataset_process_rule_id=process_rule_id,
-            batch=batch,
-            name=name,
-            created_from=created_from,
-            created_by=account.id,
-            doc_form=document_form,
-            doc_language=document_language,
-        )
+        if account.current_role == TenantAccountRole.EDITOR:
+            document = Document(
+                tenant_id=dataset.tenant_id,
+                dataset_id=dataset.id,
+                position=position,
+                data_source_type=data_source_type,
+                data_source_info=json.dumps(data_source_info),
+                dataset_process_rule_id=process_rule_id,
+                batch=batch,
+                name=name,
+                created_from=created_from,
+                created_by=account.id,
+                doc_form=document_form,
+                doc_language=document_language,
+                check_status=1,
+                enable_applicant=account.id,
+            )
+        else:
+            document = Document(
+                tenant_id=dataset.tenant_id,
+                dataset_id=dataset.id,
+                position=position,
+                data_source_type=data_source_type,
+                data_source_info=json.dumps(data_source_info),
+                dataset_process_rule_id=process_rule_id,
+                batch=batch,
+                name=name,
+                created_from=created_from,
+                created_by=account.id,
+                doc_form=document_form,
+                doc_language=document_language,
+                check_status=3,
+                check_by=account.id,
+            )
+
         doc_metadata = {}
         if dataset.built_in_field_enabled:
             doc_metadata = {