From 9f6485771939519190d1971bfa02a2bb1aca6746 Mon Sep 17 00:00:00 2001 From: evazion Date: Thu, 4 May 2017 14:58:03 -0500 Subject: [PATCH] flags: move status locked check to post_flag.rb. --- app/models/post.rb | 4 ---- app/models/post_flag.rb | 9 ++++----- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/app/models/post.rb b/app/models/post.rb index 9906baff8..0fd17a293 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -296,10 +296,6 @@ class Post < ActiveRecord::Base end def flag!(reason, options = {}) - if is_status_locked? - raise PostFlag::Error.new("Post is locked and cannot be flagged") - end - flag = flags.create(:reason => reason, :is_resolved => false, :is_deletion => options[:is_deletion]) if flag.errors.any? diff --git a/app/models/post_flag.rb b/app/models/post_flag.rb index 1bd137f1e..17a625653 100644 --- a/app/models/post_flag.rb +++ b/app/models/post_flag.rb @@ -11,7 +11,7 @@ class PostFlag < ActiveRecord::Base belongs_to :post validates_presence_of :reason, :creator_id, :creator_ip_addr validate :validate_creator_is_not_limited - validate :validate_post_is_active + validate :validate_post before_validation :initialize_creator, :on => :create validates_uniqueness_of :creator_id, :scope => :post_id, :on => :create, :unless => :is_deletion, :message => "have already flagged this post" before_save :update_post @@ -146,10 +146,9 @@ class PostFlag < ActiveRecord::Base end end - def validate_post_is_active - if post.is_deleted? - errors[:post] << "is deleted" - end + def validate_post + errors[:post] << "is locked and cannot be flagged" if post.is_status_locked? + errors[:post] << "is deleted" if post.is_deleted? end def initialize_creator