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 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 constants.base import ABUSE_TYPE_RATING
|
||||
from notifications.models import Notification
|
||||
from ratings.models import Rating
|
||||
|
||||
POST_DATA = {
|
||||
'message': 'test message',
|
||||
@ -83,3 +85,23 @@ class ResolveReportTest(TestCase):
|
||||
self.assertEqual(report.processed_by, moderator)
|
||||
new_notification_nr = Notification.objects.filter(recipient=report.reporter).count()
|
||||
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,
|
||||
)
|
||||
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)
|
||||
|
@ -142,11 +142,15 @@ class ReportView(LoginRequiredMixin, UpdateView):
|
||||
|
||||
@transaction.atomic
|
||||
def form_valid(self, form):
|
||||
response = super().form_valid(form)
|
||||
if 'dismiss' in form.data:
|
||||
verb = Verb.DISMISSED_ABUSE_REPORT
|
||||
if 'resolve' in form.data:
|
||||
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'})
|
||||
response = super().form_valid(form)
|
||||
action.send(
|
||||
self.request.user,
|
||||
verb=verb,
|
||||
|
@ -26,9 +26,9 @@
|
||||
v{{ rating.version.version }}
|
||||
</a>
|
||||
</li>
|
||||
{% if not rating.is_listed %}
|
||||
{% if rating.status == rating.STATUSES.REJECTED %}
|
||||
<li>
|
||||
<span class="badge">Awating approval</span>
|
||||
<span class="badge">Rejected</span>
|
||||
</li>
|
||||
{% endif %}
|
||||
<li>
|
||||
|
Loading…
Reference in New Issue
Block a user