Converted flag threshold constants to enums
This commit is contained in:
parent
aea848f164
commit
5aec5261a7
|
@ -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?
|
||||
|
|
|
@ -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])
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue