diff --git a/oarepo_requests/actions/delete_draft.py b/oarepo_requests/actions/delete_draft.py index 02846f46..a412e942 100644 --- a/oarepo_requests/actions/delete_draft.py +++ b/oarepo_requests/actions/delete_draft.py @@ -10,6 +10,4 @@ def apply(self, identity, request_type, topic, uow, *args, **kwargs): if not topic_service: raise KeyError(f"topic {topic} service not found") topic_service.delete_draft(identity, topic["id"], uow=uow, *args, **kwargs) - cancel_requests_on_topic_delete( - self.request, topic, uow - ) + cancel_requests_on_topic_delete(self.request, topic, uow) diff --git a/oarepo_requests/actions/delete_published_record.py b/oarepo_requests/actions/delete_published_record.py index c571c747..cf6e9543 100644 --- a/oarepo_requests/actions/delete_published_record.py +++ b/oarepo_requests/actions/delete_published_record.py @@ -1,13 +1,20 @@ from oarepo_runtime.datastreams.utils import get_record_service_for_record +from oarepo_runtime.i18n import lazy_gettext as _ from .cascade_events import cancel_requests_on_topic_delete -from .generic import OARepoAcceptAction +from .generic import OARepoAcceptAction, OARepoDeclineAction class DeletePublishedRecordAcceptAction(OARepoAcceptAction): + name = _("Permanently delete") + def apply(self, identity, request_type, topic, uow, *args, **kwargs): topic_service = get_record_service_for_record(topic) if not topic_service: raise KeyError(f"topic {topic} service not found") topic_service.delete(identity, topic["id"], uow=uow, *args, **kwargs) cancel_requests_on_topic_delete(self.request, topic, uow) + + +class DeletePublishedRecordDeclineAction(OARepoDeclineAction): + name = _("Keep the record") diff --git a/oarepo_requests/actions/generic.py b/oarepo_requests/actions/generic.py index 46a30477..e84089a8 100644 --- a/oarepo_requests/actions/generic.py +++ b/oarepo_requests/actions/generic.py @@ -1,11 +1,16 @@ from functools import cached_property from invenio_requests.customizations import actions +from oarepo_runtime.i18n import lazy_gettext as _ from oarepo_requests.proxies import current_oarepo_requests class OARepoGenericActionMixin: + @classmethod + def stateful_name(cls, identity, **kwargs): + return cls.name + def apply(self, identity, request_type, topic, uow, *args, **kwargs): pass @@ -57,14 +62,17 @@ def apply(self, identity, request_type, topic, uow, *args, **kwargs): class OARepoSubmitAction(OARepoGenericActionMixin, actions.SubmitAction): + name = _("Submit") """""" class OARepoDeclineAction(OARepoGenericActionMixin, actions.DeclineAction): + name = _("Decline") """""" class OARepoAcceptAction(OARepoGenericActionMixin, actions.AcceptAction): + name = _("Accept") """""" diff --git a/oarepo_requests/actions/publish_draft.py b/oarepo_requests/actions/publish_draft.py index bf7e9caa..2be10fa9 100644 --- a/oarepo_requests/actions/publish_draft.py +++ b/oarepo_requests/actions/publish_draft.py @@ -2,9 +2,15 @@ from invenio_records_resources.services.uow import RecordCommitOp from marshmallow import ValidationError from oarepo_runtime.datastreams.utils import get_record_service_for_record +from oarepo_runtime.i18n import lazy_gettext as _ from .cascade_events import update_topic -from .generic import AddTopicLinksOnPayloadMixin, OARepoAcceptAction, OARepoSubmitAction +from .generic import ( + AddTopicLinksOnPayloadMixin, + OARepoAcceptAction, + OARepoDeclineAction, + OARepoSubmitAction, +) class PublishDraftSubmitAction(OARepoSubmitAction): @@ -27,6 +33,8 @@ class PublishDraftAcceptAction(AddTopicLinksOnPayloadMixin, OARepoAcceptAction): self_link = "published_record:links:self" self_html_link = "published_record:links:self_html" + name = _("Publish") + def apply(self, identity, request_type, topic, uow, *args, **kwargs): topic_service = get_record_service_for_record(topic) if not topic_service: @@ -44,3 +52,7 @@ def apply(self, identity, request_type, topic, uow, *args, **kwargs): return super().apply( identity, request_type, published_topic, uow, *args, **kwargs ) + + +class PublishDraftDeclineAction(OARepoDeclineAction): + name = _("Return for correction") diff --git a/oarepo_requests/types/delete_published_record.py b/oarepo_requests/types/delete_published_record.py index 69670b2a..437db83a 100644 --- a/oarepo_requests/types/delete_published_record.py +++ b/oarepo_requests/types/delete_published_record.py @@ -3,6 +3,7 @@ from oarepo_requests.actions.delete_published_record import ( DeletePublishedRecordAcceptAction, + DeletePublishedRecordDeclineAction, ) from ..utils import is_auto_approved, request_identity_matches @@ -22,6 +23,7 @@ def available_actions(cls): return { **super().available_actions, "accept": DeletePublishedRecordAcceptAction, + "decline": DeletePublishedRecordDeclineAction, } description = _("Request deletion of published record") diff --git a/oarepo_requests/types/publish_draft.py b/oarepo_requests/types/publish_draft.py index 5c5e00ec..a5ba6f45 100644 --- a/oarepo_requests/types/publish_draft.py +++ b/oarepo_requests/types/publish_draft.py @@ -11,6 +11,7 @@ from oarepo_requests.actions.publish_draft import ( PublishDraftAcceptAction, + PublishDraftDeclineAction, PublishDraftSubmitAction, ) @@ -51,6 +52,7 @@ def available_actions(cls): **super().available_actions, "submit": PublishDraftSubmitAction, "accept": PublishDraftAcceptAction, + "decline": PublishDraftDeclineAction, } description = _("Request publishing of a draft") diff --git a/oarepo_requests/ui/components/__init__.py b/oarepo_requests/ui/components/__init__.py index a6e210a4..9613bc5f 100644 --- a/oarepo_requests/ui/components/__init__.py +++ b/oarepo_requests/ui/components/__init__.py @@ -1,3 +1,4 @@ +from oarepo_requests.ui.components.action_labels import ActionLabelsComponent from oarepo_requests.ui.components.custom_fields import ( FormConfigCustomFieldsComponent, FormConfigRequestTypePropertiesComponent, @@ -6,4 +7,5 @@ __all__ = ( "FormConfigCustomFieldsComponent", "FormConfigRequestTypePropertiesComponent", + "ActionLabelsComponent", ) diff --git a/oarepo_requests/ui/components/action_labels.py b/oarepo_requests/ui/components/action_labels.py new file mode 100644 index 00000000..a5f9c04b --- /dev/null +++ b/oarepo_requests/ui/components/action_labels.py @@ -0,0 +1,15 @@ +from oarepo_ui.resources.components import UIResourceComponent + + +class ActionLabelsComponent(UIResourceComponent): + def form_config(self, *, identity, view_args, form_config, **kwargs): + type_ = view_args.get("request_type") + action_labels = {} + for action_type, action in type_.available_actions.items(): + if hasattr(action, "stateful_name"): + name = action.stateful_name(identity, **kwargs) + else: + name = action_type.capitalize() + action_labels[action_type] = name + + form_config["action_labels"] = action_labels diff --git a/oarepo_requests/ui/config.py b/oarepo_requests/ui/config.py index e9b83bad..a42c888b 100644 --- a/oarepo_requests/ui/config.py +++ b/oarepo_requests/ui/config.py @@ -18,6 +18,7 @@ from oarepo_ui.resources.links import UIRecordLink from oarepo_requests.ui.components import ( + ActionLabelsComponent, FormConfigCustomFieldsComponent, FormConfigRequestTypePropertiesComponent, ) @@ -46,6 +47,7 @@ class RequestsFormConfigResourceConfig(FormConfigResourceConfig): AllowedHtmlTagsComponent, FormConfigCustomFieldsComponent, FormConfigRequestTypePropertiesComponent, + ActionLabelsComponent, ] request_view_args = {"request_type": RequestTypeSchema()} routes = { diff --git a/setup.cfg b/setup.cfg index 690359d8..db00a150 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = oarepo-requests -version = 2.2.3 +version = 2.2.4 description = authors = Ronald Krist readme = README.md diff --git a/tests/test_ui/test_ui_resource.py b/tests/test_ui/test_ui_resource.py index bb8a3405..aa2c6fd2 100644 --- a/tests/test_ui/test_ui_resource.py +++ b/tests/test_ui/test_ui_resource.py @@ -94,7 +94,6 @@ def test_request_detail_page( assert c.status_code == 200 print(c.text) - def test_form_config(app, client, record_ui_resource, fake_manifest): with client.get("/requests/configs/publish_draft") as c: assert c.json == { @@ -160,4 +159,13 @@ def test_form_config(app, client, record_ui_resource, fake_manifest): "editable": False, "has_form": True, }, + "action_labels": { + "accept": "Publish", + "cancel": "Cancel", + "create": "Create", + "decline": "Return for correction", + "delete": "Delete", + "expire": "Expire", + "submit": "Submit", + }, }