Skip to content

Commit b38e1d6

Browse files
committed
[#2076] Fix admin index with 2fa
1 parent e7a0507 commit b38e1d6

File tree

5 files changed

+32
-18
lines changed

5 files changed

+32
-18
lines changed

requirements/dev.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ django-elasticsearch-dsl==7.2.1
312312
# via
313313
# -c requirements/ci.txt
314314
# -r requirements/ci.txt
315-
django-extensions==3.1.3
315+
django-extensions==3.2.3
316316
# via -r requirements/dev.in
317317
django-extra-fields==3.0.2
318318
# via

src/open_inwoner/conf/base.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -480,11 +480,6 @@
480480
"open_inwoner.accounts.backends.CustomOIDCBackend",
481481
]
482482

483-
# Allowing OIDC admins to bypass 2FA
484-
MAYKIN_2FA_ALLOW_MFA_BYPASS_BACKENDS = [
485-
"open_inwoner.accounts.backends.CustomOIDCBackend",
486-
]
487-
488483

489484
SESSION_COOKIE_NAME = "open_inwoner_sessionid"
490485
SESSION_ENGINE = "django.contrib.sessions.backends.cache"
@@ -609,6 +604,11 @@
609604
ADMIN_INDEX_SHOW_REMAINING_APPS = False
610605
ADMIN_INDEX_AUTO_CREATE_APP_GROUP = False
611606
ADMIN_INDEX_SHOW_REMAINING_APPS_TO_SUPERUSERS = False
607+
ADMIN_INDEX_SHOW_MENU = True
608+
ADMIN_INDEX_DISPLAY_DROP_DOWN_MENU_CONDITION_FUNCTION = (
609+
"open_inwoner.utils.django_two_factor_auth.should_display_dropdown_menu"
610+
)
611+
612612

613613
#
614614
# DJANGO-AXES (4.0+)
@@ -816,6 +816,10 @@
816816
TWO_FACTOR_PATCH_ADMIN = False
817817
TWO_FACTOR_WEBAUTHN_RP_NAME = f"OpenInwoner {ENVIRONMENT}"
818818
TWO_FACTOR_WEBAUTHN_AUTHENTICATOR_ATTACHMENT = "cross-platform"
819+
# Allow OIDC admins to bypass 2FA
820+
MAYKIN_2FA_ALLOW_MFA_BYPASS_BACKENDS = [
821+
"open_inwoner.accounts.backends.CustomOIDCBackend",
822+
]
819823

820824
# file upload limits
821825
MIN_UPLOAD_SIZE = 1 # in bytes

src/open_inwoner/conf/ci.py

-4
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@
6060
# Django privates
6161
SENDFILE_BACKEND = "django_sendfile.backends.development"
6262

63-
# Two factor auth
64-
TWO_FACTOR_FORCE_OTP_ADMIN = False
65-
TWO_FACTOR_PATCH_ADMIN = False
66-
6763
# THOU SHALT NOT USE NAIVE DATETIMES
6864
warnings.filterwarnings(
6965
"error",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Generated by Django 3.2.23 on 2024-02-07 15:19
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
("configurations", "0058_siteconfiguration_recipients_email_digest"),
10+
]
11+
12+
operations = [
13+
migrations.AlterModelOptions(
14+
name="siteconfigurationpage",
15+
options={
16+
"ordering": ("order",),
17+
"verbose_name": "Flatpage in the footer",
18+
"verbose_name_plural": "Flatpages in the footer",
19+
},
20+
),
21+
]
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from django.conf import settings
2-
31
from django_admin_index.utils import (
42
should_display_dropdown_menu as default_should_display_dropdown_menu,
53
)
@@ -8,12 +6,7 @@
86
def should_display_dropdown_menu(request) -> bool:
97
default = default_should_display_dropdown_menu(request)
108

11-
two_factor_enabled = settings.TWO_FACTOR_PATCH_ADMIN
12-
if not two_factor_enabled:
13-
return default
14-
15-
# never display the dropdown in two-factor admin views
16-
if request.resolver_match.view_name.startswith("admin:two_factor:"):
9+
if request.resolver_match.view_name.startswith("maykin_2fa"):
1710
return False
1811

1912
return default and request.user.is_verified()

0 commit comments

Comments
 (0)