From 3fc01de19cef50b10a79279a76050ac9fc230168 Mon Sep 17 00:00:00 2001 From: evazion Date: Mon, 21 Mar 2022 03:51:01 -0500 Subject: [PATCH] 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. --- app/models/moderation_report.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/moderation_report.rb b/app/models/moderation_report.rb index 7a8f3ed72..ed2a7ad10 100644 --- a/app/models/moderation_report.rb +++ b/app/models/moderation_report.rb @@ -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