From 2929e9826095155d49433b5cfb722eaf35c3a9f9 Mon Sep 17 00:00:00 2001 From: Quentin BEY Date: Mon, 24 Mar 2025 12:22:08 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F(documents)=20inherit=20manag?= =?UTF-8?q?er=20from=20queryset?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit During a code review, I saw we are overriding the MP_NodeManager and redefine the queryset filters: - The MP_NodeManager sorts the queryset by `path` by default and it's not done on our side, is it on purpose? - The fact we need to redefine `readable_per_se` as a boilerplate is surprising. I suggest we use the Django mechanism to generate the manager from the queryset. --- src/backend/core/models.py | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/src/backend/core/models.py b/src/backend/core/models.py index e66bde1b..cff7933b 100644 --- a/src/backend/core/models.py +++ b/src/backend/core/models.py @@ -445,28 +445,15 @@ class DocumentQuerySet(MP_NodeQuerySet): return self.filter(link_reach=LinkReachChoices.PUBLIC) -class DocumentManager(MP_NodeManager): +class DocumentManager(MP_NodeManager.from_queryset(DocumentQuerySet)): """ Custom manager for the Document model, enabling the use of the custom queryset methods directly from the model manager. """ def get_queryset(self): - """ - Overrides the default get_queryset method to return a custom queryset. - :return: An instance of DocumentQuerySet. - """ - return DocumentQuerySet(self.model, using=self._db) - - def readable_per_se(self, user): - """ - Filters documents based on user permissions using the custom queryset. - :param user: The user for whom readable documents are to be fetched. - :return: A queryset of documents for which the user has direct access, - team access or link access. This will not return all the documents - that a user can read because it can be obtained via an ancestor. - """ - return self.get_queryset().readable_per_se(user) + """Sets the custom queryset as the default.""" + return self._queryset_class(self.model).order_by("path") class Document(MP_Node, BaseModel):