Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 18 additions & 19 deletions src/olympia/abuse/tests/test_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,9 @@
from olympia.constants.abuse import DECISION_ACTIONS
from olympia.constants.blocklist import BlockReason, BlockType
from olympia.constants.permissions import ADDONS_HIGH_IMPACT_APPROVE
from olympia.constants.promoted import PROMOTED_GROUP_CHOICES
from olympia.constants.reviewers import REVIEWER_DELAYED_REJECTION_PERIOD_DAYS_DEFAULT
from olympia.core import set_user
from olympia.files.models import File
from olympia.promoted.models import PromotedGroup
from olympia.ratings.models import Rating
from olympia.reviewers.models import AutoApprovalSummary, NeedsHumanReview
from olympia.versions.models import VersionReviewerFlags
Expand Down Expand Up @@ -585,7 +583,7 @@ def test_should_hold_action(self):
assert action_helper.should_hold_action() is False
addon = addon_factory(users=[self.user])
assert action_helper.should_hold_action() is False
self.make_addon_promoted(addon, PROMOTED_GROUP_CHOICES.RECOMMENDED)
self.make_addon_promoted(addon, api_name='high_profile', high_profile=True)
assert action_helper.should_hold_action() is True

self.user.banned = datetime.now()
Expand Down Expand Up @@ -867,7 +865,7 @@ def test_should_hold_action(self):
action_helper = self.ActionClass(self.decision)
assert action_helper.should_hold_action() is False

self.make_addon_promoted(self.addon, PROMOTED_GROUP_CHOICES.RECOMMENDED)
self.make_addon_promoted(self.addon, api_name='high_profile', high_profile=True)
assert action_helper.should_hold_action() is True

self.addon.status = amo.STATUS_DISABLED
Expand Down Expand Up @@ -1473,7 +1471,7 @@ def test_execute_action_with_stakeholder_email(self):
)
self.version.file.update(is_signed=True)
self.another_version.file.update(approval_date=datetime(2025, 2, 3))
self.make_addon_promoted(self.addon, PROMOTED_GROUP_CHOICES.RECOMMENDED)
self.make_addon_promoted(self.addon, api_name='high_profile', high_profile=True)
self._test_reject_version(content_review=False, expected_emails_from_action=1)
assert len(mail.outbox) == 4
assert mail.outbox[0].recipients() == [stakeholder.email]
Expand Down Expand Up @@ -1629,7 +1627,7 @@ def test_execute_action_delayed_with_stakeholder_email(self):
)
self.version.file.update(is_signed=True)
self.another_version.file.update(approval_date=datetime(2025, 2, 3))
self.make_addon_promoted(self.addon, PROMOTED_GROUP_CHOICES.RECOMMENDED)
self.make_addon_promoted(self.addon, api_name='high_profile', high_profile=True)
self._test_reject_version_delayed(
content_review=False, expected_emails_from_action=1
)
Expand Down Expand Up @@ -1743,7 +1741,7 @@ def test_should_hold_action(self):
action_helper = self.ActionClass(self.decision)
assert action_helper.should_hold_action() is False

self.make_addon_promoted(self.addon, PROMOTED_GROUP_CHOICES.RECOMMENDED)
self.make_addon_promoted(self.addon, api_name='high_profile', high_profile=True)
self.decision.target_versions.add(self.another_version)
assert self.decision.target_versions.filter(file__is_signed=True).exists()
assert action_helper.should_hold_action() is True
Expand All @@ -1755,7 +1753,7 @@ def test_should_hold_action(self):

def test_should_hold_action_some_versions_remain(self):
self.decision.update(action=DECISION_ACTIONS.AMO_REJECT_VERSION_ADDON)
self.make_addon_promoted(self.addon, PROMOTED_GROUP_CHOICES.RECOMMENDED)
self.make_addon_promoted(self.addon, api_name='high_profile', high_profile=True)
self.version.file.update(is_signed=True)

# While there are more public listed versions that wouldn't be affected
Expand Down Expand Up @@ -1830,7 +1828,7 @@ def test_notify_stakeholders(self):
assert len(mail.outbox) == 0

# make the addon promoted
self.make_addon_promoted(self.addon, PROMOTED_GROUP_CHOICES.RECOMMENDED)
self.make_addon_promoted(self.addon, api_name='high_profile', high_profile=True)
action_helper.notify_stakeholders('teh reason')
assert len(mail.outbox) == 1
body = mail.outbox[0].body
Expand Down Expand Up @@ -1912,7 +1910,7 @@ def test_notify_stakeholders_with_private_notes(self):
self.decision.update(private_notes='These are the private notes.')

# make the addon promoted
self.make_addon_promoted(self.addon, PROMOTED_GROUP_CHOICES.RECOMMENDED)
self.make_addon_promoted(self.addon, api_name='high_profile', high_profile=True)
action_helper.notify_stakeholders('teh reason')
assert len(mail.outbox) == 1
assert mail.outbox[0].recipients() == [stakeholder.email]
Expand Down Expand Up @@ -1943,7 +1941,7 @@ def test_notify_stakeholders_with_policy_texts(self):
)

# make the addon promoted
self.make_addon_promoted(self.addon, PROMOTED_GROUP_CHOICES.RECOMMENDED)
self.make_addon_promoted(self.addon, api_name='high_profile', high_profile=True)
action_helper.notify_stakeholders('teh reason')
assert len(mail.outbox) == 1
assert mail.outbox[0].recipients() == [stakeholder.email]
Expand Down Expand Up @@ -2080,14 +2078,11 @@ def test_already_blocked(self):
assert ActivityLog.objects.count() == 0

def test_should_hold_action(self):
PromotedGroup.objects.get_or_create(
group_id=PROMOTED_GROUP_CHOICES.RECOMMENDED, high_profile=True
)
self.decision.update(action=self.default_decision_action)
action_helper = self.ActionClass(self.decision)
assert action_helper.should_hold_action() is False

self.make_addon_promoted(self.addon, PROMOTED_GROUP_CHOICES.RECOMMENDED)
self.make_addon_promoted(self.addon, api_name='high_profile', high_profile=True)
assert action_helper.should_hold_action() is True

# if one version is not blocked we still hold the action
Expand Down Expand Up @@ -2949,15 +2944,17 @@ def test_execute_action_unlisted(self):
assert 'has been approved' in mail.outbox[0].body

def test_execute_action_promoted(self):
self.make_addon_promoted(self.addon, PROMOTED_GROUP_CHOICES.RECOMMENDED)
self.make_addon_promoted(
self.addon, api_name='pre_review', listed_pre_review=True
)
assert not self.addon.promoted_groups()
self.test_execute_action()
assert self.addon.promoted_groups()
assert self.version.promoted_versions.filter(
promoted_group__group_id=PROMOTED_GROUP_CHOICES.RECOMMENDED
promoted_group__api_name='pre_review'
).exists()
assert self.old_version.promoted_versions.filter(
promoted_group__group_id=PROMOTED_GROUP_CHOICES.RECOMMENDED
promoted_group__api_name='pre_review'
).exists()

def test_execute_action_not_human(self):
Expand Down Expand Up @@ -3567,7 +3564,9 @@ def test_should_hold_action(self):

AddonUser.objects.create(addon=self.rating.addon, user=self.rating.user)
assert action_helper.should_hold_action() is False
self.make_addon_promoted(self.rating.addon, PROMOTED_GROUP_CHOICES.RECOMMENDED)
self.make_addon_promoted(
self.rating.addon, api_name='high_profile_rating', high_profile_rating=True
)
assert action_helper.should_hold_action() is False
self.rating.update(
reply_to=Rating.objects.create(
Expand Down
8 changes: 4 additions & 4 deletions src/olympia/abuse/tests/test_cinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
ILLEGAL_CATEGORIES,
ILLEGAL_SUBCATEGORIES,
)
from olympia.constants.promoted import PROMOTED_GROUP_CHOICES
from olympia.constants.promoted import RECOMMENDED_API_NAME
from olympia.promoted.models import PromotedAddon
from olympia.ratings.models import Rating
from olympia.reviewers.models import NeedsHumanReview
Expand Down Expand Up @@ -389,7 +389,7 @@ def test_build_report_payload_promoted_recommended(self):
privacy_policy='Söme privacy policy',
version_kw={'release_notes': 'Søme release notes'},
)
self.make_addon_promoted(addon, group_id=PROMOTED_GROUP_CHOICES.RECOMMENDED)
self.make_addon_promoted(addon, api_name=RECOMMENDED_API_NAME)
message = ' bad addon!'
cinder_addon = self.CinderClass(addon)
encoded_message = cinder_addon.get_str(message)
Expand Down Expand Up @@ -457,7 +457,7 @@ def test_build_report_payload_promoted_notable(self):
privacy_policy='Söme privacy policy',
version_kw={'release_notes': 'Søme release notes'},
)
self.make_addon_promoted(addon, group_id=PROMOTED_GROUP_CHOICES.NOTABLE)
self.make_addon_promoted(addon, api_name='notable', high_profile=True)
message = ' bad addon!'
cinder_addon = self.CinderClass(addon)
encoded_message = cinder_addon.get_str(message)
Expand Down Expand Up @@ -1802,7 +1802,7 @@ def test_build_event_payload_promoted_notable(self):
version_kw={'release_notes': 'Søme release notes'},
requires_payment=True,
)
self.make_addon_promoted(addon, group_id=PROMOTED_GROUP_CHOICES.NOTABLE)
self.make_addon_promoted(addon, api_name='notable', high_profile=True)
cinder_addon = self.CinderClass(addon)

data = cinder_addon.build_event_payload()
Expand Down
12 changes: 7 additions & 5 deletions src/olympia/abuse/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
ILLEGAL_SUBCATEGORIES,
)
from olympia.constants.permissions import ADDONS_HIGH_IMPACT_APPROVE
from olympia.constants.promoted import PROMOTED_GROUP_CHOICES
from olympia.core import set_user
from olympia.files.models import File
from olympia.ratings.models import Rating
Expand Down Expand Up @@ -3415,7 +3414,7 @@ def test_execute_action_disable_addon_held(self):
self.grant_permission(user_factory(), ':'.join(ADDONS_HIGH_IMPACT_APPROVE))
addon = addon_factory(users=[user_factory()])
self.make_addon_promoted(
addon, PROMOTED_GROUP_CHOICES.RECOMMENDED, approve_version=True
addon, api_name='high_profile', high_profile=True, approve_version=True
)
decision = ContentDecision.objects.create(
addon=addon,
Expand Down Expand Up @@ -3547,7 +3546,7 @@ def test_execute_action_reject_version_held(self):
addon = addon_factory(users=[user_factory()], file_kw={'is_signed': True})
version = addon.current_version
self.make_addon_promoted(
addon, PROMOTED_GROUP_CHOICES.RECOMMENDED, approve_version=True
addon, api_name='high_profile', high_profile=True, approve_version=True
)
version.needshumanreview_set.create(
reason=NeedsHumanReview.REASONS.ABUSE_ADDON_VIOLATION
Expand Down Expand Up @@ -3738,7 +3737,7 @@ def test_execute_action_reject_version_delayed_held(self):
addon = addon_factory(users=[user_factory()], file_kw={'is_signed': True})
version = addon.current_version
self.make_addon_promoted(
addon, PROMOTED_GROUP_CHOICES.RECOMMENDED, approve_version=True
addon, api_name='high_profile', high_profile=True, approve_version=True
)
some_time_ago = self.days_ago(13)
little_over_fourteen_days = timedelta(days=14, minutes=1)
Expand Down Expand Up @@ -4020,7 +4019,10 @@ def test_execute_action_delete_rating_held(self):
reviewer_user=self.reviewer_user,
)
self.make_addon_promoted(
rating.addon, PROMOTED_GROUP_CHOICES.RECOMMENDED, approve_version=True
rating.addon,
api_name='high_profile_rating',
high_profile_rating=True,
approve_version=True,
)
assert decision.action_date is None
mail.outbox.clear()
Expand Down
7 changes: 1 addition & 6 deletions src/olympia/abuse/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
from olympia.blocklist.models import Block, BlockVersion
from olympia.constants.abuse import DECISION_ACTIONS
from olympia.constants.blocklist import BlockReason, BlockType
from olympia.constants.promoted import PROMOTED_GROUP_CHOICES
from olympia.promoted.models import PromotedGroup
from olympia.ratings.models import Rating
from olympia.users.models import UserProfile

Expand All @@ -39,11 +37,8 @@ def test_reject_and_block_addons():
user_factory(id=settings.TASK_USER_ID)
normal_addon = addon_factory(users=[user_factory()])
normal_addon_version = normal_addon.current_version
PromotedGroup.objects.get_or_create(
group_id=PROMOTED_GROUP_CHOICES.RECOMMENDED, high_profile=True
)
recommended_addon = addon_factory(
promoted_id=PROMOTED_GROUP_CHOICES.RECOMMENDED,
promoted_kwargs={'api_name': 'high_profile', 'high_profile': True},
users=[user_factory()],
version_kw={'promotion_approved': False},
)
Expand Down
6 changes: 1 addition & 5 deletions src/olympia/access/acl.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,7 @@ def check_addon_ownership(


def is_listed_addons_reviewer(user, allow_content_reviewers=True):
permissions = [
amo.permissions.ADDONS_REVIEW,
amo.permissions.ADDONS_RECOMMENDED_REVIEW,
]
permissions = [amo.permissions.ADDONS_REVIEW]
if allow_content_reviewers:
permissions.append(amo.permissions.ADDONS_CONTENT_REVIEW)
allow_access = any(action_allowed_for(user, perm) for perm in permissions)
Expand Down Expand Up @@ -178,7 +175,6 @@ def is_user_any_kind_of_reviewer(user, allow_viewers=False):
amo.permissions.ADDONS_REVIEW,
amo.permissions.ADDONS_REVIEW_UNLISTED,
amo.permissions.ADDONS_CONTENT_REVIEW,
amo.permissions.ADDONS_RECOMMENDED_REVIEW,
amo.permissions.STATIC_THEMES_REVIEW,
]
if allow_viewers:
Expand Down
8 changes: 2 additions & 6 deletions src/olympia/addons/indexers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from olympia import amo
from olympia.amo.celery import create_chunked_tasks_signatures
from olympia.amo.utils import attach_trans_dict, to_language
from olympia.constants.promoted import PROMOTED_GROUP_CHOICES
from olympia.constants.promoted import RECOMMENDED_API_NAME
from olympia.constants.search import SEARCH_LANGUAGE_TO_ANALYZER
from olympia.search.utils import create_index
from olympia.versions.compare import version_int
Expand Down Expand Up @@ -487,7 +487,6 @@ def get_mapping(cls):
'promoted': {
'type': 'object',
'properties': {
'group_id': {'type': 'byte'},
'category': {'type': 'keyword'},
'approved_for_apps': {'type': 'byte'},
},
Expand Down Expand Up @@ -662,7 +661,7 @@ def extract_document(cls, obj):
data['has_privacy_policy'] = bool(obj.privacy_policy)

data['is_recommended'] = any(
PROMOTED_GROUP_CHOICES.RECOMMENDED == promotion.group_id
promotion.api_name == RECOMMENDED_API_NAME
for promotion in obj.publicly_promoted_groups
)

Expand All @@ -678,7 +677,6 @@ def extract_document(cls, obj):

data['promoted'] = [
{
'group_id': promotion.group_id,
'category': promotion.api_name,
# store the app approvals because .approved_applications needs it.
'approved_for_apps': [
Expand All @@ -688,8 +686,6 @@ def extract_document(cls, obj):
for promotion in obj.publicly_promoted_groups
]
# Add an additional bump for certain promoted groups.
# TODO: actually use this value in the search ranking algorithm, and drop
# the existing function that uses PROMOTED_GROUPS_CHOICES
max_promoted_ranking_bump = max(
(
promotion.search_ranking_bump
Expand Down
10 changes: 2 additions & 8 deletions src/olympia/addons/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@
from olympia.constants.blocklist import BlockReason
from olympia.constants.browsers import BROWSERS
from olympia.constants.categories import CATEGORIES_BY_ID
from olympia.constants.promoted import (
PROMOTED_GROUP_CHOICES,
)
from olympia.constants.promoted import RECOMMENDED_API_NAME
from olympia.constants.reviewers import REPUTATION_CHOICES
from olympia.files.models import File
from olympia.files.utils import extract_translations, resolve_i18n_message
Expand Down Expand Up @@ -1631,11 +1629,7 @@ def publicly_promoted_groups(self):
if self._is_recommended_theme():
from olympia.promoted.models import PromotedGroup

return [
PromotedGroup.objects.get(
group_id=PROMOTED_GROUP_CHOICES.RECOMMENDED
)
]
return [PromotedGroup.objects.get(api_name=RECOMMENDED_API_NAME)]
return []

@cached_property
Expand Down
15 changes: 5 additions & 10 deletions src/olympia/addons/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
from olympia.constants.applications import APP_IDS, APPS_ALL
from olympia.constants.base import ADDON_TYPE_CHOICES_API
from olympia.constants.categories import CATEGORIES_BY_ID
from olympia.constants.promoted import PROMOTED_GROUP_CHOICES
from olympia.constants.promoted import RECOMMENDED_API_NAME
from olympia.files.models import File, FileUpload
from olympia.files.utils import DuplicateAddonID, parse_addon
from olympia.promoted.models import PromotedGroup
Expand Down Expand Up @@ -1000,10 +1000,7 @@ def validate_user_id(self, value):

class PromotedGroupSerializer(AMOModelSerializer):
apps = serializers.SerializerMethodField()
category = ReverseChoiceField(
choices=PROMOTED_GROUP_CHOICES.api_choices,
source='group_id',
)
category = serializers.CharField(source='api_name')

class Meta:
model = PromotedGroup
Expand Down Expand Up @@ -1204,7 +1201,7 @@ def get_is_featured(self, obj):
# fake it with promoted status instead.
def is_recommended(obj):
return any(
PROMOTED_GROUP_CHOICES.RECOMMENDED == promotion.group_id
promotion.api_name == RECOMMENDED_API_NAME
for promotion in obj.publicly_promoted_groups
)

Expand Down Expand Up @@ -1652,11 +1649,9 @@ def fake_object(self, data):
obj.promoted = []
for promotion in promoted_list:
approved_for_apps = promotion.get('approved_for_apps')
group = PROMOTED_GROUP_CHOICES(promotion['group_id'])
obj.promoted.append(
{
'group_id': promotion['group_id'],
'category': promotion.get('category', group.api_value),
'category': promotion.get('category'),
'apps': [
APP_IDS.get(app_id).short for app_id in approved_for_apps
],
Expand Down Expand Up @@ -1702,7 +1697,7 @@ def get_promoted(self, obj):
def get_is_featured(self, obj):
def is_recommended(obj):
return any(
PROMOTED_GROUP_CHOICES.RECOMMENDED == promotion['group_id']
promotion['category'] == RECOMMENDED_API_NAME
for promotion in obj.promoted
)

Expand Down
Loading
Loading