From 7a843d2ac242bb1a585bccb2452e864fa0934cd3 Mon Sep 17 00:00:00 2001 From: riking Date: Thu, 27 Mar 2014 22:45:51 -0700 Subject: [PATCH] FIX: Only unhide flagged post if editor is the author Also, rename @user to @editor in PostRevisor --- lib/post_revisor.rb | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/post_revisor.rb b/lib/post_revisor.rb index 851f888e1ad..bf796428a6f 100644 --- a/lib/post_revisor.rb +++ b/lib/post_revisor.rb @@ -8,10 +8,17 @@ class PostRevisor @post = post end - def revise!(user, new_raw, opts = {}) - @user, @new_raw, @opts = user, new_raw, opts - return false if not should_revise? - @post.acting_user = @user + # Recognized options: + # :edit_reason User-supplied edit reason + # :revised_at changes the date of the revision + # :force_new_version bypass ninja-edit window + # :bypass_bump do not bump the topic, even if last post + # :skip_validation ask ActiveRecord to skip validations + # + def revise!(editor, new_raw, opts = {}) + @editor, @new_raw, @opts = editor, new_raw, opts + return false unless should_revise? + @post.acting_user = @editor revise_post update_category_description update_topic_excerpt @@ -54,7 +61,7 @@ class PostRevisor end def should_create_new_version? - @post.last_editor_id != @user.id || + @post.last_editor_id != @editor.id || get_revised_at - @post.last_version_at > SiteSetting.ninja_edit_window.to_i || @opts[:force_new_version] == true end @@ -64,7 +71,7 @@ class PostRevisor @post.version += 1 @post.last_version_at = get_revised_at update_post - EditRateLimiter.new(@user).performed! unless @opts[:bypass_rate_limiter] == true + EditRateLimiter.new(@editor).performed! unless @opts[:bypass_rate_limiter] == true bump_topic unless @opts[:bypass_bump] end end @@ -84,10 +91,10 @@ class PostRevisor def update_post @post.raw = @new_raw @post.word_count = @new_raw.scan(/\w+/).size - @post.last_editor_id = @user.id + @post.last_editor_id = @editor.id @post.edit_reason = @opts[:edit_reason] if @opts[:edit_reason] - if @post.hidden && @post.hidden_reason_id == Post.hidden_reasons[:flag_threshold_reached] + if @editor == @post.user && @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)