2021-08-12 08:44:06 +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
|
2021-08-12 08:44:06 +00:00
|
|
|
from common.mixins.api import RoleUserMixin, RoleAdminMixin
|
2022-07-04 03:29:39 +00:00
|
|
|
from authentication.const import ConfirmType
|
2021-08-12 08:44:06 +00:00
|
|
|
from authentication import errors
|
|
|
|
|
|
|
|
logger = get_logger(__file__)
|
|
|
|
|
|
|
|
|
|
|
|
class FeiShuQRUnBindBase(APIView):
|
|
|
|
user: User
|
|
|
|
|
|
|
|
def post(self, request: Request, **kwargs):
|
|
|
|
user = self.user
|
|
|
|
|
|
|
|
if not user.feishu_id:
|
|
|
|
raise errors.FeiShuNotBound
|
|
|
|
|
|
|
|
user.feishu_id = None
|
|
|
|
user.save()
|
|
|
|
return Response()
|
|
|
|
|
|
|
|
|
|
|
|
class FeiShuQRUnBindForUserApi(RoleUserMixin, FeiShuQRUnBindBase):
|
2022-07-04 03:29:39 +00:00
|
|
|
permission_classes = (UserConfirmation.require(ConfirmType.ReLogin),)
|
2021-08-12 08:44:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
class FeiShuQRUnBindForAdminApi(RoleAdminMixin, FeiShuQRUnBindBase):
|
|
|
|
user_id_url_kwarg = 'user_id'
|
|
|
|
|
|
|
|
|
|
|
|
class FeiShuEventSubscriptionCallback(APIView):
|
|
|
|
"""
|
|
|
|
# https://open.feishu.cn/document/ukTMukTMukTM/uUTNz4SN1MjL1UzM
|
|
|
|
"""
|
|
|
|
permission_classes = ()
|
|
|
|
|
|
|
|
def post(self, request: Request, *args, **kwargs):
|
|
|
|
return Response(data=request.data)
|