Skip to content

✨(backend) add a public_search API view to the Document viewset#2068

Open
Ash-Crow wants to merge 1 commit intomainfrom
sbl-search-public-docs
Open

✨(backend) add a public_search API view to the Document viewset#2068
Ash-Crow wants to merge 1 commit intomainfrom
sbl-search-public-docs

Conversation

@Ash-Crow
Copy link
Collaborator

@Ash-Crow Ash-Crow commented Mar 18, 2026

Purpose

This allows searching (on document titles only) on a public document and related public documents on the same tree.

A new get_highest_public_ancestor() helper method is also added to the Document model.

Fixes the backend part of #1826

Proposal

  • Add a public_search() method on the DocumentViewSet
  • Add a get_highest_public_ancestor() method on the Document model.

@Ash-Crow Ash-Crow force-pushed the sbl-search-public-docs branch 2 times, most recently from e0ed891 to bfa5a48 Compare March 18, 2026 11:17
@Ash-Crow Ash-Crow requested a review from lunika March 18, 2026 11:23
@Ash-Crow Ash-Crow force-pushed the sbl-search-public-docs branch 3 times, most recently from 8e716e7 to ab27d46 Compare March 18, 2026 15:40

text = params.validated_data["q"]

document = self.get_object()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be moved to the top of the method, to check permissions first

Comment on lines +1574 to +1576
context={
"request": request,
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The get_response_for_queryset is already adding a context that contains more info than the request. Is it intended to not use this mechanism and limit only to the request ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why I added it, I'll remove it.

Comment on lines +18 to +29
def build_public_search_url(document_id, **params):
"""Build the public_search URL for a given document."""

return (
RequestFactory()
.get(
f"/api/v1.0/documents/{document_id}/public_search/",
dict(sorted(params.items())),
)
.build_absolute_uri()
)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not used and I think it is not a test.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot to remove this unused helper, yes.

assert response.status_code == 403
assert response.json() == {
"detail": "You do not have permission to perform this action."
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a test for an authenticated user on a document with a link_reach authenticated ?

)
assert response.status_code == 200

result_ids = {r["id"] for r in response.json()["results"]}
Copy link
Member

@lunika lunika Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In all your tests you should assert the lenght of the response or explicitely check every documents present. Here you don't know exactly what is returned. This comment is also valid for all your tests.

CHANGELOG.md Outdated

### Added

- ✨(backend) add a public_search API view to the Document viewset#2068
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- ✨(backend) add a public_search API view to the Document viewset#2068
- ✨(backend) add a public_search API view to the Document viewset #2068

@Ash-Crow Ash-Crow force-pushed the sbl-search-public-docs branch from ab27d46 to ca402a2 Compare March 23, 2026 11:18
This allows searching (on document titles only) on a public documents
and related public documents on the same tree.

A new get_highest_public_ancestor() helper method is also added to the
Document model.
@Ash-Crow Ash-Crow force-pushed the sbl-search-public-docs branch from ca402a2 to a9ef0ec Compare March 23, 2026 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants