-
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 #68 from oarepo/krist/be-475-delete-draft
Krist/be 475 delete draft
- Loading branch information
Showing
13 changed files
with
237 additions
and
49 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,11 @@ | ||
from oarepo_runtime.datastreams.utils import get_record_service_for_record | ||
|
||
from .generic import OARepoAcceptAction | ||
|
||
|
||
class DeleteDraftAcceptAction(OARepoAcceptAction): | ||
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_draft(identity, topic["id"], uow=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
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
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,62 @@ | ||
from oarepo_runtime.i18n import lazy_gettext as _ | ||
from typing_extensions import override | ||
|
||
from ..actions.delete_draft import DeleteDraftAcceptAction | ||
from ..utils import is_auto_approved, request_identity_matches | ||
from .generic import NonDuplicableOARepoRequestType | ||
from .ref_types import ModelRefTypes | ||
|
||
|
||
class DeleteDraftRequestType(NonDuplicableOARepoRequestType): | ||
type_id = "delete_draft" | ||
name = _("Delete draft") | ||
|
||
dangerous = True | ||
|
||
@classmethod | ||
@property | ||
def available_actions(cls): | ||
return { | ||
**super().available_actions, | ||
"accept": DeleteDraftAcceptAction, | ||
} | ||
|
||
description = _("Request deletion of draft") | ||
receiver_can_be_none = True | ||
allowed_topic_ref_types = ModelRefTypes(published=False, draft=True) | ||
|
||
@override | ||
def stateful_name(self, identity, *, topic=None, request=None): | ||
if is_auto_approved(self, identity=identity, topic=topic): | ||
return self.name | ||
if not request: | ||
return _("Request draft deletion") | ||
match request.status: | ||
case "submitted": | ||
return _("Draft deletion requested") | ||
case _: | ||
return _("Request draft deletion") | ||
|
||
@override | ||
def stateful_description(self, identity, *, topic=None, request=None): | ||
if is_auto_approved(self, identity=identity, topic=topic): | ||
return _("Click to permanently delete the draft.") | ||
|
||
if not request: | ||
return _("Request permission to delete the draft.") | ||
match request.status: | ||
case "submitted": | ||
if request_identity_matches(request.created_by, identity): | ||
return _( | ||
"Permission to delete draft requested. " | ||
"You will be notified about the decision by email." | ||
) | ||
if request_identity_matches(request.receiver, identity): | ||
return _( | ||
"You have been asked to approve the request to permanently delete the draft. " | ||
"You can approve or reject the request." | ||
) | ||
return _("Permission to delete draft (including files) requested. ") | ||
case _: | ||
if request_identity_matches(request.created_by, identity): | ||
return _("Submit request to get permission to delete the draft.") |
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
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
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.