mirror of https://github.com/langgenius/dify.git
fix: use account id in workflow app log filter
This commit is contained in:
parent
9fc2a0a3a1
commit
b6d9360f72
|
|
@ -86,14 +86,20 @@ class WorkflowAppService:
|
|||
),
|
||||
)
|
||||
if created_by_account:
|
||||
stmt = stmt.join(
|
||||
Account,
|
||||
and_(
|
||||
WorkflowAppLog.created_by == Account.id,
|
||||
WorkflowAppLog.created_by_role == CreatorUserRole.ACCOUNT,
|
||||
Account.email == created_by_account,
|
||||
),
|
||||
account = session.scalar(
|
||||
select(Account).where(Account.email == created_by_account)
|
||||
)
|
||||
if account:
|
||||
stmt = stmt.join(
|
||||
Account,
|
||||
and_(
|
||||
WorkflowAppLog.created_by == Account.id,
|
||||
WorkflowAppLog.created_by_role == CreatorUserRole.ACCOUNT,
|
||||
Account.id == account.id,
|
||||
),
|
||||
)
|
||||
else:
|
||||
stmt = stmt.where(False)
|
||||
|
||||
stmt = stmt.order_by(WorkflowAppLog.created_at.desc())
|
||||
|
||||
|
|
|
|||
|
|
@ -789,6 +789,48 @@ class TestWorkflowAppService:
|
|||
assert result_account_filter["total"] == 3
|
||||
assert all(log.created_by_role == CreatorUserRole.ACCOUNT for log in result_account_filter["data"])
|
||||
|
||||
# Test filtering by changed account email
|
||||
original_email = account.email
|
||||
new_email = "changed@example.com"
|
||||
account.email = new_email
|
||||
db_session_with_containers.commit()
|
||||
|
||||
assert account.email == new_email
|
||||
|
||||
# Results for new email, is expected to be the same as the original email
|
||||
result_with_new_email = service.get_paginate_workflow_app_logs(
|
||||
session=db_session_with_containers,
|
||||
app_model=app,
|
||||
created_by_account=new_email,
|
||||
page=1,
|
||||
limit=20
|
||||
)
|
||||
assert result_with_new_email["total"] == 3
|
||||
assert all(log.created_by_role == CreatorUserRole.ACCOUNT for log in result_with_new_email["data"])
|
||||
|
||||
# Old email unbound, is expected to be 0
|
||||
result_with_old_email = service.get_paginate_workflow_app_logs(
|
||||
session=db_session_with_containers,
|
||||
app_model=app,
|
||||
created_by_account=original_email,
|
||||
page=1,
|
||||
limit=20
|
||||
)
|
||||
assert result_with_old_email["total"] == 0
|
||||
|
||||
# Result with unknown email, is expected to be 0
|
||||
result_with_unknown_email = service.get_paginate_workflow_app_logs(
|
||||
session=db_session_with_containers,
|
||||
app_model=app,
|
||||
created_by_account="unknown@example.com",
|
||||
page=1,
|
||||
limit=20
|
||||
)
|
||||
assert result_with_old_email["total"] == 0
|
||||
|
||||
account.email = original_email
|
||||
db_session_with_containers.commit()
|
||||
|
||||
# Test filtering by non-existent session ID
|
||||
result_no_session = service.get_paginate_workflow_app_logs(
|
||||
session=db_session_with_containers,
|
||||
|
|
|
|||
Loading…
Reference in New Issue