闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

13 lines
522 B

  1. # frozen_string_literal: true
  2. class VoteValidator < ActiveModel::Validator
  3. def validate(vote)
  4. vote.errors.add(:base, I18n.t('polls.errors.expired')) if vote.poll.expired?
  5. if vote.poll.multiple? && vote.poll.votes.where(account: vote.account, choice: vote.choice).exists?
  6. vote.errors.add(:base, I18n.t('polls.errors.already_voted'))
  7. elsif !vote.poll.multiple? && vote.poll.votes.where(account: vote.account).exists?
  8. vote.errors.add(:base, I18n.t('polls.errors.already_voted'))
  9. end
  10. end
  11. end