Repository: readthedocs/readthedocs.org

Issue:
Filter by my own repositories when importing
When Github account is connected and you want to import a project, it's kind of "annoying" (don't know the proper word) to look for your owns. If you belong to a couple of organizations and they have a lot of projects, you have to click Next many times before you reach the project you want to import.

![captura de pantalla_2017-11-30_12-47-21](https://user-images.githubusercontent.com/244656/33446006-b5783462-d5cc-11e7-9f0b-042a92736ed3.png)

I'm just posting this here just to be considered in case it's something easy to do, but it would be zero priority for me.



Discussion:

Resolving patch:
diff --git a/readthedocs/restapi/serializers.py b/readthedocs/restapi/serializers.py
--- a/readthedocs/restapi/serializers.py
+++ b/readthedocs/restapi/serializers.py
@@ -3,6 +3,8 @@
 from __future__ import absolute_import
 
 from builtins import object
+
+from allauth.socialaccount.models import SocialAccount
 from rest_framework import serializers
 
 from readthedocs.builds.models import Build, BuildCommandResult, Version
@@ -157,3 +159,27 @@ def get_matches(self, obj):
         request = self.context['request']
         if request.user is not None and request.user.is_authenticated():
             return obj.matches(request.user)
+
+
+class ProviderSerializer(serializers.Serializer):
+
+    id = serializers.CharField(max_length=20)
+    name = serializers.CharField(max_length=20)
+
+
+class SocialAccountSerializer(serializers.ModelSerializer):
+
+    username = serializers.SerializerMethodField()
+    avatar_url = serializers.URLField(source='get_avatar_url')
+    provider = ProviderSerializer(source='get_provider')
+
+    class Meta(object):
+        model = SocialAccount
+        exclude = ('extra_data',)
+
+    def get_username(self, obj):
+        return (
+            obj.extra_data.get('username') or
+            obj.extra_data.get('login')
+            # FIXME: which one is GitLab?
+        )
diff --git a/readthedocs/restapi/urls.py b/readthedocs/restapi/urls.py
--- a/readthedocs/restapi/urls.py
+++ b/readthedocs/restapi/urls.py
@@ -17,7 +17,8 @@
                                 ProjectViewSet, NotificationViewSet,
                                 VersionViewSet, DomainViewSet,
                                 RemoteOrganizationViewSet,
-                                RemoteRepositoryViewSet)
+                                RemoteRepositoryViewSet,
+                                SocialAccountViewSet)
 
 router = routers.DefaultRouter()
 router.register(r'build', BuildViewSet, base_name='build')
@@ -30,6 +31,8 @@
     r'remote/org', RemoteOrganizationViewSet, base_name='remoteorganization')
 router.register(
     r'remote/repo', RemoteRepositoryViewSet, base_name='remoterepository')
+router.register(
+    r'remote/account', SocialAccountViewSet, base_name='remoteaccount')
 router.register(r'comments', CommentViewSet, base_name="comments")
 
 urlpatterns = [
diff --git a/readthedocs/restapi/views/model_views.py b/readthedocs/restapi/views/model_views.py
--- a/readthedocs/restapi/views/model_views.py
+++ b/readthedocs/restapi/views/model_views.py
@@ -6,6 +6,7 @@
 
 import logging
 
+from allauth.socialaccount.models import SocialAccount
 from django.shortcuts import get_object_or_404
 from rest_framework import decorators, permissions, status, viewsets
 from rest_framework.decorators import detail_route
@@ -28,7 +29,7 @@
     BuildAdminSerializer, BuildCommandSerializer, BuildSerializer,
     DomainSerializer, ProjectAdminSerializer, ProjectSerializer,
     RemoteOrganizationSerializer, RemoteRepositorySerializer,
-    VersionAdminSerializer, VersionSerializer)
+    SocialAccountSerializer, VersionAdminSerializer, VersionSerializer)
 
 log = logging.getLogger(__name__)
 
@@ -275,8 +276,26 @@ def get_queryset(self):
         org = self.request.query_params.get('org', None)
         if org is not None:
             query = query.filter(organization__pk=org)
+
+        own = self.request.query_params.get('own', None)
+        if own is not None:
+            query = query.filter(
+                account__provider=own,
+                organization=None,
+            )
+
         query = query.filter(
             account__provider__in=[
                 service.adapter.provider_id for service in registry
             ])
         return query
+
+
+class SocialAccountViewSet(viewsets.ReadOnlyModelViewSet):
+    permission_classes = [IsOwner]
+    renderer_classes = (JSONRenderer,)
+    serializer_class = SocialAccountSerializer
+    model = SocialAccount
+
+    def get_queryset(self):
+        return self.model.objects.filter(user=self.request.user.pk)


Test patch:
diff --git a/readthedocs/rtd_tests/tests/test_privacy_urls.py b/readthedocs/rtd_tests/tests/test_privacy_urls.py
--- a/readthedocs/rtd_tests/tests/test_privacy_urls.py
+++ b/readthedocs/rtd_tests/tests/test_privacy_urls.py
@@ -2,6 +2,7 @@
 from __future__ import print_function
 import re
 
+from allauth.socialaccount.models import SocialAccount
 from builtins import object
 from django.contrib.admindocs.views import extract_views_from_urlpatterns
 from django.test import TestCase
@@ -295,6 +296,7 @@ def setUp(self):
         self.domain = get(Domain, url='http://docs.foobar.com', project=self.pip)
         self.comment = get(DocumentComment, node__project=self.pip)
         self.snapshot = get(NodeSnapshot, node=self.comment.node)
+        self.social_account = get(SocialAccount)
         self.remote_org = get(RemoteOrganization)
         self.remote_repo = get(RemoteRepository, organization=self.remote_org)
         self.integration = get(Integration, project=self.pip, provider_data='')
@@ -314,6 +316,7 @@ def setUp(self):
             'footer_html': {'data': {'project': 'pip', 'version': 'latest', 'page': 'index'}},
             'remoteorganization-detail': {'pk': self.remote_org.pk},
             'remoterepository-detail': {'pk': self.remote_repo.pk},
+            'remoteaccount-detail': {'pk': self.social_account.pk},
             'api_webhook': {'integration_pk': self.integration.pk},
         }
         self.response_data = {
@@ -337,6 +340,7 @@ def setUp(self):
             'api_webhook_generic': {'status_code': 403},
             'remoteorganization-detail': {'status_code': 404},
             'remoterepository-detail': {'status_code': 404},
+            'remoteaccount-detail': {'status_code': 404},
         }