Remove edit logs for rating flags (#21389)
This commit is contained in:
Родитель
42f26f29dc
Коммит
df13ba9df7
|
@ -160,6 +160,9 @@ class RatingAdmin(AMOModelAdmin):
|
|||
def has_add_permission(self, request):
|
||||
return False
|
||||
|
||||
def has_change_permission(self, request, obj=None):
|
||||
return False
|
||||
|
||||
def truncated_body(self, obj):
|
||||
return truncate_text(obj.body, 140)[0] if obj.body else ''
|
||||
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
# Generated by Django 4.2.6 on 2023-11-06 15:33
|
||||
|
||||
from django.db import migrations
|
||||
from olympia import amo
|
||||
from olympia.activity.models import ActivityLog
|
||||
from django.db.models import F
|
||||
|
||||
def remove_flagged_rating_edit_log_activity(apps, schema_editor):
|
||||
ActivityLog.objects.filter(action=amo.LOG.EDIT_RATING.id).exclude(ratinglog__rating__user=F('user')).delete()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
("ratings", "0009_alter_deniedratingword_word"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(remove_flagged_rating_edit_log_activity),
|
||||
]
|
|
@ -352,5 +352,5 @@ class RatingFlagSerializer(AMOModelSerializer):
|
|||
|
||||
def save(self, **kwargs):
|
||||
instance = super().save(**kwargs)
|
||||
instance.rating.update(editorreview=True)
|
||||
instance.rating.update(editorreview=True, _signal=False)
|
||||
return instance
|
||||
|
|
|
@ -438,6 +438,16 @@ class TestRatingAdmin(TestCase):
|
|||
assert Rating.objects.count() == 0
|
||||
assert Rating.unfiltered.count() == 1
|
||||
|
||||
def test_can_not_change_detail(self):
|
||||
user = user_factory(email='someone@mozilla.com')
|
||||
self.grant_permission(user, 'Admin:Advanced')
|
||||
self.grant_permission(user, 'Ratings:Moderate')
|
||||
self.client.force_login(user)
|
||||
|
||||
response = self.client.get(self.detail_url, follow=True)
|
||||
assert response.status_code == 200
|
||||
assert b'Save' not in response.content
|
||||
|
||||
def test_detail(self):
|
||||
user = UserProfile.objects.get(pk=999)
|
||||
self.grant_permission(user, 'Admin:Advanced')
|
||||
|
|
|
@ -2772,6 +2772,15 @@ class TestRatingViewSetFlag(TestCase):
|
|||
assert data['flag'] == ['This field is required.']
|
||||
assert self.rating.reload().editorreview is False
|
||||
|
||||
def test_flag_logged_in_no_edit_log(self):
|
||||
ActivityLog.objects.all().delete()
|
||||
self.user = user_factory()
|
||||
self.client.login_api(self.user)
|
||||
response = self.client.post(self.url, data={'flag': 'review_flag_reason_spam'})
|
||||
assert response.status_code == 202
|
||||
assert self.rating.reload().editorreview is True
|
||||
assert not ActivityLog.objects.filter(action=amo.LOG.EDIT_RATING.id).exists()
|
||||
|
||||
def test_flag_logged_in(self):
|
||||
self.user = user_factory()
|
||||
self.client.login_api(self.user)
|
||||
|
|
Загрузка…
Ссылка в новой задаче