Fix #5035: Double flags being created in certain conditions.

Lock the post to prevent a race condition when validating that the user
hasn't already flagged the post.
This commit is contained in:
evazion
2022-03-08 03:15:16 -06:00
parent 0713dae49d
commit f0a5936091

View File

@@ -8,6 +8,8 @@ class PostFlag < ApplicationRecord
belongs_to :creator, class_name: "User"
belongs_to :post
before_validation { post.lock! }
validates :reason, presence: true, length: { in: 1..140 }
validate :validate_creator_is_not_limited, on: :create
validate :validate_post, on: :create