-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #111 from oarepo/miroslavsimek/be-667-create-a-new…
…-publish_new_version-request-type Miroslavsimek/be 667 create a new publish new version request type
- Loading branch information
Showing
9 changed files
with
8,431 additions
and
4,492 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# | ||
# Copyright (C) 2024 CESNET z.s.p.o. | ||
# | ||
# oarepo-requests is free software; you can redistribute it and/or | ||
# modify it under the terms of the MIT License; see LICENSE file for more | ||
# details. | ||
# | ||
"""Actions for publishing draft requests.""" | ||
|
||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING, Any | ||
|
||
from invenio_records_resources.services.uow import RecordCommitOp, UnitOfWork | ||
from oarepo_runtime.datastreams.utils import get_record_service_for_record | ||
from oarepo_runtime.i18n import lazy_gettext as _ | ||
|
||
if TYPE_CHECKING: | ||
from flask_principal import Identity | ||
from invenio_drafts_resources.records import Record | ||
from invenio_requests.customizations import RequestType | ||
|
||
from .publish_draft import PublishDraftAcceptAction | ||
|
||
|
||
class PublishNewVersionAcceptAction(PublishDraftAcceptAction): | ||
"""Accept action for publishing draft requests.""" | ||
|
||
self_link = "published_record:links:self" | ||
self_html_link = "published_record:links:self_html" | ||
|
||
name = _("Publish") | ||
|
||
def apply( | ||
self, | ||
identity: Identity, | ||
request_type: RequestType, | ||
topic: Record, | ||
uow: UnitOfWork, | ||
*args: Any, | ||
**kwargs: Any, | ||
) -> Record: | ||
"""Publish the draft.""" | ||
topic_service = get_record_service_for_record(topic) | ||
if not topic_service: | ||
raise KeyError(f"topic {topic} service not found") | ||
|
||
if "payload" in self.request and "version" in self.request["payload"]: | ||
topic.metadata["version"] = self.request["payload"]["version"] | ||
uow.register(RecordCommitOp(topic, indexer=topic_service.indexer)) | ||
|
||
return super().apply(identity, request_type, topic, uow, *args, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# | ||
# Copyright (C) 2024 CESNET z.s.p.o. | ||
# | ||
# oarepo-requests is free software; you can redistribute it and/or | ||
# modify it under the terms of the MIT License; see LICENSE file for more | ||
# details. | ||
# | ||
"""Publish draft request type.""" | ||
|
||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
import marshmallow as ma | ||
from oarepo_runtime.i18n import lazy_gettext as _ | ||
|
||
from ..actions.publish_draft import ( | ||
PublishDraftDeclineAction, | ||
PublishDraftSubmitAction, | ||
) | ||
from ..actions.publish_new_version import PublishNewVersionAcceptAction | ||
from ..utils import classproperty | ||
from .ref_types import ModelRefTypes | ||
|
||
if TYPE_CHECKING: | ||
from invenio_requests.customizations.actions import RequestAction | ||
|
||
|
||
from .publish_draft import PublishDraftRequestType | ||
|
||
|
||
class PublishNewVersionRequestType(PublishDraftRequestType): | ||
"""Publish draft request type.""" | ||
|
||
type_id = "publish_new_version" | ||
name = _("Publish new version") | ||
payload_schema = { | ||
**PublishDraftRequestType.payload_schema, | ||
"version": ma.fields.Str(), | ||
} | ||
|
||
form = { | ||
"field": "version", | ||
"ui_widget": "Input", | ||
"props": { | ||
"label": _("Resource version"), | ||
"placeholder": _("Write down the version (first, second…)."), | ||
"required": False, | ||
}, | ||
} | ||
|
||
@classproperty | ||
def available_actions(cls) -> dict[str, type[RequestAction]]: | ||
"""Return available actions for the request type.""" | ||
return { | ||
**super().available_actions, | ||
"submit": PublishDraftSubmitAction, | ||
"accept": PublishNewVersionAcceptAction, | ||
"decline": PublishDraftDeclineAction, | ||
} | ||
|
||
description = _("Request publishing of a draft") | ||
receiver_can_be_none = True | ||
allowed_topic_ref_types = ModelRefTypes(published=True, draft=True) | ||
|
||
editable = False # type: ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[metadata] | ||
name = oarepo-requests | ||
version = 2.3.16 | ||
version = 2.3.17 | ||
description = | ||
authors = Ronald Krist <[email protected]> | ||
readme = README.md | ||
|
@@ -57,6 +57,7 @@ invenio_requests.types = | |
edit_published_record = oarepo_requests.types.edit_record:EditPublishedRecordRequestType | ||
publish_draft = oarepo_requests.types.publish_draft:PublishDraftRequestType | ||
new_version = oarepo_requests.types.new_version:NewVersionRequestType | ||
publish_new_version = oarepo_requests.types.publish_new_version:PublishNewVersionRequestType | ||
oarepo_workflows.state_changed_notifiers = | ||
auto-requester = oarepo_requests.services.permissions.requester:auto_request_state_change_notifier | ||
invenio_base.finalize_app = | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.