Exemple #1
0
def handle_create_comms_channel(ac: ActionContext):
    if CommsChannel.objects.filter(incident=ac.incident).exists():
        return

    comms_channel = CommsChannel.objects.create_comms_channel(ac.incident)

    # Invite the bot to the channel
    invite_user_to_channel(settings.INCIDENT_BOT_ID, comms_channel.channel_id)

    # Un-invite the user who owns the Slack token,
    #   otherwise they'll be added to every incident channel
    slack_token_owner = get_slack_token_owner()
    if ac.incident.reporter != slack_token_owner:
        leave_channel(comms_channel.channel_id)

    # Update the headline post to link to this
    headline_post = HeadlinePost.objects.get(incident=ac.incident)
    headline_post.comms_channel = comms_channel
    headline_post.save()
Exemple #2
0
def update_headline_after_incident_save(sender, instance, **kwargs):
    """
    Reflect changes to incidents in the headline post

    Important: this is called in the synchronous /incident flow so must remain fast (<2 secs)

    """
    try:
        headline_post = HeadlinePost.objects.get(
            incident=instance
        )
        if instance.lead is not None:
            if CommsChannel.objects.filter(incident=instance).exists():
                chan = CommsChannel.objects.get(incident=instance)
                invite_user_to_channel(instance.lead, chan.channel_id)

        headline_post.update_in_slack()

    except HeadlinePost.DoesNotExist:
        headline_post = HeadlinePost.objects.create_headline_post(
            incident=instance
        )