2021-03-24 11:01:35 +00:00
|
|
|
from rest_framework.views import APIView
|
|
|
|
from rest_framework.request import Request
|
|
|
|
from rest_framework.response import Response
|
|
|
|
|
|
|
|
from users.models import User
|
|
|
|
from common.utils import get_logger
|
2022-07-04 03:29:39 +00:00
|
|
|
from common.permissions import UserConfirmation
|
2023-01-16 11:02:09 +00:00
|
|
|
from common.api import RoleUserMixin, RoleAdminMixin
|
2022-07-04 03:29:39 +00:00
|
|
|
from authentication.const import ConfirmType
|
2021-03-24 11:01:35 +00:00
|
|
|
from authentication import errors
|
|
|
|
|
|
|
|
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
|
2021-03-24 11:01:35 +00:00
|
|
|
user.save()
|
|
|
|
return Response()
|
|
|
|
|
|
|
|
|
|
|
|
class DingTalkQRUnBindForUserApi(RoleUserMixin, DingTalkQRUnBindBase):
|
2022-07-04 03:29:39 +00:00
|
|
|
permission_classes = (UserConfirmation.require(ConfirmType.ReLogin),)
|
2021-03-24 11:01:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
class DingTalkQRUnBindForAdminApi(RoleAdminMixin, DingTalkQRUnBindBase):
|
|
|
|
user_id_url_kwarg = 'user_id'
|