fix delete admin user bug
This commit is contained in:
@@ -13,9 +13,6 @@ from rest_framework.views import APIView
|
||||
from rest_framework.viewsets import ModelViewSet
|
||||
from rest_framework_simplejwt.views import TokenObtainPairView
|
||||
|
||||
from apps.authentication.exceptions import AdminDeleteException
|
||||
from apps.core.api import BaseViewSet
|
||||
|
||||
from apps.authentication.api.v1.serializers.jwt import CustomizedTokenObtainPairSerializer
|
||||
from apps.authentication.api.v1.serializers.serializer import (
|
||||
CitySerializer,
|
||||
@@ -25,7 +22,7 @@ from apps.authentication.api.v1.serializers.serializer import (
|
||||
UserSerializer,
|
||||
BankAccountSerializer,
|
||||
)
|
||||
from apps.authentication.mixins.region_filter import RegionFilterMixin
|
||||
from apps.authentication.exceptions import AdminDeleteException
|
||||
from apps.authentication.models import (
|
||||
User,
|
||||
City,
|
||||
@@ -37,6 +34,7 @@ from apps.authentication.models import (
|
||||
)
|
||||
from apps.authentication.tools import get_token_jti
|
||||
from apps.authorization.api.v1 import api as authorize_view
|
||||
from apps.core.api import BaseViewSet
|
||||
from apps.core.mixins.search_mixin import DynamicSearchMixin
|
||||
from apps.core.mixins.soft_delete_mixin import SoftDeleteMixin
|
||||
from common.helpers import get_organization_by_user
|
||||
@@ -171,10 +169,10 @@ class UserViewSet(SoftDeleteMixin, ModelViewSet):
|
||||
"""
|
||||
user = self.get_object()
|
||||
user_relations = authorize_view.UserRelations.objects.filter(user=user).first()
|
||||
if user_relations.role.type.key != 'ADM':
|
||||
if user_relations.role.type.key == 'ADM':
|
||||
raise AdminDeleteException()
|
||||
else:
|
||||
user_relations.objects.update(trash=True)
|
||||
user_relations.soft_delete()
|
||||
|
||||
return Response(status=status.HTTP_204_NO_CONTENT)
|
||||
|
||||
|
||||
@@ -109,8 +109,6 @@ class UserSerializer(serializers.ModelSerializer):
|
||||
|
||||
def validate(self, attrs):
|
||||
mobile = attrs['mobile']
|
||||
if 'username' in attrs.keys():
|
||||
username = attrs['username']
|
||||
|
||||
if not self.instance:
|
||||
if self.Meta.model.objects.filter(
|
||||
|
||||
Reference in New Issue
Block a user