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(
|
||||
|
||||
@@ -45,3 +45,29 @@
|
||||
[2025-10-27 16:49:53,321] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authentication\api\v1\serializers\serializer.py changed, reloading.
|
||||
[2025-10-27 16:49:55,766] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader
|
||||
[2025-10-27 17:04:59,459] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authentication\api\v1\serializers\serializer.py changed, reloading.
|
||||
[2025-10-27 17:05:01,207] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader
|
||||
[2025-10-27 17:06:57,008] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authentication\api\v1\serializers\serializer.py changed, reloading.
|
||||
[2025-10-27 17:07:00,982] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader
|
||||
[2025-10-28 08:27:42,138] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader
|
||||
[2025-10-28 08:27:48,986] INFO django.server | IP: - | Path: - | "POST /captcha/ HTTP/1.1" 200 710
|
||||
[2025-10-28 08:28:45,512] INFO django.server | IP: - | Path: - | "POST /auth/api/v1/login/ HTTP/1.1" 200 681
|
||||
[2025-10-28 08:29:31,225] INFO django.server | IP: - | Path: - | "DELETE /auth/api/v1/user/2/ HTTP/1.1" 204 0
|
||||
[2025-10-28 08:29:36,772] INFO django.server | IP: - | Path: - | "DELETE /auth/api/v1/user/2/ HTTP/1.1" 204 0
|
||||
[2025-10-28 08:30:44,539] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authentication\api\v1\api.py changed, reloading.
|
||||
[2025-10-28 08:30:47,004] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader
|
||||
[2025-10-28 08:30:51,273] WARNING django.request | IP: 127.0.0.1 | Path: /auth/api/v1/user/2/ | Forbidden: /auth/api/v1/user/2/
|
||||
[2025-10-28 08:30:51,273] WARNING django.server | IP: - | Path: - | "DELETE /auth/api/v1/user/2/ HTTP/1.1" 403 101
|
||||
[2025-10-28 08:30:57,128] WARNING django.request | IP: 127.0.0.1 | Path: /auth/api/v1/user/2/ | Forbidden: /auth/api/v1/user/2/
|
||||
[2025-10-28 08:30:57,129] WARNING django.server | IP: - | Path: - | "DELETE /auth/api/v1/user/2/ HTTP/1.1" 403 101
|
||||
[2025-10-28 08:31:34,074] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authentication\api\v1\api.py changed, reloading.
|
||||
[2025-10-28 08:31:37,706] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader
|
||||
[2025-10-28 08:31:43,093] WARNING django.request | IP: 127.0.0.1 | Path: /auth/api/v1/user/2/ | Forbidden: /auth/api/v1/user/2/
|
||||
[2025-10-28 08:31:43,095] WARNING django.server | IP: - | Path: - | "DELETE /auth/api/v1/user/2/ HTTP/1.1" 403 101
|
||||
[2025-10-28 08:31:44,476] WARNING django.request | IP: 127.0.0.1 | Path: /auth/api/v1/user/2/ | Forbidden: /auth/api/v1/user/2/
|
||||
[2025-10-28 08:31:44,477] WARNING django.server | IP: - | Path: - | "DELETE /auth/api/v1/user/2/ HTTP/1.1" 403 101
|
||||
[2025-10-28 08:32:55,392] INFO django.utils.autoreload | IP: - | Path: - | D:\Project\Rasaddam_Backend\apps\authentication\api\v1\api.py changed, reloading.
|
||||
[2025-10-28 08:32:58,368] INFO django.utils.autoreload | IP: - | Path: - | Watching for file changes with StatReloader
|
||||
[2025-10-28 08:33:13,414] WARNING django.request | IP: 127.0.0.1 | Path: /auth/api/v1/user/2/ | Forbidden: /auth/api/v1/user/2/
|
||||
[2025-10-28 08:33:13,415] WARNING django.server | IP: - | Path: - | "DELETE /auth/api/v1/user/2/ HTTP/1.1" 403 101
|
||||
[2025-10-28 08:33:17,023] WARNING django.request | IP: 127.0.0.1 | Path: /auth/api/v1/user/2/ | Forbidden: /auth/api/v1/user/2/
|
||||
[2025-10-28 08:33:17,023] WARNING django.server | IP: - | Path: - | "DELETE /auth/api/v1/user/2/ HTTP/1.1" 403 101
|
||||
|
||||
Reference in New Issue
Block a user