Skip to content

Commit

Permalink
Adds resolved liaison and scribe roles to incident resources (#1726)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvilanova authored Oct 13, 2021
1 parent a53c725 commit 26316fd
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/dispatch/incident/flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -750,10 +750,14 @@ def incident_create_flow(*, organization_slug: str, incident_id: int, db_session
)
log.exception(e)

# we defer this setup until after resources have been created
for user_email in set(
[incident.commander.individual.email, incident.reporter.individual.email]
):
# we defer this setup for all resolved incident roles until after resources have been created
roles = ["reporter", "commander", "liaison", "scribe"]
user_emails = [
resolve_attr(incident, f"{role}.individual.email")
for role in roles
if resolve_attr(incident, role)
]
for user_email in user_emails:
# we add the participant to the tactical group
add_participant_to_tactical_group(user_email, incident, db_session)

Expand Down
46 changes: 46 additions & 0 deletions src/dispatch/incident/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,52 @@ def reporter(cls):
.first()
)

@hybrid_property
def liaison(self):
liaison = None
if self.participants:
most_recent_assumed_at = self.created_at
for p in self.participants:
for pr in p.participant_roles:
if pr.role == ParticipantRoleType.liaison:
if pr.assumed_at > most_recent_assumed_at:
most_recent_assumed_at = pr.assumed_at
liaison = p
return liaison

@liaison.expression
def liaison(cls):
return (
select([Participant])
.where(Participant.incident_id == cls.id)
.where(ParticipantRole.role == ParticipantRoleType.liaison)
.order_by(ParticipantRole.assumed_at.desc())
.first()
)

@hybrid_property
def scribe(self):
scribe = None
if self.participants:
most_recent_assumed_at = self.created_at
for p in self.participants:
for pr in p.participant_roles:
if pr.role == ParticipantRoleType.scribe:
if pr.assumed_at > most_recent_assumed_at:
most_recent_assumed_at = pr.assumed_at
scribe = p
return scribe

@scribe.expression
def scribe(cls):
return (
select([Participant])
.where(Participant.incident_id == cls.id)
.where(ParticipantRole.role == ParticipantRoleType.scribe)
.order_by(ParticipantRole.assumed_at.desc())
.first()
)

@hybrid_property
def tactical_group(self):
if self.groups:
Expand Down
16 changes: 16 additions & 0 deletions src/dispatch/incident/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,22 @@ def create(*, db_session, incident_in: IncidentCreate) -> Incident:
role=ParticipantRoleType.liaison,
)

# add scribe
scribe_email, scribe_service_id = resolve_and_associate_role(
db_session=db_session, incident=incident, role=ParticipantRoleType.scribe
)

if scribe_email:
# we only add the scribe if we are able to resolve its email
# via incident role policies
participant_flows.add_participant(
scribe_email,
incident,
db_session,
service_id=scribe_service_id,
role=ParticipantRoleType.scribe,
)

return incident


Expand Down

0 comments on commit 26316fd

Please sign in to comment.