mirror of https://github.com/jumpserver/jumpserver
perf: LDAP 测试 api 改为异步的
parent
f20a4beef3
commit
fa21c83db3
|
@ -2,37 +2,44 @@
|
|||
#
|
||||
|
||||
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 ..utils import (
|
||||
LDAPServerUtil, LDAPCacheUtil, LDAPImportUtil, LDAPSyncUtil,
|
||||
LDAP_USE_CACHE_FLAGS, LDAPTestUtil
|
||||
)
|
||||
from ..tasks import sync_ldap_user
|
||||
from django.conf import settings
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from rest_framework import generics
|
||||
from rest_framework.generics import CreateAPIView
|
||||
from rest_framework.views import Response, APIView
|
||||
|
||||
from common.api import AsyncApiMixin
|
||||
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 (
|
||||
LDAPTestConfigSerializer, LDAPUserSerializer,
|
||||
LDAPTestLoginSerializer
|
||||
)
|
||||
from orgs.utils import current_org
|
||||
from users.models import User
|
||||
from ..tasks import sync_ldap_user
|
||||
from ..utils import (
|
||||
LDAPServerUtil, LDAPCacheUtil, LDAPImportUtil, LDAPSyncUtil,
|
||||
LDAP_USE_CACHE_FLAGS, LDAPTestUtil
|
||||
)
|
||||
|
||||
logger = get_logger(__file__)
|
||||
|
||||
|
||||
class LDAPTestingConfigAPI(APIView):
|
||||
class LDAPTestingConfigAPI(AsyncApiMixin, CreateAPIView):
|
||||
serializer_class = LDAPTestConfigSerializer
|
||||
perm_model = Setting
|
||||
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)
|
||||
if not serializer.is_valid():
|
||||
return Response({"error": str(serializer.errors)}, status=400)
|
||||
|
|
Loading…
Reference in New Issue