mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2024-12-29 16:41:56 +00:00
支持用户的删除
This commit is contained in:
parent
6ef16c8253
commit
1af50c0f4c
@ -121,25 +121,15 @@ class UserAdminAPI(APIView):
|
|||||||
Q(email__icontains=keyword))
|
Q(email__icontains=keyword))
|
||||||
return self.success(self.paginate_data(request, user, UserAdminSerializer))
|
return self.success(self.paginate_data(request, user, UserAdminSerializer))
|
||||||
|
|
||||||
def delete_one(self, user_id):
|
|
||||||
try:
|
|
||||||
user = User.objects.get(id=user_id)
|
|
||||||
except User.DoesNotExist:
|
|
||||||
return f"User {user_id} does not exist"
|
|
||||||
if Submission.objects.filter(user_id=user_id).exists():
|
|
||||||
return f"Can't delete the user {user_id} as he/she has submissions"
|
|
||||||
user.delete()
|
|
||||||
|
|
||||||
@super_admin_required
|
@super_admin_required
|
||||||
def delete(self, request):
|
def delete(self, request):
|
||||||
id = request.GET.get("id")
|
id = request.GET.get("id")
|
||||||
if not id:
|
if not id:
|
||||||
return self.error("Invalid Parameter, id is required")
|
return self.error("Invalid Parameter, id is required")
|
||||||
for user_id in id.split(","):
|
ids = id.split(",")
|
||||||
if user_id:
|
if str(request.user.id) in ids:
|
||||||
error = self.delete_one(user_id)
|
return self.error("Current user can not be deleted")
|
||||||
if error:
|
User.objects.filter(id__in=ids).delete()
|
||||||
return self.error(error)
|
|
||||||
return self.success()
|
return self.success()
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user