mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-07-07 03:49:00 +00:00
perf: LDAP 测试 api 改为异步的
This commit is contained in:
parent
f20a4beef3
commit
fa21c83db3
@ -2,37 +2,44 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
import threading
|
import threading
|
||||||
from rest_framework import generics
|
|
||||||
from rest_framework.views import Response, APIView
|
|
||||||
from orgs.models import Organization
|
|
||||||
from django.utils.translation import ugettext_lazy as _
|
|
||||||
from django.conf import settings
|
|
||||||
|
|
||||||
from ..models import Setting
|
from django.conf import settings
|
||||||
from ..utils import (
|
from django.utils.translation import ugettext_lazy as _
|
||||||
LDAPServerUtil, LDAPCacheUtil, LDAPImportUtil, LDAPSyncUtil,
|
from rest_framework import generics
|
||||||
LDAP_USE_CACHE_FLAGS, LDAPTestUtil
|
from rest_framework.generics import CreateAPIView
|
||||||
)
|
from rest_framework.views import Response, APIView
|
||||||
from ..tasks import sync_ldap_user
|
|
||||||
|
from common.api import AsyncApiMixin
|
||||||
from common.utils import get_logger, is_uuid
|
from common.utils import get_logger, is_uuid
|
||||||
|
from orgs.models import Organization
|
||||||
|
from orgs.utils import current_org
|
||||||
|
from users.models import User
|
||||||
|
from ..models import Setting
|
||||||
from ..serializers import (
|
from ..serializers import (
|
||||||
LDAPTestConfigSerializer, LDAPUserSerializer,
|
LDAPTestConfigSerializer, LDAPUserSerializer,
|
||||||
LDAPTestLoginSerializer
|
LDAPTestLoginSerializer
|
||||||
)
|
)
|
||||||
from orgs.utils import current_org
|
from ..tasks import sync_ldap_user
|
||||||
from users.models import User
|
from ..utils import (
|
||||||
|
LDAPServerUtil, LDAPCacheUtil, LDAPImportUtil, LDAPSyncUtil,
|
||||||
|
LDAP_USE_CACHE_FLAGS, LDAPTestUtil
|
||||||
|
)
|
||||||
|
|
||||||
logger = get_logger(__file__)
|
logger = get_logger(__file__)
|
||||||
|
|
||||||
|
|
||||||
class LDAPTestingConfigAPI(APIView):
|
class LDAPTestingConfigAPI(AsyncApiMixin, CreateAPIView):
|
||||||
serializer_class = LDAPTestConfigSerializer
|
serializer_class = LDAPTestConfigSerializer
|
||||||
perm_model = Setting
|
perm_model = Setting
|
||||||
rbac_perms = {
|
rbac_perms = {
|
||||||
'POST': 'settings.change_auth'
|
'POST': 'settings.change_auth',
|
||||||
|
'create': 'settings.change_auth',
|
||||||
}
|
}
|
||||||
|
|
||||||
def post(self, request):
|
def is_need_async(self):
|
||||||
|
return True
|
||||||
|
|
||||||
|
def create(self, request, *args, **kwargs):
|
||||||
serializer = self.serializer_class(data=request.data)
|
serializer = self.serializer_class(data=request.data)
|
||||||
if not serializer.is_valid():
|
if not serializer.is_valid():
|
||||||
return Response({"error": str(serializer.errors)}, status=400)
|
return Response({"error": str(serializer.errors)}, status=400)
|
||||||
|
Loading…
Reference in New Issue
Block a user