diff --git a/site/zenodo_rdm/filters.py b/site/zenodo_rdm/filters.py index 366567c8..a570582c 100644 --- a/site/zenodo_rdm/filters.py +++ b/site/zenodo_rdm/filters.py @@ -7,6 +7,7 @@ """Filters to be used in the Jinja templates.""" +from invenio_communities.proxies import current_communities from invenio_rdm_records.proxies import current_rdm_records_service as records_service from invenio_records.dictutils import dict_lookup @@ -46,3 +47,17 @@ def is_verified_record(record): return record.parent.is_verified except Exception: return False + + +def is_verified_community(community): + """Return ``True`` if record is verified. + + NOTE: This is not a good way to check in a Jinja template if a record is verified, + since it fetches again the record from the DB. We should include the verification + information in the template context. + """ + try: + comm = current_communities.service.record_cls.pid.resolve(community["id"]) + return comm.is_verified + except Exception: + return False diff --git a/site/zenodo_rdm/views.py b/site/zenodo_rdm/views.py index ea180c90..3bcabe52 100644 --- a/site/zenodo_rdm/views.py +++ b/site/zenodo_rdm/views.py @@ -14,7 +14,7 @@ from marshmallow import ValidationError from .decorators import cached_unless_authenticated_or_flashes -from .filters import is_blr_related_record, is_verified_record +from .filters import is_blr_related_record, is_verified_community, is_verified_record from .support.support import ZenodoSupport @@ -91,5 +91,6 @@ def handle_validation_errors(e): # Register template filters blueprint.add_app_template_filter(is_blr_related_record) blueprint.add_app_template_test(is_verified_record, name="verified_record") + blueprint.add_app_template_test(is_verified_community, name="verified_community") return blueprint diff --git a/templates/semantic-ui/invenio_communities/details/base.html b/templates/semantic-ui/invenio_communities/details/base.html new file mode 100644 index 00000000..98695fbb --- /dev/null +++ b/templates/semantic-ui/invenio_communities/details/base.html @@ -0,0 +1,30 @@ +{# -*- coding: utf-8 -*- + + This file is part of Zenodo. + Copyright (C) 2024 CERN. + + Zenodo is a free software; you can redistribute it and/or modify it + under the terms of the MIT License; see LICENSE file for more details. +#} + +{% extends "invenio_communities/base.html" %} + +{%- if community is not verified_community -%} + {% set meta_robot_tags = [ + { + "name": "robots", + "content": "noindex, nofollow", + "data-reason": ("Community is not verified" if permissions.can_moderate), + } + ] %} +{%- endif -%} + +{%- block javascript %} +{{ super() }} +{{ webpack['invenio-communities-header.js'] }} +{%- endblock javascript %} + +{%- block page_body %} + {% set community_menu_active = True %} + {% include "invenio_communities/details/header.html" %} +{%- endblock page_body %}