Skip to content

Commit bfbd9f5

Browse files
committed
fix authenticated ORCID is not shown
1 parent 6e204bb commit bfbd9f5

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

api/users/serializers.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,26 @@ def to_representation(self, value):
6363
value = social
6464
return super().to_representation(value)
6565

66+
class ExternalIdentityField(ser.DictField):
67+
def __init__(self, **kwargs):
68+
super().__init__(**kwargs)
69+
70+
def to_representation(self, value):
71+
if not value or not isinstance(value, dict):
72+
return value
73+
result = {}
74+
for provider, identities in value.items():
75+
if not identities or not isinstance(identities, dict):
76+
result[provider] = identities
77+
continue
78+
identity_id, status = next(iter(identities.items()))
79+
if status != 'VERIFIED':
80+
continue
81+
result[provider] = {
82+
'id': identity_id,
83+
'status': status,
84+
}
85+
return result
6686

6787
class UserSerializer(JSONAPISerializer):
6888
filterable_fields = frozenset([
@@ -97,6 +117,7 @@ class UserSerializer(JSONAPISerializer):
97117
allow_indexing = ShowIfCurrentUser(ser.BooleanField(required=False, allow_null=True))
98118
can_view_reviews = ShowIfCurrentUser(ser.SerializerMethodField(help_text='Whether the current user has the `view_submissions` permission to ANY reviews provider.'))
99119
accepted_terms_of_service = ShowIfCurrentUser(ser.SerializerMethodField())
120+
external_identity = HideIfDisabled(ExternalIdentityField(required=False))
100121

101122
links = HideIfDisabled(
102123
LinksField(

0 commit comments

Comments
 (0)