From 716d5f6ae0141d4fc14a84950d26a56765b70218 Mon Sep 17 00:00:00 2001 From: Marc Vilanova Date: Tue, 3 Oct 2023 10:08:18 -0700 Subject: [PATCH] Fixes issues with updating case tickets --- src/dispatch/case/flows.py | 15 ++++++++++----- src/dispatch/case/service.py | 2 +- src/dispatch/ticket/flows.py | 14 +++++++++++--- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/dispatch/case/flows.py b/src/dispatch/case/flows.py index 6c06cb88113d..0aa1ed6b0176 100644 --- a/src/dispatch/case/flows.py +++ b/src/dispatch/case/flows.py @@ -186,6 +186,7 @@ def case_new_create_flow( # we create the ticket ticket_flows.create_case_ticket(case=case, db_session=db_session) + # we resolve participants individual_participants, team_participants = get_case_participants( case=case, db_session=db_session ) @@ -198,6 +199,9 @@ def case_new_create_flow( team_participants=team_participants, conversation_target=conversation_target, ) + else: + # we still want to update the ticket, but not twice if resources are created + ticket_flows.update_case_ticket(case=case, db_session=db_session) if case.case_priority.page_assignee: if not service_id: @@ -341,8 +345,9 @@ def case_update_flow( db_session=db_session, ) - # we send the case updated notification - update_conversation(case, db_session) + if case.conversation: + # we send the case updated notification + update_conversation(case, db_session) def case_delete_flow(case: Case, db_session: SessionLocal): @@ -654,14 +659,14 @@ def case_create_resources_flow( db_session=db_session, ) - # we update the ticket - ticket_flows.update_case_ticket(case=case, db_session=db_session) - # we update the case document document_flows.update_document( document=case.case_document, project_id=case.project.id, db_session=db_session ) + # we update the ticket + ticket_flows.update_case_ticket(case=case, db_session=db_session) + try: # we create the conversation and add participants to the thread conversation_flows.create_case_conversation(case, conversation_target, db_session) diff --git a/src/dispatch/case/service.py b/src/dispatch/case/service.py index 70499d0b5acc..e46c16da28f5 100644 --- a/src/dispatch/case/service.py +++ b/src/dispatch/case/service.py @@ -318,7 +318,7 @@ def update(*, db_session, case: Case, case_in: CaseUpdate, current_user: Dispatc db_session=db_session, source="Dispatch Core App", description=( - f"Case status changed to {case_in.status.lower()} " f"by {current_user.email}" + f"Case status changed to {case_in.status.lower()} by {current_user.email}" ), dispatch_user_id=current_user.id, case_id=case.id, diff --git a/src/dispatch/ticket/flows.py b/src/dispatch/ticket/flows.py index c17d22836a81..94a96313d489 100644 --- a/src/dispatch/ticket/flows.py +++ b/src/dispatch/ticket/flows.py @@ -196,7 +196,7 @@ def update_case_ticket( case: Case, db_session: SessionLocal, ): - """Updates an case ticket.""" + """Updates a case ticket.""" plugin = plugin_service.get_active_instance( db_session=db_session, project_id=case.project.id, plugin_type="ticket" ) @@ -215,6 +215,14 @@ def update_case_ticket( case_type_in=case.case_type, ).get_meta(plugin.plugin.slug) + case_document_weblink = "" + if case.case_document: + case_document_weblink = resolve_attr(case, "case_document.weblink") + + case_storage_weblink = "" + if case.storage: + case_storage_weblink = resolve_attr(case, "storage.weblink") + # we update the external case ticket try: plugin.instance.update_case_ticket( @@ -227,8 +235,8 @@ def update_case_ticket( case.case_priority.name, case.status.lower(), case.assignee.individual.email, - resolve_attr(case, "case_document.weblink"), - resolve_attr(case, "storage.weblink"), + case_document_weblink, + case_storage_weblink, case_type_plugin_metadata=case_type_plugin_metadata, ) except Exception as e: