diff --git a/.gitignore b/.gitignore index de3cbf82..7ef69fe2 100644 --- a/.gitignore +++ b/.gitignore @@ -89,3 +89,6 @@ dist/ .model_venv/ .vscode + +tests/thesis +thesis diff --git a/oarepo_requests/actions/delete_topic.py b/oarepo_requests/actions/delete_topic.py index 85d23269..7082ad02 100644 --- a/oarepo_requests/actions/delete_topic.py +++ b/oarepo_requests/actions/delete_topic.py @@ -7,6 +7,8 @@ class DeleteTopicAcceptAction(actions.AcceptAction): + log_event = True + def execute(self, identity, uow): topic = self.request.topic.resolve() topic_service = get_matching_service_for_record(topic) diff --git a/oarepo_requests/actions/edit_topic.py b/oarepo_requests/actions/edit_topic.py new file mode 100644 index 00000000..1c5f15d5 --- /dev/null +++ b/oarepo_requests/actions/edit_topic.py @@ -0,0 +1,18 @@ +from invenio_records_resources.services.uow import RecordDeleteOp + +# from .generic import AcceptAction +from invenio_requests.customizations import actions + +from ..utils import get_matching_service_for_record + + +class EditTopicAcceptAction(actions.AcceptAction): + log_event = True + + def execute(self, identity, uow): + topic = self.request.topic.resolve() + topic_service = get_matching_service_for_record(topic) + if not topic_service: + raise KeyError(f"topic {topic} service not found") + topic_service.edit(identity, topic.id, uow=uow) + super().execute(identity, uow) diff --git a/oarepo_requests/actions/publish_draft.py b/oarepo_requests/actions/publish_draft.py index dea6beea..563de6a0 100644 --- a/oarepo_requests/actions/publish_draft.py +++ b/oarepo_requests/actions/publish_draft.py @@ -12,6 +12,8 @@ def publish_draft(draft, identity, uow): class PublishDraftAcceptAction(actions.AcceptAction): + log_event = True + def execute(self, identity, uow): topic = self.request.topic.resolve() publish_draft(topic, identity, uow) diff --git a/oarepo_requests/types/delete_record.py b/oarepo_requests/types/delete_record.py index 4c1a1147..ff94b1fa 100644 --- a/oarepo_requests/types/delete_record.py +++ b/oarepo_requests/types/delete_record.py @@ -4,11 +4,12 @@ from .generic import OARepoRequestType +from oarepo_runtime.i18n import lazy_gettext as _ class DeleteRecordRequestType(OARepoRequestType): available_actions = { **RequestType.available_actions, "accept": DeleteTopicAcceptAction, } - description = "request deletion of published record" + description = _("Request deletion of published record") receiver_can_be_none = True diff --git a/oarepo_requests/types/edit_record.py b/oarepo_requests/types/edit_record.py new file mode 100644 index 00000000..d19bfd84 --- /dev/null +++ b/oarepo_requests/types/edit_record.py @@ -0,0 +1,16 @@ +from invenio_requests.customizations import RequestType + +from oarepo_requests.actions.edit_topic import EditTopicAcceptAction + +from .generic import OARepoRequestType + +from oarepo_runtime.i18n import lazy_gettext as _ + + +class EditRecordRequestType(OARepoRequestType): + available_actions = { + **RequestType.available_actions, + "accept": EditTopicAcceptAction, + } + description = _("Request re-opening of published record") + receiver_can_be_none = True diff --git a/oarepo_requests/types/publish_draft.py b/oarepo_requests/types/publish_draft.py index 0482f4d9..0438271b 100644 --- a/oarepo_requests/types/publish_draft.py +++ b/oarepo_requests/types/publish_draft.py @@ -4,11 +4,13 @@ from .generic import OARepoRequestType +from oarepo_runtime.i18n import lazy_gettext as _ + class PublishDraftRequestType(OARepoRequestType): available_actions = { **RequestType.available_actions, "accept": PublishDraftAcceptAction, } - description = "request publishing of a draft" + description = _("Request publishing of a draft") receiver_can_be_none = True diff --git a/oarepo_requests/utils.py b/oarepo_requests/utils.py index 33337050..71a2ae5f 100644 --- a/oarepo_requests/utils.py +++ b/oarepo_requests/utils.py @@ -1,5 +1,4 @@ from invenio_access.permissions import system_identity -from invenio_records_resources.proxies import current_service_registry from invenio_requests import current_requests_service from invenio_requests.proxies import current_request_type_registry from invenio_requests.resolvers.registry import ResolverRegistry @@ -103,8 +102,8 @@ def resolve_reference_dict(reference_dict): except ValueError: # Value error ignored from matches_reference_dict pass - obj = topic_resolver.proxy_cls( - topic_resolver, reference_dict, topic_resolver.record_cls + obj = topic_resolver.get_entity_proxy( + reference_dict ).resolve() return obj diff --git a/setup.cfg b/setup.cfg index 4e01855a..ea3d5609 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = oarepo-requests -version = 1.1.2 +version = 1.1.3 description = authors = Ronald Krist readme = README.md @@ -12,10 +12,13 @@ long_description_content_type = text/markdown python = >=3.9 install_requires = invenio-requests -#packages = find: +packages = find: [options.package_data] -* = *.json, *.rst, *.md, *.json5, *.jinja2 +* = *.json, *.rst, *.md, *.json5, *.jinja2, *.html, *.jinja + +[options.packages.find] +exclude = thesis [options.extras_require] tests = diff --git a/tests/conftest.py b/tests/conftest.py index d9407e33..827bb8e7 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -84,7 +84,7 @@ def _result(topic_id, request_id): "reference": {"user": "1"}, "type": "user", }, - "description": "request publishing of a draft", + "description": "Request publishing of a draft", "expires_at": None, "id": request_id, "is_closed": False, @@ -253,27 +253,6 @@ def users(app, db): db.session.commit() return [user1, user2] - """ - from invenio_db import db - - user1 = UserFixture( - email="user1@example.org", - password="password", - preferences={"visibility": "public"}, - ) - user1.create(app, db) - - user2 = UserFixture( - email="user2@example.org", - password="password", - preferences={"visibility": "public"}, - ) - user2.create(app, db) - - return [user1, user2] - """ - - @pytest.fixture() def client_with_login(client, users): """Log in a user to the client.""" diff --git a/tests/test_ui/test_ui_resource.py b/tests/test_ui/test_ui_resource.py index e09041a1..431cbac8 100644 --- a/tests/test_ui/test_ui_resource.py +++ b/tests/test_ui/test_ui_resource.py @@ -20,7 +20,7 @@ def test_draft_publish_request_present( "name": "Non-duplicable", } assert data["creatable_request_types"]["thesis_draft_publish_draft"] == { - "description": "request publishing of a draft", + "description": "Request publishing of a draft", "links": {"actions": {"create": "https://127.0.0.1:5000/api/requests"}}, "name": "Publish-draft", } @@ -48,7 +48,7 @@ def test_record_delete_request_present( "name": "Generic-request", } assert data["creatable_request_types"]["thesis_delete_record"] == { - "description": "request deletion of published record", + "description": "Request deletion of published record", "links": {"actions": {"create": "https://127.0.0.1:5000/api/requests"}}, "name": "Delete-record", }