Rewrite Notification subsystem
[pharos-tools.git] / dashboard / src / notifier / views.py
1 ##############################################################################
2 # Copyright (c) 2018 Sawyer Bergeron and others.
3 #
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9
10 from notifier.models import Notification
11 from django.shortcuts import render
12
13
14 def InboxView(request):
15     if request.user.is_authenticated:
16         user = request.user
17     else:
18         return render(request, "dashboard/login.html", {'title': 'Authentication Required'})
19
20     return render(request, "notifier/inbox.html", {'notifications': Notification.objects.filter(recipient=user.userprofile)})
21
22
23 def NotificationView(request, notification_id):
24     if request.user.is_authenticated:
25         user = request.user
26     else:
27         return render(request, "dashboard/login.html", {'title': 'Authentication Required'})
28
29     notification = Notification.objects.get(id=notification_id)
30     if user not in notification.recipients:
31         return render(request, "dashboard/login.html", {'title': 'Access Denied'})
32
33     return render(request, "notifier/notification.html", {'notification': notification})