From e2928f78d21c26e7e8337664cf6f4c8e80dbc437 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Mon, 2 May 2016 15:26:23 +0200 Subject: [PATCH] FIX: don't show top links from private categories in user summary --- app/models/topic.rb | 8 +++----- app/models/user_summary.rb | 4 ++-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/app/models/topic.rb b/app/models/topic.rb index 556130d79..1b433d84a 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -139,14 +139,12 @@ class Topic < ActiveRecord::Base # Query conditions condition = if ids.present? - ["NOT c.read_restricted or c.id in (:cats)", cats: ids] + ["NOT read_restricted OR id IN (:cats)", cats: ids] else - ["NOT c.read_restricted"] + ["NOT read_restricted"] end - where("category_id IS NULL OR category_id IN ( - SELECT c.id FROM categories c - WHERE #{condition[0]})", condition[1]) + where("topics.category_id IS NULL OR topics.category_id IN (SELECT id FROM categories WHERE #{condition[0]})", condition[1]) } attr_accessor :ignore_category_auto_close diff --git a/app/models/user_summary.rb b/app/models/user_summary.rb index a95094e0e..fc1c45578 100644 --- a/app/models/user_summary.rb +++ b/app/models/user_summary.rb @@ -30,7 +30,6 @@ class UserSummary .merge(Topic.listable_topics.visible.secured(@guardian)) .where(user: @user) .where('post_number > 1') - .where('topics.archetype <> ?', Archetype.private_message) .order('posts.like_count DESC, posts.created_at ASC') .limit(MAX_SUMMARY_RESULTS) end @@ -39,7 +38,8 @@ class UserSummary TopicLink .joins(:topic, :post) .includes(:topic, :post) - .where('topics.archetype <> ?', Archetype.private_message) + .where('posts.post_type IN (?)', Topic.visible_post_types(@guardian && @guardian.user)) + .merge(Topic.listable_topics.visible.secured(@guardian)) .where(user: @user) .where(internal: false, reflection: false, quote: false) .order('clicks DESC, topic_links.created_at ASC')