Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show related cases in the incident details tab #2546

Merged
merged 4 commits into from
Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/dispatch/case/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from typing import List, Optional

from pydantic import validator
from dispatch.models import NameStr, PrimaryKey
from sqlalchemy import (
Column,
DateTime,
Expand All @@ -29,6 +28,7 @@
from dispatch.incident.models import IncidentRead
from dispatch.messaging.strings import CASE_RESOLUTION_DEFAULT
from dispatch.models import DispatchBase, ProjectMixin, TimeStampMixin
from dispatch.models import NameStr, PrimaryKey
from dispatch.storage.models import StorageRead
from dispatch.tag.models import TagRead
from dispatch.ticket.models import TicketRead
Expand All @@ -45,6 +45,15 @@
PrimaryKeyConstraint("case_id", "tag_id"),
)

# Assoc table for cases and incidents
assoc_cases_incidents = Table(
"assoc_case_incidents",
Base.metadata,
Column("case_id", Integer, ForeignKey("case.id", ondelete="CASCADE")),
Column("incident_id", Integer, ForeignKey("incident.id", ondelete="CASCADE")),
PrimaryKeyConstraint("case_id", "incident_id"),
)


class Case(Base, TimeStampMixin, ProjectMixin):
__table_args__ = (UniqueConstraint("name", "project_id"),)
Expand Down Expand Up @@ -95,11 +104,12 @@ class Case(Base, TimeStampMixin, ProjectMixin):
groups = relationship(
"Group", backref="case", cascade="all, delete-orphan", foreign_keys=[Group.case_id]
)

incidents = relationship("Incident", secondary=assoc_cases_incidents, backref="cases")

tactical_group_id = Column(Integer, ForeignKey("group.id"))
tactical_group = relationship("Group", foreign_keys=[tactical_group_id])

incidents = relationship("Incident", backref="case")

related_id = Column(Integer, ForeignKey("case.id"))
related = relationship("Case", remote_side=[id], uselist=True, foreign_keys=[related_id])

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""Allows for many-to-many relationships for cases and incidents

Revision ID: df200ca113f7
Revises: e49209df586d
Create Date: 2022-09-30 10:02:46.584358

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "df200ca113f7"
down_revision = "e49209df586d"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table(
"assoc_case_incidents",
sa.Column("case_id", sa.Integer(), nullable=False),
sa.Column("incident_id", sa.Integer(), nullable=False),
sa.ForeignKeyConstraint(["case_id"], ["case.id"], ondelete="CASCADE"),
sa.ForeignKeyConstraint(["incident_id"], ["incident.id"], ondelete="CASCADE"),
sa.PrimaryKeyConstraint("case_id", "incident_id"),
)
op.drop_constraint("incident_case_id_fkey", "incident", type_="foreignkey")
op.drop_column("incident", "case_id")
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column(
"incident", sa.Column("case_id", sa.INTEGER(), autoincrement=False, nullable=True)
)
op.create_foreign_key("incident_case_id_fkey", "incident", "case", ["case_id"], ["id"])
op.drop_table("assoc_case_incidents")
# ### end Alembic commands ###
9 changes: 7 additions & 2 deletions src/dispatch/incident/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,6 @@ def last_executive_report(self):
return sorted(self.executive_reports, key=lambda r: r.created_at)[-1]

# resources
case_id = Column(Integer, ForeignKey("case.id"))

incident_costs = relationship(
"IncidentCost",
backref="incident",
Expand Down Expand Up @@ -216,6 +214,11 @@ class ProjectRead(DispatchBase):
color: Optional[str]


class CaseRead(DispatchBase):
id: PrimaryKey
name: Optional[NameStr]


# Pydantic models...
class IncidentBase(DispatchBase):
title: str
Expand Down Expand Up @@ -261,6 +264,7 @@ class IncidentCreate(IncidentBase):


class IncidentUpdate(IncidentBase):
cases: Optional[List[CaseRead]] = []
commander: Optional[ParticipantUpdate]
duplicates: Optional[List[IncidentReadNested]] = []
incident_costs: Optional[List[IncidentCostUpdate]] = []
Expand Down Expand Up @@ -290,6 +294,7 @@ def find_exclusive(cls, v):

class IncidentReadMinimal(IncidentBase):
id: PrimaryKey
cases: Optional[List[CaseRead]]
closed_at: Optional[datetime] = None
commander: Optional[ParticipantRead]
commanders_location: Optional[str]
Expand Down
9 changes: 8 additions & 1 deletion src/dispatch/incident/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
from typing import List, Optional
from pydantic.error_wrappers import ErrorWrapper, ValidationError

from dispatch.case import service as case_service
from dispatch.database.core import SessionLocal
from dispatch.exceptions import NotFoundError
from dispatch.event import service as event_service
from dispatch.exceptions import NotFoundError
from dispatch.incident_cost import service as incident_cost_service
from dispatch.incident_priority import service as incident_priority_service
from dispatch.incident_role.service import resolve_role
Expand Down Expand Up @@ -269,6 +270,10 @@ def update(*, db_session, incident: Incident, incident_in: IncidentUpdate) -> In
incident_priority_in=incident_in.incident_priority,
)

cases = []
for c in incident_in.cases:
cases.append(case_service.get(db_session=db_session, case_id=c.id))

tags = []
for t in incident_in.tags:
tags.append(tag_service.get_or_create(db_session=db_session, tag_in=t))
Expand All @@ -292,6 +297,7 @@ def update(*, db_session, incident: Incident, incident_in: IncidentUpdate) -> In
update_data = incident_in.dict(
skip_defaults=True,
exclude={
"cases",
"commander",
"duplicates",
"incident_costs",
Expand All @@ -309,6 +315,7 @@ def update(*, db_session, incident: Incident, incident_in: IncidentUpdate) -> In
for field in update_data.keys():
setattr(incident, field, update_data[field])

incident.cases = cases
incident.duplicates = duplicates
incident.incident_costs = incident_costs
incident.incident_priority = incident_priority
Expand Down
169 changes: 0 additions & 169 deletions src/dispatch/static/dispatch/src/case/CaseTypeCombobox.vue

This file was deleted.

8 changes: 4 additions & 4 deletions src/dispatch/static/dispatch/src/case/Table.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
</div>
<v-row no-gutters>
<new-sheet />
<delete-dialog />
<escalate-dialog />
<delete-dialog />
<v-col>
<div class="headline">Cases</div>
</v-col>
Expand Down Expand Up @@ -80,9 +80,6 @@
</v-btn>
</template>
<v-list>
<v-list-item @click="showEscalateDialog(item)">
<v-list-item-title>Escalate</v-list-item-title>
</v-list-item>
mvilanova marked this conversation as resolved.
Show resolved Hide resolved
<v-list-item
:to="{
name: 'CaseTableEdit',
Expand All @@ -91,6 +88,9 @@
>
<v-list-item-title>View / Edit</v-list-item-title>
</v-list-item>
<v-list-item @click="showEscalateDialog(item)">
<v-list-item-title>Escalate</v-list-item-title>
</v-list-item>
<v-list-item @click="showDeleteDialog(item)">
<v-list-item-title>Delete</v-list-item-title>
</v-list-item>
Expand Down
6 changes: 6 additions & 0 deletions src/dispatch/static/dispatch/src/incident/DetailsTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@
<v-flex xs12>
<incident-filter-combobox label="Duplicates" v-model="duplicates" :project="project" />
</v-flex>
<v-flex xs12>
<case-filter-combobox label="Cases" v-model="cases" />
</v-flex>
</v-layout>
</v-container>
</template>
Expand All @@ -117,6 +120,7 @@ import { ValidationProvider, extend } from "vee-validate"
import { mapFields } from "vuex-map-fields"
import { required } from "vee-validate/dist/rules"

import CaseFilterCombobox from "@/case/CaseFilterCombobox.vue"
import DateTimePickerMenu from "@/components/DateTimePickerMenu.vue"
import IncidentFilterCombobox from "@/incident/IncidentFilterCombobox.vue"
import IncidentPrioritySelect from "@/incident_priority/IncidentPrioritySelect.vue"
Expand All @@ -134,6 +138,7 @@ export default {
name: "IncidentDetailsTab",

components: {
CaseFilterCombobox,
DateTimePickerMenu,
IncidentFilterCombobox,
IncidentPrioritySelect,
Expand All @@ -153,6 +158,7 @@ export default {

computed: {
...mapFields("incident", [
"selected.cases",
"selected.commander",
"selected.created_at",
"selected.description",
Expand Down
Loading