Skip to content

Only Show Recommended/By Firefox in Devhub #23372

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
4 changes: 2 additions & 2 deletions src/olympia/abuse/cinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ def get_attributes(self):
# promoted in any way, but we don't care about the promotion being
# approved for the current version, it would make more queries and it's
# not useful for moderation purposes anyway.
promoted_group = self.addon.promoted_groups(currently_approved=False)
promoted_groups = self.addon.promoted_groups(currently_approved=False)
data = {
'id': self.id,
'average_daily_users': self.addon.average_daily_users,
Expand All @@ -353,7 +353,7 @@ def get_attributes(self):
'name': self.get_str(self.addon.name),
'slug': self.addon.slug,
'summary': self.get_str(self.addon.summary),
'promoted': self.get_str(promoted_group.name),
'promoted': self.get_str(promoted_groups.get_names(needs_badged=False)),
}
return data

Expand Down
6 changes: 4 additions & 2 deletions src/olympia/addons/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,12 +516,14 @@ def validate_is_disabled(self, disable):
):
raise exceptions.ValidationError(gettext('File is already disabled.'))
if not version.can_be_disabled_and_deleted():
group = version.addon.promoted_groups()
group_name = version.addon.promoted_groups().get_names(
needs_badged=False
)
msg = gettext(
'The latest approved version of this %s add-on cannot be deleted '
'because the previous version was not approved for %s promotion. '
'Please contact AMO Admins if you need help with this.'
) % (group.name, group.name)
) % (group_name, group_name)
raise exceptions.ValidationError(msg)
return disable

Expand Down
6 changes: 4 additions & 2 deletions src/olympia/addons/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,12 +733,14 @@ def update(self, request, *args, **kwargs):
def destroy(self, request, *args, **kwargs):
instance = self.get_object()
if not instance.can_be_disabled_and_deleted():
group = self.get_addon_object().promoted_groups()
group_name = (
self.get_addon_object().promoted_groups().get_names(needs_badged=False)
)
msg = gettext(
'The latest approved version of this %s add-on cannot be deleted '
'because the previous version was not approved for %s promotion. '
'Please contact AMO Admins if you need help with this.'
) % (group.name, group.name)
) % (group_name, group_name)
raise exceptions.ValidationError(msg)

return super().destroy(request, *args, **kwargs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
{% set status_text = _('Invisible') %}
{% set tooltip_text = status_tips['invisible'] %}
{% else %}
{% set promoted_group = addon.promoted_groups() %}
{% if addon.status == amo.STATUS_APPROVED and promoted_group.badged|python_any %}
{% set status_text = _('Approved and %s' % promoted_group.name) %}
{% set promoted_groups = addon.promoted_groups() %}
{% if addon.status == amo.STATUS_APPROVED and promoted_groups.badged|python_any %}
{% set status_text = _('Approved and %s' % promoted_groups.get_names()) %}
{% else %}
{% set status_text = addon.get_status_display() %}
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{% macro render_status(addon) %}
{% set promoted_group = addon.promoted_groups() %}
{% set promoted_groups = addon.promoted_groups() %}
{% if addon.status != amo.STATUS_DISABLED and addon.disabled_by_user %}
{% set status_text = _('Invisible') %}
{% elif addon.status == amo.STATUS_APPROVED and promoted_group.badged|python_any %}
{% set status_text = _('Approved and %s' % promoted_group.name) %}
{% elif addon.status == amo.STATUS_APPROVED and promoted_groups.badged|python_any %}
{% set status_text = _('Approved and %s' % promoted_groups.get_names()) %}
{% else %}
{% set status_text = addon.get_status_display() %}
{% endif %}
Expand Down
2 changes: 1 addition & 1 deletion src/olympia/devhub/templates/devhub/versions/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ <h3 data-tmpl="{{ _('Delete Version {version}') }}"></h3>
</form>
<p class="promoted-version-warning">
{# will be hidden by default, shown by javascript if data-can-be-disabled is falsey #}
{% trans promoted_group_name = addon.promoted_groups().name %}
{% trans promoted_group_name = addon.promoted_groups().get_names(needs_badged=False) %}
The latest approved version of this {{ promoted_group_name }} add-on cannot be deleted or disabled
because the previous version was not approved for {{ promoted_group_name }} promotion.
Please contact AMO Admins if you need help with this.
Expand Down
22 changes: 22 additions & 0 deletions src/olympia/devhub/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,28 @@ def test_disabled_post_admin(self):
assert 'no-edit' not in doc('body')[0].attrib['class']
self.assert3xx(self.client.post(self.delete_url), self.get_url)

def test_dev_promoted_status(self):
self.make_addon_promoted(
addon=self.addon, group_id=PROMOTED_GROUP_CHOICES.RECOMMENDED
)
self.make_addon_promoted(addon=self.addon, group_id=PROMOTED_GROUP_CHOICES.LINE)
self.make_addon_promoted(
addon=self.addon, group_id=PROMOTED_GROUP_CHOICES.SPOTLIGHT
)
self.addon.approve_for_version()
assert (
PROMOTED_GROUP_CHOICES.RECOMMENDED in self.addon.promoted_groups().group_id
)
assert PROMOTED_GROUP_CHOICES.LINE in self.addon.promoted_groups().group_id
assert PROMOTED_GROUP_CHOICES.SPOTLIGHT in self.addon.promoted_groups().group_id

response = self.client.get(self.get_url)
assert response.status_code == 200
doc = pq(response.content)
assert 'Recommended' in doc('.addon-listed-status').text()
assert 'By Firefox' in doc('.addon-listed-status').text()
assert 'Spotlight' not in doc('.addon-listed-status').text()


class TestVersionStats(TestCase):
fixtures = ['base/users', 'base/addon_3615']
Expand Down
4 changes: 2 additions & 2 deletions src/olympia/devhub/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1208,13 +1208,13 @@ def version_delete(request, addon_id, addon):
if not version.can_be_disabled_and_deleted():
# Developers shouldn't be able to delete/disable the current version
# of a promoted approved add-on.
group = addon.promoted_groups()
group_name = addon.promoted_groups().get_names(needs_badged=False)
msg = gettext(
'The latest approved version of this %s add-on cannot '
'be deleted or disabled because the previous version was not '
'approved for %s promotion. '
'Please contact AMO Admins if you need help with this.'
) % (group.name, group.name)
) % (group_name, group_name)
messages.error(request, msg)
elif 'disable_version' in request.POST:
messages.success(request, gettext('Version %s disabled.') % version.version)
Expand Down
6 changes: 3 additions & 3 deletions src/olympia/promoted/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ def __getattr__(self, attribute):
return self.values_list(attribute, flat=True)
raise AttributeError(f'PromotedGroup has no attribute: {attribute}')

@property
def name(self):
return ', '.join(self.__getattr__('name'))
def get_names(self, needs_badged=True):
groups = self.filter(badged=True) if needs_badged else self
return ', '.join(groups.__getattr__('name'))


class PromotedGroupManager(ManagerBase):
Expand Down
16 changes: 8 additions & 8 deletions src/olympia/reviewers/templates/reviewers/review.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ <h4 class="author">by

</hgroup>

{% if promoted_group %}
{% if promoted_groups %}
{# Technically could be just pending approval, but that doesn't matter for this message. #}
<p class="is_promoted">
This is a {{ promoted_group.name }} add-on.
{% if (amo.promoted.PROMOTED_GROUP_CHOICES.RECOMMENDED in promoted_group.group_id and not action_allowed_for(request.user, amo.permissions.ADDONS_RECOMMENDED_REVIEW)) or
(promoted_group.admin_review|python_any and not action_allowed_for(request.user, amo.permissions.REVIEWS_ADMIN)) %}
This is a {{ promoted_groups.get_names(needs_badged=False) }} add-on.
{% if (amo.promoted.PROMOTED_GROUP_CHOICES.RECOMMENDED in promoted_groups.group_id and not action_allowed_for(request.user, amo.permissions.ADDONS_RECOMMENDED_REVIEW)) or
(promoted_groups.admin_review|python_any and not action_allowed_for(request.user, amo.permissions.REVIEWS_ADMIN)) %}
You don't have permission to review it.
{% endif %}
</p>
Expand Down Expand Up @@ -131,12 +131,12 @@ <h3 id="history">
</div>
</div>

{% if promoted_group %}
{% if promoted_groups %}
{# Technically could be just pending approval, but that doesn't matter for this message. #}
<p class="is_promoted">
This is a {{ promoted_group.name }} add-on.
{% if (amo.promoted.PROMOTED_GROUP_CHOICES.RECOMMENDED in promoted_group.group_id and not action_allowed_for(request.user, amo.permissions.ADDONS_RECOMMENDED_REVIEW)) or
(promoted_group.admin_review|python_any and not action_allowed_for(request.user, amo.permissions.REVIEWS_ADMIN)) %}
This is a {{ promoted_groups.get_names(needs_badged=False) }} add-on.
{% if (amo.promoted.PROMOTED_GROUP_CHOICES.RECOMMENDED in promoted_groups.group_id and not action_allowed_for(request.user, amo.permissions.ADDONS_RECOMMENDED_REVIEW)) or
(promoted_groups.admin_review|python_any and not action_allowed_for(request.user, amo.permissions.REVIEWS_ADMIN)) %}
You don't have permission to review it.
{% endif %}
</p>
Expand Down
4 changes: 2 additions & 2 deletions src/olympia/reviewers/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ def review(request, addon, channel=None):
channel, content_review = determine_channel(channel)

is_static_theme = addon.type == amo.ADDON_STATICTHEME
promoted_group = addon.promoted_groups(currently_approved=False)
promoted_groups = addon.promoted_groups(currently_approved=False)

# Are we looking at an unlisted review page, or (weirdly) the listed
# review page of an unlisted-only add-on?
Expand Down Expand Up @@ -764,7 +764,7 @@ def review(request, addon, channel=None):
and version.is_unreviewed
and not version.pending_rejection
),
promoted_group=promoted_group,
promoted_groups=promoted_groups,
name_translations=name_translations,
now=datetime.now(),
num_pages=num_pages,
Expand Down
Loading