diff --git a/src/dispatch/case/models.py b/src/dispatch/case/models.py index f227d8f6430d..0b709c51e9ec 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, @@ -268,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") @@ -278,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 @@ -309,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 @@ -338,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 4094ee820550..5ed67f2e5bf1 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 @@ -301,7 +301,9 @@ class IncidentCreate(IncidentBase): tags: Optional[List[TagRead]] = [] -IncidentReadMinimal = ForwardRef("IncidentReadMinimal") +class IncidentReadBasic(DispatchBase): + id: PrimaryKey + name: Optional[NameStr] class IncidentReadMinimal(IncidentBase): @@ -310,7 +312,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 @@ -332,15 +334,12 @@ class IncidentReadMinimal(IncidentBase): total_cost: Optional[float] -IncidentReadMinimal.update_forward_refs() - - class IncidentUpdate(IncidentBase): cases: Optional[List[CaseRead]] = [] 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 @@ -380,7 +379,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]