Skip to content

Commit

Permalink
fix: usable waffle-flag admin
Browse files Browse the repository at this point in the history
- set `WAFFLE_ENABLE_ADMIN_PAGES=False`
- register waffle admins explicitly
    - customized `FlagAdmin` to work with many groups
    - `SwitchAdmin` and `SampleAdmin` left as-is
  • Loading branch information
aaxelb committed Sep 11, 2024
1 parent 9384d76 commit 5f14e81
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions api/base/settings/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,3 +364,5 @@

CITATION_STYLES_REPO_URL = 'https://github.com/CenterForOpenScience/styles/archive/88e6ed31a91e9f5a480b486029cda97b535935d4.zip'
DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'

WAFFLE_ENABLE_ADMIN_PAGES = False # instead, customized waffle admins in osf/admin.py
18 changes: 18 additions & 0 deletions osf/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from django.db.models import Q, Count
from django.http import HttpResponseRedirect
from django.urls import reverse
import waffle

from osf.external.spam.tasks import reclassify_domain_references
from osf.models import OSFUser, Node, NotableDomain, NodeLicense
Expand Down Expand Up @@ -140,7 +141,24 @@ def get_queryset(self, request):
qs = super().get_queryset(request).annotate(number_of_references=Count('domainreference'))
return qs


class _ManygroupWaffleFlagAdmin(waffle.admin.FlagAdmin):
'''customized `waffle.admin.FlagAdmin` to support many groups
waffle assumes "there are likely not that many" groups [0],
but in osf there are, in fact, that many groups.
[0]: https://github.com/jazzband/django-waffle/commit/bf36c19ee03baf1c5850ffe0b284900a5c416f53
'''
raw_id_fields = (*waffle.admin.FlagAdmin.raw_id_fields, 'groups')


admin.site.register(OSFUser, OSFUserAdmin)
admin.site.register(Node, NodeAdmin)
admin.site.register(NotableDomain, NotableDomainAdmin)
admin.site.register(NodeLicense, LicenseAdmin)

# waffle admins, with Flag admin override
admin.site.register(waffle.models.Flag, _ManygroupWaffleFlagAdmin)
admin.site.register(waffle.models.Sample, waffle.admin.SampleAdmin)
admin.site.register(waffle.models.Switch, waffle.admin.SwitchAdmin)

0 comments on commit 5f14e81

Please sign in to comment.