mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-21 21:53:30 +00:00
pedagogy: send notification to pedagogy admins at comment report
This commit is contained in:
parent
75a2aefd69
commit
6e7d351e8e
40
core/migrations/0030_auto_20190704_1500.py
Normal file
40
core/migrations/0030_auto_20190704_1500.py
Normal file
@ -0,0 +1,40 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.20 on 2019-07-04 13:00
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [("core", "0029_auto_20180426_2013")]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name="notification",
|
||||
name="type",
|
||||
field=models.CharField(
|
||||
choices=[
|
||||
("POSTER_MODERATION", "A new poster needs to be moderated"),
|
||||
("MAILING_MODERATION", "A new mailing list needs to be moderated"),
|
||||
(
|
||||
"PEDAGOGY_MODERATION",
|
||||
"A new pedagogy comment has been signaled for moderation",
|
||||
),
|
||||
("NEWS_MODERATION", "There are %s fresh news to be moderated"),
|
||||
("FILE_MODERATION", "New files to be moderated"),
|
||||
(
|
||||
"SAS_MODERATION",
|
||||
"There are %s pictures to be moderated in the SAS",
|
||||
),
|
||||
("NEW_PICTURES", "You've been identified on some pictures"),
|
||||
("REFILLING", "You just refilled of %s €"),
|
||||
("SELLING", "You just bought %s"),
|
||||
("GENERIC", "You have a notification"),
|
||||
],
|
||||
default="GENERIC",
|
||||
max_length=32,
|
||||
verbose_name="type",
|
||||
),
|
||||
)
|
||||
]
|
@ -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}
|
||||
|
@ -560,6 +560,10 @@ SITH_LAUNDERETTE_PRICES = {"WASHING": 1.0, "DRYING": 0.75}
|
||||
SITH_NOTIFICATIONS = [
|
||||
("POSTER_MODERATION", _("A new poster needs to be moderated")),
|
||||
("MAILING_MODERATION", _("A new mailing list needs to be moderated")),
|
||||
(
|
||||
"PEDAGOGY_MODERATION",
|
||||
_("A new pedagogy comment has been signaled for moderation"),
|
||||
),
|
||||
("NEWS_MODERATION", _("There are %s fresh news to be moderated")),
|
||||
("FILE_MODERATION", _("New files to be moderated")),
|
||||
("SAS_MODERATION", _("There are %s pictures to be moderated in the SAS")),
|
||||
|
Loading…
Reference in New Issue
Block a user