Skip to content

Commit

Permalink
Merge pull request #10786 from diox/abuse-api-parameters-tweaks
Browse files Browse the repository at this point in the history
Tweak abuse reporting API fields to match existing API and PRD updates
  • Loading branch information
diox authored Feb 26, 2019
2 parents 6843f24 + 2bbc009 commit 29d6773
Show file tree
Hide file tree
Showing 9 changed files with 283 additions and 112 deletions.
17 changes: 11 additions & 6 deletions docs/topics/api/abuse.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,25 @@ either listed on https://addons.mozilla.org or not.
Authentication is not required, but is recommended so reports can be responded
to if necessary.

Except for the ``message``, all strings have a maximum length of 255 characters
and should be truncated by the client where necessary.

.. http:post:: /api/v4/abuse/report/addon/
.. _addonabusereport-create-request:

:<json string addon: The id, slug, or guid of the add-on to report for abuse (required).
:<json string message: The body/content of the abuse report (required).
:<json string|null addon_install_entry_point: The add-on install entry point. Accepted values: TBD.
:<json string|null addon_install_method: The add-on install method. Accepted values: TBD.
:<json string|null addon_install_entry_point: The add-on install entry point. Accepted values: ``uninstall`` and ``menu``.
:<json string|null addon_install_method: The add-on install method. Accepted values: ``amwebapi``, ``link``, ``installtrigger``, ``install-from-file``, ``management-webext-api``, ``drag-and-drop`` and ``sideload``.
:<json string|null addon_install_origin: The add-on install origin.
:<json string|null addon_name: The add-on name in the locale used by the client.
:<json string|null addon_signature: The add-on signature state. Accepted values: TBD.
:<json string|null addon_summary: The add-on summary in the locale used by the client.
:<json string|null addon_version: The add-on version string.
:<json string|null application: The application used by the client. Can be either ``firefox`` or ``android``.
:<json string|null application_locale: The locale used by the client for the application.
:<json string|null app: The :ref:`application <addon-detail-application>` used by the client. Can be either ``firefox`` or ``android``.
:<json string|null appversion: The application version used by the client.
:<json string|null lang: The language code of the locale used by the client for the application.
:<json string|null client_id: The client's hashed telemetry ID.
:<json string|null install_date: The add-on install date.
:<json string|null operating_system: The client's operating system.
Expand All @@ -58,8 +62,9 @@ to if necessary.
:>json string|null addon_signature: The add-on signature state.
:>json string|null addon_summary: The add-on summary in the locale used by the client.
:>json string|null addon_version: The add-on version string.
:>json string|null application: The application used by the client.
:>json string|null application_locale: The locale used by the client for the application.
:>json string|null app: The application used by the client.
:>json string|null appversion: The locale used by the client for the application.
:<json string|null lang: The language code of the locale used by the client for the application.
:>json string|null client_id: The client's hashed telemetry ID.
:>json string|null install_date: The add-on install date.
:>json string|null operating_system: The client's operating system.
Expand Down
3 changes: 3 additions & 0 deletions requirements/prod_common.txt
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ django-csp==3.5 \
django-environ==0.4.5 \
--hash=sha256:c57b3c11ec1f319d9474e3e5a79134f40174b17c7cc024bbb2fad84646b120c4 \
--hash=sha256:6c9d87660142608f63ec7d5ce5564c49b603ea8ff25da595fd6098f6dc82afde
django-extended-choices==1.3.2 \
--hash=sha256:22c4d500d6ded58b270c4b314c82b894649011c4205935878875219048b6181d \
--hash=sha256:7d95674d593d4ccf5c6393e83a787d8e55377e3efd88fa0ff5dc29f6f81d9a49
django-extensions==2.1.6 \
--hash=sha256:109004f80b6f45ad1f56addaa59debca91d94aa0dc1cb19678b9364b4fe9b6f4 \
--hash=sha256:307766e5e6c1caffe76c5d99239d8115d14ae3f7cab2cd991fcffd763dad904b
Expand Down
60 changes: 27 additions & 33 deletions src/olympia/abuse/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from olympia.addons.models import Addon
from olympia.amo.models import ModelBase
from olympia.amo.utils import send_mail
from olympia.api.utils import APIChoicesWithNone
from olympia.users.models import UserProfile


Expand All @@ -22,36 +23,29 @@ class AbuseReport(ModelBase):
# Note: those choices don't need to be translated for now, the
# human-readable values are only exposed in the admin. The values will be
# updated once they are finalized in the PRD.
ADDON_SIGNATURE_CHOICES = (
(None, 'None'),
ADDON_SIGNATURES = APIChoicesWithNone()
REASONS = APIChoicesWithNone(
('MALWARE', 1, 'Malware'),
('SPAM_OR_ADVERTISING', 2, 'Spam / Advertising'),
('SEARCH_TAKEOVER', 3, 'Search takeover'),
('NEW_TAB_TAKEOVER', 4, 'New tab takeover'),
('BREAKS_WEBSITES', 5, 'Breaks websites'),
('OFFENSIVE', 6, 'Offensive'),
('DOES_NOT_MATCH_DESCRIPTION', 7, 'Doesn\'t match description'),
('DOES_NOT_WORK', 8, 'Doesn\'t work'),
)
REASON_CHOICES = (
(None, 'None'),
(1, 'Malware'),
(2, 'Spam / Advertising'),
(3, 'Search takeover'),
(4, 'New tab takeover'),
(5, 'Breaks websites'),
(6, 'Offensive'),
(7, 'Doesn\'t match description'),
(8, 'Doesn\'t work'),
ADDON_INSTALL_METHODS = APIChoicesWithNone(
('AMWEBAPI', 1, 'Add-on Manager Web API'),
('LINK', 2, 'Direct link'),
('INSTALLTRIGGER', 3, 'Install Trigger'),
('INSTALL-FROM-FILE', 4, 'From File'),
('MANAGEMENT-WEBEXT-API', 5, 'Webext management API'),
('DRAG-AND-DROP', 6, 'Drag & Drop'),
('SIDELOAD', 7, 'Sideload'),
)
REASON_CHOICES_API = {
None: None,
1: 'malware',
2: 'spam_or_advertising',
3: 'search_takeover',
4: 'new_tab_takeover',
5: 'breaks_websites',
6: 'offensive',
7: 'does_not_match_description',
8: 'does_not_work',
}
ADDON_INSTALL_METHOD_CHOICES = (
(None, 'None'),
)
ADDON_INSTALL_ENTRY_POINTS_CHOICES = (
(None, 'None'),
REPORT_ENTRY_POINTS = APIChoicesWithNone(
('UNINSTALL', 1, 'Uninstall'),
('MENU', 2, 'Menu'),
)

# NULL if the reporter is anonymous.
Expand Down Expand Up @@ -88,7 +82,7 @@ class AbuseReport(ModelBase):
addon_version = models.CharField(
default=None, max_length=255, blank=True, null=True)
addon_signature = models.PositiveSmallIntegerField(
default=None, choices=ADDON_SIGNATURE_CHOICES, blank=True, null=True)
default=None, choices=ADDON_SIGNATURES.choices, blank=True, null=True)
application = models.PositiveSmallIntegerField(
default=amo.FIREFOX.id, choices=amo.APPS_CHOICES, blank=True,
null=True)
Expand All @@ -103,14 +97,14 @@ class AbuseReport(ModelBase):
install_date = models.DateTimeField(
default=None, blank=True, null=True)
reason = models.PositiveSmallIntegerField(
default=None, choices=REASON_CHOICES, blank=True, null=True)
default=None, choices=REASONS.choices, blank=True, null=True)
addon_install_origin = models.CharField(
default=None, max_length=255, blank=True, null=True)
addon_install_method = models.PositiveSmallIntegerField(
default=None, choices=ADDON_INSTALL_METHOD_CHOICES, blank=True,
default=None, choices=ADDON_INSTALL_METHODS.choices, blank=True,
null=True)
addon_install_entry_point = models.PositiveSmallIntegerField(
default=None, choices=ADDON_INSTALL_ENTRY_POINTS_CHOICES, blank=True,
report_entry_point = models.PositiveSmallIntegerField(
default=None, choices=REPORT_ENTRY_POINTS.choices, blank=True,
null=True)

class Meta:
Expand Down
29 changes: 22 additions & 7 deletions src/olympia/abuse/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,44 @@ def to_internal_value(self, data):
class AddonAbuseReportSerializer(BaseAbuseReportSerializer):
addon = serializers.SerializerMethodField()
reason = ReverseChoiceField(
choices=list(AbuseReport.REASON_CHOICES_API.items()), required=False)
application = ReverseChoiceField(
choices=list((v.id, k) for k, v in amo.APPS.items()), required=False)
choices=list(AbuseReport.REASONS.api_choices), required=False,
allow_null=True)
app = ReverseChoiceField(
choices=list((v.id, k) for k, v in amo.APPS.items()), required=False,
source='application')
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, allow_null=True)
addon_install_method = ReverseChoiceField(
choices=list(AbuseReport.ADDON_INSTALL_METHODS.api_choices),
required=False, allow_null=True)
addon_signature = ReverseChoiceField(
choices=list(AbuseReport.ADDON_SIGNATURES.api_choices),
required=False, allow_null=True)

class Meta:
model = AbuseReport
fields = BaseAbuseReportSerializer.Meta.fields + (
'addon',
'addon_install_entry_point',
'addon_install_method',
'addon_install_origin',
'addon_name',
'addon_signature',
'addon_summary',
'addon_version',
'application',
'application_locale',
'application_version',
'app',
'appversion',
'client_id',
'install_date',
'lang',
'operating_system',
'operating_system_version',
'reason',
'report_entry_point'
)

def to_internal_value(self, data):
Expand Down
59 changes: 59 additions & 0 deletions src/olympia/abuse/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,65 @@
class TestAbuse(TestCase):
fixtures = ['base/addon_3615', 'base/user_999']

def test_choices(self):
assert AbuseReport.ADDON_SIGNATURES.choices == ((None, 'None'),)
assert AbuseReport.ADDON_SIGNATURES.api_choices == ((None, None),)

assert AbuseReport.REASONS.choices == (
(None, 'None'),
(1, 'Malware'),
(2, 'Spam / Advertising'),
(3, 'Search takeover'),
(4, 'New tab takeover'),
(5, 'Breaks websites'),
(6, 'Offensive'),
(7, "Doesn't match description"),
(8, "Doesn't work"),
)
assert AbuseReport.REASONS.api_choices == (
(None, None),
(1, 'malware'),
(2, 'spam_or_advertising'),
(3, 'search_takeover'),
(4, 'new_tab_takeover'),
(5, 'breaks_websites'),
(6, 'offensive'),
(7, 'does_not_match_description'),
(8, 'does_not_work'),
)

assert AbuseReport.ADDON_INSTALL_METHODS.choices == (
(None, 'None'),
(1, 'Add-on Manager Web API'),
(2, 'Direct link'),
(3, 'Install Trigger'),
(4, 'From File'),
(5, 'Webext management API'),
(6, 'Drag & Drop'),
(7, 'Sideload'),
)
assert AbuseReport.ADDON_INSTALL_METHODS.api_choices == (
(None, None),
(1, 'amwebapi'),
(2, 'link'),
(3, 'installtrigger'),
(4, 'install-from-file'),
(5, 'management-webext-api'),
(6, 'drag-and-drop'),
(7, 'sideload')
)

assert AbuseReport.REPORT_ENTRY_POINTS.choices == (
(None, 'None'),
(1, 'Uninstall'),
(2, 'Menu')
)
assert AbuseReport.REPORT_ENTRY_POINTS.api_choices == (
(None, None),
(1, 'uninstall'),
(2, 'menu')
)

def test_user(self):
report = AbuseReport(user_id=999)
report.send()
Expand Down
Loading

0 comments on commit 29d6773

Please sign in to comment.