mirror of https://github.com/langgenius/dify.git
fix: use account id in workflow app log filter (#26811)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: crazywoola <100913391+crazywoola@users.noreply.github.com>
This commit is contained in:
parent
9e3b4dc90d
commit
15a5ba67f1
|
|
@ -86,12 +86,16 @@ class WorkflowAppService:
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
if created_by_account:
|
if created_by_account:
|
||||||
|
account = session.scalar(select(Account).where(Account.email == created_by_account))
|
||||||
|
if not account:
|
||||||
|
raise ValueError(f"Account not found: {created_by_account}")
|
||||||
|
|
||||||
stmt = stmt.join(
|
stmt = stmt.join(
|
||||||
Account,
|
Account,
|
||||||
and_(
|
and_(
|
||||||
WorkflowAppLog.created_by == Account.id,
|
WorkflowAppLog.created_by == Account.id,
|
||||||
WorkflowAppLog.created_by_role == CreatorUserRole.ACCOUNT,
|
WorkflowAppLog.created_by_role == CreatorUserRole.ACCOUNT,
|
||||||
Account.email == created_by_account,
|
Account.id == account.id,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -789,6 +789,31 @@ class TestWorkflowAppService:
|
||||||
assert result_account_filter["total"] == 3
|
assert result_account_filter["total"] == 3
|
||||||
assert all(log.created_by_role == CreatorUserRole.ACCOUNT for log in result_account_filter["data"])
|
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 unexpected input, should raise ValueError
|
||||||
|
with pytest.raises(ValueError) as exc_info:
|
||||||
|
service.get_paginate_workflow_app_logs(
|
||||||
|
session=db_session_with_containers, app_model=app, created_by_account=original_email, page=1, limit=20
|
||||||
|
)
|
||||||
|
assert "Account not found" in str(exc_info.value)
|
||||||
|
|
||||||
|
account.email = original_email
|
||||||
|
db_session_with_containers.commit()
|
||||||
|
|
||||||
# Test filtering by non-existent session ID
|
# Test filtering by non-existent session ID
|
||||||
result_no_session = service.get_paginate_workflow_app_logs(
|
result_no_session = service.get_paginate_workflow_app_logs(
|
||||||
session=db_session_with_containers,
|
session=db_session_with_containers,
|
||||||
|
|
@ -799,15 +824,16 @@ class TestWorkflowAppService:
|
||||||
)
|
)
|
||||||
assert result_no_session["total"] == 0
|
assert result_no_session["total"] == 0
|
||||||
|
|
||||||
# Test filtering by non-existent account email
|
# Test filtering by non-existent account email, is unexpected input, should raise ValueError
|
||||||
result_no_account = service.get_paginate_workflow_app_logs(
|
with pytest.raises(ValueError) as exc_info:
|
||||||
session=db_session_with_containers,
|
service.get_paginate_workflow_app_logs(
|
||||||
app_model=app,
|
session=db_session_with_containers,
|
||||||
created_by_account="nonexistent@example.com",
|
app_model=app,
|
||||||
page=1,
|
created_by_account="nonexistent@example.com",
|
||||||
limit=20,
|
page=1,
|
||||||
)
|
limit=20,
|
||||||
assert result_no_account["total"] == 0
|
)
|
||||||
|
assert "Account not found" in str(exc_info.value)
|
||||||
|
|
||||||
def test_get_paginate_workflow_app_logs_with_uuid_keyword_search(
|
def test_get_paginate_workflow_app_logs_with_uuid_keyword_search(
|
||||||
self, db_session_with_containers, mock_external_service_dependencies
|
self, db_session_with_containers, mock_external_service_dependencies
|
||||||
|
|
@ -1057,15 +1083,15 @@ class TestWorkflowAppService:
|
||||||
assert len(result_no_session["data"]) == 0
|
assert len(result_no_session["data"]) == 0
|
||||||
|
|
||||||
# Test with account email that doesn't exist
|
# Test with account email that doesn't exist
|
||||||
result_no_account = service.get_paginate_workflow_app_logs(
|
with pytest.raises(ValueError) as exc_info:
|
||||||
session=db_session_with_containers,
|
service.get_paginate_workflow_app_logs(
|
||||||
app_model=app,
|
session=db_session_with_containers,
|
||||||
created_by_account="nonexistent@example.com",
|
app_model=app,
|
||||||
page=1,
|
created_by_account="nonexistent@example.com",
|
||||||
limit=20,
|
page=1,
|
||||||
)
|
limit=20,
|
||||||
assert result_no_account["total"] == 0
|
)
|
||||||
assert len(result_no_account["data"]) == 0
|
assert "Account not found" in str(exc_info.value)
|
||||||
|
|
||||||
def test_get_paginate_workflow_app_logs_with_complex_query_combinations(
|
def test_get_paginate_workflow_app_logs_with_complex_query_combinations(
|
||||||
self, db_session_with_containers, mock_external_service_dependencies
|
self, db_session_with_containers, mock_external_service_dependencies
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue