From 32419da6cb8d012928c0c484e6a8a1197eac2f8f Mon Sep 17 00:00:00 2001 From: David Whittaker Date: Fri, 13 Dec 2024 15:35:25 -0800 Subject: [PATCH 1/4] fix(models): reducing information for duplicates or associated incidents and cases --- src/dispatch/case/models.py | 22 ++++++++++++++++------ src/dispatch/feedback/incident/models.py | 4 ++-- src/dispatch/incident/models.py | 11 ++++++++--- src/dispatch/incident/views.py | 1 + src/dispatch/task/models.py | 4 ++-- 5 files changed, 29 insertions(+), 13 deletions(-) diff --git a/src/dispatch/case/models.py b/src/dispatch/case/models.py index 7405bd194282..9b19742b9c4c 100644 --- a/src/dispatch/case/models.py +++ b/src/dispatch/case/models.py @@ -267,6 +267,16 @@ class CaseCreate(CaseBase): tags: Optional[List[TagRead]] = [] +class CaseReadBasic(DispatchBase): + id: PrimaryKey + name: Optional[NameStr] + + +class IncidentReadBasic(DispatchBase): + id: PrimaryKey + name: Optional[NameStr] + + CaseReadMinimal = ForwardRef("CaseReadMinimal") @@ -277,8 +287,8 @@ class CaseReadMinimal(CaseBase): case_priority: CasePriorityRead case_severity: CaseSeverityRead case_type: CaseTypeRead - duplicates: Optional[List[CaseReadMinimal]] = [] - incidents: Optional[List[IncidentReadMinimal]] = [] + duplicates: Optional[List[CaseReadBasic]] = [] + incidents: Optional[List[IncidentReadBasic]] = [] related: Optional[List[CaseReadMinimal]] = [] closed_at: Optional[datetime] = None created_at: Optional[datetime] = None @@ -308,12 +318,12 @@ class CaseRead(CaseBase): conversation: Optional[ConversationRead] = None created_at: Optional[datetime] = None documents: Optional[List[DocumentRead]] = [] - duplicates: Optional[List[CaseReadMinimal]] = [] + duplicates: Optional[List[CaseReadBasic]] = [] escalated_at: Optional[datetime] = None events: Optional[List[EventRead]] = [] genai_analysis: Optional[dict[str, Any]] = {} groups: Optional[List[GroupRead]] = [] - incidents: Optional[List[IncidentReadMinimal]] = [] + incidents: Optional[List[IncidentReadBasic]] = [] name: Optional[NameStr] participants: Optional[List[ParticipantRead]] = [] project: ProjectRead @@ -337,11 +347,11 @@ class CaseUpdate(CaseBase): case_severity: Optional[CaseSeverityBase] case_type: Optional[CaseTypeBase] closed_at: Optional[datetime] = None - duplicates: Optional[List[CaseRead]] = [] + duplicates: Optional[List[CaseReadBasic]] = [] related: Optional[List[CaseRead]] = [] reporter: Optional[ParticipantUpdate] escalated_at: Optional[datetime] = None - incidents: Optional[List[IncidentReadMinimal]] = [] + incidents: Optional[List[IncidentReadBasic]] = [] reported_at: Optional[datetime] = None tags: Optional[List[TagRead]] = [] triage_at: Optional[datetime] = None diff --git a/src/dispatch/feedback/incident/models.py b/src/dispatch/feedback/incident/models.py index a6389093c2f7..e235a6cc6c8f 100644 --- a/src/dispatch/feedback/incident/models.py +++ b/src/dispatch/feedback/incident/models.py @@ -6,7 +6,7 @@ from sqlalchemy_utils import TSVectorType from dispatch.database.core import Base -from dispatch.incident.models import IncidentReadMinimal +from dispatch.incident.models import IncidentReadBasic from dispatch.models import ( DispatchBase, TimeStampMixin, @@ -45,7 +45,7 @@ class FeedbackBase(DispatchBase): created_at: Optional[datetime] rating: FeedbackRating = FeedbackRating.very_satisfied feedback: Optional[str] = Field(None, nullable=True) - incident: Optional[IncidentReadMinimal] + incident: Optional[IncidentReadBasic] case: Optional[CaseReadMinimal] participant: Optional[ParticipantRead] diff --git a/src/dispatch/incident/models.py b/src/dispatch/incident/models.py index d5e727d6ecd6..8898809dc687 100644 --- a/src/dispatch/incident/models.py +++ b/src/dispatch/incident/models.py @@ -300,6 +300,11 @@ class IncidentCreate(IncidentBase): tags: Optional[List[TagRead]] = [] +class IncidentReadBasic(DispatchBase): + id: PrimaryKey + name: Optional[NameStr] + + IncidentReadMinimal = ForwardRef("IncidentReadMinimal") @@ -309,7 +314,7 @@ class IncidentReadMinimal(IncidentBase): commander: Optional[ParticipantReadMinimal] commanders_location: Optional[str] created_at: Optional[datetime] = None - duplicates: Optional[List[IncidentReadMinimal]] = [] + duplicates: Optional[List[IncidentReadBasic]] = [] incident_costs: Optional[List[IncidentCostRead]] = [] incident_document: Optional[DocumentRead] = None incident_priority: IncidentPriorityReadMinimal @@ -339,7 +344,7 @@ class IncidentUpdate(IncidentBase): commander: Optional[ParticipantUpdate] delay_executive_report_reminder: Optional[datetime] = None delay_tactical_report_reminder: Optional[datetime] = None - duplicates: Optional[List[IncidentReadMinimal]] = [] + duplicates: Optional[List[IncidentReadBasic]] = [] incident_costs: Optional[List[IncidentCostUpdate]] = [] incident_priority: IncidentPriorityBase incident_severity: IncidentSeverityBase @@ -379,7 +384,7 @@ class IncidentRead(IncidentBase): delay_executive_report_reminder: Optional[datetime] = None delay_tactical_report_reminder: Optional[datetime] = None documents: Optional[List[DocumentRead]] = [] - duplicates: Optional[List[IncidentReadMinimal]] = [] + duplicates: Optional[List[IncidentReadBasic]] = [] events: Optional[List[EventRead]] = [] incident_costs: Optional[List[IncidentCostRead]] = [] incident_priority: IncidentPriorityRead diff --git a/src/dispatch/incident/views.py b/src/dispatch/incident/views.py index 8bab7317001c..4d201cb6d73e 100644 --- a/src/dispatch/incident/views.py +++ b/src/dispatch/incident/views.py @@ -144,6 +144,7 @@ def create_incident( "/{incident_id}/resources", response_model=IncidentRead, summary="Creates resources for an existing incident.", + dependencies=[Depends(PermissionsDependency([IncidentViewPermission]))], ) def create_incident_resources( organization: OrganizationSlug, diff --git a/src/dispatch/task/models.py b/src/dispatch/task/models.py index 4d92ba7e514c..9cae8c461476 100644 --- a/src/dispatch/task/models.py +++ b/src/dispatch/task/models.py @@ -19,7 +19,7 @@ from sqlalchemy_utils import TSVectorType from dispatch.database.core import Base -from dispatch.incident.models import IncidentReadMinimal +from dispatch.incident.models import IncidentReadBasic from dispatch.models import ResourceBase, ResourceMixin, PrimaryKey, Pagination from dispatch.participant.models import ParticipantRead, ParticipantUpdate from dispatch.project.models import ProjectRead @@ -95,7 +95,7 @@ class TaskBase(ResourceBase): created_at: Optional[datetime] creator: Optional[ParticipantRead] description: Optional[str] = Field(None, nullable=True) - incident: IncidentReadMinimal + incident: IncidentReadBasic owner: Optional[ParticipantRead] priority: Optional[str] = Field(None, nullable=True) resolve_by: Optional[datetime] From 299b00a184118e83117089a3335e77f7d55909f8 Mon Sep 17 00:00:00 2001 From: David Whittaker Date: Fri, 13 Dec 2024 15:53:21 -0800 Subject: [PATCH 2/4] fixing lint errors --- src/dispatch/case/models.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/dispatch/case/models.py b/src/dispatch/case/models.py index 9b19742b9c4c..5f967b625d48 100644 --- a/src/dispatch/case/models.py +++ b/src/dispatch/case/models.py @@ -33,7 +33,6 @@ from dispatch.enums import Visibility from dispatch.event.models import EventRead from dispatch.group.models import Group, GroupRead -from dispatch.incident.models import IncidentReadMinimal from dispatch.messaging.strings import CASE_RESOLUTION_DEFAULT from dispatch.models import ( DispatchBase, From 3975ad95b90ae4c80c99d56ea011aee346173baf Mon Sep 17 00:00:00 2001 From: David Whittaker Date: Fri, 13 Dec 2024 16:35:46 -0800 Subject: [PATCH 3/4] forward reference no longer needed --- src/dispatch/incident/models.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/dispatch/incident/models.py b/src/dispatch/incident/models.py index 8898809dc687..7e5381ca843c 100644 --- a/src/dispatch/incident/models.py +++ b/src/dispatch/incident/models.py @@ -305,9 +305,6 @@ class IncidentReadBasic(DispatchBase): name: Optional[NameStr] -IncidentReadMinimal = ForwardRef("IncidentReadMinimal") - - class IncidentReadMinimal(IncidentBase): id: PrimaryKey closed_at: Optional[datetime] = None @@ -336,9 +333,6 @@ class IncidentReadMinimal(IncidentBase): total_cost: Optional[float] -IncidentReadMinimal.update_forward_refs() - - class IncidentUpdate(IncidentBase): cases: Optional[List[CaseRead]] = [] commander: Optional[ParticipantUpdate] From c5ee86fd1fc8d22a07fde926d79a9b9583a80917 Mon Sep 17 00:00:00 2001 From: David Whittaker Date: Fri, 13 Dec 2024 16:38:46 -0800 Subject: [PATCH 4/4] fixing lint errors --- src/dispatch/incident/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dispatch/incident/models.py b/src/dispatch/incident/models.py index 7e5381ca843c..516ae69dc3e9 100644 --- a/src/dispatch/incident/models.py +++ b/src/dispatch/incident/models.py @@ -1,6 +1,6 @@ from collections import Counter, defaultdict from datetime import datetime -from typing import ForwardRef, List, Optional +from typing import List, Optional from pydantic import validator, Field, AnyHttpUrl