mirror of
https://github.com/langgenius/dify.git
synced 2024-11-16 03:32:23 +08:00
workflow logs support workflow run id filter (#6833)
This commit is contained in:
parent
4ffa706e4f
commit
5542ee4d0d
|
@ -1,3 +1,5 @@
|
|||
import uuid
|
||||
|
||||
from flask_sqlalchemy.pagination import Pagination
|
||||
from sqlalchemy import and_, or_
|
||||
|
||||
|
@ -25,20 +27,26 @@ class WorkflowAppService:
|
|||
)
|
||||
|
||||
status = WorkflowRunStatus.value_of(args.get('status')) if args.get('status') else None
|
||||
if args['keyword'] or status:
|
||||
keyword = args['keyword']
|
||||
if keyword or status:
|
||||
query = query.join(
|
||||
WorkflowRun, WorkflowRun.id == WorkflowAppLog.workflow_run_id
|
||||
)
|
||||
|
||||
if args['keyword']:
|
||||
keyword_val = f"%{args['keyword'][:30]}%"
|
||||
if keyword:
|
||||
keyword_like_val = f"%{args['keyword'][:30]}%"
|
||||
keyword_conditions = [
|
||||
WorkflowRun.inputs.ilike(keyword_val),
|
||||
WorkflowRun.outputs.ilike(keyword_val),
|
||||
WorkflowRun.inputs.ilike(keyword_like_val),
|
||||
WorkflowRun.outputs.ilike(keyword_like_val),
|
||||
# filter keyword by end user session id if created by end user role
|
||||
and_(WorkflowRun.created_by_role == 'end_user', EndUser.session_id.ilike(keyword_val))
|
||||
and_(WorkflowRun.created_by_role == 'end_user', EndUser.session_id.ilike(keyword_like_val))
|
||||
]
|
||||
|
||||
# filter keyword by workflow run id
|
||||
keyword_uuid = self._safe_parse_uuid(keyword)
|
||||
if keyword_uuid:
|
||||
keyword_conditions.append(WorkflowRun.id == keyword_uuid)
|
||||
|
||||
query = query.outerjoin(
|
||||
EndUser,
|
||||
and_(WorkflowRun.created_by == EndUser.id, WorkflowRun.created_by_role == CreatedByRole.END_USER.value)
|
||||
|
@ -60,3 +68,14 @@ class WorkflowAppService:
|
|||
)
|
||||
|
||||
return pagination
|
||||
|
||||
@staticmethod
|
||||
def _safe_parse_uuid(value: str):
|
||||
# fast check
|
||||
if len(value) < 32:
|
||||
return None
|
||||
|
||||
try:
|
||||
return uuid.UUID(value)
|
||||
except ValueError:
|
||||
return None
|
||||
|
|
Loading…
Reference in New Issue
Block a user