From bb60d2a1d91a296957fc804e530e5574c6ad77ab Mon Sep 17 00:00:00 2001 From: Bai Date: Wed, 15 Jul 2020 20:10:47 +0800 Subject: [PATCH] =?UTF-8?q?fix(users):=20=E7=BB=84=E7=BB=87=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=91=98=E5=88=9B=E5=BB=BA=E7=94=A8=E6=88=B7=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E8=A7=92=E8=89=B2=E5=8F=AA=E8=83=BD=E9=80=89=E6=8B=A9?= =?UTF-8?q?:=20=E7=94=A8=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/users/serializers/user.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/apps/users/serializers/user.py b/apps/users/serializers/user.py index 351f33337..bebc5042b 100644 --- a/apps/users/serializers/user.py +++ b/apps/users/serializers/user.py @@ -87,7 +87,11 @@ class UserSerializer(CommonBulkSerializerMixin, serializers.ModelSerializer): if not role: return choices = role._choices - choices.pop('App', None) + choices.pop(User.ROLE_APP, None) + request = self.context.get('request') + if request and hasattr(request, 'user') and not request.user.is_superuser: + choices.pop(User.ROLE_ADMIN, None) + choices.pop(User.ROLE_AUDITOR, None) role._choices = choices def validate_role(self, value):