Skip to content

Commit ae56a88

Browse files
authored
Add PromotedGroupAdmin (#23321)
1 parent f5594b0 commit ae56a88

File tree

4 files changed

+82
-0
lines changed

4 files changed

+82
-0
lines changed

src/olympia/constants/permissions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@
177177
'discovery.add_discoveryaddon': DISCOVERY_EDIT,
178178
'discovery.change_discoveryaddon': DISCOVERY_EDIT,
179179
'discovery.delete_discoveryaddon': DISCOVERY_EDIT,
180+
'discovery.view_discoverypromotedgroup': DISCOVERY_EDIT,
180181
'files.change_file': ADMIN_ADVANCED,
181182
'files.change_webextpermission': ADMIN_ADVANCED,
182183
'files.change_filevalidation': ADMIN_ADVANCED,

src/olympia/discovery/admin.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
from olympia.promoted.admin import (
2525
PromotedAddonPromotionAdminInline,
2626
PromotedAddonVersionInline,
27+
PromotedGroupAdmin,
2728
)
29+
from olympia.promoted.models import PromotedGroup
2830
from olympia.shelves.admin import ShelfAdmin
2931
from olympia.shelves.models import Shelf
3032

@@ -203,6 +205,11 @@ class Meta:
203205
proxy = True
204206

205207

208+
class DiscoveryPromotedGroup(PromotedGroup):
209+
class Meta:
210+
proxy = True
211+
212+
206213
DISCOVERY_ADDON_FIELDS = ['__str__', 'addon', 'guid', 'has_promotions']
207214

208215

@@ -244,6 +251,7 @@ def has_promotions(self, obj):
244251

245252

246253
admin.site.register(DiscoveryAddon, DiscoveryAddonAdmin)
254+
admin.site.register(DiscoveryPromotedGroup, PromotedGroupAdmin)
247255
admin.site.register(DiscoveryItem, DiscoveryItemAdmin)
248256
admin.site.register(PrimaryHeroImageUpload, PrimaryHeroImageAdmin)
249257
admin.site.register(SecondaryHeroShelf, SecondaryHeroAdmin)

src/olympia/promoted/admin.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from django.forms.models import modelformset_factory
44

55
from olympia.addons.models import Addon
6+
from olympia.amo.admin import AMOModelAdmin
67
from olympia.constants.promoted import PROMOTED_GROUP_CHOICES
78
from olympia.hero.models import PrimaryHero
89
from olympia.versions.models import Version
@@ -117,3 +118,32 @@ def has_delete_permission(self, request, obj=None):
117118
if shelf and shelf.enabled and qs.count() == 1:
118119
return False
119120
return super().has_delete_permission(request=request, obj=obj)
121+
122+
123+
class PromotedGroupAdmin(AMOModelAdmin):
124+
model = PromotedGroup
125+
list_display = [
126+
'name',
127+
'listed_pre_review',
128+
'unlisted_pre_review',
129+
'admin_review',
130+
'badged',
131+
'can_primary_hero',
132+
'flag_for_human_review',
133+
'can_be_compatible_with_all_fenix_versions',
134+
'high_profile',
135+
'high_profile_rating',
136+
'search_ranking_bump',
137+
'active',
138+
]
139+
list_filter = list_display
140+
search_fields = ('name',)
141+
142+
def has_add_permission(self, request, obj=None):
143+
return False
144+
145+
def has_change_permission(self, request, obj=None):
146+
return False
147+
148+
def has_delete_permission(self, request, obj=None):
149+
return False

src/olympia/promoted/tests/test_admin.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,49 @@
1919
)
2020

2121

22+
class TestDiscoveryPromotedGroupAdmin(TestCase):
23+
def setUp(self):
24+
self.list_url_name = 'admin:discovery_discoverypromotedgroup_changelist'
25+
26+
def test_can_see_in_admin_with_discovery_edit(self):
27+
user = user_factory(email='someone@mozilla.com')
28+
self.grant_permission(user, 'Discovery:Edit')
29+
self.client.force_login(user)
30+
url = reverse('admin:index')
31+
response = self.client.get(url)
32+
assert response.status_code == 200
33+
34+
# Use django's reverse, since that's what the admin will use. Using our
35+
# own would fail the assertion because of the locale that gets added.
36+
self.list_url = django_reverse(self.list_url_name)
37+
assert self.list_url in response.content.decode('utf-8')
38+
39+
def test_cannot_see_in_admin_without_discovery_edit(self):
40+
user = user_factory(email='someone@mozilla.com')
41+
self.client.force_login(user)
42+
url = reverse('admin:index')
43+
response = self.client.get(url)
44+
assert response.status_code == 200
45+
46+
self.list_url = django_reverse(self.list_url_name)
47+
assert self.list_url not in response.content.decode('utf-8')
48+
49+
def test_can_list_with_discovery_edit(self):
50+
addon_factory(name='FooBâr')
51+
user = user_factory(email='someone@mozilla.com')
52+
self.grant_permission(user, 'Discovery:Edit')
53+
self.client.force_login(user)
54+
response = self.client.get(reverse(self.list_url_name), follow=True)
55+
assert response.status_code == 200
56+
57+
def test_cannot_list_without_discovery_edit(self):
58+
addon_factory(name='FooBâr')
59+
user = user_factory(email='someone@mozilla.com')
60+
self.client.force_login(user)
61+
response = self.client.get(reverse(self.list_url_name), follow=True)
62+
assert response.status_code == 403
63+
64+
2265
class TestDiscoveryAddonAdmin(TestCase):
2366
def setUp(self):
2467
self.list_url = reverse('admin:discovery_discoveryaddon_changelist')

0 commit comments

Comments
 (0)