Skip to content

Commit 0eb0dc1

Browse files
committed
Merge branch 'main' into sbl-proximity-search
2 parents 44654d3 + f9f32db commit 0eb0dc1

3 files changed

Lines changed: 10 additions & 6 deletions

File tree

src/backend/core/api/viewsets.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,11 @@ def get_queryset(self):
225225
# For performance reasons we filter first by similarity, which relies on an
226226
# index, then only calculate precise similarity scores for sorting purposes.
227227
#
228-
# Additionally we reorder results to prefer users "closer" to the current
228+
# Additionally results are reordered to prefer users "closer" to the current
229229
# user: users they recently shared documents with, same full domain, same
230230
# partial domain (e.g. both end with "gouv.fr"). To achieve that without
231-
# complex SQL we build a proximity score in Python and returnthe top N results.
231+
# complex SQL, we build a proximity score in Python and return the
232+
# top N results.
232233
current_user = self.request.user
233234
shared_map = users_sharing_documents_with(current_user)
234235

@@ -287,9 +288,6 @@ def _sort_key(u):
287288
sim,
288289
)
289290

290-
# Sort candidates by the key descending and return top N as a queryset-like
291-
# list. Keep return type consistent with previous behavior (QuerySet slice
292-
# was returned) by returning a list of model instances.
293291
candidates.sort(key=_sort_key, reverse=True)
294292

295293
return candidates[: settings.API_USERS_LIST_LIMIT]
@@ -2295,7 +2293,8 @@ def get_queryset(self):
22952293
)
22962294
# Abilities are computed based on logged-in user's role and
22972295
# the user role on each document access
2298-
.annotate(user_roles=db.Subquery(user_roles_query)).distinct()
2296+
.annotate(user_roles=db.Subquery(user_roles_query))
2297+
.distinct()
22992298
)
23002299
return queryset
23012300

src/backend/core/tests/test_utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ def test_utils_extract_email_domain_parts_when_email_is_valid():
111111

112112

113113
def test_utils_extract_email_domain_parts_when_email_is_empty():
114+
"""Test extraction of email domain parts in case of an empty email."""
114115
empty_email = ""
115116
full_domain, partial_domain = utils.extract_email_domain_parts(empty_email)
116117
assert full_domain == ""

src/backend/core/tests/test_utils_users_sharing_documents_with.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
"""
2+
Unit tests for the users_sharing_documents_with utility function.
3+
"""
4+
15
from django.utils import timezone
26

37
import pytest

0 commit comments

Comments
 (0)