Skip to content

Commit b4de44b

Browse files
committed
[fix] Allowed managing social auth secrets when needed
Before, OpenWISP Users removed the ``allauth.socialaccount`` admin sections to keep the admin UI simple, but over time more users need this to support OAuth/SAML authentication to the admin interface (manage app secrets). With this change, the admin allows managing app secrets if any ``allauth.socialaccount.provider`` is installed, eg: microsoft, google, openid, etc. [backport 1.2] (cherry picked from commit 8c19f71)
1 parent 9d8790a commit b4de44b

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

openwisp_users/admin.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -652,11 +652,14 @@ def get_user(self, obj):
652652
admin.site.unregister(EmailAddress)
653653

654654
if allauth_settings.SOCIALACCOUNT_ENABLED:
655-
for model in [
656-
("socialaccount", "SocialApp"),
655+
socialaccount_models = [
657656
("socialaccount", "SocialToken"),
658657
("socialaccount", "SocialAccount"),
659-
]:
658+
]
659+
# Allow managing secrets if OAuth/SAML is enabled
660+
if not app_settings.SOCIALACCOUNT_ADMIN_NEEDED:
661+
socialaccount_models.append(("socialaccount", "SocialApp"))
662+
for model in socialaccount_models:
660663
model_class = apps.get_model(*model)
661664
if admin.site.is_registered(model_class):
662665
admin.site.unregister(model_class)

openwisp_users/settings.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,12 @@
4949
"openwisp_users.views.AutocompleteJsonView",
5050
),
5151
)
52+
53+
# if OAuth/SAML is enabled, allow manging keys/secrets
54+
if any(
55+
app.startswith("allauth.socialaccount.providers") for app in settings.INSTALLED_APPS
56+
): # pragma: no cover
57+
SOCIALACCOUNT_ADMIN_NEEDED = True
58+
# otherwise hide the socialaccount admin (not needed)
59+
else:
60+
SOCIALACCOUNT_ADMIN_NEEDED = False

0 commit comments

Comments
 (0)