Refactor code getting a user's comments
This way it's more readable and easier to change.
This commit is contained in:
@@ -43,7 +43,11 @@ class Users::PublicActivityComponent < ApplicationComponent
|
|||||||
end
|
end
|
||||||
|
|
||||||
def comments
|
def comments
|
||||||
only_active_commentables.includes(:commentable)
|
Comment.not_valuations
|
||||||
|
.not_as_admin_or_moderator
|
||||||
|
.where(user_id: user.id)
|
||||||
|
.where.not(commentable_type: disabled_commentables)
|
||||||
|
.includes(:commentable)
|
||||||
end
|
end
|
||||||
|
|
||||||
def budget_investments
|
def budget_investments
|
||||||
@@ -66,18 +70,10 @@ class Users::PublicActivityComponent < ApplicationComponent
|
|||||||
params[:page]
|
params[:page]
|
||||||
end
|
end
|
||||||
|
|
||||||
def only_active_commentables
|
def disabled_commentables
|
||||||
disabled_commentables = []
|
[
|
||||||
disabled_commentables << "Debate" unless Setting["process.debates"]
|
("Debate" unless feature?(:debates)),
|
||||||
disabled_commentables << "Budget::Investment" unless Setting["process.budgets"]
|
("Budget::Investment" unless feature?(:budgets))
|
||||||
if disabled_commentables.present?
|
].compact
|
||||||
all_user_comments.where.not(commentable_type: disabled_commentables)
|
|
||||||
else
|
|
||||||
all_user_comments
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def all_user_comments
|
|
||||||
Comment.not_valuations.not_as_admin_or_moderator.where(user_id: user.id)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user