Skip to content

Commit bf42f5e

Browse files
committed
fix: Deactivate mfa for OIDC_ONLY setting, otherwise not working
Fixes #274
1 parent 6eb8744 commit bf42f5e

4 files changed

Lines changed: 18 additions & 4 deletions

File tree

pdfding/core/settings/prod.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@
145145
SOCIALACCOUNT_ONLY = True
146146
ACCOUNT_EMAIL_VERIFICATION = 'none'
147147

148+
# need to remove mfa as not compatible with this setting
149+
INSTALLED_APPS.remove('allauth.mfa') # noqa: F405
150+
148151
OIDC_GROUPS_CLAIM = environ.get('OIDC_GROUPS_CLAIM', 'groups')
149152
OIDC_ADMIN_GROUP = environ.get('OIDC_ADMIN_GROUP', '')
150153
OIDC_EXTRA_SCOPE = environ.get('OIDC_EXTRA_SCOPE', '')

pdfding/e2e/test_users_e2e.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,11 @@ def test_settings_edit_cancel_viewer_settings(self):
191191
self.page.get_by_text("Cancel").click()
192192
expect(self.page.locator(name)).to_contain_text('Edit')
193193

194+
def test_settings_mfa_edit_visible(self):
195+
with sync_playwright() as p:
196+
self.open(reverse('account_settings'), p)
197+
expect(self.page.locator('#edit_mfa')).to_be_visible()
198+
194199
def test_settings_mfa_activated(self):
195200
Authenticator.objects.create(user=self.user, type='totp', data={})
196201

pdfding/users/models.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,12 @@ def collections(self) -> QuerySet:
191191
def mfa_activated(self) -> bool:
192192
"""Check if multi factor authentication is activated"""
193193

194-
if self.user.authenticator_set.count():
195-
return True
196-
else:
194+
try:
195+
if self.user.authenticator_set.count():
196+
return True
197+
else:
198+
return False
199+
except AttributeError: # pragma: no cover
197200
return False
198201

199202
@property

pdfding/users/templates/account_settings.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,12 @@
7171
{% endif %}
7272
</div>
7373
<div class="pr-0 md:pr-6">
74-
<a id="edit_mfa" href="{% url 'mfa_index' %}" class="cursor-pointer text-primary hover:text-secondary">
74+
{% url 'mfa_index' as mfa_index_url %}
75+
{% if mfa_index_url %}
76+
<a id="edit_mfa" href="{{ mfa_index_url }}" class="cursor-pointer text-primary hover:text-secondary">
7577
Edit
7678
</a>
79+
{% endif %}
7780
</div>
7881
</div>
7982
{% endif %}

0 commit comments

Comments
 (0)