Skip to content

Commit

Permalink
deposit-ui: permissions-based record access config (#2142)
Browse files Browse the repository at this point in the history
* deposit-ui: permissions-based record access config

* Passes config to the upload form based on permissions, to control
  the display of record access and metadata-only toggles.
  • Loading branch information
slint committed Mar 21, 2023
1 parent b4e1948 commit 4f28646
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
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):
"""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

0 comments on commit 4f28646

Please sign in to comment.