Merge pull request #3631 from jumpserver/dev_admin_user

[Update] 修改删除管理用户(存在关联资产)的Bug
pull/3632/head
BaiJiangJie 5 years ago committed by GitHub
commit db3b60faf9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -16,6 +16,8 @@
from django.db import transaction
from django.db.models import Count
from django.shortcuts import get_object_or_404
from django.utils.translation import ugettext as _
from rest_framework import status
from rest_framework.response import Response
from orgs.mixins.api import OrgBulkModelViewSet
from orgs.mixins import generics
@ -50,6 +52,14 @@ class AdminUserViewSet(OrgBulkModelViewSet):
queryset = queryset.annotate(_assets_amount=Count('assets'))
return queryset
def destroy(self, request, *args, **kwargs):
instance = self.get_object()
has_related_asset = instance.assets.exists()
if has_related_asset:
data = {'msg': _('Deleted failed, There are related assets')}
return Response(data=data, status=status.HTTP_400_BAD_REQUEST)
return super().destroy(request, *args, **kwargs)
class AdminUserAuthApi(generics.UpdateAPIView):
model = AdminUser

Loading…
Cancel
Save