From 824d4a426b79dee2e77b09795d9a828cceaf6b7c Mon Sep 17 00:00:00 2001 From: Rafael Silva Date: Tue, 21 Jan 2025 12:45:57 -0300 Subject: [PATCH] Restrict tags and categories to user visibility level --- app/services/discourse_rewind/action/favorite_categories.rb | 1 + app/services/discourse_rewind/action/favorite_tags.rb | 1 + app/services/discourse_rewind/fetch_reports.rb | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/services/discourse_rewind/action/favorite_categories.rb b/app/services/discourse_rewind/action/favorite_categories.rb index c0d4f76..641ae18 100644 --- a/app/services/discourse_rewind/action/favorite_categories.rb +++ b/app/services/discourse_rewind/action/favorite_categories.rb @@ -23,6 +23,7 @@ module DiscourseRewind .joins("INNER JOIN categories ON categories.id = topics.category_id") .where(user: user) .where(viewed_at: date) + .where(categories: { id: user.guardian.allowed_category_ids }) .group("categories.id, categories.name") .order("COUNT(*) DESC") .limit(5) diff --git a/app/services/discourse_rewind/action/favorite_tags.rb b/app/services/discourse_rewind/action/favorite_tags.rb index 0c75c72..112268d 100644 --- a/app/services/discourse_rewind/action/favorite_tags.rb +++ b/app/services/discourse_rewind/action/favorite_tags.rb @@ -25,6 +25,7 @@ module DiscourseRewind .joins("INNER JOIN tags ON tags.id = topic_tags.tag_id") .where(user: user) .where(viewed_at: date) + .where(tags: { id: Tag.visible(user.guardian).pluck(:id) }) .group("tags.id, tags.name") .order("COUNT(DISTINCT topic_views.topic_id) DESC") .limit(5) diff --git a/app/services/discourse_rewind/fetch_reports.rb b/app/services/discourse_rewind/fetch_reports.rb index e88f1cc..361711f 100644 --- a/app/services/discourse_rewind/fetch_reports.rb +++ b/app/services/discourse_rewind/fetch_reports.rb @@ -26,7 +26,7 @@ module DiscourseRewind Action::ReadingTime, Action::Reactions, Action::Fbff, - # Action::FavoriteTags, + Action::FavoriteTags, Action::FavoriteCategories, Action::BestTopics, Action::BestPosts,