models: refactor search visibility methods.
Refactor how model visibility works in index actions: * Call `visible` in the controller instead of in model `search` methods. This decouples model visibility from model searching. * Explicitly pass CurrentUser when calling `visible`. This reduces hidden dependencies on the current user inside models. * Standardize on calling the method `visible`. In some places it was called `permitted` instead. * Add a `visible` base method to ApplicationModel.
This commit is contained in:
@@ -8,7 +8,10 @@ class ForumPostVote < ApplicationRecord
|
||||
scope :down, -> {where(score: -1)}
|
||||
scope :by, ->(user_id) {where(creator_id: user_id)}
|
||||
scope :excluding_user, ->(user_id) {where("creator_id <> ?", user_id)}
|
||||
scope :visible, -> { where(forum_post: ForumPost.permitted) }
|
||||
|
||||
def self.visible(user)
|
||||
where(forum_post: ForumPost.visible(user))
|
||||
end
|
||||
|
||||
def self.forum_post_matches(params)
|
||||
return all if params.blank?
|
||||
|
||||
Reference in New Issue
Block a user