Skip to content

Commit

Permalink
Merge pull request #7 from oarepo/miroslavsimek/be-232-request-type-f…
Browse files Browse the repository at this point in the history
…or-edit-published-record

edit action
  • Loading branch information
SilvyPuzzlewell authored Mar 14, 2024
2 parents 85e5273 + baab0da commit 1b43724
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 32 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,6 @@ dist/

.model_venv/
.vscode

tests/thesis
thesis
2 changes: 2 additions & 0 deletions oarepo_requests/actions/delete_topic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 18 additions & 0 deletions oarepo_requests/actions/edit_topic.py
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 2 additions & 0 deletions oarepo_requests/actions/publish_draft.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion oarepo_requests/types/delete_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 16 additions & 0 deletions oarepo_requests/types/edit_record.py
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion oarepo_requests/types/publish_draft.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 2 additions & 3 deletions oarepo_requests/utils.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

Expand Down
9 changes: 6 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = oarepo-requests
version = 1.1.2
version = 1.1.3
description =
authors = Ronald Krist <[email protected]>
readme = README.md
Expand All @@ -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 =
Expand Down
23 changes: 1 addition & 22 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -253,27 +253,6 @@ def users(app, db):
db.session.commit()
return [user1, user2]

"""
from invenio_db import db
user1 = UserFixture(
email="[email protected]",
password="password",
preferences={"visibility": "public"},
)
user1.create(app, db)
user2 = UserFixture(
email="[email protected]",
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."""
Expand Down
4 changes: 2 additions & 2 deletions tests/test_ui/test_ui_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
Expand Down Expand Up @@ -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",
}
Expand Down

0 comments on commit 1b43724

Please sign in to comment.