reports: fix exception when deleting reported comments or forum posts.

Fix regression in 1a4efbda3. Locking the comment before validation
failed when the comment had unsaved changes, as is the case when
clearing reports from a comment before it is deleted.
This commit is contained in:
evazion
2022-03-21 03:51:01 -05:00
parent 56f47c60e1
commit 3fc01de19c

View File

@@ -8,7 +8,7 @@ class ModerationReport < ApplicationRecord
belongs_to :model, polymorphic: true
belongs_to :creator, class_name: "User"
before_validation { model.lock! }
before_validation(on: :create) { model.lock! }
validates :reason, presence: true
validates :model_type, inclusion: { in: MODEL_TYPES }
validates :creator, uniqueness: { scope: [:model_type, :model_id], message: "have already reported this message." }, on: :create