Skip to content

Commit

Permalink
Add the github id to the v1/user serializer for auditing purposes. (#…
Browse files Browse the repository at this point in the history
…1969)

To match data from old and new galaxy, we need the github id for each user.
It's squirreled away in the social auth table and can be fetched by filtering on the user.

* Wrap social query with try/except.
* Defer the social import to avoid missing table errors.

No-Issue

Signed-off-by: James Tanner <[email protected]>
  • Loading branch information
jctanner authored Nov 8, 2023
1 parent 530d71c commit 2f0740a
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion galaxy_ng/app/api/v1/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class LegacyUserSerializer(serializers.ModelSerializer):
url = serializers.SerializerMethodField()
username = serializers.SerializerMethodField()
avatar_url = serializers.SerializerMethodField()
github_id = serializers.SerializerMethodField()

class Meta:
model = User
Expand All @@ -138,7 +139,7 @@ class Meta:
'full_name',
'date_joined',
'avatar_url',
# 'active'
'github_id',
]

def get_username(self, obj):
Expand Down Expand Up @@ -178,6 +179,23 @@ def get_avatar_url(self, obj):
url = f'https://github.com/{username}.png'
return url

def get_github_id(self, obj):

# have to defer this import because of the other
# deployment profiles trying to access the missing
# database table.
from social_django.models import UserSocialAuth

try:
social_user = UserSocialAuth.objects.filter(user=obj).first()
if not social_user:
return None
return social_user.id
except Exception:
return None

return None


class LegacyRoleSerializer(serializers.ModelSerializer):

Expand Down

0 comments on commit 2f0740a

Please sign in to comment.