store/return lang param for all abuse report types (#21531)

This commit is contained in:
Andrew Williamson 2023-12-04 10:19:47 +00:00 коммит произвёл GitHub
Родитель 8b46afbecd
Коммит 26aad235d8
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
5 изменённых файлов: 76 добавлений и 5 удалений

Просмотреть файл

@ -244,6 +244,7 @@ so reports can be responded to if necessary.
:<json string|int user: The id or username of the user to report for abuse (required).
:<json string message: The body/content of the abuse report (required).
:<json string|null lang: The language code of the locale used by the client for the application.
:<json string|null reason: The reason for the report. The accepted values are documented in the :ref:`table below <abuse-user-reason-parameter>`.
:<json string|null reporter_name: The provided name of the reporter, if not authenticated.
:<json string|null reporter_email: The provided email of the reporter, if not authenticated.
@ -260,6 +261,7 @@ so reports can be responded to if necessary.
:>json string user.url: The link to the profile page for of the user reported.
:>json string user.username: The username of the user reported.
:>json string message: The body/content of the abuse report.
:>json string|null lang: The language code of the locale used by the client for the application.
.. _abuse-user-reason-parameter:
@ -291,6 +293,7 @@ so reports can be responded to if necessary.
:<json string|int rating: The id of the rating to report for abuse (required).
:<json string message: The body/content of the abuse report (required).
:<json string|null lang: The language code of the locale used by the client for the application.
:<json string|null reason: The reason for the report. The accepted values are documented in the :ref:`table below <abuse-rating-reason-parameter>`.
:<json string|null reporter_name: The provided name of the reporter, if not authenticated.
:<json string|null reporter_email: The provided email of the reporter, if not authenticated.
@ -304,6 +307,7 @@ so reports can be responded to if necessary.
:>json object rating: The user reported for abuse.
:>json int rating.id: The id of the rating reported.
:>json string message: The body/content of the abuse report.
:>json string|null lang: The language code of the locale used by the client for the application.
:>json string|null reason: The reason for the report.
@ -336,6 +340,7 @@ so reports can be responded to if necessary.
:<json string|int collection: The id of the collection to report for abuse (required).
:<json string message: The body/content of the abuse report (required).
:<json string|null lang: The language code of the locale used by the client for the application.
:<json string|null reason: The reason for the report. The accepted values are documented in the :ref:`table below <abuse-collection-reason-parameter>`.
:<json string|null reporter_name: The provided name of the reporter, if not authenticated.
:<json string|null reporter_email: The provided email of the reporter, if not authenticated.
@ -349,6 +354,7 @@ so reports can be responded to if necessary.
:>json object collection: The collection reported for abuse.
:>json int collection.id: The id of the collection reported.
:>json string message: The body/content of the abuse report.
:>json string|null lang: The language code of the locale used by the client for the application.
.. _abuse-collection-reason-parameter:

Просмотреть файл

@ -468,6 +468,7 @@ These are `v5` specific changes - `v4` changes apply also.
* 2023-10-26: added ``location`` to abuse api. https://github.com/mozilla/addons-server/issues/21330
* 2023-11-02: removed ``application`` from categories endpoint, flattened ``categories`` in addon detail/search endpoint. https://github.com/mozilla/addons-server/issues/5989
* 2023-11-09: removed reviewers /enable and /disable endpoints. https://github.com/mozilla/addons-server/issues/21356
* 2023-12-07: added ``lang`` parameter to all /abuse/report/ endpoints. https://github.com/mozilla/addons-server/issues/21529
.. _`#11380`: https://github.com/mozilla/addons-server/issues/11380/
.. _`#11379`: https://github.com/mozilla/addons-server/issues/11379/

Просмотреть файл

@ -43,10 +43,20 @@ class BaseAbuseReportSerializer(AMOModelSerializer):
max_length=10000,
error_messages=error_messages,
)
lang = serializers.CharField(
required=False, source='application_locale', max_length=255
)
class Meta:
model = AbuseReport
fields = ('reason', 'message', 'reporter', 'reporter_name', 'reporter_email')
fields = (
'lang',
'reason',
'message',
'reporter',
'reporter_name',
'reporter_email',
)
def validate(self, data):
if not data.get('reason'):
@ -97,9 +107,6 @@ class AddonAbuseReportSerializer(BaseAbuseReportSerializer):
appversion = serializers.CharField(
required=False, source='application_version', max_length=255
)
lang = serializers.CharField(
required=False, source='application_locale', max_length=255
)
report_entry_point = ReverseChoiceField(
choices=list(AbuseReport.REPORT_ENTRY_POINTS.api_choices),
required=False,
@ -148,7 +155,6 @@ class AddonAbuseReportSerializer(BaseAbuseReportSerializer):
'appversion',
'client_id',
'install_date',
'lang',
'operating_system',
'operating_system_version',
'report_entry_point',

Просмотреть файл

@ -268,6 +268,7 @@ class TestUserAbuseReportSerializer(TestCase):
'reporter_name': None,
'user': serialized_user,
'message': 'bad stuff',
'lang': None,
'reason': None,
}
@ -303,6 +304,7 @@ class TestRatingAbuseReportSerializer(TestCase):
},
'reason': 'illegal',
'message': 'bad stuff',
'lang': None,
}
@ -335,4 +337,5 @@ class TestCollectionAbuseReportSerializer(TestCase):
},
'reason': 'feedback_spam',
'message': 'this is some spammy stûff',
'lang': None,
}

Просмотреть файл

@ -765,6 +765,23 @@ class UserAbuseViewSetTestBase:
self._setup_reportable_reason(None, 'Some message since no reason is provided')
task_mock.assert_not_called()
def test_lang(self):
user = user_factory()
response = self.client.post(
self.url,
data={
'user': str(user.id),
'message': 'abuse!',
'lang': 'Lô-käl',
},
REMOTE_ADDR='123.45.67.89',
)
assert response.status_code == 201
report = AbuseReport.objects.get(user_id=user.id)
self.check_report(report, f'Abuse Report for User {user.pk}')
assert report.application_locale == 'Lô-käl'
class TestUserAbuseViewSetLoggedOut(UserAbuseViewSetTestBase, TestCase):
def check_reporter(self, report):
@ -1214,6 +1231,26 @@ class RatingAbuseViewSetTestBase:
self._setup_reportable_reason('hateful_violent_deceptive')
task_mock.assert_not_called()
def test_lang(self):
target_rating = Rating.objects.create(
addon=addon_factory(), user=user_factory(), body='Booh', rating=1
)
response = self.client.post(
self.url,
data={
'rating': str(target_rating.pk),
'message': 'abuse!',
'reason': 'illegal',
'lang': 'Lô-käl',
},
REMOTE_ADDR='123.45.67.89',
)
assert response.status_code == 201
report = AbuseReport.objects.get(rating=target_rating)
self.check_report(report, f'Abuse Report for Rating {target_rating.pk}')
assert report.application_locale == 'Lô-käl'
class TestRatingAbuseViewSetLoggedOut(RatingAbuseViewSetTestBase, TestCase):
def check_reporter(self, report):
@ -1446,6 +1483,24 @@ class CollectionAbuseViewSetTestBase:
self._setup_reportable_reason('hateful_violent_deceptive')
task_mock.assert_not_called()
def test_lang(self):
target_collection = collection_factory()
response = self.client.post(
self.url,
data={
'collection': str(target_collection.pk),
'message': 'abusé!',
'reason': 'hateful_violent_deceptive',
'lang': 'Lô-käl',
},
REMOTE_ADDR='123.45.67.89',
)
assert response.status_code == 201
report = AbuseReport.objects.get(collection=target_collection)
self.check_report(report, f'Abuse Report for Collection {target_collection.pk}')
assert report.application_locale == 'Lô-käl'
class TestCollectionAbuseViewSetLoggedOut(CollectionAbuseViewSetTestBase, TestCase):
def check_reporter(self, report):