Skip to content

Commit

Permalink
Add ACCOUNT_GROUPS and SOCIALACCOUNT_GROUPS to settings
Browse files Browse the repository at this point in the history
  • Loading branch information
jochenklar committed Oct 19, 2023
1 parent 9ef195e commit 7d60faf
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
19 changes: 19 additions & 0 deletions rdmo/accounts/adapter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.conf import settings
from django.contrib.auth.models import Group

from allauth.account.adapter import DefaultAccountAdapter
from allauth.socialaccount.adapter import DefaultSocialAccountAdapter
Expand All @@ -9,8 +10,26 @@ class AccountAdapter(DefaultAccountAdapter):
def is_open_for_signup(self, request):
return settings.ACCOUNT_SIGNUP

def save_user(self, request, user, form, commit=True):
user = super().save_user(request, user, form, commit)

if settings.ACCOUNT_GROUPS:
groups = Group.objects.filter(name__in=settings.ACCOUNT_GROUPS)
user.groups.set(groups)

return user

class SocialAccountAdapter(DefaultSocialAccountAdapter):

def is_open_for_signup(self, request, sociallogin):
return settings.SOCIALACCOUNT_SIGNUP

def save_user(self, request, sociallogin, form=None):
user = super().save_user(request, sociallogin, form)

if settings.SOCIALACCOUNT_GROUPS:
provider = str(sociallogin.account.provider)
groups = Group.objects.filter(name__in=settings.SOCIALACCOUNT_GROUPS.get(provider, []))
user.groups.set(groups)

return user
21 changes: 10 additions & 11 deletions rdmo/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,9 @@

ACCOUNT = False
ACCOUNT_SIGNUP = False
ACCOUNT_GROUPS = []
ACCOUNT_TERMS_OF_USE = False

SOCIALACCOUNT = False

SHIBBOLETH = False
SHIBBOLETH_LOGIN_URL = '/Shibboleth.sso/Login'
SHIBBOLETH_LOGOUT_URL = '/Shibboleth.sso/Logout'
SHIBBOLETH_USERNAME_PATTERN = None

ACCOUNT_ADAPTER = 'rdmo.accounts.adapter.AccountAdapter'
ACCOUNT_SIGNUP_FORM_CLASS = 'rdmo.accounts.forms.SignupForm'
ACCOUNT_USER_DISPLAY = 'rdmo.accounts.utils.get_full_name'
ACCOUNT_EMAIL_REQUIRED = True
Expand All @@ -120,11 +114,16 @@
ACCOUNT_PREVENT_ENUMERATION = False
ACCOUNT_ALLOW_USER_TOKEN = False

ACCOUNT_ADAPTER = 'rdmo.accounts.adapter.AccountAdapter'

SOCIALACCOUNT_ADAPTER = 'rdmo.accounts.adapter.SocialAccountAdapter'
SOCIALACCOUNT = False
SOCIALACCOUNT_SIGNUP = False
SOCIALACCOUNT_GROUPS = []
SOCIALACCOUNT_AUTO_SIGNUP = False
SOCIALACCOUNT_ADAPTER = 'rdmo.accounts.adapter.SocialAccountAdapter'

SHIBBOLETH = False
SHIBBOLETH_LOGIN_URL = '/Shibboleth.sso/Login'
SHIBBOLETH_LOGOUT_URL = '/Shibboleth.sso/Logout'
SHIBBOLETH_USERNAME_PATTERN = None

LANGUAGE_CODE = 'en-us'

Expand Down

0 comments on commit 7d60faf

Please sign in to comment.