diff --git a/app/models/poll.rb b/app/models/poll.rb index a4435d321..caa374dc8 100644 --- a/app/models/poll.rb +++ b/app/models/poll.rb @@ -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 diff --git a/app/models/poll/question.rb b/app/models/poll/question.rb index 6d56a31f2..d6534e420 100644 --- a/app/models/poll/question.rb +++ b/app/models/poll/question.rb @@ -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,