From c4af78c9f0fa49de146c4d7a5a9bd49c22e6573c Mon Sep 17 00:00:00 2001 From: Bai Date: Wed, 16 Jun 2021 14:41:00 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9AuthBook=E5=88=A0?= =?UTF-8?q?=E9=99=A4raise=E5=BC=82=E5=B8=B8=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/assets/backends/db.py | 5 +++-- apps/assets/models/authbook.py | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/apps/assets/backends/db.py b/apps/assets/backends/db.py index aa3e1ef78..0e5d288b9 100644 --- a/apps/assets/backends/db.py +++ b/apps/assets/backends/db.py @@ -4,6 +4,7 @@ from django.utils.translation import ugettext as _ from functools import reduce from django.db.models import F, CharField, Value, IntegerField, Q, Count from django.db.models.functions import Concat +from rest_framework.exceptions import PermissionDenied from common.utils import get_object_or_none from orgs.utils import current_org @@ -250,7 +251,7 @@ class AdminUserBackend(DBBackend): ) 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): qs = self.model.objects.all().annotate( @@ -314,7 +315,7 @@ class AuthbookBackend(DBBackend): authbook_id, asset_id = union_id_cleaned authbook = get_object_or_none(AuthBook, pk=authbook_id) 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() def all(self): diff --git a/apps/assets/models/authbook.py b/apps/assets/models/authbook.py index 35b7e3894..3a17df7b7 100644 --- a/apps/assets/models/authbook.py +++ b/apps/assets/models/authbook.py @@ -4,6 +4,7 @@ from django.db import models, transaction from django.db.models import Max from django.utils.translation import ugettext_lazy as _ +from rest_framework.exceptions import PermissionDenied from orgs.mixins.models import OrgManager from .base import BaseUser @@ -14,7 +15,7 @@ __all__ = ['AuthBook'] class AuthBookQuerySet(models.QuerySet): def delete(self): if self.count() > 1: - raise PermissionError(_("Bulk delete deny")) + raise PermissionDenied(_("Bulk delete deny")) return super().delete()