mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 08:57:10 -06:00
flagging work, we should be clearing from the mod menu if a topic or post is deleted
This commit is contained in:
parent
3fd019c6bd
commit
6f2f7b0589
@ -24,11 +24,14 @@ limit 100
|
||||
|
||||
sql.where2 "post_action_type_id in (:flag_types)", flag_types: PostActionType.FlagTypes
|
||||
|
||||
|
||||
# it may make sense to add a view that shows flags on deleted posts,
|
||||
# we don't clear the flags on post deletion, just supress counts
|
||||
# they may have deleted_at on the action not set
|
||||
if params[:filter] == 'old'
|
||||
sql.where "p.deleted_at is null"
|
||||
sql.where2 "deleted_at is not null"
|
||||
else
|
||||
sql.where "p.deleted_at is null"
|
||||
sql.where "p.deleted_at is null and t.deleted_at is null"
|
||||
sql.where2 "deleted_at is null"
|
||||
end
|
||||
|
||||
|
@ -26,6 +26,8 @@ class Post < ActiveRecord::Base
|
||||
rate_limit
|
||||
|
||||
acts_as_paranoid
|
||||
after_recover :update_flagged_posts_count
|
||||
after_destroy :update_flagged_posts_count
|
||||
|
||||
belongs_to :user
|
||||
belongs_to :topic, counter_cache: :posts_count
|
||||
@ -163,6 +165,10 @@ class Post < ActiveRecord::Base
|
||||
where("(post_number = 1) or (score >= ?)", SiteSetting.best_of_score_threshold)
|
||||
end
|
||||
|
||||
def update_flagged_posts_count
|
||||
PostAction.update_flagged_posts_count
|
||||
end
|
||||
|
||||
def filter_quotes(parent_post=nil)
|
||||
return cooked if parent_post.blank?
|
||||
|
||||
|
@ -13,7 +13,10 @@ class PostAction < ActiveRecord::Base
|
||||
rate_limit :post_action_rate_limiter
|
||||
|
||||
def self.update_flagged_posts_count
|
||||
val = exec_sql('select count(*) from posts where deleted_at is null and id in (select post_id from post_actions where post_action_type_id in (?) and deleted_at is null)', PostActionType.FlagTypes).values[0][0].to_i
|
||||
val = exec_sql('select count(*) from posts p
|
||||
join topics t on t.id = p.topic_id
|
||||
where p.deleted_at is null and t.deleted_at is null and p.id in
|
||||
(select post_id from post_actions where post_action_type_id in (?) and deleted_at is null)', PostActionType.FlagTypes).values[0][0].to_i
|
||||
$redis.set('posts_flagged_count', val)
|
||||
|
||||
admins = User.exec_sql("select id from users where admin = 't'").map{|r| r["id"].to_i}
|
||||
|
@ -11,7 +11,9 @@ class Topic < ActiveRecord::Base
|
||||
|
||||
versioned :if => :new_version_required?
|
||||
acts_as_paranoid
|
||||
|
||||
after_recover :update_flagged_posts_count
|
||||
after_destroy :update_flagged_posts_count
|
||||
|
||||
rate_limit :default_rate_limiter
|
||||
rate_limit :limit_topics_per_day
|
||||
rate_limit :limit_private_messages_per_day
|
||||
@ -387,6 +389,10 @@ class Topic < ActiveRecord::Base
|
||||
topic
|
||||
end
|
||||
|
||||
def update_flagged_posts_count
|
||||
PostAction.update_flagged_posts_count
|
||||
end
|
||||
|
||||
|
||||
# Create the summary of the interesting posters in a topic. Cheats to avoid
|
||||
# many queries.
|
||||
|
@ -27,6 +27,19 @@ describe PostAction do
|
||||
PostAction.flagged_posts_count.should == 0
|
||||
end
|
||||
|
||||
it "should reset counts when a topic is deleted" do
|
||||
PostAction.act(codinghorror, post, PostActionType.Types[:off_topic])
|
||||
post.topic.destroy
|
||||
PostAction.flagged_posts_count.should == 0
|
||||
end
|
||||
|
||||
it "should reset counts when a post is deleted" do
|
||||
post2 = Fabricate(:post, topic_id: post.topic_id)
|
||||
PostAction.act(codinghorror, post2, PostActionType.Types[:off_topic])
|
||||
post2.destroy
|
||||
PostAction.flagged_posts_count.should == 0
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
it "increases the post's bookmark count when saved" do
|
||||
|
Loading…
Reference in New Issue
Block a user