From b6d9360f7241b1561a749ed3d303c4b9b6d1ef56 Mon Sep 17 00:00:00 2001 From: hj24 Date: Mon, 13 Oct 2025 09:50:24 +0800 Subject: [PATCH] fix: use account id in workflow app log filter --- api/services/workflow_app_service.py | 20 +++++---- .../services/test_workflow_app_service.py | 42 +++++++++++++++++++ 2 files changed, 55 insertions(+), 7 deletions(-) diff --git a/api/services/workflow_app_service.py b/api/services/workflow_app_service.py index ced6dca324..615a1c3093 100644 --- a/api/services/workflow_app_service.py +++ b/api/services/workflow_app_service.py @@ -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()) diff --git a/api/tests/test_containers_integration_tests/services/test_workflow_app_service.py b/api/tests/test_containers_integration_tests/services/test_workflow_app_service.py index 62c9bead86..ce33116222 100644 --- a/api/tests/test_containers_integration_tests/services/test_workflow_app_service.py +++ b/api/tests/test_containers_integration_tests/services/test_workflow_app_service.py @@ -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,