✨(backend) add a public_search API view to the Document viewset#2068
✨(backend) add a public_search API view to the Document viewset#2068
Conversation
e0ed891 to
bfa5a48
Compare
8e716e7 to
ab27d46
Compare
src/backend/core/api/viewsets.py
Outdated
|
|
||
| text = params.validated_data["q"] | ||
|
|
||
| document = self.get_object() |
There was a problem hiding this comment.
It should be moved to the top of the method, to check permissions first
src/backend/core/api/viewsets.py
Outdated
| context={ | ||
| "request": request, | ||
| }, |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
Not sure why I added it, I'll remove it.
| 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() | ||
| ) | ||
|
|
There was a problem hiding this comment.
This is not used and I think it is not a test.
There was a problem hiding this comment.
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." | ||
| } |
There was a problem hiding this comment.
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"]} |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
| - ✨(backend) add a public_search API view to the Document viewset#2068 | |
| - ✨(backend) add a public_search API view to the Document viewset #2068 |
ab27d46 to
ca402a2
Compare
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.
ca402a2 to
a9ef0ec
Compare
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
public_search()method on theDocumentViewSetget_highest_public_ancestor()method on theDocumentmodel.