Skip to content

Commit

Permalink
Merge pull request #76 from oarepo/krist/be-488-add-button-labels-for…
Browse files Browse the repository at this point in the history
…-approve-decline-into-request-type-form

Krist/be 488 add button labels for approve decline into request type form
  • Loading branch information
mesemus authored Oct 23, 2024
2 parents e6a7436 + 004826d commit c6e9b46
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 7 deletions.
4 changes: 1 addition & 3 deletions oarepo_requests/actions/delete_draft.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
9 changes: 8 additions & 1 deletion oarepo_requests/actions/delete_published_record.py
Original file line number Diff line number Diff line change
@@ -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")
8 changes: 8 additions & 0 deletions oarepo_requests/actions/generic.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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")
""""""


Expand Down
14 changes: 13 additions & 1 deletion oarepo_requests/actions/publish_draft.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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:
Expand All @@ -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")
2 changes: 2 additions & 0 deletions oarepo_requests/types/delete_published_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from oarepo_requests.actions.delete_published_record import (
DeletePublishedRecordAcceptAction,
DeletePublishedRecordDeclineAction,
)

from ..utils import is_auto_approved, request_identity_matches
Expand All @@ -22,6 +23,7 @@ def available_actions(cls):
return {
**super().available_actions,
"accept": DeletePublishedRecordAcceptAction,
"decline": DeletePublishedRecordDeclineAction,
}

description = _("Request deletion of published record")
Expand Down
2 changes: 2 additions & 0 deletions oarepo_requests/types/publish_draft.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from oarepo_requests.actions.publish_draft import (
PublishDraftAcceptAction,
PublishDraftDeclineAction,
PublishDraftSubmitAction,
)

Expand Down Expand Up @@ -51,6 +52,7 @@ def available_actions(cls):
**super().available_actions,
"submit": PublishDraftSubmitAction,
"accept": PublishDraftAcceptAction,
"decline": PublishDraftDeclineAction,
}

description = _("Request publishing of a draft")
Expand Down
2 changes: 2 additions & 0 deletions oarepo_requests/ui/components/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from oarepo_requests.ui.components.action_labels import ActionLabelsComponent
from oarepo_requests.ui.components.custom_fields import (
FormConfigCustomFieldsComponent,
FormConfigRequestTypePropertiesComponent,
Expand All @@ -6,4 +7,5 @@
__all__ = (
"FormConfigCustomFieldsComponent",
"FormConfigRequestTypePropertiesComponent",
"ActionLabelsComponent",
)
15 changes: 15 additions & 0 deletions oarepo_requests/ui/components/action_labels.py
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions oarepo_requests/ui/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from oarepo_ui.resources.links import UIRecordLink

from oarepo_requests.ui.components import (
ActionLabelsComponent,
FormConfigCustomFieldsComponent,
FormConfigRequestTypePropertiesComponent,
)
Expand Down Expand Up @@ -46,6 +47,7 @@ class RequestsFormConfigResourceConfig(FormConfigResourceConfig):
AllowedHtmlTagsComponent,
FormConfigCustomFieldsComponent,
FormConfigRequestTypePropertiesComponent,
ActionLabelsComponent,
]
request_view_args = {"request_type": RequestTypeSchema()}
routes = {
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = oarepo-requests
version = 2.2.3
version = 2.2.4
description =
authors = Ronald Krist <[email protected]>
readme = README.md
Expand Down
10 changes: 9 additions & 1 deletion tests/test_ui/test_ui_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 == {
Expand Down Expand Up @@ -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",
},
}

0 comments on commit c6e9b46

Please sign in to comment.