Sfoglia il codice sorgente

角色的资源过滤掉删除的

zhaoqingang 1 anno fa
parent
commit
ee8df9424f
4 ha cambiato i file con 22 aggiunte e 13 eliminazioni
  1. 10 6
      app/api/agent.py
  2. 3 1
      app/api/dialog.py
  3. 3 2
      app/models/role_model.py
  4. 6 4
      app/service/dialog.py

+ 10 - 6
app/api/agent.py

@@ -81,11 +81,15 @@ async def chat_list(
 
 
 @router.get("/{agent_id}/{conversation_id}/session_log")
 @router.get("/{agent_id}/{conversation_id}/session_log")
 async def session_log(agent_id: str, conversation_id: str, db: Session = Depends(get_db), current_user: UserModel = Depends(get_current_user)):
 async def session_log(agent_id: str, conversation_id: str, db: Session = Depends(get_db), current_user: UserModel = Depends(get_current_user)):
-    agent = db.query(AgentModel).filter(AgentModel.id == agent_id).first()
+    # agent = db.query(AgentModel).filter(AgentModel.id == agent_id).first()
+    # if not agent:
+    #     return Response(code=404, msg="Agent not found")
+    agent = db.query(MenuCapacityModel).filter(MenuCapacityModel.chat_id == agent_id).first()
     if not agent:
     if not agent:
-        return Response(code=404, msg="Agent not found")
+        return ResponseList(code=404, msg="Agent not found")
+    agent_type = int(agent.capacity_type)
 
 
-    if agent.agent_type == AgentType.RAGFLOW:
+    if agent_type == AgentType.RAGFLOW:
         ragflow_service = RagflowService(base_url=settings.fwr_base_url)
         ragflow_service = RagflowService(base_url=settings.fwr_base_url)
         try:
         try:
             token = await get_ragflow_token(db, current_user.id)
             token = await get_ragflow_token(db, current_user.id)
@@ -116,7 +120,7 @@ async def session_log(agent_id: str, conversation_id: str, db: Session = Depends
                 return JSONResponse(status_code=200, content={"code": 400, "message": "Invalid result structure"})
                 return JSONResponse(status_code=200, content={"code": 400, "message": "Invalid result structure"})
         except Exception as e:
         except Exception as e:
             raise HTTPException(status_code=500, detail=str(e))
             raise HTTPException(status_code=500, detail=str(e))
-    elif agent.agent_type == AgentType.BISHENG:
+    elif agent_type == AgentType.BISHENG:
         is_join = False
         is_join = False
         if agent.name == "报告生成":
         if agent.name == "报告生成":
             is_join = True
             is_join = True
@@ -180,7 +184,7 @@ async def session_log(agent_id: str, conversation_id: str, db: Session = Depends
                             'answer': answer_str, 'files': files}]})
                             'answer': answer_str, 'files': files}]})
         except Exception as e:
         except Exception as e:
             raise HTTPException(status_code=500, detail=str(e))
             raise HTTPException(status_code=500, detail=str(e))
-    elif agent.agent_type == AgentType.BASIC:
+    elif agent_type == AgentType.BASIC:
         data = []
         data = []
         session = db.query(SessionModel).filter(SessionModel.id == conversation_id).first()
         session = db.query(SessionModel).filter(SessionModel.id == conversation_id).first()
         if session:
         if session:
@@ -219,7 +223,7 @@ async def session_log(agent_id: str, conversation_id: str, db: Session = Depends
                 data.append(tmp_data)
                 data.append(tmp_data)
 
 
         return JSONResponse(status_code=200, content={"code": 200, "data": data})
         return JSONResponse(status_code=200, content={"code": 200, "data": data})
-    elif agent.agent_type == AgentType.DIFY:
+    elif agent_type == AgentType.DIFY:
         data = []
         data = []
         session = db.query(SessionModel).filter(SessionModel.id == conversation_id).first()
         session = db.query(SessionModel).filter(SessionModel.id == conversation_id).first()
         if session:
         if session:

+ 3 - 1
app/api/dialog.py

@@ -20,7 +20,9 @@ async def dialog_list(current: int,
                       current_user: UserModel = Depends(get_current_user),
                       current_user: UserModel = Depends(get_current_user),
                       db=Depends(get_db)):
                       db=Depends(get_db)):
     if current and not pageSize:
     if current and not pageSize:
-        return ResponseList(code=400, msg="缺少参数")
+        return Response(code=400, msg="缺少参数")
+    if status and status not in ["0", "1"]:
+        return Response(code=400, msg="Parameter status exception")
     return Response(code=200, msg="", data=await get_dialog_list(db, current_user.id, keyword, label, status, pageSize, current))
     return Response(code=200, msg="", data=await get_dialog_list(db, current_user.id, keyword, label, status, pageSize, current))
 
 
 
 

+ 3 - 2
app/models/role_model.py

@@ -5,6 +5,7 @@ from pydantic import BaseModel, constr
 from sqlalchemy import Column, Integer, String, DateTime, Table, ForeignKey
 from sqlalchemy import Column, Integer, String, DateTime, Table, ForeignKey
 from sqlalchemy.orm import relationship, backref
 from sqlalchemy.orm import relationship, backref
 
 
+from app.config.const import RESOURCE_STATUS_DELETE, DEPT_STATUS_DELETE
 from app.models.base_model import Base
 from app.models.base_model import Base
 
 
 # 角色资源关联表
 # 角色资源关联表
@@ -59,9 +60,9 @@ class RoleModel(Base):
         }
         }
 
 
         # if len(self.resources) > 0:
         # if len(self.resources) > 0:
-        json['resources'] = [resource.to_json() for resource in self.resources]
+        json['resources'] = [resource.to_json() for resource in self.resources if resource.status != DEPT_STATUS_DELETE]
 
 
-        json['dept'] = [dept.to_base_json() for dept in self.organizations]
+        json['dept'] = [dept.to_base_json() for dept in self.organizationsif if dept.status != RESOURCE_STATUS_DELETE]
 
 
         return json
         return json
 
 

+ 6 - 4
app/service/dialog.py

@@ -13,7 +13,11 @@ async def get_dialog_list(db, user_id, keyword, label, status, page_size, page_i
     user = db.query(UserModel).filter(UserModel.id == user_id).first()
     user = db.query(UserModel).filter(UserModel.id == user_id).first()
     if user is None:
     if user is None:
         return {"rows": []}
         return {"rows": []}
-    query = db.query(DialogModel).filter(DialogModel.status != Dialog_STATSU_DELETE)
+    query = db.query(DialogModel)
+    if status:
+        query = query.filter(DialogModel.status == status)
+    else:
+        query = query.filter(DialogModel.status != Dialog_STATSU_DELETE)
     id_list = []
     id_list = []
     if label:
     if label:
         id_list = [i.object_id for i in db.query(LabelWorkerModel).filter(LabelWorkerModel.label_id==label).all()]
         id_list = [i.object_id for i in db.query(LabelWorkerModel).filter(LabelWorkerModel.label_id==label).all()]
@@ -27,9 +31,7 @@ async def get_dialog_list(db, user_id, keyword, label, status, page_size, page_i
     if keyword:
     if keyword:
         query = query.filter(DialogModel.name.like('%{}%'.format(keyword)))
         query = query.filter(DialogModel.name.like('%{}%'.format(keyword)))
 
 
-    if status:
-        # print(status)
-        query = query.filter(DialogModel.status == status)
+
     query = query.order_by(DialogModel.update_date.desc())
     query = query.order_by(DialogModel.update_date.desc())
     total = query.count()
     total = query.count()
     if page_size:
     if page_size: