dtext links: fix links from mod-only forum posts being exposed.

Fix links from mod-only forum posts being publicly visible in the
/dtext_links page.
This commit is contained in:
evazion
2021-03-10 02:33:51 -06:00
parent b169d60f64
commit 4320e2ef70
2 changed files with 10 additions and 0 deletions

View File

@@ -11,6 +11,12 @@ class DtextLink < ApplicationRecord
scope :wiki_page, -> { where(model_type: "WikiPage") }
scope :forum_post, -> { where(model_type: "ForumPost") }
def self.visible(user)
# XXX the double negation is to prevent postgres from choosing a bad query
# plan (it doesn't know that most forum posts aren't mod-only posts).
wiki_page.or(forum_post.where.not(model_id: ForumPost.not_visible(user)))
end
def self.model_types
%w[WikiPage ForumPost]
end

View File

@@ -40,6 +40,10 @@ class ForumPost < ApplicationRecord
where(topic_id: ForumTopic.visible(user))
end
def not_visible(user)
where.not(topic_id: ForumTopic.visible(user))
end
def wiki_link_matches(title)
where(id: DtextLink.forum_post.wiki_link.where(link_target: WikiPage.normalize_title(title)).select(:model_id))
end