diff --git a/oarepo_communities/ui/communities_components/templates/oarepo/invenio_communities/details/header.html b/oarepo_communities/ui/communities_components/templates/oarepo/invenio_communities/details/header.html index d9f9700..c2e1a89 100644 --- a/oarepo_communities/ui/communities_components/templates/oarepo/invenio_communities/details/header.html +++ b/oarepo_communities/ui/communities_components/templates/oarepo/invenio_communities/details/header.html @@ -3,7 +3,7 @@ {%- block subheader_buttons %}
- {%- if not community_use_jinja_header and can_view_deposit_page %} + {% if active_community_header_menu_item == "search" and permissions.can_create_record %} diff --git a/oarepo_communities/ui/oarepo_communities/components.py b/oarepo_communities/ui/oarepo_communities/components.py index 53970b4..3c05e2a 100644 --- a/oarepo_communities/ui/oarepo_communities/components.py +++ b/oarepo_communities/ui/oarepo_communities/components.py @@ -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" + )