Skip to content

Commit 0f45e3e

Browse files
github-actions[bot]matmairSchrodingersGat
authored
refactor(backend): SSO registration cleanup (#11239) (#11241)
* add more debugging and remove possible problematic inheritance * remove unused functions * remove extra conversion * ensure cirrect type is used --------- (cherry picked from commit e607756) Co-authored-by: Matthias Mair <code@mjmair.com> Co-authored-by: Oliver <oliver.henry.walters@gmail.com>
1 parent e3fcb83 commit 0f45e3e

File tree

4 files changed

+15
-21
lines changed

4 files changed

+15
-21
lines changed

docs/docs/settings/error_codes.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,13 @@ Therefore the registration user interface elements will not be shown.
174174

175175
To enable registration, the email settings must be configured correctly. See [email configuration](../start/config.md#email-settings).
176176

177+
#### INVE-W12
178+
**Signup attempt blocked because registration is disabled - Backend**
179+
180+
A user attempted to sign up but registration is currently disabled via the system settings. This is to prevent unauthorized or unwanted user registrations.
181+
182+
To enable registration, adjust the relevant settings (for regular or SSO registration) to allow user signups.
183+
177184
### INVE-I (InvenTree Information)
178185
Information — These are not errors but information messages. They might point out potential issues or just provide information.
179186

src/backend/InvenTree/InvenTree/api.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
from InvenTree import helpers
2626
from InvenTree.auth_overrides import registration_enabled
2727
from InvenTree.mixins import ListCreateAPI
28-
from InvenTree.sso import sso_registration_enabled
2928
from plugin.serializers import MetadataSerializer
3029
from users.models import ApiToken
3130
from users.permissions import check_user_permission
@@ -318,8 +317,8 @@ def get(self, request, *args, **kwargs):
318317
if (is_staff and settings.INVENTREE_ADMIN_ENABLED)
319318
else None,
320319
'settings': {
321-
'sso_registration': sso_registration_enabled(),
322-
'registration_enabled': registration_enabled(),
320+
'sso_registration': registration_enabled('LOGIN_ENABLE_SSO_REG'),
321+
'registration_enabled': registration_enabled('LOGIN_ENABLE_REG'),
323322
'password_forgotten_enabled': get_global_setting(
324323
'LOGIN_ENABLE_PWD_FORGOT'
325324
),

src/backend/InvenTree/InvenTree/auth_overrides.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from common.settings import get_global_setting
2020
from InvenTree.exceptions import log_error
2121

22+
from .helpers import str2bool
2223
from .helpers_email import is_email_configured
2324

2425
logger = structlog.get_logger('inventree')
@@ -91,7 +92,7 @@ def clean(self):
9192

9293
def registration_enabled(setting_name: RegistrationKeys = 'LOGIN_ENABLE_REG'):
9394
"""Determine whether user registration is enabled."""
94-
if get_global_setting(setting_name):
95+
if str2bool(get_global_setting(setting_name)):
9596
if is_email_configured():
9697
return True
9798
else:
@@ -112,7 +113,10 @@ def is_open_for_signup(self, request, *args, **kwargs):
112113
Configure the class variable `REGISTRATION_SETTING` to set which setting should be used, default: `LOGIN_ENABLE_REG`.
113114
"""
114115
if registration_enabled(self.REGISTRATION_SETTING):
115-
return super().is_open_for_signup(request, *args, **kwargs)
116+
return True
117+
logger.warning(
118+
f'INVE-W12: Signup attempt blocked, because registration is disabled via setting {self.REGISTRATION_SETTING}.'
119+
)
116120
return False
117121

118122
def clean_email(self, email):

src/backend/InvenTree/InvenTree/sso.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from allauth.socialaccount.models import SocialAccount, SocialLogin
1111

1212
from common.settings import get_global_setting
13-
from InvenTree.helpers import str2bool
1413

1514
logger = structlog.get_logger('inventree')
1615

@@ -69,21 +68,6 @@ def provider_display_name(provider):
6968
return provider.name
7069

7170

72-
def sso_login_enabled() -> bool:
73-
"""Return True if SSO login is enabled."""
74-
return str2bool(get_global_setting('LOGIN_ENABLE_SSO'))
75-
76-
77-
def sso_registration_enabled() -> bool:
78-
"""Return True if SSO registration is enabled."""
79-
return str2bool(get_global_setting('LOGIN_ENABLE_SSO_REG'))
80-
81-
82-
def auto_registration_enabled() -> bool:
83-
"""Return True if SSO auto-registration is enabled."""
84-
return str2bool(get_global_setting('LOGIN_SIGNUP_SSO_AUTO'))
85-
86-
8771
def ensure_sso_groups(sender, sociallogin: SocialLogin, **kwargs):
8872
"""Sync groups from IdP each time a SSO user logs on.
8973

0 commit comments

Comments
 (0)