Skip to content

Commit

Permalink
Merge branch 'master' into bugfix/details-tab-selects
Browse files Browse the repository at this point in the history
  • Loading branch information
whitdog47 authored Oct 23, 2024
2 parents 14375e4 + 0ddfb61 commit efe0670
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 38 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ default_language_version:
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# ruff version.
rev: v0.6.4
rev: v0.7.0
hooks:
# Run the linter.
#
Expand All @@ -28,7 +28,7 @@ repos:

# Typos
- repo: https://github.com/crate-ci/typos
rev: v1.24.5
rev: v1.26.1
hooks:
- id: typos
exclude: ^(data/dispatch-sample-data.dump|src/dispatch/static/dispatch/src/|src/dispatch/database/revisions/)
Expand Down
23 changes: 11 additions & 12 deletions src/dispatch/case/flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,34 @@
from dispatch.database.core import SessionLocal
from dispatch.decorators import background_task
from dispatch.document import flows as document_flows
from dispatch.enums import DocumentResourceTypes, Visibility, EventType
from dispatch.enums import DocumentResourceTypes, EventType, Visibility
from dispatch.event import service as event_service
from dispatch.group import flows as group_flows
from dispatch.group.enums import GroupAction, GroupType
from dispatch.incident import flows as incident_flows
from dispatch.incident import service as incident_service
from dispatch.incident.enums import IncidentStatus
from dispatch.incident.messaging import send_participant_announcement_message
from dispatch.incident.models import IncidentCreate, Incident
from dispatch.incident.type.models import IncidentType
from dispatch.incident.models import Incident, IncidentCreate
from dispatch.incident.priority.models import IncidentPriority
from dispatch.incident.type.models import IncidentType
from dispatch.individual.models import IndividualContactRead
from dispatch.models import OrganizationSlug, PrimaryKey
from dispatch.participant import flows as participant_flows
from dispatch.participant import service as participant_service
from dispatch.participant.models import ParticipantUpdate
from dispatch.participant_role import flows as role_flow
from dispatch.participant_role.models import ParticipantRoleType, ParticipantRole
from dispatch.participant_role.models import ParticipantRole, ParticipantRoleType
from dispatch.plugin import service as plugin_service
from dispatch.storage import flows as storage_flows
from dispatch.storage.enums import StorageAction
from dispatch.ticket import flows as ticket_flows

from .messaging import (
send_case_created_notifications,
send_case_update_notifications,
send_case_rating_feedback_message,
send_case_update_notifications,
)

from .models import Case, CaseStatus
from .service import get

Expand Down Expand Up @@ -337,17 +336,17 @@ def case_update_flow(
# we get the case
case = get(db_session=db_session, case_id=case_id)

if reporter_email:
# we run the case assign role flow for the reporter
if reporter_email and case and reporter_email != case.reporter.email:
# we run the case assign role flow for the reporter if it changed
case_assign_role_flow(
case_id=case.id,
participant_email=reporter_email,
participant_role=ParticipantRoleType.reporter,
db_session=db_session,
)

if assignee_email:
# we run the case assign role flow for the assignee
if assignee_email and case and assignee_email != case.assignee.email:
# we run the case assign role flow for the assignee if it changed
case_assign_role_flow(
case_id=case.id,
participant_email=assignee_email,
Expand Down Expand Up @@ -375,15 +374,15 @@ def case_update_flow(

if case.tactical_group:
# we update the tactical group
if reporter_email:
if reporter_email and reporter_email != case.reporter.email:
group_flows.update_group(
subject=case,
group=case.tactical_group,
group_action=GroupAction.add_member,
group_member=reporter_email,
db_session=db_session,
)
if assignee_email:
if assignee_email and assignee_email != case.assignee.email:
group_flows.update_group(
subject=case,
group=case.tactical_group,
Expand Down
40 changes: 16 additions & 24 deletions src/dispatch/plugins/dispatch_slack/case/interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -1660,49 +1660,41 @@ def handle_resolve_submission_event(
user: DispatchUser,
):
ack()
# we get the current or previous case
case = case_service.get(db_session=db_session, case_id=context["subject"].id)
previous_case = CaseRead.from_orm(case)
# we get the current case and store it as previous case
current_case = case_service.get(db_session=db_session, case_id=context["subject"].id)
previous_case = CaseRead.from_orm(current_case)

# we run the case status transition flow
case_flows.case_status_transition_flow_dispatcher(
case=case,
current_status=CaseStatus.closed,
db_session=db_session,
previous_status=case.status,
organization_slug=context["subject"].organization_slug,
)

# we update the case with the new resolution and status
# we update the case with the new resolution, resolution reason and status
case_in = CaseUpdate(
title=case.title,
title=current_case.title,
resolution_reason=form_data[DefaultBlockIds.case_resolution_reason_select]["value"],
resolution=form_data[DefaultBlockIds.resolution_input],
visibility=case.visibility,
visibility=current_case.visibility,
status=CaseStatus.closed,
)
case = case_service.update(
updated_case = case_service.update(
db_session=db_session,
case=case,
case=current_case,
case_in=case_in,
current_user=user,
)

# we run the case update flow
case_flows.case_update_flow(
case_id=case.id,
case_id=updated_case.id,
previous_case=previous_case,
db_session=db_session,
reporter_email=case.reporter.individual.email if case.reporter else None,
assignee_email=case.assignee.individual.email if case.assignee else None,
reporter_email=updated_case.reporter.individual.email if updated_case.reporter else None,
assignee_email=updated_case.assignee.individual.email if updated_case.assignee else None,
organization_slug=context["subject"].organization_slug,
)

# We update the case message with the new resolution and status
blocks = create_case_message(case=case, channel_id=context["subject"].channel_id)
# we update the case notification with the resolution, resolution reason and status
blocks = create_case_message(case=updated_case, channel_id=context["subject"].channel_id)
client.chat_update(
blocks=blocks,
ts=case.conversation.thread_id,
channel=case.conversation.channel_id,
ts=updated_case.conversation.thread_id,
channel=updated_case.conversation.channel_id,
)


Expand Down

0 comments on commit efe0670

Please sign in to comment.