Skip to content

Commit

Permalink
Put hiding held items behind FF
Browse files Browse the repository at this point in the history
  • Loading branch information
NuckChorris committed Dec 8, 2024
1 parent e15c9f8 commit 7db68ae
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 18 deletions.
19 changes: 13 additions & 6 deletions app/models/post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 13 additions & 6 deletions app/policies/comment_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
19 changes: 13 additions & 6 deletions app/policies/media_reaction_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 7db68ae

Please sign in to comment.