Skip to content

Commit db1ef13

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

File tree

9 files changed

+41
-24
lines changed

9 files changed

+41
-24
lines changed

requirements/base.txt

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ diff-match-patch==20200713
8080
django==3.2.23
8181
# via
8282
# -r requirements/base.in
83+
# django-admin-index
8384
# django-appconf
8485
# django-appdata
8586
# django-axes

requirements/ci.txt

+3-2
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ django==3.2.23
152152
# via
153153
# -c requirements/base.txt
154154
# -r requirements/base.txt
155+
# django-admin-index
155156
# django-appconf
156157
# django-appdata
157158
# django-axes
@@ -196,7 +197,7 @@ django==3.2.23
196197
# mozilla-django-oidc-db
197198
# notifications-api-common
198199
# zgw-consumers
199-
django-admin-index==1.5.0
200+
django-admin-index==3.1.0
200201
# via
201202
# -c requirements/base.txt
202203
# -r requirements/base.txt
@@ -330,7 +331,7 @@ django-open-forms-client==0.2.3
330331
# via
331332
# -c requirements/base.txt
332333
# -r requirements/base.txt
333-
django-ordered-model==3.4.3
334+
django-ordered-model==3.7.4
334335
# via
335336
# -c requirements/base.txt
336337
# -r requirements/base.txt

requirements/dev.txt

+4-3
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ django==3.2.23
185185
# -c requirements/ci.txt
186186
# -r requirements/ci.txt
187187
# ddt-api-calls
188+
# django-admin-index
188189
# django-appconf
189190
# django-appdata
190191
# django-axes
@@ -231,7 +232,7 @@ django==3.2.23
231232
# mozilla-django-oidc-db
232233
# notifications-api-common
233234
# zgw-consumers
234-
django-admin-index==1.5.0
235+
django-admin-index==3.1.0
235236
# via
236237
# -c requirements/ci.txt
237238
# -r requirements/ci.txt
@@ -312,7 +313,7 @@ django-elasticsearch-dsl==7.2.1
312313
# via
313314
# -c requirements/ci.txt
314315
# -r requirements/ci.txt
315-
django-extensions==3.1.3
316+
django-extensions==3.2.3
316317
# via -r requirements/dev.in
317318
django-extra-fields==3.0.2
318319
# via
@@ -369,7 +370,7 @@ django-open-forms-client==0.2.3
369370
# via
370371
# -c requirements/ci.txt
371372
# -r requirements/ci.txt
372-
django-ordered-model==3.4.3
373+
django-ordered-model==3.7.4
373374
# via
374375
# -c requirements/ci.txt
375376
# -r requirements/ci.txt

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+
]

src/open_inwoner/configurations/models.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ class SiteConfigurationPage(OrderedModel):
611611

612612
objects = OrderedModelManager()
613613

614-
class Meta:
614+
class Meta(OrderedModel.Meta):
615615
verbose_name = _("Flatpage in the footer")
616616
verbose_name_plural = _("Flatpages in the footer")
617617

src/open_inwoner/pdc/models/product.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ class ProductCondition(OrderedModel):
414414
help_text=_("Rule for the automated check"),
415415
)
416416

417-
class Meta:
417+
class Meta(OrderedModel.Meta):
418418
verbose_name = _("Condition")
419419
verbose_name_plural = _("Conditions")
420420
ordering = ("order",)
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)