Skip to content

Commit

Permalink
Runs tasks common between case status transition flows (#2426)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvilanova authored Aug 17, 2022
1 parent d5027cc commit 5397631
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[flake8]
ignore = E203
ignore = E203, C901
max-line-length = 100
exclude =
max-complexity = 10
33 changes: 21 additions & 12 deletions src/dispatch/case/flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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."""
Expand All @@ -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."""
Expand All @@ -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,
Expand Down Expand Up @@ -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,
)

0 comments on commit 5397631

Please sign in to comment.