perf: 删除管理用户错误提醒 (#11596)

Co-authored-by: feng <1304903146@qq.com>
This commit is contained in:
fit2bot
2023-09-18 18:42:02 +08:00
committed by GitHub
parent 24ed57b98a
commit 018f1a0e8d
5 changed files with 114 additions and 95 deletions

View File

@@ -18,6 +18,7 @@ from django.shortcuts import reverse
from django.utils import timezone
from django.utils.module_loading import import_string
from django.utils.translation import gettext_lazy as _
from rest_framework.exceptions import PermissionDenied
from common.db import fields, models as jms_models
from common.utils import (
@@ -973,7 +974,7 @@ class User(AuthMixin, TokenMixin, RoleMixin, MFAMixin, JSONFilterMixin, Abstract
def delete(self, using=None, keep_parents=False):
if self.pk == 1 or self.username == 'admin':
return
raise PermissionDenied(_('Can not delete admin user'))
return super(User, self).delete(using=using, keep_parents=keep_parents)
@classmethod