• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

inventree / InvenTree / 8395139503

22 Mar 2024 06:56PM UTC coverage: 92.794% (+0.003%) from 92.791%
8395139503

Pull #6821

github

web-flow
Merge df929157b into 9576b5015
Pull Request #6821: Bump @types/react from 18.2.67 to 18.2.68 in /src/frontend

31717 of 34180 relevant lines covered (92.79%)

0.93 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

16.0
/InvenTree/InvenTree/sso.py
1
"""Helper functions for Single Sign On functionality."""
2

3
import logging
4

5
from common.models import InvenTreeSetting
6
from InvenTree.helpers import str2bool
7

8
logger = logging.getLogger('inventree')
9

10

11
def get_provider_app(provider):
12
    """Return the SocialApp object for the given provider."""
13
    from allauth.socialaccount.models import SocialApp
×
14

15
    try:
×
16
        apps = SocialApp.objects.filter(provider__iexact=provider.id)
×
17
    except SocialApp.DoesNotExist:
×
18
        logger.warning("SSO SocialApp not found for provider '%s'", provider.id)
×
19
        return None
×
20

21
    if apps.count() > 1:
×
22
        logger.warning("Multiple SocialApps found for provider '%s'", provider.id)
×
23

24
    if apps.count() == 0:
×
25
        logger.warning("SSO SocialApp not found for provider '%s'", provider.id)
×
26

27
    return apps.first()
×
28

29

30
def check_provider(provider, raise_error=False):
1✔
31
    """Check if the given provider is correctly configured.
32

33
    To be correctly configured, the following must be true:
34

35
    - Provider must either have a registered SocialApp
36
    - Must have at least one site enabled
37
    """
38
    import allauth.app_settings
×
39

40
    # First, check that the provider is enabled
41
    app = get_provider_app(provider)
×
42

43
    if not app:
×
44
        return False
×
45

46
    if allauth.app_settings.SITES_ENABLED:
×
47
        # At least one matching site must be specified
48
        if not app.sites.exists():
×
49
            logger.error('SocialApp %s has no sites configured', app)
×
50
            return False
×
51

52
    # At this point, we assume that the provider is correctly configured
53
    return True
×
54

55

56
def provider_display_name(provider):
1✔
57
    """Return the 'display name' for the given provider."""
58
    if app := get_provider_app(provider):
59
        return app.name
60

61
    # Fallback value if app not found
62
    return provider.name
63

64

65
def login_enabled() -> bool:
66
    """Return True if SSO login is enabled."""
67
    return str2bool(InvenTreeSetting.get_setting('LOGIN_ENABLE_SSO'))
1✔
68

69

70
def registration_enabled() -> bool:
1✔
71
    """Return True if SSO registration is enabled."""
72
    return str2bool(InvenTreeSetting.get_setting('LOGIN_ENABLE_SSO_REG'))
73

74

75
def auto_registration_enabled() -> bool:
76
    """Return True if SSO auto-registration is enabled."""
77
    return str2bool(InvenTreeSetting.get_setting('LOGIN_SIGNUP_SSO_AUTO'))
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc