diff --git a/app/models/post.rb b/app/models/post.rb index 77c82499972..4acccaaace0 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -9,11 +9,6 @@ require 'digest/sha1' class Post < ActiveRecord::Base include RateLimiter::OnCreateRecord - module HiddenReason - FLAG_THRESHOLD_REACHED = 1 - FLAG_THRESHOLD_REACHED_AGAIN = 2 - end - versioned if: :raw_changed? rate_limit @@ -51,6 +46,10 @@ class Post < ActiveRecord::Base scope :by_newest, order('created_at desc, id desc') scope :with_user, includes(:user) + def self.hidden_reasons + @hidden_reasons ||= Enum.new(:flag_threshold_reached, :flag_threshold_reached_again) + end + def raw_quality sentinel = TextSentinel.new(raw, min_entropy: SiteSetting.body_min_entropy) if sentinel.valid? diff --git a/app/models/post_action.rb b/app/models/post_action.rb index 1eb0e10d4a4..dd51a390b6b 100644 --- a/app/models/post_action.rb +++ b/app/models/post_action.rb @@ -160,7 +160,7 @@ class PostAction < ActiveRecord::Base old_flags, new_flags = flag_counts['old_flags'].to_i, flag_counts['new_flags'].to_i if new_flags >= SiteSetting.flags_required_to_hide_post - reason = old_flags > 0 ? Post::HiddenReason::FLAG_THRESHOLD_REACHED_AGAIN : Post::HiddenReason::FLAG_THRESHOLD_REACHED + reason = old_flags > 0 ? Post.hidden_reasons[:flag_threshold_reached_again] : Post.hidden_reasons[:flag_threshold_reached] Post.update_all(["hidden = true, hidden_reason_id = COALESCE(hidden_reason_id, ?)", reason], id: post_id) Topic.update_all({ visible: false }, ["id = :topic_id AND NOT EXISTS(SELECT 1 FROM POSTS WHERE topic_id = :topic_id AND NOT hidden)", topic_id: post.topic_id]) diff --git a/lib/post_revisor.rb b/lib/post_revisor.rb index 74522e1a1b3..8ff983dc87b 100644 --- a/lib/post_revisor.rb +++ b/lib/post_revisor.rb @@ -69,7 +69,7 @@ class PostRevisor @post.updated_by = @user @post.last_editor_id = @user.id - if @post.hidden && @post.hidden_reason_id == Post::HiddenReason::FLAG_THRESHOLD_REACHED + if @post.hidden && @post.hidden_reason_id == Post.hidden_reasons[:flag_threshold_reached] @post.hidden = false @post.hidden_reason_id = nil @post.topic.update_attributes(visible: true) diff --git a/spec/models/post_action_spec.rb b/spec/models/post_action_spec.rb index 62feb32c1be..3ac3e78b06c 100644 --- a/spec/models/post_action_spec.rb +++ b/spec/models/post_action_spec.rb @@ -149,7 +149,7 @@ describe PostAction do post.reload post.hidden.should.should be_true - post.hidden_reason_id.should == Post::HiddenReason::FLAG_THRESHOLD_REACHED + post.hidden_reason_id.should == Post.hidden_reasons[:flag_threshold_reached] post.topic.visible.should be_false post.revise(post.user, post.raw + " ha I edited it ") @@ -165,14 +165,14 @@ describe PostAction do post.reload post.hidden.should be_true - post.hidden_reason_id.should == Post::HiddenReason::FLAG_THRESHOLD_REACHED_AGAIN + post.hidden_reason_id.should == Post.hidden_reasons[:flag_threshold_reached_again] post.revise(post.user, post.raw + " ha I edited it again ") post.reload post.hidden.should be_true - post.hidden_reason_id.should == Post::HiddenReason::FLAG_THRESHOLD_REACHED_AGAIN + post.hidden_reason_id.should == Post.hidden_reasons[:flag_threshold_reached_again] end end