FIX: disagree flag should unhide hidden post
This commit is contained in:
parent
f897c89d48
commit
e64d3b8a42
|
@ -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);
|
||||
});
|
||||
},
|
||||
|
||||
|
|
|
@ -44,7 +44,6 @@ class Admin::FlagsController < Admin::AdminController
|
|||
|
||||
PostAction.clear_flags!(post, current_user)
|
||||
|
||||
post.reload
|
||||
post.unhide!
|
||||
|
||||
render nothing: true
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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?
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue