From 7db68ae6faca15e67a3a900d0c479614fe5e8276 Mon Sep 17 00:00:00 2001 From: Emma Lejeck Date: Sun, 8 Dec 2024 14:37:25 -0800 Subject: [PATCH] Put hiding held items behind FF --- app/models/post.rb | 19 +++++++++++++------ app/policies/comment_policy.rb | 19 +++++++++++++------ app/policies/media_reaction_policy.rb | 19 +++++++++++++------ 3 files changed, 39 insertions(+), 18 deletions(-) diff --git a/app/models/post.rb b/app/models/post.rb index f54f60537..c24459c4a 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -33,12 +33,19 @@ class Post < ApplicationRecord scope :sfw, -> { where(nsfw: false) } scope :in_group, ->(group) { where(target_group: group) } scope :visible_for, ->(user) { - where(target_group_id: Group.visible_for(user)) - .or(where(target_group_id: nil)) - .where(hidden_at: nil) - .not_held - .or(where(user_id: user).where.not(hidden_at: nil)) - .or(where(user_id: user).held) + if Flipper[:hide_held].enabled?(user) + where(target_group_id: Group.visible_for(user)) + .or(where(target_group_id: nil)) + .where(hidden_at: nil) + .not_held + .or(where(user_id: user).where.not(hidden_at: nil)) + .or(where(user_id: user).held) + else + where(target_group_id: Group.visible_for(user)) + .or(where(target_group_id: nil)) + .where(hidden_at: nil) + .or(where(user_id: user).where.not(hidden_at: nil)) + end } validates :content, :content_formatted, presence: true, unless: :uploads diff --git a/app/policies/comment_policy.rb b/app/policies/comment_policy.rb index 329ef4014..db23b046d 100644 --- a/app/policies/comment_policy.rb +++ b/app/policies/comment_policy.rb @@ -49,12 +49,19 @@ class Scope < Scope def resolve return scope if can_administrate? - scope - .where.not(user_id: blocked_users) - .not_held - .where(hidden_at: nil) - .or(scope.where(user_id: user).where.not(hidden_at: nil)) - .or(scope.where(user_id: user).held) + if Flipper[:hide_held].enabled?(user) + scope + .where.not(user_id: blocked_users) + .not_held + .where(hidden_at: nil) + .or(scope.where(user_id: user).where.not(hidden_at: nil)) + .or(scope.where(user_id: user).held) + else + scope + .where.not(user_id: blocked_users) + .where(hidden_at: nil) + .or(scope.where(user_id: user).where.not(hidden_at: nil)) + end end end end diff --git a/app/policies/media_reaction_policy.rb b/app/policies/media_reaction_policy.rb index 7fd6835cb..0caf3ceb8 100644 --- a/app/policies/media_reaction_policy.rb +++ b/app/policies/media_reaction_policy.rb @@ -27,12 +27,19 @@ class Scope < Scope def resolve return scope if can_administrate? - scope - .where.not(user_id: blocked_users) - .not_held - .where(hidden_at: nil) - .or(scope.where(user_id: user).where.not(hidden_at: nil)) - .or(scope.where(user_id: user).held) + if Flipper[:hide_held].enabled?(user) + scope + .where.not(user_id: blocked_users) + .not_held + .where(hidden_at: nil) + .or(scope.where(user_id: user).where.not(hidden_at: nil)) + .or(scope.where(user_id: user).held) + else + scope + .where.not(user_id: blocked_users) + .where(hidden_at: nil) + .or(scope.where(user_id: user).where.not(hidden_at: nil)) + end end end end