From 47847e224aea5c6d1c826bf9c4429ff8f58612c3 Mon Sep 17 00:00:00 2001
From: Maximilian Moser <maximilian.moser@tuwien.ac.at>
Date: Tue, 2 Jul 2024 11:29:48 +0200
Subject: [PATCH] Allow access requests for new records by default
* through a service component, because the deposit form defaults would
be set under `record.metadata.[...]` which is invalid
* the `access` API endpoint and the share modal only become active once
the draft has been created, so the `create` hook should indeed be the
first spot where the access settings are available
---
invenio_config_tuw/config.py | 6 +++++-
invenio_config_tuw/services.py | 30 ++++++++++++++++++++++++++++++
2 files changed, 35 insertions(+), 1 deletion(-)
create mode 100644 invenio_config_tuw/services.py
diff --git a/invenio_config_tuw/config.py b/invenio_config_tuw/config.py
index 958c58c..fc913aa 100644
--- a/invenio_config_tuw/config.py
+++ b/invenio_config_tuw/config.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
-# Copyright (C) 2020-2023 TU Wien.
+# Copyright (C) 2020-2024 TU Wien.
#
# Invenio-Config-TUW is free software; you can redistribute it and/or modify
# it under the terms of the MIT License; see LICENSE file for more details.
@@ -21,6 +21,7 @@ from .permissions import (
TUWRequestsPermissionPolicy,
)
from .schemas import TUWUserPreferencesSchema, TUWUserProfileSchema, TUWUserSchema
+from .services import TUWRecordsComponents
from .utils import check_user_email_for_tuwien, current_user_as_creator
# Invenio-Config-TUW
@@ -166,6 +167,9 @@ APP_RDM_DEPOSIT_FORM_DEFAULTS = {
"description": "<h2>A primer on your dataset's description (to be edited)</h2><p>The influence of proper documentation on the reusability for research data should not be underestimated!<br>In order to help others understand how to interpret and reuse your data, we provide you with a few questions to help you structure your dataset's description (though please don't feel obligated to stick to them):</p><h3>Context and methodology</h3><ul><li>What is the research domain or project in which this dataset was created?</li><li>Which purpose does this dataset serve?</li><li>How was this dataset created?</li></ul><h3>Technical details</h3><ul><li>What is the structure of this dataset? Do the folders and files follow a certain naming convention?</li><li>Is any specific software required to open and work with this dataset?</li><li>Are there any additional resources available regarding the dataset, e.g. documentation, source code, etc.?</li></ul><h3>Further details</h3><ul><li>Is there anything else that other people may need to know when they want to reuse the dataset?</li></ul>", # noqa
}
+RDM_RECORDS_SERVICE_COMPONENTS = TUWRecordsComponents
+"""Override for the default record service components."""
+
RDM_CITATION_STYLES = [
("apa", _("APA")),
("bibtex", _("BibTeX")),
diff --git a/invenio_config_tuw/services.py b/invenio_config_tuw/services.py
new file mode 100644
index 0000000..4d88d1e
--- /dev/null
+++ b/invenio_config_tuw/services.py
@@ -0,0 +1,30 @@
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2024 TU Wien.
+#
+# Invenio-Config-TUW is free software; you can redistribute it and/or
+# modify it under the terms of the MIT License; see LICENSE file for more
+# details.
+
+
+"""Overrides for core services."""
+
+from invenio_drafts_resources.services.records.components import ServiceComponent
+from invenio_rdm_records.services.components import DefaultRecordsComponents
+
+
+class ParentAccessSettingsComponent(ServiceComponent):
+ """Service component that allows access requests per default."""
+
+ def create(self, identity, record, **kwargs):
+ """Set the parent access settings to allow access requests."""
+ settings = record.parent.access.settings
+ settings.allow_guest_requests = True
+ settings.allow_user_requests = True
+ settings.secret_link_expiration = 30
+
+
+TUWRecordsComponents = [
+ *DefaultRecordsComponents,
+ ParentAccessSettingsComponent,
+]
--
GitLab