Factorize

This commit is contained in:
ricola 2026-03-23 18:57:25 -06:00
parent d5f77d338b
commit 185e47c5ff

View file

@ -585,7 +585,7 @@ def close_expired_votes
puts "#{Time.now.utc} Closing vote \"#{vote.title}\" because it expired on #{vote.expire_on}..." puts "#{Time.now.utc} Closing vote \"#{vote.title}\" because it expired on #{vote.expire_on}..."
vote.state = 'closed' vote.state = 'closed'
vote.save vote.save
User.all.each do |user| all_users_sorted.each do |user|
puts "#{Time.now.utc} Sending results by email to #{user.email}..." puts "#{Time.now.utc} Sending results by email to #{user.email}..."
mail = Mail.new mail = Mail.new
mail.from = settings.admin_email mail.from = settings.admin_email
@ -603,7 +603,7 @@ def send_reminders
settings.reminders.slice(vote.reminders..settings.reminders.length-1).each do |reminder| settings.reminders.slice(vote.reminders..settings.reminders.length-1).each do |reminder|
minutes_to_expiry = ( vote.expire_on - Time.now.utc ) / 60 minutes_to_expiry = ( vote.expire_on - Time.now.utc ) / 60
if minutes_to_expiry < reminder[:timeout] / 60 if minutes_to_expiry < reminder[:timeout] / 60
User.all.each do |user| all_users_sorted.each do |user|
if not vote.ratings.collect { |rating| rating.user }.include?(user) if not vote.ratings.collect { |rating| rating.user }.include?(user)
puts "#{Time.now.utc} Sending reminder #{reminder[:template]} for '#{vote.title}' to #{user.email}..." puts "#{Time.now.utc} Sending reminder #{reminder[:template]} for '#{vote.title}' to #{user.email}..."
mail = Mail.new mail = Mail.new
@ -660,6 +660,10 @@ helpers do
@candidate = Candidate.find(params[:cid]) @candidate = Candidate.find(params[:cid])
end end
def all_users_sorted
User.all.each.sort_by { |user| user.email }
end
def require_candidate_in_vote def require_candidate_in_vote
redirect '/votes/' + @vote.secure_id unless @candidate.vote == @vote redirect '/votes/' + @vote.secure_id unless @candidate.vote == @vote
end end