mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-12 20:34:01 +08:00
What is the problem? `TopicLink` records can reference deleted topics or posts. When a topic or the target post being linked to is deleted, these orphaned links continue to appear in topic maps and post link counts. Note that `TopicLink` records are already deleted when the source post containing the link is trashed (see `Post#trash!`), so we only need to filter for deleted target topics/posts. Additionally, internal links stored with http:// are not normalized to https:// when `force_https` site setting is enabled. --- What is the solution? Extend filtering in `TopicLink.topic_map` and `TopicLink.counts_for` to exclude links where the target topic or target post is deleted. Extract common visibility filters into `TopicLink.apply_link_visibility_filters` helper method. Normalize internal http:// URLs to https:// in `TopicLinkSerializer#url` when `force_https` is enabled.
34 lines
693 B
Ruby
34 lines
693 B
Ruby
# frozen_string_literal: true
|
|
|
|
class TopicLinkSerializer < ApplicationSerializer
|
|
attributes :url,
|
|
:title,
|
|
# :fancy_title,
|
|
:internal,
|
|
:attachment,
|
|
:reflection,
|
|
:clicks,
|
|
:user_id,
|
|
:domain,
|
|
:root_domain
|
|
|
|
def url
|
|
if object.internal && SiteSetting.force_https && object.url.start_with?("http://")
|
|
object.url.sub("http://", "https://")
|
|
else
|
|
object.url
|
|
end
|
|
end
|
|
|
|
def attachment
|
|
Discourse.store.has_been_uploaded?(object.url)
|
|
end
|
|
|
|
def include_user_id?
|
|
object.user_id.present?
|
|
end
|
|
|
|
def root_domain
|
|
MiniSuffix.domain(domain)
|
|
end
|
|
end
|