Skip to content

Commit

Permalink
Record added and removed tags in timeline (#3758)
Browse files Browse the repository at this point in the history
  • Loading branch information
whitdog47 authored Sep 6, 2023
1 parent b1d2599 commit 7ddb4ed
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/dispatch/incident/flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from dispatch.storage import flows as storage_flows
from dispatch.task.enums import TaskStatus
from dispatch.ticket import flows as ticket_flows
from dispatch.tag.flows import check_for_tag_change

from .messaging import (
# get_suggested_document_items,
Expand Down Expand Up @@ -469,6 +470,19 @@ def conversation_topic_dispatcher(
individual_id=individual.id,
)

description, details = check_for_tag_change(
previous_incident_tags=previous_incident.tags, current_incident_tags=incident.tags
)
if description:
event_service.log_incident_event(
db_session=db_session,
source="Incident Participant",
description=f"{individual.name} {description}",
details=details,
incident_id=incident.id,
individual_id=individual.id,
)

if previous_incident.incident_type.name != incident.incident_type.name:
conversation_topic_change = True

Expand Down
30 changes: 30 additions & 0 deletions src/dispatch/tag/flows.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from .models import Tag


def check_for_tag_change(
previous_incident_tags: list[Tag], current_incident_tags: list[Tag]
) -> tuple[str, dict]:
"""Determines if there is any tag change and builds the description string and details if so"""
added_tags = []
removed_tags = []
description = ""
details = {}

for tag in previous_incident_tags:
if tag.id not in [t.id for t in current_incident_tags]:
removed_tags.append(f"{tag.tag_type.name}/{tag.name}")

for tag in current_incident_tags:
if tag.id not in [t.id for t in previous_incident_tags]:
added_tags.append(f"{tag.tag_type.name}/{tag.name}")

if added_tags:
description = f"added {len(added_tags)} tag{'s' if len(added_tags) > 1 else ''}"
details.update({"added tags": ", ".join(added_tags)})
if removed_tags:
description += " and "
if removed_tags:
description += f"removed {len(removed_tags)} tag{'s' if len(removed_tags) > 1 else ''}"
details.update({"removed tags": ", ".join(removed_tags)})

return (description, details)

0 comments on commit 7ddb4ed

Please sign in to comment.