Skip to content

Commit

Permalink
rm sponsored, verified (#22671)
Browse files Browse the repository at this point in the history
* rm sponsored, verified

* more clean-up

* still accept obsolete groups as search params, behind a gate

* add clean up migration
  • Loading branch information
eviljeff committed Sep 20, 2024
1 parent b16c616 commit ddc1070
Show file tree
Hide file tree
Showing 18 changed files with 119 additions and 105 deletions.
4 changes: 1 addition & 3 deletions docs/topics/api/addons.rst
Original file line number Diff line number Diff line change
Expand Up @@ -278,14 +278,12 @@ This endpoint allows you to fetch a specific add-on by id, slug or guid.
line "By Firefox" category
notable Notable category
recommended Recommended category
sponsored Sponsored category
spotlight Spotlight category
strategic Strategic category
verified Verified category
badged A meta category that's available for the ``promoted``
search filter that is all the categories we expect an API
client to expose as "reviewed" by Mozilla.
Currently equal to ``line&recommended&sponsored&verified``.
Currently equal to ``line&recommended``.
============== ==========================================================


Expand Down
4 changes: 1 addition & 3 deletions docs/topics/api/v4_frozen/addons.rst
Original file line number Diff line number Diff line change
Expand Up @@ -270,14 +270,12 @@ This endpoint allows you to fetch a specific add-on by id, slug or guid.
============== ==========================================================
line "By Firefox" category
recommended Recommended category
sponsored Sponsored category
spotlight Spotlight category
strategic Strategic category
verified Verified category
badged A meta category that's available for the ``promoted``
search filter that is all the categories we expect an API
client to expose as "reviewed" by Mozilla.
Currently equal to ``line&recommended&sponsored&verified``.
Currently equal to ``line&recommended``.
============== ==========================================================

-----------------------------
Expand Down
1 change: 0 additions & 1 deletion scripts/autograph_localdev_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ signers:
states:
recommended: true
recommended-android: true
verified: true
line: true
relative_start: 0h
duration: 26298h
Expand Down
2 changes: 1 addition & 1 deletion src/olympia/addons/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ def get_current_compatible_version(self, addon):
try:
# AddonAppVersionQueryParam.get_values() returns (app_id, min, max)
# but we want {'min': min, 'max': max}.
value = AddonAppVersionQueryParam(request.GET).get_values()
value = AddonAppVersionQueryParam(request).get_values()
application = value[0]
appversions = dict(zip(('min', 'max'), value[1:], strict=True))
except ValueError as exc:
Expand Down
14 changes: 7 additions & 7 deletions src/olympia/addons/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
from olympia.bandwagon.models import Collection
from olympia.blocklist.models import Block, BlocklistSubmission
from olympia.constants.categories import CATEGORIES
from olympia.constants.promoted import LINE, NOT_PROMOTED, RECOMMENDED, SPONSORED
from olympia.constants.promoted import LINE, NOT_PROMOTED, RECOMMENDED, SPOTLIGHT
from olympia.devhub.models import RssKey
from olympia.files.models import File
from olympia.files.tests.test_models import UploadMixin
Expand Down Expand Up @@ -1765,17 +1765,17 @@ def test_promoted_group(self):

# if the group has changes the approval for the current version isn't
# valid
promoted.update(group_id=SPONSORED.id)
promoted.update(group_id=SPOTLIGHT.id)
assert not addon.promoted_group()
assert addon.promoted_group(currently_approved=False)
assert addon.promoted_group(currently_approved=False) == SPONSORED
assert addon.promoted_group(currently_approved=False) == SPOTLIGHT

promoted.approve_for_version(version=addon.current_version)
assert addon.promoted_group() == SPONSORED
assert addon.promoted_group() == SPOTLIGHT

# Application specific group membership should work too
# if no app is specifed in the PromotedAddon everything should match
assert addon.promoted_group() == SPONSORED
assert addon.promoted_group() == SPOTLIGHT
# update to mobile app
promoted.update(application_id=amo.ANDROID.id)
assert addon.promoted_group()
Expand All @@ -1786,7 +1786,7 @@ def test_promoted_group(self):
del addon.current_version.approved_for_groups
assert not addon.promoted_group()
promoted.update(application_id=amo.FIREFOX.id)
assert addon.promoted_group() == SPONSORED
assert addon.promoted_group() == SPOTLIGHT

# check it doesn't error if there's no current_version
addon.current_version.file.update(status=amo.STATUS_DISABLED)
Expand All @@ -1812,7 +1812,7 @@ def test_promoted(self):

# If the group changes the approval for the current version isn't
# valid.
promoted.update(group_id=SPONSORED.id)
promoted.update(group_id=SPOTLIGHT.id)
del addon.promoted
assert addon.promoted is None

Expand Down
23 changes: 8 additions & 15 deletions src/olympia/addons/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,7 @@
from olympia.constants.browsers import CHROME
from olympia.constants.categories import CATEGORIES, CATEGORIES_BY_ID
from olympia.constants.licenses import LICENSE_GPL3
from olympia.constants.promoted import (
LINE,
RECOMMENDED,
SPONSORED,
SPOTLIGHT,
STRATEGIC,
VERIFIED,
)
from olympia.constants.promoted import LINE, RECOMMENDED, SPOTLIGHT, STRATEGIC
from olympia.files.tests.test_models import UploadMixin
from olympia.files.utils import parse_addon, parse_xpi
from olympia.ratings.models import Rating
Expand Down Expand Up @@ -5705,7 +5698,7 @@ def test_filter_by_promoted(self):
assert {res['id'] for res in data['results']} == {addon.pk, addon5.pk}

# test with other other promotions
for promo in (SPONSORED, VERIFIED, LINE, SPOTLIGHT, STRATEGIC):
for promo in (LINE, SPOTLIGHT, STRATEGIC):
self.make_addon_promoted(addon, promo, approve_version=True)
self.reindex(Addon)
data = self.perform_search(
Expand Down Expand Up @@ -6495,8 +6488,8 @@ def test_sort_ignored(self):

def test_promoted(self):
not_promoted = addon_factory(name='not promoted')
sponsored = addon_factory(name='is promoted')
self.make_addon_promoted(sponsored, SPONSORED, approve_version=True)
spotlight = addon_factory(name='is promoted')
self.make_addon_promoted(spotlight, SPOTLIGHT, approve_version=True)
addon_factory(name='something')

self.refresh()
Expand All @@ -6507,14 +6500,14 @@ def test_promoted(self):
assert 'prev' not in data
assert len(data['results']) == 2

assert {itm['id'] for itm in data['results']} == {not_promoted.pk, sponsored.pk}
assert {itm['id'] for itm in data['results']} == {not_promoted.pk, spotlight.pk}

sponsored_result, not_result = (
spotlight_result, not_result = (
(data['results'][0], data['results'][1])
if data['results'][0]['id'] == sponsored.id
if data['results'][0]['id'] == spotlight.id
else (data['results'][1], data['results'][0])
)
assert sponsored_result['promoted']['category'] == 'sponsored'
assert spotlight_result['promoted']['category'] == 'spotlight'
assert not_result['promoted'] is None


Expand Down
8 changes: 4 additions & 4 deletions src/olympia/addons/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1060,14 +1060,14 @@ def get_query_params(self):
if AddonAppVersionQueryParam.query_param in self.request.GET:
# app parameter is mandatory with appversion
try:
application = AddonAppQueryParam(self.request.GET).get_value()
application = AddonAppQueryParam(self.request).get_value()
except ValueError as exc:
raise exceptions.ParseError(
'Invalid or missing app parameter while appversion parameter is '
'set.'
) from exc
try:
value = AddonAppVersionQueryParam(self.request.GET).get_values()
value = AddonAppVersionQueryParam(self.request).get_values()
appversions = {'min': value[1], 'max': value[2]}
except ValueError as exc:
raise exceptions.ParseError('Invalid appversion parameter.') from exc
Expand All @@ -1081,7 +1081,7 @@ def get_query_params(self):
# to filter by type if they want appversion filtering.
if AddonTypeQueryParam.query_param in self.request.GET or appversions:
try:
addon_types = tuple(AddonTypeQueryParam(self.request.GET).get_values())
addon_types = tuple(AddonTypeQueryParam(self.request).get_values())
except ValueError as exc:
raise exceptions.ParseError(
'Invalid or missing type parameter while appversion '
Expand All @@ -1093,7 +1093,7 @@ def get_query_params(self):
# author is optional. It's a string representing the username(s) we're
# filtering on.
if AddonAuthorQueryParam.query_param in self.request.GET:
authors = AddonAuthorQueryParam(self.request.GET).get_values()
authors = AddonAuthorQueryParam(self.request).get_values()
else:
authors = None

Expand Down
27 changes: 1 addition & 26 deletions src/olympia/constants/promoted.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,30 +69,7 @@ def __bool__(self):
can_be_compatible_with_all_fenix_versions=True,
)

SPONSORED = PromotedClass(
id=2,
name=_('Sponsored'),
api_name='sponsored',
listed_pre_review=True,
badged=True,
autograph_signing_states={
applications.FIREFOX.short: 'verified',
applications.ANDROID.short: 'verified',
},
can_primary_hero=True,
)

VERIFIED = PromotedClass(
id=3,
name=_('Verified'),
api_name='verified',
listed_pre_review=True,
badged=True,
autograph_signing_states={
applications.FIREFOX.short: 'verified',
applications.ANDROID.short: 'verified',
},
)
# id 3 & 4 were previously used for Sponsored and Verified

LINE = PromotedClass(
id=4,
Expand Down Expand Up @@ -139,8 +116,6 @@ def __bool__(self):
PROMOTED_GROUPS = [
NOT_PROMOTED,
RECOMMENDED,
SPONSORED,
VERIFIED,
LINE,
SPOTLIGHT,
STRATEGIC,
Expand Down
12 changes: 6 additions & 6 deletions src/olympia/hero/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from olympia.amo.tests import TestCase, addon_factory
from olympia.amo.tests.test_helpers import get_uploaded_file
from olympia.constants.promoted import RECOMMENDED, SPOTLIGHT, VERIFIED
from olympia.constants.promoted import RECOMMENDED, SPOTLIGHT, STRATEGIC
from olympia.hero.models import (
PrimaryHero,
PrimaryHeroImage,
Expand Down Expand Up @@ -62,17 +62,17 @@ def test_clean_requires_approved_can_primary_hero_group(self):
ph.clean() # it raises if there's an error

# change to a different group
ph.promoted_addon.update(group_id=VERIFIED.id)
ph.promoted_addon.update(group_id=STRATEGIC.id)
ph.promoted_addon.approve_for_version(ph.promoted_addon.addon.current_version)
ph.reload()
ph.enabled = True
assert ph.promoted_addon.addon.promoted_group() == VERIFIED
assert ph.promoted_addon.addon.promoted_group() == STRATEGIC
with self.assertRaises(ValidationError) as context:
# VERIFIED isn't a group that can be added as a primary hero
# STRATEGIC isn't a group that can be added as a primary hero
ph.clean()
assert context.exception.messages == [
'Only add-ons that are Recommended, Sponsored, By Firefox, '
'Spotlight can be enabled for non-external primary shelves.'
'Only add-ons that are Recommended, By Firefox, Spotlight can be enabled '
'for non-external primary shelves.'
]

# change to a different group that *can* be added as a primary hero
Expand Down
3 changes: 3 additions & 0 deletions src/olympia/lib/settings_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1383,6 +1383,7 @@ def read_only_mode(env):
'del-version-license-slug',
'del-preview-position',
'categories-application',
'promoted-verified-sponsored',
),
'v4': (
'l10n_flat_input_output',
Expand All @@ -1398,12 +1399,14 @@ def read_only_mode(env):
'del-version-license-slug',
'del-preview-position',
'categories-application',
'promoted-verified-sponsored',
),
'v5': (
'addons-search-_score-field',
'ratings-can_reply',
'ratings-score-filter',
'addon-submission-api',
'promoted-verified-sponsored',
),
}

Expand Down
21 changes: 21 additions & 0 deletions src/olympia/promoted/migrations/0021_auto_20240919_0952.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 4.2.16 on 2024-09-19 09:52

from django.db import migrations


def delete_verified_sponsored_promoted_usage(apps, schema_editor):
PromotedAddon = apps.get_model('promoted', 'PromotedAddon')
PromotedApproval = apps.get_model('promoted', 'PromotedApproval')
PromotedAddon.objects.filter(group_id__in=(3, 4)).update(group_id=0)
PromotedApproval.objects.filter(group_id__in=(3, 4)).delete()


class Migration(migrations.Migration):

dependencies = [
('promoted', '0020_auto_20221214_1331'),
]

operations = [
migrations.RunPython(delete_verified_sponsored_promoted_usage, migrations.RunPython.noop)
]
13 changes: 4 additions & 9 deletions src/olympia/promoted/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@
from olympia.amo.reverse import django_reverse
from olympia.amo.tests import TestCase, addon_factory, user_factory, version_factory
from olympia.amo.tests.test_helpers import get_uploaded_file
from olympia.constants.promoted import (
LINE,
NOT_PROMOTED,
RECOMMENDED,
VERIFIED,
)
from olympia.constants.promoted import LINE, NOT_PROMOTED, RECOMMENDED
from olympia.hero.models import PrimaryHero, PrimaryHeroImage
from olympia.promoted.models import PromotedAddon, PromotedApproval

Expand Down Expand Up @@ -523,7 +518,7 @@ def test_can_delete_when_primary_hero_too(self):
# The approval *won't* have been deleted though
assert PromotedApproval.objects.filter().exists()

def test_updates_not_promoted_to_verified(self):
def test_updates_not_promoted_to_line(self):
item = PromotedAddon.objects.create(
addon=addon_factory(), group_id=NOT_PROMOTED.id
)
Expand All @@ -537,11 +532,11 @@ def test_updates_not_promoted_to_verified(self):
dict(
self._get_approval_form(item, []),
**self._get_heroform(item.id),
**{'group_id': VERIFIED.id}, # change group
**{'group_id': LINE.id}, # change group
),
follow=True,
)
item.reload()

assert response.status_code == 200
assert item.group_id == VERIFIED.id
assert item.group_id == LINE.id
8 changes: 4 additions & 4 deletions src/olympia/promoted/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ def setUp(self):

def test_basic(self):
promoted_addon = PromotedAddon.objects.create(
addon=addon_factory(), group_id=promoted.SPONSORED.id
addon=addon_factory(), group_id=promoted.LINE.id
)
assert promoted_addon.group == promoted.SPONSORED
assert promoted_addon.group == promoted.LINE
assert promoted_addon.application_id is None
assert promoted_addon.all_applications == [
applications.FIREFOX,
Expand Down Expand Up @@ -49,12 +49,12 @@ def test_is_approved_applications(self):
]

# but not if it's for a different type of promotion
promoted_addon.update(group_id=promoted.SPONSORED.id)
promoted_addon.update(group_id=promoted.SPOTLIGHT.id)
assert addon.promotedaddon.approved_applications == []
# unless that group has an approval too
PromotedApproval.objects.create(
version=addon.current_version,
group_id=promoted.SPONSORED.id,
group_id=promoted.SPOTLIGHT.id,
application_id=applications.FIREFOX.id,
)
addon.reload()
Expand Down
3 changes: 1 addition & 2 deletions src/olympia/reviewers/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
LINE,
NOTABLE,
RECOMMENDED,
SPONSORED,
SPOTLIGHT,
STRATEGIC,
)
Expand Down Expand Up @@ -551,7 +550,7 @@ def test_actions_promoted_admin_review_needs_admin_permission(self):
)

# only for groups that are admin_review though
self.make_addon_promoted(self.addon, SPONSORED, approve_version=True)
self.make_addon_promoted(self.addon, NOTABLE, approve_version=True)
expected = [
'public',
'reject',
Expand Down
Loading

0 comments on commit ddc1070

Please sign in to comment.