11"""Overrides for allauth and adjacent packages to enforce InvenTree specific auth settings and restirctions."""
22
3+ from typing import Literal
4+
35from django import forms
46from django .conf import settings
57from django .contrib .auth .models import Group
1416from allauth .headless .adapter import DefaultHeadlessAdapter
1517from allauth .socialaccount .adapter import DefaultSocialAccountAdapter
1618
17- import InvenTree .sso
1819from common .settings import get_global_setting
1920from InvenTree .exceptions import log_error
2021
@@ -85,12 +86,12 @@ def clean(self):
8586 return cleaned_data
8687
8788
88- def registration_enabled ():
89+ RegistrationKeys = Literal ['LOGIN_ENABLE_REG' , 'LOGIN_ENABLE_SSO_REG' ]
90+
91+
92+ def registration_enabled (setting_name : RegistrationKeys = 'LOGIN_ENABLE_REG' ):
8993 """Determine whether user registration is enabled."""
90- if (
91- get_global_setting ('LOGIN_ENABLE_REG' )
92- or InvenTree .sso .sso_registration_enabled ()
93- ):
94+ if get_global_setting (setting_name ):
9495 if is_email_configured ():
9596 return True
9697 else :
@@ -103,12 +104,14 @@ def registration_enabled():
103104class RegistrationMixin :
104105 """Mixin to check if registration should be enabled."""
105106
107+ REGISTRATION_SETTING : RegistrationKeys = 'LOGIN_ENABLE_REG'
108+
106109 def is_open_for_signup (self , request , * args , ** kwargs ):
107110 """Check if signup is enabled in settings.
108111
109112 Configure the class variable `REGISTRATION_SETTING` to set which setting should be used, default: `LOGIN_ENABLE_REG`.
110113 """
111- if registration_enabled ():
114+ if registration_enabled (self . REGISTRATION_SETTING ):
112115 return super ().is_open_for_signup (request , * args , ** kwargs )
113116 return False
114117
@@ -187,6 +190,8 @@ def send_password_reset_mail(self, user, email, context):
187190class CustomSocialAccountAdapter (RegistrationMixin , DefaultSocialAccountAdapter ):
188191 """Override of adapter to use dynamic settings."""
189192
193+ REGISTRATION_SETTING = 'LOGIN_ENABLE_SSO_REG'
194+
190195 def is_auto_signup_allowed (self , request , sociallogin ):
191196 """Check if auto signup is enabled in settings."""
192197 if get_global_setting ('LOGIN_SIGNUP_SSO_AUTO' , True ):
0 commit comments