Extracts some logic from poll_question to poll

This commit is contained in:
kikito
2016-11-07 17:34:24 +01:00
parent d39f19abb8
commit 83fd70b048
2 changed files with 13 additions and 3 deletions

View File

@@ -22,4 +22,13 @@ class Poll < ActiveRecord::Base
def expired?(timestamp = DateTime.now)
ends_at < timestamp
end
def answerable_by?(user)
user.present? && user.level_two_or_three_verified? && current?
end
def self.answerable_by(user)
return none if user.nil? || user.unverified?
current
end
end

View File

@@ -47,12 +47,13 @@ class Poll::Question < ActiveRecord::Base
end
def answerable_by?(user)
user.present? && poll.current? && (self.all_geozones || self.geozone_ids.include?(user.geozone_id))
poll.answerable_by?(user) && (self.all_geozones || self.geozone_ids.include?(user.geozone_id))
end
def self.answerable_by(user)
return where(false) unless user.present?
where(poll_id: Poll.current.pluck(:id))
return none if user.nil? || user.unverified?
where(poll_id: Poll.answerable_by(user).pluck(:id))
.joins(:geozones)
.where('poll_questions.all_geozones = ? or geozones.id = ?',
true,