Skip to content

Commit

Permalink
added checks to self_join before creating join buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Laventure authored and milavent committed Jun 21, 2024
1 parent dd427df commit 883d4e2
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 9 deletions.
11 changes: 9 additions & 2 deletions src/dispatch/incident/messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
INCIDENT_TYPE_CHANGE,
INCIDENT_COMPLETED_FORM_MESSAGE,
INCIDENT_TASK_ADD_TO_INCIDENT,
INCIDENT_NAME_WITH_ENGAGEMENT_NO_SELF_JOIN,
MessageType,
generate_welcome_message,
)
Expand Down Expand Up @@ -379,7 +380,10 @@ def send_incident_created_notifications(incident: Incident, db_session: SessionL
notification_template = INCIDENT_NOTIFICATION.copy()

if incident.status != IncidentStatus.closed:
notification_template.insert(0, INCIDENT_NAME_WITH_ENGAGEMENT)
if incident.project.allow_self_join == True:
notification_template.insert(0, INCIDENT_NAME_WITH_ENGAGEMENT)
else:
notification_template.insert(0, INCIDENT_NAME_WITH_ENGAGEMENT_NO_SELF_JOIN)
else:
notification_template.insert(0, INCIDENT_NAME)

Expand Down Expand Up @@ -526,7 +530,10 @@ def send_incident_update_notifications(
# we send a notification to the notification conversations and emails
fyi_notification_template = notification_template.copy()
if incident.status != IncidentStatus.closed:
fyi_notification_template.insert(0, INCIDENT_NAME_WITH_ENGAGEMENT)
if incident.project.allow_self_join == True:
fyi_notification_template.insert(0, INCIDENT_NAME_WITH_ENGAGEMENT)
else:
fyi_notification_template.insert(0, INCIDENT_NAME_WITH_ENGAGEMENT_NO_SELF_JOIN)
else:
fyi_notification_template.insert(0, INCIDENT_NAME)

Expand Down
15 changes: 8 additions & 7 deletions src/dispatch/incident/scheduled.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,14 @@ def incident_report_daily(db_session: SessionLocal, project: Project):
"button_action": f"{ConversationButtonActions.subscribe_user}-{incident.status}-{idx}",
}
)
item["buttons"].append(
{
"button_text": "Join",
"button_value": f"{incident.project.organization.slug}-{incident.id}",
"button_action": f"{ConversationButtonActions.invite_user}-{incident.status}-{idx}",
}
)
if incident.project.allow_self_join == True:
item["buttons"].append(
{
"button_text": "Join",
"button_value": f"{incident.project.organization.slug}-{incident.id}",
"button_action": f"{ConversationButtonActions.invite_user}-{incident.status}-{idx}",
}
)

items_grouped.append(item)
except Exception as e:
Expand Down
25 changes: 25 additions & 0 deletions src/dispatch/messaging/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,31 @@ class MessageType(DispatchEnum):
],
}

INCIDENT_NAME_WITH_ENGAGEMENT_NO_SELF_JOIN = {
"title": "{{name}} Incident Notification",
"title_link": "{{ticket_weblink}}",
"text": INCIDENT_NOTIFICATION_PURPOSES_FYI,
"buttons": [
{
"button_text": "Subscribe",
"button_value": "{{organization_slug}}-{{incident_id}}",
"button_action": ConversationButtonActions.subscribe_user,
},
],
}

INCIDENT_NAME_WITH_ENGAGEMENT_NO_DESCRIPTION_NO_SELF_JOIN = {
"title": "{{name}}",
"title_link": "{{ticket_weblink}}",
"text": "{{ignore}}",
"buttons": [
{
"button_text": "Subscribe",
"button_value": "{{organization_slug}}-{{incident_id}}",
"button_action": ConversationButtonActions.subscribe_user,
},
],
}
INCIDENT_NAME = {
"title": "{{name}} Incident Notification",
"title_link": "{{ticket_weblink}}",
Expand Down

0 comments on commit 883d4e2

Please sign in to comment.