diff --git a/src/olympia/ratings/admin.py b/src/olympia/ratings/admin.py index eb10cad82b..de918c24aa 100644 --- a/src/olympia/ratings/admin.py +++ b/src/olympia/ratings/admin.py @@ -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 '' diff --git a/src/olympia/ratings/migrations/0010_auto_20231106_1533.py b/src/olympia/ratings/migrations/0010_auto_20231106_1533.py new file mode 100644 index 0000000000..c36f70e5a8 --- /dev/null +++ b/src/olympia/ratings/migrations/0010_auto_20231106_1533.py @@ -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), + ] diff --git a/src/olympia/ratings/serializers.py b/src/olympia/ratings/serializers.py index 71c448c432..b946697e0e 100644 --- a/src/olympia/ratings/serializers.py +++ b/src/olympia/ratings/serializers.py @@ -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 diff --git a/src/olympia/ratings/tests/test_admin.py b/src/olympia/ratings/tests/test_admin.py index 827774c4c8..7b2ae24ddc 100644 --- a/src/olympia/ratings/tests/test_admin.py +++ b/src/olympia/ratings/tests/test_admin.py @@ -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') diff --git a/src/olympia/ratings/tests/test_views.py b/src/olympia/ratings/tests/test_views.py index b9a855d968..16bd388fb3 100644 --- a/src/olympia/ratings/tests/test_views.py +++ b/src/olympia/ratings/tests/test_views.py @@ -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)