fix: 添加profile myorgs (#7887)

Co-authored-by: feng626 <1304903146@qq.com>
pull/7886/head^2
fit2bot 2022-03-16 20:36:12 +08:00 committed by GitHub
parent 3b507dc795
commit 433d829c29
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View File

@ -790,6 +790,10 @@ class User(AuthMixin, TokenMixin, RoleMixin, MFAMixin, AbstractUser):
orgs = [Organization.root()] + orgs
return orgs
@property
def my_orgs(self):
return list(self.orgs.all().distinct())
class Meta:
ordering = ['username']
verbose_name = _("User")

View File

@ -122,12 +122,13 @@ class UserProfileSerializer(UserSerializer):
guide_url = serializers.SerializerMethodField()
receive_backends = serializers.ListField(child=serializers.CharField(), read_only=True)
orgs = UserOrgSerializer(many=True, read_only=True, source='all_orgs')
myorgs = UserOrgSerializer(many=True, read_only=True, source='my_orgs')
perms = serializers.ListField(label=_("Perms"), read_only=True)
class Meta(UserSerializer.Meta):
read_only_fields = [
'date_joined', 'last_login', 'created_by', 'source',
'receive_backends', 'orgs', 'perms',
'receive_backends', 'orgs', 'myorgs', 'perms',
]
fields = UserSerializer.Meta.fields + [
'public_key_comment', 'public_key_hash_md5', 'guide_url',