Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose the true github ID in the v1 user serializer. #3233

Merged
merged 2 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci_unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ jobs:
# - name: Install LDAP requirements
# run: sudo apt-get install -y libsasl2-dev python3 libldap2-dev libssl-dev build-essential

- name: Install docker-compose
run: pip3 install --upgrade docker-compose
# - name: Install docker-compose
# run: pip3 install --upgrade docker-compose

- name: build the image
run: make dev/build
Expand Down
11 changes: 10 additions & 1 deletion galaxy/api/serializers/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from collections import OrderedDict

from allauth.account.models import EmailAddress
from allauth.socialaccount.models import SocialAccount

from django.contrib.auth import get_user_model
from django.contrib.auth.models import AnonymousUser
Expand All @@ -18,7 +19,8 @@

USER_FIELDS = (
'id', 'url', 'related', 'summary_fields', 'created', 'modified',
'username', 'staff', 'full_name', 'date_joined', 'avatar_url'
'username', 'staff', 'full_name', 'date_joined', 'avatar_url',
'github_id'
)

__all__ = [
Expand Down Expand Up @@ -55,6 +57,7 @@ def get_primary_email(self, obj):

class UserSerializer(BaseSerializer):
staff = serializers.ReadOnlyField(source='is_staff')
github_id = serializers.SerializerMethodField()

class Meta:
model = User
Expand Down Expand Up @@ -93,3 +96,9 @@ def get_summary_fields(self, obj):
('github_repo', g.repository.github_repo)
]) for g in obj.starred.select_related('repository').all()]
return d

def get_github_id(self, obj):
social_user = SocialAccount.objects.filter(user_id=obj.id).first()
if social_user is None:
return None
return social_user.extra_data.get('id')
Loading