From 53976318657ab38f2a681d2c3b5a79a9cdb3d631 Mon Sep 17 00:00:00 2001 From: Marc Vilanova <39573146+mvilanova@users.noreply.github.com> Date: Wed, 17 Aug 2022 12:22:51 -0700 Subject: [PATCH] Runs tasks common between case status transition flows (#2426) --- .flake8 | 2 +- src/dispatch/case/flows.py | 33 +++++++++++++++++++++------------ 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/.flake8 b/.flake8 index fbdd8b35ad17..6fa65682c526 100644 --- a/.flake8 +++ b/.flake8 @@ -1,5 +1,5 @@ [flake8] -ignore = E203 +ignore = E203, C901 max-line-length = 100 exclude = max-complexity = 10 diff --git a/src/dispatch/case/flows.py b/src/dispatch/case/flows.py index 17b737946348..a7bd06f80f0f 100644 --- a/src/dispatch/case/flows.py +++ b/src/dispatch/case/flows.py @@ -186,9 +186,23 @@ def case_delete_flow(case: Case, db_session: SessionLocal): storage_flows.delete_storage(storage=case.storage, db_session=db_session) +def case_status_flow_common(case: Case, db_session=None): + """Runs tasks common across case status transition flows.""" + # we update the ticket + ticket_flows.update_case_ticket(case=case, db_session=db_session) + + # we update the timeline + event_service.log_case_event( + db_session=db_session, + source="Dispatch Core App", + description=f"The case status has been changed to {case.status.lower()}", + case_id=case.id, + ) + + def case_new_status_flow(case: Case, db_session=None): """Runs the case new transition flow.""" - pass + case_status_flow_common(case=case, db_session=db_session) def case_triage_status_flow(case: Case, db_session=None): @@ -198,6 +212,8 @@ def case_triage_status_flow(case: Case, db_session=None): db_session.add(case) db_session.commit() + case_status_flow_common(case=case, db_session=db_session) + def case_escalated_status_flow(case: Case, db_session=None): """Runs the case escalated transition flow.""" @@ -206,6 +222,8 @@ def case_escalated_status_flow(case: Case, db_session=None): db_session.add(case) db_session.commit() + case_status_flow_common(case=case, db_session=db_session) + def case_closed_status_flow(case: Case, db_session=None): """Runs the case closed transition flow.""" @@ -214,6 +232,8 @@ def case_closed_status_flow(case: Case, db_session=None): db_session.add(case) db_session.commit() + case_status_flow_common(case=case, db_session=db_session) + def case_status_transition_flow_dispatcher( case: Case, @@ -270,14 +290,3 @@ def case_status_transition_flow_dispatcher( elif previous_status == CaseStatus.escalated: # Escalated -> Closed case_closed_status_flow(case, db_session) - - if previous_status != current_status: - event_service.log_case_event( - db_session=db_session, - source="Dispatch Core App", - description=( - f"The case status has been changed from {previous_status.lower()} ", - f"to {current_status.lower()}", - ), - case_id=case.id, - )