From a94f63b58cb4c9c8ab93e2b78af5474452a43ff0 Mon Sep 17 00:00:00 2001
From: Maximilian Moser <maximilian.moser@tuwien.ac.at>
Date: Mon, 31 Mar 2025 17:11:11 +0200
Subject: [PATCH] Chase reworked "shared_with_me" draft search parameter

* the name and behaviour of the upstream draft search parameter class
  have changed, and the UI has been reworked
* we extend the default behaviour to yield more results for admins in
  the "shared with me" tab
---
 invenio_config_tuw/startup/misc.py | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)

diff --git a/invenio_config_tuw/startup/misc.py b/invenio_config_tuw/startup/misc.py
index cec10ed..4d28f51 100644
--- a/invenio_config_tuw/startup/misc.py
+++ b/invenio_config_tuw/startup/misc.py
@@ -16,13 +16,30 @@ initialized, and thus we can rely on them being already available.
 from logging import ERROR
 from logging.handlers import SMTPHandler
 
-from invenio_rdm_records.services.search_params import MyDraftsParam
+from invenio_administration.permissions import administration_permission
+from invenio_rdm_records.services.search_params import SharedOrMyDraftsParam
 from invenio_requests.proxies import current_request_type_registry
+from invenio_search.engine import dsl
 
 from ..curations import TUWCurationRequest
 from ..logs import DetailedFormatter
 
 
+class TUWSharedOrMyDraftsParm(SharedOrMyDraftsParam):
+    """Variant of the "shared_with_me" interpreter that gives more results to admins."""
+
+    def _generate_shared_with_me_query(self, identity):
+        """Generate the "shared_with_me" query.
+
+        For admins, this matches all records.
+        For normal users, this typically involves records with access grants.
+        """
+        if administration_permission.allows(identity):
+            return dsl.Q("match_all")
+
+        return super()._generate_shared_with_me_query(identity)
+
+
 def register_smtp_error_handler(app):
     """Register email error handler to the application."""
     handler_name = "invenio-config-tuw-smtp-error-handler"
@@ -88,7 +105,12 @@ def override_search_drafts_options(app):
     # cf. https://github.com/inveniosoftware/invenio-rdm-records/blob/maint-10.x/invenio_rdm_records/services/config.py#L327-L332
     try:
         service = app.extensions["invenio-rdm-records"].records_service
-        service.config.search_drafts.params_interpreters_cls.remove(MyDraftsParam)
+        service.config.search_drafts.params_interpreters_cls.remove(
+            SharedOrMyDraftsParam
+        )
+        service.config.search_drafts.params_interpreters_cls.append(
+            TUWSharedOrMyDraftsParm
+        )
     except ValueError:
         pass
 
-- 
GitLab