jumpserver/apps/authentication/api/dingtalk.py

36 lines
1010 B
Python
Raw Normal View History

from rest_framework.request import Request
from rest_framework.response import Response
2023-09-13 09:05:01 +00:00
from rest_framework.views import APIView
from authentication import errors
2023-09-13 09:05:01 +00:00
from authentication.const import ConfirmType
from authentication.permissions import UserConfirmation
2023-09-13 09:05:01 +00:00
from common.api import RoleUserMixin, RoleAdminMixin
from common.permissions import IsValidUser
2023-09-13 09:05:01 +00:00
from common.utils import get_logger
from users.models import User
logger = get_logger(__file__)
class DingTalkQRUnBindBase(APIView):
user: User
def post(self, request: Request, **kwargs):
user = self.user
if not user.dingtalk_id:
raise errors.DingTalkNotBound
2021-05-18 05:55:44 +00:00
user.dingtalk_id = None
user.save()
return Response()
class DingTalkQRUnBindForUserApi(RoleUserMixin, DingTalkQRUnBindBase):
permission_classes = (IsValidUser, UserConfirmation.require(ConfirmType.RELOGIN),)
class DingTalkQRUnBindForAdminApi(RoleAdminMixin, DingTalkQRUnBindBase):
user_id_url_kwarg = 'user_id'