Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deposit-ui: permissions-based record access config #2142

Merged
merged 2 commits into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions invenio_app_rdm/records_ui/views/deposits.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ def get_form_pids_config():
return pids_providers


def get_record_permissions(actions, record=None):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it make sense to make it a part of the service class?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels a lot like a utility function, since service methods usually return ResultItem objects. Another issue is that the record argument has to be an API Record which is difficult to get hold of without calling a service and accessing item._record...

There's a similar method on ResultItem.has_permissions_to, used on the deposit_edit view below, which does exactly that. The issue is that in the deposit_create view, we don't have a draft item result from the service to call it (since we're starting a new one).

It would look something like inveniosoftware/invenio-records-resources#456, but kwargs would need to be low-level objects.

"""Helper for generating (default) record action permissions."""
service = current_rdm_records.records_service
return {
f"can_{action}": service.check_permission(g.identity, action, record=record)
for action in actions
}


class VocabulariesOptions:
"""Holds React form vocabularies options."""

Expand Down Expand Up @@ -305,7 +314,6 @@ def get_form_config(**kwargs):
pids=get_form_pids_config(),
quota=conf.get("APP_RDM_DEPOSIT_FORM_QUOTA"),
decimal_size_display=conf.get("APP_RDM_DISPLAY_DECIMAL_FILE_SIZES", True),
can_have_metadata_only_records=conf.get("RDM_ALLOW_METADATA_ONLY_RECORDS"),
links=dict(
user_dashboard_request=conf["RDM_REQUESTS_ROUTES"][
"user-dashboard-request-details"
Expand Down Expand Up @@ -355,6 +363,12 @@ def deposit_create(community=None):
record=new_record(),
files=dict(default_preview=None, entries=[], links={}),
preselectedCommunity=community,
permissions=get_record_permissions(
[
"manage_files",
"manage_record_access",
]
),
)


Expand All @@ -373,5 +387,12 @@ def deposit_edit(pid_value, draft=None, draft_files=None):
record=record,
files=files_dict,
searchbar_config=dict(searchUrl=get_search_url()),
permissions=draft.has_permissions_to(["new_version", "delete_draft"]),
permissions=draft.has_permissions_to(
[
"new_version",
"delete_draft",
"manage_files",
"manage_record_access",
]
),
)
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ export class RDMDepositForm extends Component {
isDraftRecord={!record.is_published}
quota={this.config.quota}
decimalSizeDisplay={this.config.decimal_size_display}
showMetadataOnlyToggle={permissions?.can_manage_files}
/>
</Overridable>
</AccordionField>
Expand Down Expand Up @@ -608,6 +609,7 @@ export class RDMDepositForm extends Component {
label={i18next.t("Visibility")}
labelIcon="shield"
fieldPath="access"
showMetadataAccess={permissions?.can_manage_record_access}
/>
</Overridable>
{permissions?.can_delete_draft && (
Expand Down