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

communities: Add noindex meta tags to unverified community pages #1096

Merged
merged 1 commit into from
Dec 12, 2024
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
15 changes: 15 additions & 0 deletions site/zenodo_rdm/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
3 changes: 2 additions & 1 deletion site/zenodo_rdm/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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
30 changes: 30 additions & 0 deletions templates/semantic-ui/invenio_communities/details/base.html
Original file line number Diff line number Diff line change
@@ -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 %}