Do not allow adding votes to expired polls (#10214)
* Do not allow adding votes to expired polls * Only validate expires_at on create
This commit is contained in:
@ -241,6 +241,7 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
|
||||
|
||||
def poll_vote?
|
||||
return false if replied_to_status.nil? || replied_to_status.poll.nil? || !replied_to_status.local? || !replied_to_status.poll.options.include?(@object['name'])
|
||||
return true if replied_to_status.poll.expired?
|
||||
replied_to_status.poll.votes.create!(account: @account, choice: replied_to_status.poll.options.index(@object['name']), uri: @object['id'])
|
||||
end
|
||||
|
||||
|
@ -28,7 +28,7 @@ class Poll < ApplicationRecord
|
||||
|
||||
validates :options, presence: true
|
||||
validates :expires_at, presence: true, if: :local?
|
||||
validates_with PollValidator, if: :local?
|
||||
validates_with PollValidator, on: :create, if: :local?
|
||||
|
||||
scope :attached, -> { where.not(status_id: nil) }
|
||||
scope :unattached, -> { where(status_id: nil) }
|
||||
|
@ -11,6 +11,8 @@ class VoteService < BaseService
|
||||
@choices = choices
|
||||
@votes = []
|
||||
|
||||
return if @poll.expired?
|
||||
|
||||
ApplicationRecord.transaction do
|
||||
@choices.each do |choice|
|
||||
@votes << @poll.votes.create!(account: @account, choice: choice)
|
||||
|
Reference in New Issue
Block a user