Skip to content
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ and this project adheres to

### Fixed

- 🐛(backend) fix full-text search scoped to a document
- 🐛(frontend) refresh pins after document deletion and restoration
- 🐛(frontend) redirect homepage to login when homepage feat is disabled #2521
- 🐛(backend) ignore CSPs for API docs in development
Expand Down
4 changes: 2 additions & 2 deletions src/backend/core/api/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1550,8 +1550,8 @@ def _search_using_indexer(indexer, request, params, search_type):
document_id = params.validated_data.get("document")
if document_id:
try:
path = models.Document.objects.get(pk=document_id).values_list(
"path", flat=True
path = models.Document.objects.values_list("path", flat=True).get(
pk=document_id
)
except models.Document.DoesNotExist as exc:
raise drf.exceptions.NotFound("Document not found.") from exc
Expand Down
17 changes: 17 additions & 0 deletions src/backend/core/tests/documents/test_api_documents_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,3 +612,20 @@ def test_api_documents_search_success(indexer_settings):
assert results == [
{"id": document["id"], "title": document["title"], "path": document["path"]}
]


@mock.patch("core.services.search_indexers.FindDocumentIndexer.search_query")
def test_api_documents_search_success_scoped(search_query, indexer_settings):
"""A document-scoped indexer search should use the document path."""
indexer_settings.SEARCH_URL = "http://find/api/v1.0/search"
search_query.return_value = []
document = factories.DocumentFactory()

response = APIClient().get(
"/api/v1.0/documents/search/",
data={"q": "alpha", "document": document.id},
)

assert response.status_code == 200
assert search_query.call_count == 1
assert search_query.call_args.kwargs["data"]["path"] == document.path