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:
@@ -40,13 +40,12 @@ class ForumPost < ApplicationRecord
|
||||
where(topic_id: ForumTopic.search(title_matches: title).select(:id))
|
||||
end
|
||||
|
||||
def permitted
|
||||
where(topic_id: ForumTopic.permitted)
|
||||
def visible(user)
|
||||
where(topic_id: ForumTopic.visible(user))
|
||||
end
|
||||
|
||||
def search(params)
|
||||
q = super
|
||||
q = q.permitted
|
||||
q = q.search_attributes(params, :creator, :updater, :topic_id, :is_deleted, :body)
|
||||
q = q.text_attribute_matches(:body, params[:body_matches], index_column: :text_index)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user