diff --git a/app/assets/javascripts/discourse/models/action_summary.js b/app/assets/javascripts/discourse/models/action_summary.js index f1d4abb53..26a649df0 100644 --- a/app/assets/javascripts/discourse/models/action_summary.js +++ b/app/assets/javascripts/discourse/models/action_summary.js @@ -109,16 +109,15 @@ Discourse.ActionSummary = Discourse.Model.extend({ }, deferFlags: function() { - var actionSummary = this; + var self = this; return Discourse.ajax("/post_actions/defer_flags", { type: "POST", data: { - post_action_type_id: this.get('id'), - id: this.get('post.id') + post_action_type_id: this.get("id"), + id: this.get("post.id") } - }).then(function(result) { - actionSummary.set('post.hidden', result.hidden); - actionSummary.set('count', 0); + }).then(function () { + self.set("count", 0); }); }, diff --git a/app/controllers/admin/flags_controller.rb b/app/controllers/admin/flags_controller.rb index 1fdbab0eb..976b070d8 100644 --- a/app/controllers/admin/flags_controller.rb +++ b/app/controllers/admin/flags_controller.rb @@ -44,7 +44,6 @@ class Admin::FlagsController < Admin::AdminController PostAction.clear_flags!(post, current_user) - post.reload post.unhide! render nothing: true diff --git a/app/controllers/post_actions_controller.rb b/app/controllers/post_actions_controller.rb index 2b4964881..aa1d14b9e 100644 --- a/app/controllers/post_actions_controller.rb +++ b/app/controllers/post_actions_controller.rb @@ -50,14 +50,8 @@ class PostActionsController < ApplicationController guardian.ensure_can_defer_flags!(@post) PostAction.defer_flags!(@post, current_user) - @post.reload - if @post.is_flagged? - render json: { success: true, hidden: true } - else - @post.unhide! - render json: { success: true, hidden: false } - end + render json: { success: true } end private diff --git a/app/models/post.rb b/app/models/post.rb index 7064cad4d..60678011f 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -281,10 +281,9 @@ class Post < ActiveRecord::Base end def unhide! - self.hidden = false - self.hidden_reason_id = nil + self.update_attributes(hidden: false, hidden_at: nil, hidden_reason_id: nil) self.topic.update_attributes(visible: true) - save + save(validate: false) end def url diff --git a/lib/post_revisor.rb b/lib/post_revisor.rb index d1d84d661..d33f2b367 100644 --- a/lib/post_revisor.rb +++ b/lib/post_revisor.rb @@ -101,12 +101,8 @@ class PostRevisor @post.self_edits += 1 if @editor == @post.user 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.hidden_at = nil - @post.topic.update_attributes(visible: true) - PostAction.clear_flags!(@post, Discourse.system_user) + @post.unhide! end @post.extract_quoted_post_numbers diff --git a/lib/validators/post_validator.rb b/lib/validators/post_validator.rb index da32daee8..c61768194 100644 --- a/lib/validators/post_validator.rb +++ b/lib/validators/post_validator.rb @@ -68,7 +68,7 @@ class Validators::PostValidator < ActiveModel::Validator def unique_post_validator(post) return if SiteSetting.unique_posts_mins == 0 return if post.skip_unique_check - return if post.acting_user.admin? || post.acting_user.moderator? + return if post.acting_user.staff? # If the post is empty, default to the validates_presence_of return if post.raw.blank? diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index 12402e3bc..a40c88729 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -847,4 +847,21 @@ describe Post do end end + describe ".unhide!" do + before { SiteSetting.stubs(:unique_posts_mins).returns(5) } + + it "will unhide the post" do + post = create_post(user: Fabricate(:newuser)) + post.update_columns(hidden: true, hidden_at: Time.now, hidden_reason_id: 1) + post.reload + + post.hidden.should == true + + post.unhide! + post.reload + + post.hidden.should == false + end + end + end