2021-03-24 11:01:35 +00:00
|
|
|
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
|
2021-03-24 11:01:35 +00:00
|
|
|
|
|
|
|
from authentication import errors
|
2023-09-13 09:05:01 +00:00
|
|
|
from authentication.const import ConfirmType
|
2023-10-12 08:17:32 +00:00
|
|
|
from authentication.permissions import UserConfirmation
|
2023-09-13 09:05:01 +00:00
|
|
|
from common.api import RoleUserMixin, RoleAdminMixin
|
2023-10-12 08:17:32 +00:00
|
|
|
from common.permissions import IsValidUser
|
2023-09-13 09:05:01 +00:00
|
|
|
from common.utils import get_logger
|
|
|
|
from users.models import User
|
2021-03-24 11:01:35 +00:00
|
|
|
|
|
|
|
logger = get_logger(__file__)
|
|
|
|
|
|
|
|
|
|
|
|
class WeComQRUnBindBase(APIView):
|
|
|
|
user: User
|
|
|
|
|
|
|
|
def post(self, request: Request, **kwargs):
|
|
|
|
user = self.user
|
|
|
|
|
|
|
|
if not user.wecom_id:
|
|
|
|
raise errors.WeComNotBound
|
|
|
|
|
2021-05-18 05:55:44 +00:00
|
|
|
user.wecom_id = None
|
2021-03-24 11:01:35 +00:00
|
|
|
user.save()
|
|
|
|
return Response()
|
|
|
|
|
|
|
|
|
|
|
|
class WeComQRUnBindForUserApi(RoleUserMixin, WeComQRUnBindBase):
|
2023-10-10 09:52:52 +00:00
|
|
|
permission_classes = (IsValidUser, UserConfirmation.require(ConfirmType.RELOGIN),)
|
2021-03-24 11:01:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
class WeComQRUnBindForAdminApi(RoleAdminMixin, WeComQRUnBindBase):
|
|
|
|
user_id_url_kwarg = 'user_id'
|