FIX: disagree flag should unhide hidden post

This commit is contained in:
Régis Hanol 2014-08-11 10:48:00 +02:00
parent f897c89d48
commit e64d3b8a42
7 changed files with 27 additions and 23 deletions
app
assets/javascripts/discourse/models
controllers
models
lib
spec/models

View File

@ -109,16 +109,15 @@ Discourse.ActionSummary = Discourse.Model.extend({
}, },
deferFlags: function() { deferFlags: function() {
var actionSummary = this; var self = this;
return Discourse.ajax("/post_actions/defer_flags", { return Discourse.ajax("/post_actions/defer_flags", {
type: "POST", type: "POST",
data: { data: {
post_action_type_id: this.get('id'), post_action_type_id: this.get("id"),
id: this.get('post.id') id: this.get("post.id")
} }
}).then(function(result) { }).then(function () {
actionSummary.set('post.hidden', result.hidden); self.set("count", 0);
actionSummary.set('count', 0);
}); });
}, },

View File

@ -44,7 +44,6 @@ class Admin::FlagsController < Admin::AdminController
PostAction.clear_flags!(post, current_user) PostAction.clear_flags!(post, current_user)
post.reload
post.unhide! post.unhide!
render nothing: true render nothing: true

View File

@ -50,14 +50,8 @@ class PostActionsController < ApplicationController
guardian.ensure_can_defer_flags!(@post) guardian.ensure_can_defer_flags!(@post)
PostAction.defer_flags!(@post, current_user) PostAction.defer_flags!(@post, current_user)
@post.reload
if @post.is_flagged? render json: { success: true }
render json: { success: true, hidden: true }
else
@post.unhide!
render json: { success: true, hidden: false }
end
end end
private private

View File

@ -281,10 +281,9 @@ class Post < ActiveRecord::Base
end end
def unhide! def unhide!
self.hidden = false self.update_attributes(hidden: false, hidden_at: nil, hidden_reason_id: nil)
self.hidden_reason_id = nil
self.topic.update_attributes(visible: true) self.topic.update_attributes(visible: true)
save save(validate: false)
end end
def url def url

View File

@ -101,12 +101,8 @@ class PostRevisor
@post.self_edits += 1 if @editor == @post.user @post.self_edits += 1 if @editor == @post.user
if @editor == @post.user && @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.hidden_at = nil
@post.topic.update_attributes(visible: true)
PostAction.clear_flags!(@post, Discourse.system_user) PostAction.clear_flags!(@post, Discourse.system_user)
@post.unhide!
end end
@post.extract_quoted_post_numbers @post.extract_quoted_post_numbers

View File

@ -68,7 +68,7 @@ class Validators::PostValidator < ActiveModel::Validator
def unique_post_validator(post) def unique_post_validator(post)
return if SiteSetting.unique_posts_mins == 0 return if SiteSetting.unique_posts_mins == 0
return if post.skip_unique_check 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 # If the post is empty, default to the validates_presence_of
return if post.raw.blank? return if post.raw.blank?

View File

@ -847,4 +847,21 @@ describe Post do
end end
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 end