mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-10 11:59:23 +00:00
pedagogy: send notification to pedagogy admins at comment report
This commit is contained in:
@ -23,7 +23,7 @@
|
||||
{% for widget in form.accepted_reports.subwidgets %}
|
||||
{% set report = queryset.get(id=widget.data.value) %}
|
||||
<tr>
|
||||
<td>{{ report.comment.uv }}</td>
|
||||
<td><a href="{{ url('pedagogy:uv_detail', uv_id=report.comment.uv.id) }}">{{ report.comment.uv }}</a></td>
|
||||
<td>{{ report.comment.comment|markdown }}</td>
|
||||
<td>{{ report.reason|markdown }}</td>
|
||||
<td>{{ widget.tag() }}</td>
|
||||
@ -50,7 +50,7 @@
|
||||
{% for widget in form.denied_reports.subwidgets %}
|
||||
{% set report = queryset.get(id=widget.data.value) %}
|
||||
<tr>
|
||||
<td>{{ report.comment.uv }}</td>
|
||||
<td><a href="{{ url('pedagogy:uv_detail', uv_id=report.comment.uv.id) }}">{{ report.comment.uv }}</a></td>
|
||||
<td>{{ report.comment.comment|markdown }}</td>
|
||||
<td>{{ report.reason|markdown }}</td>
|
||||
<td>{{ widget.tag() }}</td>
|
||||
|
@ -22,11 +22,12 @@
|
||||
#
|
||||
#
|
||||
|
||||
from django.conf import settings
|
||||
from django.test import TestCase
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.core.management import call_command
|
||||
|
||||
from core.models import User
|
||||
from core.models import User, Notification
|
||||
|
||||
from pedagogy.models import UV, UVComment, UVCommentReport
|
||||
|
||||
@ -968,6 +969,7 @@ class UVCommentReportCreateTest(TestCase):
|
||||
call_command("populate")
|
||||
|
||||
self.krophil = User.objects.get(username="krophil")
|
||||
self.tutu = User.objects.get(username="tutu")
|
||||
|
||||
# Prepare a comment
|
||||
comment_kwargs = create_uv_comment_template(self.krophil.id)
|
||||
@ -1011,3 +1013,38 @@ class UVCommentReportCreateTest(TestCase):
|
||||
)
|
||||
self.assertEquals(response.status_code, 403)
|
||||
self.assertFalse(UVCommentReport.objects.all().exists())
|
||||
|
||||
def test_notifications(self):
|
||||
self.assertFalse(
|
||||
self.tutu.notifications.filter(type="PEDAGOGY_MODERATION").exists()
|
||||
)
|
||||
# Create a comment report
|
||||
self.create_report_test("tutu", True)
|
||||
|
||||
# Check that a notification has been created for pedagogy admins
|
||||
self.assertTrue(
|
||||
self.tutu.notifications.filter(type="PEDAGOGY_MODERATION").exists()
|
||||
)
|
||||
|
||||
# Check that only pedagogy admins recieves this notification
|
||||
for notif in Notification.objects.filter(type="PEDAGOGY_MODERATION").all():
|
||||
self.assertTrue(
|
||||
notif.user.is_in_group(settings.SITH_GROUP_PEDAGOGY_ADMIN_ID)
|
||||
)
|
||||
|
||||
# Check that notifications are not duplicated if not viewed
|
||||
self.create_report_test("tutu", True)
|
||||
self.assertEquals(
|
||||
self.tutu.notifications.filter(type="PEDAGOGY_MODERATION").count(), 1
|
||||
)
|
||||
|
||||
# Check that a new notification is created when the old one has been viewed
|
||||
notif = self.tutu.notifications.filter(type="PEDAGOGY_MODERATION").first()
|
||||
notif.viewed = True
|
||||
notif.save()
|
||||
|
||||
self.create_report_test("tutu", True)
|
||||
|
||||
self.assertEquals(
|
||||
self.tutu.notifications.filter(type="PEDAGOGY_MODERATION").count(), 2
|
||||
)
|
||||
|
@ -35,8 +35,9 @@ from django.core import serializers
|
||||
from django.utils import html
|
||||
from django.http import HttpResponse
|
||||
from django.core.exceptions import PermissionDenied, ObjectDoesNotExist
|
||||
from django.core.urlresolvers import reverse_lazy
|
||||
from django.core.urlresolvers import reverse_lazy, reverse
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.conf import settings
|
||||
|
||||
from core.views import (
|
||||
DetailFormView,
|
||||
@ -45,6 +46,7 @@ from core.views import (
|
||||
CanViewMixin,
|
||||
CanEditPropMixin,
|
||||
)
|
||||
from core.models import RealGroup, Notification
|
||||
|
||||
from haystack.query import SearchQuerySet
|
||||
|
||||
@ -226,6 +228,26 @@ class UVCommentReportCreateView(CanCreateMixin, CreateView):
|
||||
kwargs["comment_id"] = self.uv_comment.id
|
||||
return kwargs
|
||||
|
||||
def form_valid(self, form):
|
||||
resp = super(UVCommentReportCreateView, self).form_valid(form)
|
||||
|
||||
# Send a message to moderation admins
|
||||
for user in (
|
||||
RealGroup.objects.filter(id=settings.SITH_GROUP_PEDAGOGY_ADMIN_ID)
|
||||
.first()
|
||||
.users.all()
|
||||
):
|
||||
if not user.notifications.filter(
|
||||
type="PEDAGOGY_MODERATION", viewed=False
|
||||
).exists():
|
||||
Notification(
|
||||
user=user,
|
||||
url=reverse("pedagogy:moderation"),
|
||||
type="PEDAGOGY_MODERATION",
|
||||
).save()
|
||||
|
||||
return resp
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse_lazy(
|
||||
"pedagogy:uv_detail", kwargs={"uv_id": self.uv_comment.uv.id}
|
||||
|
Reference in New Issue
Block a user