mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 18:33:52 +08:00
FIX: 'undo flag' marks the flag as disagreed
This commit is contained in:
parent
87ca49e26e
commit
220f9e21e3
|
@ -18,22 +18,22 @@ class PostAction < ActiveRecord::Base
|
||||||
scope :spam_flags, -> { where(post_action_type_id: PostActionType.types[:spam]) }
|
scope :spam_flags, -> { where(post_action_type_id: PostActionType.types[:spam]) }
|
||||||
scope :flags, -> { where(post_action_type_id: PostActionType.notify_flag_type_ids) }
|
scope :flags, -> { where(post_action_type_id: PostActionType.notify_flag_type_ids) }
|
||||||
scope :publics, -> { where(post_action_type_id: PostActionType.public_type_ids) }
|
scope :publics, -> { where(post_action_type_id: PostActionType.public_type_ids) }
|
||||||
scope :active, -> { where(defered_at: nil, agreed_at: nil, deleted_at: nil) }
|
scope :active, -> { where(disagreed_at: nil, defered_at: nil, agreed_at: nil, deleted_at: nil) }
|
||||||
|
|
||||||
after_save :update_counters
|
after_save :update_counters
|
||||||
after_save :enforce_rules
|
after_save :enforce_rules
|
||||||
after_commit :notify_subscribers
|
after_commit :notify_subscribers
|
||||||
|
|
||||||
def disposed_by_id
|
def disposed_by_id
|
||||||
deleted_by_id || agreed_by_id || defered_by_id
|
disagreed_by_id || agreed_by_id || defered_by_id
|
||||||
end
|
end
|
||||||
|
|
||||||
def disposed_at
|
def disposed_at
|
||||||
deleted_at || agreed_at || defered_at
|
disagreed_at || agreed_at || defered_at
|
||||||
end
|
end
|
||||||
|
|
||||||
def disposition
|
def disposition
|
||||||
return :disagreed if deleted_at
|
return :disagreed if disagreed_at
|
||||||
return :agreed if agreed_at
|
return :agreed if agreed_at
|
||||||
return :defered if defered_at
|
return :defered if defered_at
|
||||||
nil
|
nil
|
||||||
|
@ -60,7 +60,7 @@ class PostAction < ActiveRecord::Base
|
||||||
return {} if collection.blank?
|
return {} if collection.blank?
|
||||||
|
|
||||||
collection_ids = collection.map(&:id)
|
collection_ids = collection.map(&:id)
|
||||||
user_id = user.present? ? user.id : 0
|
user_id = user.try(:id) || 0
|
||||||
|
|
||||||
post_actions = PostAction.where(post_id: collection_ids, user_id: user_id)
|
post_actions = PostAction.where(post_id: collection_ids, user_id: user_id)
|
||||||
|
|
||||||
|
@ -107,8 +107,8 @@ class PostAction < ActiveRecord::Base
|
||||||
.where(post_action_type_id: action_type_ids)
|
.where(post_action_type_id: action_type_ids)
|
||||||
|
|
||||||
actions.each do |action|
|
actions.each do |action|
|
||||||
action.deleted_at = Time.zone.now
|
action.disagreed_at = Time.zone.now
|
||||||
action.deleted_by_id = moderator.id
|
action.disagreed_by_id = moderator.id
|
||||||
# so callback is called
|
# so callback is called
|
||||||
action.save
|
action.save
|
||||||
action.add_moderator_post_if_needed(moderator, :disagreed)
|
action.add_moderator_post_if_needed(moderator, :disagreed)
|
||||||
|
@ -276,6 +276,7 @@ class PostAction < ActiveRecord::Base
|
||||||
.where(post_id: post_id)
|
.where(post_id: post_id)
|
||||||
.where(post_action_type_id: post_action_type_ids)
|
.where(post_action_type_id: post_action_type_ids)
|
||||||
.where(deleted_at: nil)
|
.where(deleted_at: nil)
|
||||||
|
.where(disagreed_at: nil)
|
||||||
.where(targets_topic: targets_topic)
|
.where(targets_topic: targets_topic)
|
||||||
.exists?
|
.exists?
|
||||||
end
|
end
|
||||||
|
@ -284,19 +285,20 @@ class PostAction < ActiveRecord::Base
|
||||||
# can weigh flags differently.
|
# can weigh flags differently.
|
||||||
def self.flag_counts_for(post_id)
|
def self.flag_counts_for(post_id)
|
||||||
flag_counts = exec_sql("SELECT SUM(CASE
|
flag_counts = exec_sql("SELECT SUM(CASE
|
||||||
WHEN pa.deleted_at IS NULL AND (pa.staff_took_action) THEN :flags_required_to_hide_post
|
WHEN pa.disagreed_at IS NULL AND pa.staff_took_action THEN :flags_required_to_hide_post
|
||||||
WHEN pa.deleted_at IS NULL AND (NOT pa.staff_took_action) THEN 1
|
WHEN pa.disagreed_at IS NULL AND NOT pa.staff_took_action THEN 1
|
||||||
ELSE 0
|
ELSE 0
|
||||||
END) AS new_flags,
|
END) AS new_flags,
|
||||||
SUM(CASE
|
SUM(CASE
|
||||||
WHEN pa.deleted_at IS NOT NULL AND (pa.staff_took_action) THEN :flags_required_to_hide_post
|
WHEN pa.disagreed_at IS NOT NULL AND pa.staff_took_action THEN :flags_required_to_hide_post
|
||||||
WHEN pa.deleted_at IS NOT NULL AND (NOT pa.staff_took_action) THEN 1
|
WHEN pa.disagreed_at IS NOT NULL AND NOT pa.staff_took_action THEN 1
|
||||||
ELSE 0
|
ELSE 0
|
||||||
END) AS old_flags
|
END) AS old_flags
|
||||||
FROM post_actions AS pa
|
FROM post_actions AS pa
|
||||||
INNER JOIN users AS u ON u.id = pa.user_id
|
INNER JOIN users AS u ON u.id = pa.user_id
|
||||||
WHERE pa.post_id = :post_id AND
|
WHERE pa.post_id = :post_id
|
||||||
pa.post_action_type_id IN (:post_action_types)",
|
AND pa.post_action_type_id IN (:post_action_types)
|
||||||
|
AND pa.deleted_at IS NULL",
|
||||||
post_id: post_id,
|
post_id: post_id,
|
||||||
post_action_types: PostActionType.auto_action_flag_types.values,
|
post_action_types: PostActionType.auto_action_flag_types.values,
|
||||||
flags_required_to_hide_post: SiteSetting.flags_required_to_hide_post).first
|
flags_required_to_hide_post: SiteSetting.flags_required_to_hide_post).first
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
class AddDisagreedAtAndDisagreedByIdToPostAction < ActiveRecord::Migration
|
||||||
|
def up
|
||||||
|
add_column :post_actions, :disagreed_at, :datetime
|
||||||
|
add_column :post_actions, :disagreed_by_id, :integer
|
||||||
|
|
||||||
|
execute <<-SQL
|
||||||
|
UPDATE post_actions
|
||||||
|
SET disagreed_at = deleted_at,
|
||||||
|
disagreed_by_id = deleted_by_id,
|
||||||
|
deleted_at = NULL,
|
||||||
|
deleted_by_id = NULL
|
||||||
|
WHERE deleted_by_id != user_id
|
||||||
|
SQL
|
||||||
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
execute <<-SQL
|
||||||
|
UPDATE post_actions
|
||||||
|
SET deleted_at = disagreed_at,
|
||||||
|
deleted_by_id = disagreed_by_id
|
||||||
|
WHERE disagreed_by_id != user_id
|
||||||
|
SQL
|
||||||
|
|
||||||
|
remove_column :post_actions, :disagreed_at
|
||||||
|
remove_column :post_actions, :disagreed_by_id
|
||||||
|
end
|
||||||
|
end
|
|
@ -112,8 +112,7 @@ module FlagQuery
|
||||||
.joins("INNER JOIN topics ON topics.id = posts.topic_id")
|
.joins("INNER JOIN topics ON topics.id = posts.topic_id")
|
||||||
|
|
||||||
if filter == "old"
|
if filter == "old"
|
||||||
post_actions.with_deleted
|
post_actions.where("post_actions.disagreed_at IS NOT NULL OR
|
||||||
.where("post_actions.deleted_at IS NOT NULL OR
|
|
||||||
post_actions.defered_at IS NOT NULL OR
|
post_actions.defered_at IS NOT NULL OR
|
||||||
post_actions.agreed_at IS NOT NULL")
|
post_actions.agreed_at IS NOT NULL")
|
||||||
else
|
else
|
||||||
|
|
|
@ -281,12 +281,13 @@ describe PostAction do
|
||||||
|
|
||||||
post.reload
|
post.reload
|
||||||
|
|
||||||
post.hidden.should.should be_true
|
post.hidden.should be_true
|
||||||
post.hidden_reason_id.should == Post.hidden_reasons[:flag_threshold_reached]
|
|
||||||
post.hidden_at.should be_present
|
post.hidden_at.should be_present
|
||||||
|
post.hidden_reason_id.should == Post.hidden_reasons[:flag_threshold_reached]
|
||||||
post.topic.visible.should be_false
|
post.topic.visible.should be_false
|
||||||
|
|
||||||
post.revise(post.user, post.raw + " ha I edited it ")
|
post.revise(post.user, post.raw + " ha I edited it ")
|
||||||
|
|
||||||
post.reload
|
post.reload
|
||||||
|
|
||||||
post.hidden.should be_false
|
post.hidden.should be_false
|
||||||
|
@ -300,8 +301,9 @@ describe PostAction do
|
||||||
post.reload
|
post.reload
|
||||||
|
|
||||||
post.hidden.should be_true
|
post.hidden.should be_true
|
||||||
|
post.hidden_at.should be_present
|
||||||
post.hidden_reason_id.should == Post.hidden_reasons[:flag_threshold_reached_again]
|
post.hidden_reason_id.should == Post.hidden_reasons[:flag_threshold_reached_again]
|
||||||
post.hidden_at.should be_true
|
post.topic.visible.should be_false
|
||||||
|
|
||||||
post.revise(post.user, post.raw + " ha I edited it again ")
|
post.revise(post.user, post.raw + " ha I edited it again ")
|
||||||
|
|
||||||
|
@ -310,6 +312,7 @@ describe PostAction do
|
||||||
post.hidden.should be_true
|
post.hidden.should be_true
|
||||||
post.hidden_at.should be_true
|
post.hidden_at.should be_true
|
||||||
post.hidden_reason_id.should == Post.hidden_reasons[:flag_threshold_reached_again]
|
post.hidden_reason_id.should == Post.hidden_reasons[:flag_threshold_reached_again]
|
||||||
|
post.topic.visible.should be_false
|
||||||
end
|
end
|
||||||
|
|
||||||
it "can flag the topic instead of a post" do
|
it "can flag the topic instead of a post" do
|
||||||
|
|
Loading…
Reference in New Issue
Block a user