This commit is contained in:
wh1te909 2024-10-18 20:26:53 +00:00 committed by sadnub
parent 899111a310
commit 61790d2261
3 changed files with 10 additions and 11 deletions

View File

@ -1,8 +1,9 @@
from rest_framework import permissions
from allauth.socialaccount.models import SocialAccount
class SSOLoginPerms(permissions.BasePermission):
def has_permission(self, r, view):
connected_apps = SocialAccount.objects.filter(user=r.user)
return len(connected_apps) > 0
return len(connected_apps) > 0

View File

@ -23,6 +23,7 @@ from logs.models import AuditLog
from tacticalrmm.utils import get_core_settings
from .permissions import SSOLoginPerms
class SocialAppSerializer(ModelSerializer):
server_url = ReadOnlyField(source="settings.server_url")
role = ReadOnlyField(source="settings.role")
@ -63,7 +64,7 @@ class GetAddSSOProvider(APIView):
"provider",
"provider_id",
"settings",
"role"
"role",
]
# removed any special characters and replaces spaces with a hyphen
@ -112,9 +113,7 @@ class GetUpdateDeleteSSOProvider(APIView):
data["settings"]["server_url"] = data["server_url"]
data["settings"]["role"] = data["role"] if data["role"] else None
serializer = self.InputSerialzer(
instance=provider, data=data, partial=True
)
serializer = self.InputSerialzer(instance=provider, data=data, partial=True)
serializer.is_valid(raise_exception=True)
serializer.save()
return Response("ok")
@ -130,9 +129,9 @@ class GetAccessToken(KnoxLoginView):
authentication_classes = [SessionAuthentication]
def post(self, request, format=None):
core = get_core_settings()
# check for auth method before signing in
if (
core.sso_enabled
@ -163,9 +162,7 @@ class GetAccessToken(KnoxLoginView):
return Response(response.data)
else:
logout(request)
return Response(
"No pending login session found", status.HTTP_403_FORBIDDEN
)
return Response("No pending login session found", status.HTTP_403_FORBIDDEN)
class GetUpdateSSOSettings(APIView):
@ -178,7 +175,7 @@ class GetUpdateSSOSettings(APIView):
return Response(
{
"block_local_user_logon": core_settings.block_local_user_logon,
"sso_enabled": core_settings.sso_enabled
"sso_enabled": core_settings.sso_enabled,
}
)

View File

@ -9,6 +9,7 @@ from ee.sso.urls import allauth_urls
from core.consumers import DashInfo, TerminalConsumer
from core.views import home
class AgentIDConverter:
regex = "[^/]{20}[^/]+"