From 17163dd909983b2ba23105cb08bec65bdccfe816 Mon Sep 17 00:00:00 2001 From: ibuler Date: Wed, 13 May 2020 11:05:58 +0800 Subject: [PATCH] =?UTF-8?q?[Update]=20=E7=94=A8=E6=88=B7Profile=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=9C=A8=E5=BD=93=E5=89=8D=E7=BB=84=E7=BB=87=E7=9A=84?= =?UTF-8?q?=E8=A7=92=E8=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/users/models/user.py | 8 ++++++++ apps/users/serializers/user.py | 16 +++++++--------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/apps/users/models/user.py b/apps/users/models/user.py index ce803064a..963b64b21 100644 --- a/apps/users/models/user.py +++ b/apps/users/models/user.py @@ -159,6 +159,14 @@ class RoleMixin: roles.append(str(_('User'))) return " | ".join(roles) + def current_org_roles(self): + roles = [] + if self.can_admin_current_org: + roles.append('Admin') + if self.can_audit_current_org: + roles.append('Auditor') + return roles + @property def is_superuser(self): if self.role == 'Admin': diff --git a/apps/users/serializers/user.py b/apps/users/serializers/user.py index 1f76c8955..fc511a941 100644 --- a/apps/users/serializers/user.py +++ b/apps/users/serializers/user.py @@ -181,19 +181,17 @@ class ResetOTPSerializer(serializers.Serializer): pass +class UserRoleSerializer(serializers.Serializer): + name = serializers.CharField(max_length=24) + display = serializers.CharField(max_length=64) + + class UserProfileSerializer(UserSerializer): admin_or_audit_orgs = UserOrgSerializer(many=True, read_only=True) + current_org_roles = serializers.ListField() class Meta(UserSerializer.Meta): - # fields = [ - # 'id', 'name', 'username', 'email', - # 'role', 'wechat', 'phone', 'mfa_level', - # 'comment', 'source', 'is_valid', 'is_expired', - # 'is_active', 'created_by', 'is_first_login', - # 'date_password_last_updated', 'date_expired', - # 'avatar_url', 'groups', 'admin_or_audit_orgs', - # ] fields = UserSerializer.Meta.fields + [ - 'admin_or_audit_orgs' + 'admin_or_audit_orgs', 'current_org_roles' ]