Reject rating when an abuse report gets resolved #223
0
abuse/tests/__init__.py
Normal file
0
abuse/tests/__init__.py
Normal file
@ -2,9 +2,11 @@ from django.test import TestCase
|
|||||||
|
|
||||||
from abuse.models import AbuseReport
|
from abuse.models import AbuseReport
|
||||||
from common.tests.factories.abuse import AbuseReportFactory
|
from common.tests.factories.abuse import AbuseReportFactory
|
||||||
from common.tests.factories.extensions import create_approved_version
|
from common.tests.factories.extensions import RatingFactory, create_approved_version
|
||||||
from common.tests.factories.users import UserFactory, create_moderator
|
from common.tests.factories.users import UserFactory, create_moderator
|
||||||
|
from constants.base import ABUSE_TYPE_RATING
|
||||||
from notifications.models import Notification
|
from notifications.models import Notification
|
||||||
|
from ratings.models import Rating
|
||||||
|
|
||||||
POST_DATA = {
|
POST_DATA = {
|
||||||
'message': 'test message',
|
'message': 'test message',
|
||||||
@ -83,3 +85,26 @@ class ResolveReportTest(TestCase):
|
|||||||
self.assertEqual(report.processed_by, moderator)
|
self.assertEqual(report.processed_by, moderator)
|
||||||
new_notification_nr = Notification.objects.filter(recipient=report.reporter).count()
|
new_notification_nr = Notification.objects.filter(recipient=report.reporter).count()
|
||||||
self.assertEqual(new_notification_nr, notification_nr + 1)
|
self.assertEqual(new_notification_nr, notification_nr + 1)
|
||||||
|
|
||||||
|
def test_rating_is_rejected(self):
|
||||||
|
version = create_approved_version()
|
||||||
|
extension = version.extension
|
||||||
|
some_user = UserFactory()
|
||||||
|
rating = RatingFactory(user=some_user, version=version, status=Rating.STATUSES.APPROVED)
|
||||||
|
report = AbuseReportFactory(
|
||||||
|
extension=extension,
|
||||||
|
status=AbuseReport.STATUSES.UNTRIAGED,
|
||||||
|
rating=rating,
|
||||||
|
type=ABUSE_TYPE_RATING,
|
||||||
|
)
|
||||||
|
notification_nr = Notification.objects.filter(recipient=some_user).count()
|
||||||
|
moderator = create_moderator()
|
||||||
|
self.client.force_login(moderator)
|
||||||
|
response = self.client.post(
|
||||||
|
report.get_absolute_url(), {'moderator_note': 'lalala', 'resolve': ''}
|
||||||
|
)
|
||||||
|
self.assertEqual(response.status_code, 302)
|
||||||
|
rating.refresh_from_db()
|
||||||
|
self.assertEqual(rating.status, Rating.STATUSES.REJECTED)
|
||||||
|
new_notification_nr = Notification.objects.filter(recipient=some_user).count()
|
||||||
|
self.assertEqual(new_notification_nr, notification_nr + 1)
|
||||||
|
@ -142,11 +142,20 @@ class ReportView(LoginRequiredMixin, UpdateView):
|
|||||||
|
|
||||||
@transaction.atomic
|
@transaction.atomic
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
response = super().form_valid(form)
|
|
||||||
if 'dismiss' in form.data:
|
if 'dismiss' in form.data:
|
||||||
verb = Verb.DISMISSED_ABUSE_REPORT
|
verb = Verb.DISMISSED_ABUSE_REPORT
|
||||||
if 'resolve' in form.data:
|
if 'resolve' in form.data:
|
||||||
verb = Verb.RESOLVED_ABUSE_REPORT
|
verb = Verb.RESOLVED_ABUSE_REPORT
|
||||||
|
if form.instance.type == ABUSE_TYPE_RATING:
|
||||||
|
rating = form.instance.rating
|
||||||
|
rating.status = Rating.STATUSES.REJECTED
|
||||||
|
rating.save(update_fields={'status'})
|
||||||
|
action.send(
|
||||||
|
self.request.user,
|
||||||
|
verb=Verb.REJECTED_RATING,
|
||||||
|
target=form.instance.rating,
|
||||||
|
)
|
||||||
|
response = super().form_valid(form)
|
||||||
action.send(
|
action.send(
|
||||||
self.request.user,
|
self.request.user,
|
||||||
verb=verb,
|
verb=verb,
|
||||||
|
@ -7,6 +7,7 @@ class Verb:
|
|||||||
COMMENTED = 'commented'
|
COMMENTED = 'commented'
|
||||||
DISMISSED_ABUSE_REPORT = 'dismissed abuse report'
|
DISMISSED_ABUSE_REPORT = 'dismissed abuse report'
|
||||||
RATED_EXTENSION = 'rated extension'
|
RATED_EXTENSION = 'rated extension'
|
||||||
|
REJECTED_RATING = 'rejected rating'
|
||||||
REPORTED_EXTENSION = 'reported extension'
|
REPORTED_EXTENSION = 'reported extension'
|
||||||
REPORTED_RATING = 'reported rating'
|
REPORTED_RATING = 'reported rating'
|
||||||
REQUESTED_CHANGES = 'requested changes'
|
REQUESTED_CHANGES = 'requested changes'
|
||||||
@ -18,5 +19,6 @@ class Verb:
|
|||||||
class Flag:
|
class Flag:
|
||||||
AUTHOR = 'author'
|
AUTHOR = 'author'
|
||||||
MODERATOR = 'moderator'
|
MODERATOR = 'moderator'
|
||||||
|
RATING_AUTHOR = 'rating_author'
|
||||||
REPORTER = 'reporter'
|
REPORTER = 'reporter'
|
||||||
REVIEWER = 'reviewer'
|
REVIEWER = 'reviewer'
|
||||||
|
@ -8,6 +8,8 @@
|
|||||||
{% blocktrans %}{{ someone }} dismissed your {{ what }}{% endblocktrans %}
|
{% blocktrans %}{{ someone }} dismissed your {{ what }}{% endblocktrans %}
|
||||||
{% elif verb == Verb.RATED_EXTENSION %}
|
{% elif verb == Verb.RATED_EXTENSION %}
|
||||||
{% blocktrans %}{{ someone }} {{ verb }} {{ what }}{% endblocktrans %}
|
{% blocktrans %}{{ someone }} {{ verb }} {{ what }}{% endblocktrans %}
|
||||||
|
{% elif verb == Verb.REJECTED_RATING %}
|
||||||
|
{% blocktrans %}Your rating {{ what }} was rejected because it violates site policy.{% endblocktrans %}
|
||||||
{% elif verb == Verb.REPORTED_EXTENSION %}
|
{% elif verb == Verb.REPORTED_EXTENSION %}
|
||||||
{% blocktrans %}{{ someone }} reported {{ what }}{% endblocktrans %}
|
{% blocktrans %}{{ someone }} reported {{ what }}{% endblocktrans %}
|
||||||
{% elif verb == Verb.REPORTED_RATING %}
|
{% elif verb == Verb.REPORTED_RATING %}
|
||||||
|
@ -8,6 +8,8 @@
|
|||||||
{% blocktrans %}Your {{ what }} was dismissed{% endblocktrans %}
|
{% blocktrans %}Your {{ what }} was dismissed{% endblocktrans %}
|
||||||
{% elif verb == Verb.RATED_EXTENSION %}
|
{% elif verb == Verb.RATED_EXTENSION %}
|
||||||
{% blocktrans %}{{ target_type }} rated: "{{ name }}"{% endblocktrans %}
|
{% blocktrans %}{{ target_type }} rated: "{{ name }}"{% endblocktrans %}
|
||||||
|
{% elif verb == Verb.REJECTED_RATING %}
|
||||||
|
{% blocktrans %}Your rating was rejected{% endblocktrans %}
|
||||||
{% elif verb == Verb.REPORTED_EXTENSION %}
|
{% elif verb == Verb.REPORTED_EXTENSION %}
|
||||||
{% blocktrans %}{{ target_type }} reported: "{{ name }}"{% endblocktrans %}
|
{% blocktrans %}{{ target_type }} reported: "{{ name }}"{% endblocktrans %}
|
||||||
{% elif verb == Verb.REPORTED_RATING %}
|
{% elif verb == Verb.REPORTED_RATING %}
|
||||||
|
@ -15,6 +15,7 @@ VERB2FLAGS = {
|
|||||||
Verb.COMMENTED: [Flag.AUTHOR, Flag.REVIEWER],
|
Verb.COMMENTED: [Flag.AUTHOR, Flag.REVIEWER],
|
||||||
Verb.DISMISSED_ABUSE_REPORT: [Flag.REPORTER],
|
Verb.DISMISSED_ABUSE_REPORT: [Flag.REPORTER],
|
||||||
Verb.RATED_EXTENSION: [Flag.AUTHOR],
|
Verb.RATED_EXTENSION: [Flag.AUTHOR],
|
||||||
|
Verb.REJECTED_RATING: [Flag.RATING_AUTHOR],
|
||||||
Verb.REPORTED_EXTENSION: [Flag.MODERATOR],
|
Verb.REPORTED_EXTENSION: [Flag.MODERATOR],
|
||||||
Verb.REPORTED_RATING: [Flag.MODERATOR],
|
Verb.REPORTED_RATING: [Flag.MODERATOR],
|
||||||
Verb.REQUESTED_CHANGES: [Flag.AUTHOR, Flag.REVIEWER],
|
Verb.REQUESTED_CHANGES: [Flag.AUTHOR, Flag.REVIEWER],
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
from statistics import median
|
from statistics import median
|
||||||
|
|
||||||
from actstream import action
|
from actstream import action
|
||||||
|
from actstream.actions import follow
|
||||||
from django.db.models.signals import post_save, pre_delete
|
from django.db.models.signals import post_save, pre_delete
|
||||||
from django.dispatch import receiver
|
from django.dispatch import receiver
|
||||||
|
|
||||||
from constants.activity import Verb
|
from constants.activity import Flag, Verb
|
||||||
from ratings.models import Rating
|
from ratings.models import Rating
|
||||||
from ratings.utils import compute_rating_sortkey
|
from ratings.utils import compute_rating_sortkey
|
||||||
|
|
||||||
@ -43,6 +44,22 @@ def _create_action_from_rating(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@receiver(post_save, sender=Rating)
|
||||||
|
def _follow_rating_as_author(
|
||||||
|
sender: object,
|
||||||
|
instance: Rating,
|
||||||
|
created: bool,
|
||||||
|
raw: bool,
|
||||||
|
**kwargs: object,
|
||||||
|
) -> None:
|
||||||
|
if raw:
|
||||||
|
return
|
||||||
|
if not created:
|
||||||
|
return
|
||||||
|
|
||||||
|
follow(instance.user, instance, send_action=False, flag=Flag.RATING_AUTHOR)
|
||||||
|
|
||||||
|
|
||||||
@receiver(pre_delete, sender=Rating)
|
@receiver(pre_delete, sender=Rating)
|
||||||
def _log_deletion(sender: object, instance: Rating, **kwargs: object) -> None:
|
def _log_deletion(sender: object, instance: Rating, **kwargs: object) -> None:
|
||||||
instance.record_deletion()
|
instance.record_deletion()
|
||||||
|
@ -26,9 +26,9 @@
|
|||||||
v{{ rating.version.version }}
|
v{{ rating.version.version }}
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
{% if not rating.is_listed %}
|
{% if rating.status == rating.STATUSES.REJECTED %}
|
||||||
<li>
|
<li>
|
||||||
<span class="badge">Awating approval</span>
|
<span class="badge">Rejected</span>
|
||||||
</li>
|
</li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<li>
|
<li>
|
||||||
|
Loading…
Reference in New Issue
Block a user