Beispiel #1
0
def send_subscriber_notifications(activity_id):
    from sentry.incidents.logic import get_incident_subscribers, unsubscribe_from_incident

    try:
        activity = IncidentActivity.objects.select_related(
            "incident", "user", "incident__organization").get(id=activity_id)
    except IncidentActivity.DoesNotExist:
        return

    # Only send notifications for specific activity types.
    if activity.type not in (
            IncidentActivityType.COMMENT.value,
            IncidentActivityType.STATUS_CHANGE.value,
    ):
        return

    # Check that the user still has access to at least one of the projects
    # related to the incident. If not then unsubscribe them.
    projects = list(activity.incident.projects.all())
    for subscriber in get_incident_subscribers(
            activity.incident).select_related("user"):
        user = subscriber.user
        access = from_user(user, activity.incident.organization)
        if not any(project for project in projects
                   if access.has_project_access(project)):
            unsubscribe_from_incident(activity.incident, user)
        elif user != activity.user:
            msg = generate_incident_activity_email(activity, user)
            msg.send_async([user.email])
 def delete(self, request, organization, incident):
     """
     Unsubscribes the authenticated user from the incident.
     ``````````````````````````````````````````````````````
     Unsubscribes the user from the incident. If they are not subscribed then
     no-op.
     :auth: required
     """
     unsubscribe_from_incident(incident, request.user)
     return Response({}, status=200)
Beispiel #3
0
 def unsubscribe(self, instance, user):
     unsubscribe_from_incident(instance, user)