Skip to content
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
31 changes: 24 additions & 7 deletions integreat_cms/cms/utils/internal_link_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def check_translation_link(
def check_object_link(
content_type: str,
manager: RelatedManager,
slug: str,
path_components: list[str] | str,
url: Url,
region: Region,
language: Language,
Expand All @@ -226,24 +226,27 @@ def check_object_link(
:param content_type: The content type (``Page``, ``Event`` or ``POI``)
:param manager: The object manager
:param url: The internal URL to check
:param slug: The slug of the translation
:param path_components: Split up path components including slug of the translation
:param region: The region
:param language: The language
"""
translation_slug = (
path_components[-1] if content_type == "Page" else path_components
)
objects = manager.filter(
translations__slug=slugify(slug, allow_unicode=True),
translations__slug=slugify(translation_slug, allow_unicode=True),
translations__language=language,
).distinct()
if not objects and region.fallback_translations_enabled:
objects = manager.filter(
translations__slug=slugify(slug, allow_unicode=True),
translations__slug=slugify(translation_slug, allow_unicode=True),
translations__language=region.default_language,
).distinct()
if not objects:
logger.debug(
"%s with slug %r does not exist in %r and %r",
content_type,
slug,
translation_slug,
region,
language,
)
Expand All @@ -252,12 +255,26 @@ def check_object_link(
_("The link target does not exist in this region and language."),
)
elif len(objects) == 1:
if content_type == "Page":
ancestors = objects[0].get_cached_ancestors()
for ancestor in ancestors:
if not (
ancestor.get_public_translation(language.slug)
or ancestor.get_public_translation(region.default_language.slug)
):
logger.debug(
"The page ancestor %r of the page %r is not public",
ancestor,
objects[0],
)
mark_invalid(url, _("One of the page ancestors is not public"))
return url.status
check_translation_link(objects[0], url, language)
else:
logger.warning(
"%s slug %r is not unique in %r and %r (also returned %r)",
content_type,
slug,
translation_slug,
region,
language,
objects,
Expand Down Expand Up @@ -424,7 +441,7 @@ def check_internal(url: Url) -> bool | None: # noqa: PLR0911
return check_object_link(
"Page",
region.pages,
path_components[-1],
path_components,
url,
region,
language,
Expand Down
11 changes: 7 additions & 4 deletions integreat_cms/locale/de/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -9419,11 +9419,10 @@ msgstr ""
"Sprachen erfordert."

#: cms/utils/content_utils.py
msgid ""
"This contact belongs to a different region and cannot be displayed."
msgid "This contact belongs to a different region and cannot be displayed."
msgstr ""
"Dieser Kontakt gehört zu einer anderen Region und kann nicht angezeigt werden. "

"Dieser Kontakt gehört zu einer anderen Region und kann nicht angezeigt "
"werden. "

#: cms/utils/content_utils.py
msgid "Oops! Error displaying contact data"
Expand Down Expand Up @@ -9522,6 +9521,10 @@ msgstr "Das Linkziel ist in dieser Sprache nicht öffentlich."
msgid "The link target does not exist in this region and language."
msgstr "Das Linkziel existiert nicht in dieser Region und Sprache."

#: cms/utils/internal_link_checker.py
msgid "One of the page ancestors is not public"
msgstr "Eine übergeordnete Seite ist nicht öffentlich"

#: cms/utils/internal_link_checker.py
msgid "The link target is not unique in this region and language."
msgstr "Das Linkziel ist in dieser Region und Sprache nicht eindeutig."
Expand Down
2 changes: 2 additions & 0 deletions integreat_cms/release_notes/current/unreleased/4325.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
en: Fix that broken links are reported as valid when target page has a ancestor that isn't public.
de: Behebe das Problem, dass defekte Links als gültig gemeldet werden, wenn die Zielseite eine übergeordnete Seite hat, die nicht öffentlich ist.
Loading