Skip to content

Commit

Permalink
Merge pull request #90 from oarepo/stojanovic/ep-139-new-record-creat…
Browse files Browse the repository at this point in the history
…ion-communities

checking permission for new record btn
  • Loading branch information
mirekys authored Jan 7, 2025
2 parents 39b197c + 5a070d4 commit eb06536
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{%- block subheader_buttons %}
<div
class="sixteen wide mobile sixteen wide tablet three wide computer right aligned middle aligned column">
{%- if not community_use_jinja_header and can_view_deposit_page %}
{% if active_community_header_menu_item == "search" and permissions.can_create_record %}
<a href="{{ config.RECORD_ROUTES['new'].format(community_slug=community.slug) }}"
class="ui positive button labeled icon rel-mt-1 theme-secondary">
<i class="upload icon" aria-hidden="true"></i>
Expand Down
24 changes: 21 additions & 3 deletions oarepo_communities/ui/oarepo_communities/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,31 @@ def before_ui_search(
self, *, search_options, extra_context, identity, view_args, **kwargs
):
community = view_args.get("community")
community_id = str(community.id)

workflow_name = community["custom_fields"].get("workflow", "default")
from oarepo_workflows.errors import InvalidWorkflowError
from oarepo_workflows.proxies import current_oarepo_workflows

if workflow_name not in current_oarepo_workflows.record_workflows:
raise InvalidWorkflowError(
f"Workflow {workflow_name} does not exist in the configuration."
)

workflow = current_oarepo_workflows.record_workflows[workflow_name]
permissions = workflow.permissions(
"create", data={"parent": {"communities": {"default": community_id}}}
)
can_create_record = permissions.allows(identity)

# for consistency with invenio-communities routes
# needed to check if there is something in the curation policy and
# about page, so that those tabs would render in the menu
request.community = community.to_dict()
permissions = community.has_permissions_to(HEADER_PERMISSIONS)
permissions["can_create_record"] = can_create_record
extra_context["community"] = community
extra_context["permissions"] = permissions
search_options["overrides"][
"ui_endpoint"
] = f"/communities/{community.id}/records"
search_options["overrides"]["ui_endpoint"] = (
f"/communities/{community_id}/records"
)

0 comments on commit eb06536

Please sign in to comment.