diff --git a/apps/assets/api/admin_user.py b/apps/assets/api/admin_user.py index 52b05fcd4..c77da1ae4 100644 --- a/apps/assets/api/admin_user.py +++ b/apps/assets/api/admin_user.py @@ -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