Skip to content

Commit

Permalink
requests: pass record topic required permission via context
Browse files Browse the repository at this point in the history
  • Loading branch information
zzacharo committed Feb 24, 2025
1 parent cbec07c commit d138c76
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 8 deletions.
1 change: 1 addition & 0 deletions invenio_rdm_records/requests/community_inclusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class CommunityInclusion(RequestType):
allowed_topic_ref_types = ["record"]
needs_context = {
"community_roles": ["owner", "manager", "curator"],
"record_permission": "preview",
}

available_actions = {
Expand Down
1 change: 1 addition & 0 deletions invenio_rdm_records/requests/community_submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ class CommunitySubmission(ReviewRequest):
allowed_topic_ref_types = ["record"]
needs_context = {
"community_roles": ["owner", "manager", "curator"],
"record_permission": "preview",
}

available_actions = {
Expand Down
11 changes: 6 additions & 5 deletions invenio_rdm_records/requests/entity_resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,12 @@ def get_needs(self, ctx=None):
A user that can preview a record can also read its requests.
"""
record = self.resolve()
# TODO: we might need different needs for drafts and published records
# e.g community submission request vs community inclusion request
needs = current_rdm_records_service.config.permission_policy_cls(
"preview", record=record
).needs
needs = []
record_permission = ctx.get("record_permission")
if record_permission:
needs = current_rdm_records_service.config.permission_policy_cls(
record_permission, record=record
).needs
return needs


Expand Down
4 changes: 2 additions & 2 deletions invenio_rdm_records/services/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
from .schemas.tombstone import TombstoneSchema
from .search_params import (
MetricsParam,
MyOrSharedWIthMeDraftsParam,
SharedOrMineDraftsParam,
PublishedRecordsParam,
StatusParam,
)
Expand Down Expand Up @@ -243,7 +243,7 @@ class RDMSearchDraftsOptions(SearchDraftsOptions, SearchOptionsMixin):
}

params_interpreters_cls = [
MyOrSharedWIthMeDraftsParam
SharedOrMineDraftsParam
] + SearchDraftsOptions.params_interpreters_cls


Expand Down
2 changes: 1 addition & 1 deletion invenio_rdm_records/services/search_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def apply(self, identity, search, params):
return search


class MyOrSharedWIthMeDraftsParam(ParamInterpreter):
class SharedOrMineDraftsParam(ParamInterpreter):
"""Evaluates the shared_with_me parameter.
Returns only drafts owned by the user or shared with the user.
Expand Down

0 comments on commit d138c76

Please sign in to comment.