Files
grecia/app/models/widget/feed.rb
taitus 7e826a9cb4 Do not show unpublished proposals on the homepage
The chances of an unpublished proposal appearing on the homepage was
very low because only the proposals with the most votes appear there and
unpublished proposals don't have any votes. However, it was technically
possible on new sites where only a few proposals had been created.
2021-09-08 12:38:54 +02:00

35 lines
631 B
Ruby

class Widget::Feed < ApplicationRecord
KINDS = %w[proposals debates processes].freeze
def active?
setting.value.present?
end
def setting
Setting.find_by(key: "homepage.widgets.feeds.#{kind}")
end
def self.active
KINDS.map do |kind|
feed = find_or_create_by!(kind: kind)
feed if feed.active?
end.compact
end
def items
send(kind)
end
def proposals
Proposal.published.sort_by_hot_score.limit(limit)
end
def debates
Debate.sort_by_hot_score.limit(limit)
end
def processes
Legislation::Process.open.published.order("created_at DESC").limit(limit)
end
end