fix(users): 组织管理员创建用户时,角色只能选择: 用户

pull/4338/head
Bai 2020-07-15 20:10:47 +08:00 committed by BaiJiangJie
parent 0014bd0cb9
commit bb60d2a1d9
1 changed files with 5 additions and 1 deletions

View File

@ -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):