Ejemplo n.º 1
0
def forward_incident(request):
    try:
        with transaction.atomic():
            incident = Incident.objects.get(id=request.POST['id'])
            user = User.objects.get(id=request.POST['user_id'])
            ScheduledNotification.remove_all_for_incident(incident)
            NotificationHelper.notify_user_about_incident(incident, user)
            event_log_message = "%s  changed assignee of incident :  %s  to %s" % (
                request.user.username, incident.incident_key, user.username)
            event_log = EventLog()
            event_log.user = request.user
            event_log.action = "forward"
            event_log.incident_key = incident
            event_log.service_key = incident.service_key
            event_log.data = event_log_message
            event_log.occurred_at = timezone.now()
            event_log.save()

    except Incident.DoesNotExist:
        messages.error(request, 'Incident not found')
        return HttpResponseRedirect(request.POST['url'])
    except User.DoesNotExist:
        messages.error(request, 'Incident not found')
        return HttpResponseRedirect(request.POST['url'])
    except ValidationError as e:
        messages.error(request, e.messages)
    return HttpResponseRedirect(request.POST['url'])
Ejemplo n.º 2
0
def testnotification(request):
    if not request.user.is_staff and int(request.user.id) != int(
            request.POST['id']):
        raise PermissionDenied("User " + str(request.user.id) + " isn't staff")
    user = User.objects.get(id=request.POST['id'])
    NotificationHelper.notify_user_about_incident(
        None, user, 1, "This is a notification test message, just ignore it")
    return HttpResponseRedirect(reverse('openduty.users.list'))
Ejemplo n.º 3
0
def forward_incident(request):
    url = reverse('IncidentsListView')
    request_url = request.POST.get('url', url)
    try:
        incident = Incident.objects.get(id=request.POST.get('id'))
        user = User.objects.get(id=request.POST.get('user_id'))
        ScheduledNotification.remove_all_for_incident(incident)
        NotificationHelper.notify_user_about_incident(incident, user)
        event_log_message = f"{request.user.username} changed assignee of " \
            f"incident : {incident.incident_key} to {user.username}"
        EventLog.objects.create(user=request.user,
                                action="forward",
                                incident_key=incident,
                                service_key=incident.service_key,
                                data=event_log_message,
                                occurred_at=timezone.now())
    except Incident.DoesNotExist:
        messages.error(request, 'Incident not found')
        return HttpResponseRedirect(request_url)
    except User.DoesNotExist:
        messages.error(request, 'Incident not found')
        return HttpResponseRedirect(request_url)
    return HttpResponseRedirect(request_url)