diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a0013f0943b2..37d7474cb362 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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. # @@ -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/) diff --git a/src/dispatch/case/flows.py b/src/dispatch/case/flows.py index 21aa8d517b4f..b0a2b0c9e457 100644 --- a/src/dispatch/case/flows.py +++ b/src/dispatch/case/flows.py @@ -11,7 +11,7 @@ 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 @@ -19,16 +19,16 @@ 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 @@ -36,10 +36,9 @@ 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 @@ -337,8 +336,8 @@ 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, @@ -346,8 +345,8 @@ def case_update_flow( 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, @@ -375,7 +374,7 @@ 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, @@ -383,7 +382,7 @@ def case_update_flow( 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, diff --git a/src/dispatch/plugins/dispatch_slack/case/interactive.py b/src/dispatch/plugins/dispatch_slack/case/interactive.py index 942a5eabf034..08500ff06d88 100644 --- a/src/dispatch/plugins/dispatch_slack/case/interactive.py +++ b/src/dispatch/plugins/dispatch_slack/case/interactive.py @@ -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, )