don't show providers list on login screen if sso is disabled globally
This commit is contained in:
parent
8d543dcc7d
commit
2cbecaa552
|
@ -6,21 +6,35 @@ For details, see: https://license.tacticalrmm.com/ee
|
||||||
|
|
||||||
from allauth.socialaccount.adapter import DefaultSocialAccountAdapter
|
from allauth.socialaccount.adapter import DefaultSocialAccountAdapter
|
||||||
from allauth.socialaccount.models import SocialApp
|
from allauth.socialaccount.models import SocialApp
|
||||||
|
from django.core.exceptions import PermissionDenied
|
||||||
|
|
||||||
from accounts.models import Role
|
from accounts.models import Role
|
||||||
|
from core.utils import token_is_valid
|
||||||
|
from tacticalrmm.logger import logger
|
||||||
|
from tacticalrmm.utils import get_core_settings
|
||||||
|
|
||||||
|
|
||||||
class TacticalSocialAdapter(DefaultSocialAccountAdapter):
|
class TacticalSocialAdapter(DefaultSocialAccountAdapter):
|
||||||
|
|
||||||
def populate_user(self, request, sociallogin, data):
|
def populate_user(self, request, sociallogin, data):
|
||||||
|
_, valid = token_is_valid()
|
||||||
|
if not valid:
|
||||||
|
raise PermissionDenied()
|
||||||
|
|
||||||
user = super().populate_user(request, sociallogin, data)
|
user = super().populate_user(request, sociallogin, data)
|
||||||
try:
|
try:
|
||||||
provider = sociallogin.account.get_provider()
|
provider = sociallogin.account.get_provider()
|
||||||
provider_settings = SocialApp.objects.get(provider_id=provider).settings
|
provider_settings = SocialApp.objects.get(provider_id=provider).settings
|
||||||
user.role = Role.objects.get(pk=provider_settings["role"])
|
user.role = Role.objects.get(pk=provider_settings["role"])
|
||||||
except:
|
except Exception:
|
||||||
print(
|
logger.debug(
|
||||||
"Provider settings or Role not found. Continuing with blank permissions."
|
"Provider settings or Role not found. Continuing with blank permissions."
|
||||||
)
|
)
|
||||||
return user
|
return user
|
||||||
|
|
||||||
|
def list_providers(self, request):
|
||||||
|
core_settings = get_core_settings()
|
||||||
|
if not core_settings.sso_enabled:
|
||||||
|
return []
|
||||||
|
|
||||||
|
return super().list_providers(request)
|
||||||
|
|
Loading…
Reference in New Issue