11from django .contrib .auth .models import User
2+ from django .db import connection
23from django .db .models import Q
34from django .http import Http404 , HttpResponse , HttpResponseForbidden
45
@@ -20,23 +21,33 @@ def userlookup(request):
2021 | Q (last_name__icontains = query ),
2122 )
2223
23- if not request .user .is_authenticated :
24- return HttpResponseForbidden ("Login required when not filtering by commitfest" )
25- _ = cf
2624 # If no commitfest filter is provided, require login
27- # if not cf:
28- # if not request.user.is_authenticated:
29- # return HttpResponseForbidden(
30- # "Login required when not filtering by commitfest"
31- # )
32- # else:
33- # # Filter users to only those who have participated in the specified commitfest
34- # # This includes authors, reviewers, and committers of patches in that commitfest
35- # users = users.filter(
36- # Q(patch_author__commitfests__id=cf)
37- # | Q(patch_reviewer__commitfests__id=cf)
38- # | Q(committer__patch__commitfests__id=cf)
39- # ).distinct()
25+ if not cf :
26+ if not request .user .is_authenticated :
27+ return HttpResponseForbidden (
28+ "Login required when not filtering by commitfest"
29+ )
30+ else :
31+ # Filter users to only those who have participated in the specified commitfest.
32+ with connection .cursor () as cursor :
33+ cursor .execute (
34+ """
35+ SELECT cpa.user_id FROM commitfest_patch_authors cpa
36+ INNER JOIN commitfest_patchoncommitfest poc ON poc.patch_id = cpa.patch_id
37+ WHERE poc.commitfest_id = %(cf)s
38+ UNION
39+ SELECT cpr.user_id FROM commitfest_patch_reviewers cpr
40+ INNER JOIN commitfest_patchoncommitfest poc ON poc.patch_id = cpr.patch_id
41+ WHERE poc.commitfest_id = %(cf)s
42+ UNION
43+ SELECT p.committer_id FROM commitfest_patch p
44+ INNER JOIN commitfest_patchoncommitfest poc ON poc.patch_id = p.id
45+ WHERE poc.commitfest_id = %(cf)s AND p.committer_id IS NOT NULL
46+ """ ,
47+ {"cf" : cf },
48+ )
49+ user_ids = [row [0 ] for row in cursor .fetchall ()]
50+ users = users .filter (id__in = user_ids )
4051
4152 return HttpResponse (
4253 json .dumps (
0 commit comments