Skip to content

Commit 807d606

Browse files
committed
Show all connected accounts
Ability to filter by each connected account independently.
1 parent 7442384 commit 807d606

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed

readthedocs/projects/static-src/projects/js/import.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ function ProjectImportView (instance, config) {
141141
self.page_next = ko.observable(null);
142142
self.page_previous = ko.observable(null);
143143
self.filter_org = ko.observable(null);
144-
self.filter_own = ko.observable(false);
144+
self.filter_own = ko.observable(null);
145145

146146
self.organizations_raw = ko.observableArray();
147147
self.organizations = ko.computed(function () {
@@ -251,9 +251,14 @@ function ProjectImportView (instance, config) {
251251
self.page_current(null);
252252
};
253253

254-
self.set_filter_own = function () {
254+
self.set_filter_own = function (account) {
255+
var current_account = self.filter_own();
256+
if (current_account == account) {
257+
account = null;
258+
}
259+
255260
// This needs to use deferred updates
256-
self.filter_own(true);
261+
self.filter_own(account);
257262
self.filter_org(null);
258263
self.page_current(null);
259264
};

readthedocs/restapi/views/model_views.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,10 @@ def get_queryset(self):
263263

264264
own = self.request.query_params.get('own', None)
265265
if own is not None:
266-
query = query.filter(organization__isnull=True)
266+
query = query.filter(
267+
account__provider=own,
268+
organization=None,
269+
)
267270

268271
query = query.filter(account__provider__in=[service.adapter.provider_id
269272
for service in registry])

readthedocs/templates/projects/project_import.html

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -209,15 +209,24 @@ <h1>{% trans "Import a Repository" %}</h1>
209209
</div>
210210
{% endblock %}
211211

212-
<h3>{% trans "Filter by Own Repositories" %}</h3>
213-
<li
214-
class="remote-org"
215-
data-bind="click: function () { $root.set_filter_own(); }">
216-
<!-- TODO: show all the connected accounts here with corresponding avatar -->
217-
<span>humitos (GitHub)</span>
218-
<!-- <img data-bind="attr: {src: avatar_url}" class="remote-org-avatar" /> -->
219-
<!-- <span data-bind="text: display_name" class="remote-org-name"></span> -->
220-
</li>
212+
{# accounts is a dictionary with the provider as key and a list of connected accounts of that provider #}
213+
{% get_social_accounts user as accounts %}
214+
{% if accounts %}
215+
<h3>{% trans "Filter by Own Repositories" %}</h3>
216+
{% for type, list in accounts.items %}
217+
{% for account in list %}
218+
<li
219+
class="remote-org"
220+
data-bind="click: function () { $root.set_filter_own('{{ account.provider }}'); }">
221+
<img src="{{ account.get_avatar_url }}" class="remote-org-avatar" />
222+
223+
<!-- TODO: get the proper username for the connected account -->
224+
<span>{{ account.user.username }} ({{ account.get_provider_display }})</span>
225+
226+
</li>
227+
{% endfor %}
228+
{% endfor %}
229+
{% endif %}
221230

222231

223232
{% block organizations %}

0 commit comments

Comments
 (0)