Skip to content

Commit

Permalink
Merge branch 'master' into bugfix/datewindow-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kevgliss authored Nov 29, 2023
2 parents c1e97d4 + c8d7dce commit a0306c7
Show file tree
Hide file tree
Showing 41 changed files with 4,389 additions and 246 deletions.
4 changes: 2 additions & 2 deletions src/dispatch/case/flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
log = logging.getLogger(__name__)


def get_case_participants(case: Case, db_session: SessionLocal):
def get_case_participants_flow(case: Case, db_session: SessionLocal):
"""Get additional case participants based on priority, type and description."""
individual_contacts = []
team_contacts = []
Expand Down Expand Up @@ -187,7 +187,7 @@ def case_new_create_flow(
ticket_flows.create_case_ticket(case=case, db_session=db_session)

# we resolve participants
individual_participants, team_participants = get_case_participants(
individual_participants, team_participants = get_case_participants_flow(
case=case, db_session=db_session
)

Expand Down
24 changes: 24 additions & 0 deletions src/dispatch/case/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from datetime import datetime, timedelta

from pydantic.error_wrappers import ErrorWrapper, ValidationError
from sqlalchemy.orm import Session, joinedload
from typing import List, Optional

from dispatch.auth.models import DispatchUser
Expand All @@ -12,6 +13,7 @@
from dispatch.event import service as event_service
from dispatch.exceptions import NotFoundError
from dispatch.incident import service as incident_service
from dispatch.participant.models import Participant
from dispatch.participant import flows as participant_flows
from dispatch.participant_role.models import ParticipantRoleType
from dispatch.project import service as project_service
Expand Down Expand Up @@ -367,3 +369,25 @@ def delete(*, db_session, case_id: int):
"""Deletes an existing case."""
db_session.query(Case).filter(Case.id == case_id).delete()
db_session.commit()


def get_participants(
*, db_session: Session, case_id: int, minimal: bool = False
) -> list[Participant] | None:
"""Returns a list of participants based on the given case id."""
if minimal:
case = (
db_session.query(Case)
.join(Case.participants) # Use join for minimal
.filter(Case.id == case_id)
.first()
)
else:
case = (
db_session.query(Case)
.options(joinedload(Case.participants)) # Use joinedload for full objects
.filter(Case.id == case_id)
.first()
)

return case.participants if case else None
41 changes: 37 additions & 4 deletions src/dispatch/case/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from dispatch.models import OrganizationSlug, PrimaryKey
from dispatch.incident.models import IncidentCreate, IncidentRead
from dispatch.incident import service as incident_service
from dispatch.participant.models import ParticipantUpdate
from dispatch.participant.models import ParticipantUpdate, ParticipantRead, ParticipantReadMinimal
from dispatch.individual.models import IndividualContactRead

from .flows import (
Expand All @@ -35,10 +35,10 @@
case_triage_create_flow,
case_update_flow,
case_create_resources_flow,
get_case_participants,
get_case_participants_flow,
)
from .models import Case, CaseCreate, CasePagination, CaseRead, CaseUpdate, CaseExpandedPagination
from .service import create, delete, get, update
from .service import create, delete, get, update, get_participants


log = logging.getLogger(__name__)
Expand Down Expand Up @@ -75,6 +75,39 @@ def get_case(
return current_case


@router.get(
"/{case_id}/participants/minimal",
response_model=List[ParticipantReadMinimal],
summary="Retrieves a minimal list of case participants.",
dependencies=[Depends(PermissionsDependency([CaseViewPermission]))],
)
def get_case_participants_minimal(
case_id: PrimaryKey,
db_session: DbSession,
):
"""Retrieves the details of a single case."""
return get_participants(case_id=case_id, db_session=db_session)


@router.get(
"/{case_id}/participants",
summary="Retrieves a list of case participants.",
dependencies=[Depends(PermissionsDependency([CaseViewPermission]))],
)
def get_case_participants(
case_id: PrimaryKey,
db_session: DbSession,
minimal: bool = Query(default=False),
):
"""Retrieves the details of a single case."""
participants = get_participants(case_id=case_id, db_session=db_session, minimal=minimal)

if minimal:
return [ParticipantReadMinimal.from_orm(p) for p in participants]
else:
return [ParticipantRead.from_orm(p) for p in participants]


@router.get("", summary="Retrieves a list of cases.")
def get_cases(
common: CommonParameters,
Expand Down Expand Up @@ -159,7 +192,7 @@ def create_case_resources(
background_tasks: BackgroundTasks,
):
"""Creates resources for an existing case."""
individual_participants, team_participants = get_case_participants(
individual_participants, team_participants = get_case_participants_flow(
case=current_case, db_session=db_session
)
background_tasks.add_task(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""Removes search vector from signal instance model
Revision ID: bdaeabba3e53
Revises: f2605bfc1f59
Create Date: 2023-11-29 12:59:45.408085
"""
from alembic import op

# revision identifiers, used by Alembic.
revision = "bdaeabba3e53"
down_revision = "f2605bfc1f59"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(
"signal_instance_search_vector_idx", table_name="signal_instance", postgresql_using="gin"
)
op.drop_column("signal_instance", "search_vector")
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
pass
4 changes: 2 additions & 2 deletions src/dispatch/plugins/dispatch_slack/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ def entity_select(
):
"""Creates an entity select."""
entity_options = [
{"text": entity.entity_type.name[:75], "value": entity.id}
{"text": entity.value[:75], "value": entity.id}
for entity in entity_service.get_all_desc_by_signal(
db_session=db_session, signal_id=signal_id
)
Expand Down Expand Up @@ -664,7 +664,7 @@ def signal_definition_select(
signals: list[Signal],
action_id: str = DefaultActionIds.signal_definition_select,
block_id: str = DefaultBlockIds.signal_definition_select,
label: str = "Signal Defintions",
label: str = "Signal Definitions",
initial_option: Participant = None,
**kwargs,
):
Expand Down
4 changes: 3 additions & 1 deletion src/dispatch/static/dispatch/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
root: true,
plugins: ["eslint-plugin-local-rules"],
plugins: ["eslint-plugin-local-rules", "@typescript-eslint"],
extends: [
"eslint:recommended",
"plugin:prettier/recommended",
Expand All @@ -9,9 +9,11 @@ module.exports = {
],
parserOptions: {
ecmaVersion: 2020,
parser: "@typescript-eslint/parser",
},
env: {
browser: true,
es2021: true,
node: true,
},
overrides: [
Expand Down
Loading

0 comments on commit a0306c7

Please sign in to comment.