Skip to content

Commit

Permalink
[#1027] Disabled applications dropdown in 2factor admin
Browse files Browse the repository at this point in the history
  • Loading branch information
vaszig committed Mar 24, 2023
1 parent 462a316 commit 8ee7a9c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/open_inwoner/conf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,9 @@
#
TWO_FACTOR_FORCE_OTP_ADMIN = config("TWO_FACTOR_FORCE_OTP_ADMIN", default=not DEBUG)
TWO_FACTOR_PATCH_ADMIN = config("TWO_FACTOR_PATCH_ADMIN", default=True)
ADMIN_INDEX_DISPLAY_DROP_DOWN_MENU_CONDITION_FUNCTION = (
"open_inwoner.utils.django_two_factor_auth.should_display_dropdown_menu"
)

# file upload limits
MIN_UPLOAD_SIZE = 1 # in bytes
Expand Down
19 changes: 19 additions & 0 deletions src/open_inwoner/utils/django_two_factor_auth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from django.conf import settings

from django_admin_index.utils import (
should_display_dropdown_menu as default_should_display_dropdown_menu,
)


def should_display_dropdown_menu(request) -> bool:
default = default_should_display_dropdown_menu(request)

two_factor_enabled = settings.TWO_FACTOR_PATCH_ADMIN
if not two_factor_enabled:
return default

# never display the dropdown in two-factor admin views
if request.resolver_match.view_name.startswith("admin:two_factor:"):
return False

return default and request.user.is_verified()

0 comments on commit 8ee7a9c

Please sign in to comment.