fix: 修改AuthBook删除raise异常类

pull/6283/head
Bai 2021-06-16 14:41:00 +08:00 committed by Jiangjie.Bai
parent a3d02decd6
commit c4af78c9f0
2 changed files with 5 additions and 3 deletions

View File

@ -4,6 +4,7 @@ from django.utils.translation import ugettext as _
from functools import reduce from functools import reduce
from django.db.models import F, CharField, Value, IntegerField, Q, Count from django.db.models import F, CharField, Value, IntegerField, Q, Count
from django.db.models.functions import Concat from django.db.models.functions import Concat
from rest_framework.exceptions import PermissionDenied
from common.utils import get_object_or_none from common.utils import get_object_or_none
from orgs.utils import current_org from orgs.utils import current_org
@ -250,7 +251,7 @@ class AdminUserBackend(DBBackend):
) )
def _perform_delete_by_union_id(self, union_id_cleaned): def _perform_delete_by_union_id(self, union_id_cleaned):
raise PermissionError(_("Could not remove asset admin user")) raise PermissionDenied(_("Could not remove asset admin user"))
def all(self): def all(self):
qs = self.model.objects.all().annotate( qs = self.model.objects.all().annotate(
@ -314,7 +315,7 @@ class AuthbookBackend(DBBackend):
authbook_id, asset_id = union_id_cleaned authbook_id, asset_id = union_id_cleaned
authbook = get_object_or_none(AuthBook, pk=authbook_id) authbook = get_object_or_none(AuthBook, pk=authbook_id)
if authbook.is_latest: if authbook.is_latest:
raise PermissionError(_("Latest version could not be delete")) raise PermissionDenied(_("Latest version could not be delete"))
AuthBook.objects.filter(id=authbook_id).delete() AuthBook.objects.filter(id=authbook_id).delete()
def all(self): def all(self):

View File

@ -4,6 +4,7 @@
from django.db import models, transaction from django.db import models, transaction
from django.db.models import Max from django.db.models import Max
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from rest_framework.exceptions import PermissionDenied
from orgs.mixins.models import OrgManager from orgs.mixins.models import OrgManager
from .base import BaseUser from .base import BaseUser
@ -14,7 +15,7 @@ __all__ = ['AuthBook']
class AuthBookQuerySet(models.QuerySet): class AuthBookQuerySet(models.QuerySet):
def delete(self): def delete(self):
if self.count() > 1: if self.count() > 1:
raise PermissionError(_("Bulk delete deny")) raise PermissionDenied(_("Bulk delete deny"))
return super().delete() return super().delete()