mirror of
https://github.com/codeninjasllc/discourse.git
synced 2025-02-17 04:01:29 -05:00
FIX: TL3 requirements now only counts agreed flags
This commit is contained in:
parent
5a8919e87a
commit
3b46b5ecbf
2 changed files with 29 additions and 9 deletions
|
@ -95,7 +95,12 @@ class LeaderRequirements
|
|||
end
|
||||
|
||||
def num_flagged_posts
|
||||
PostAction.with_deleted.where(post_id: flagged_post_ids).where.not(user_id: @user.id).pluck(:post_id).uniq.count
|
||||
PostAction.with_deleted
|
||||
.where(post_id: flagged_post_ids)
|
||||
.where.not(user_id: @user.id)
|
||||
.where.not(agreed_at: nil)
|
||||
.pluck(:post_id)
|
||||
.uniq.count
|
||||
end
|
||||
|
||||
def max_flagged_posts
|
||||
|
@ -103,7 +108,12 @@ class LeaderRequirements
|
|||
end
|
||||
|
||||
def num_flagged_by_users
|
||||
PostAction.with_deleted.where(post_id: flagged_post_ids).where.not(user_id: @user.id).pluck(:user_id).uniq.count
|
||||
PostAction.with_deleted
|
||||
.where(post_id: flagged_post_ids)
|
||||
.where.not(user_id: @user.id)
|
||||
.where.not(agreed_at: nil)
|
||||
.pluck(:user_id)
|
||||
.uniq.count
|
||||
end
|
||||
|
||||
def max_flagged_by_users
|
||||
|
@ -137,7 +147,9 @@ class LeaderRequirements
|
|||
end
|
||||
|
||||
def flagged_post_ids
|
||||
# (TODO? and moderators explicitly agreed with the flags)
|
||||
@user.posts.with_deleted.where('created_at > ? AND (spam_count > 0 OR inappropriate_count > 0)', TIME_PERIOD.days.ago).pluck(:id)
|
||||
@user.posts
|
||||
.with_deleted
|
||||
.where('created_at > ? AND (spam_count > 0 OR inappropriate_count > 0)', TIME_PERIOD.days.ago)
|
||||
.pluck(:id)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -125,20 +125,28 @@ describe LeaderRequirements do
|
|||
before do
|
||||
user.save
|
||||
flags = [:off_topic, :inappropriate, :notify_user, :notify_moderators, :spam].map do |t|
|
||||
Fabricate(:flag, post: Fabricate(:post, user: user), post_action_type_id: PostActionType.types[t])
|
||||
Fabricate(:flag, post: Fabricate(:post, user: user), post_action_type_id: PostActionType.types[t], agreed_at: 1.minute.ago)
|
||||
end
|
||||
|
||||
deferred_flags = [:off_topic, :inappropriate, :notify_user, :notify_moderators, :spam].map do |t|
|
||||
Fabricate(:flag, post: Fabricate(:post, user: user), post_action_type_id: PostActionType.types[t], defered_at: 1.minute.ago)
|
||||
end
|
||||
|
||||
deleted_flags = [:off_topic, :inappropriate, :notify_user, :notify_moderators, :spam].map do |t|
|
||||
Fabricate(:flag, post: Fabricate(:post, user: user), post_action_type_id: PostActionType.types[t], deleted_at: 1.minute.ago)
|
||||
end
|
||||
|
||||
# Same post, different user:
|
||||
Fabricate(:flag, post: flags[1].post, post_action_type_id: PostActionType.types[:spam])
|
||||
Fabricate(:flag, post: flags[1].post, post_action_type_id: PostActionType.types[:spam], agreed_at: 1.minute.ago)
|
||||
|
||||
# Flagged their own post:
|
||||
Fabricate(:flag, user: user, post: Fabricate(:post, user: user), post_action_type_id: PostActionType.types[:spam])
|
||||
Fabricate(:flag, user: user, post: Fabricate(:post, user: user), post_action_type_id: PostActionType.types[:spam], agreed_at: 1.minute.ago)
|
||||
|
||||
# More than 100 days ago:
|
||||
Fabricate(:flag, post: Fabricate(:post, user: user, created_at: 101.days.ago), post_action_type_id: PostActionType.types[:spam], created_at: 101.days.ago)
|
||||
Fabricate(:flag, post: Fabricate(:post, user: user, created_at: 101.days.ago), post_action_type_id: PostActionType.types[:spam], created_at: 101.days.ago, agreed_at: 1.day.ago)
|
||||
end
|
||||
|
||||
it "num_flagged_posts and num_flagged_by_users count spam and inappropriate flags in the last 100 days" do
|
||||
it "num_flagged_posts and num_flagged_by_users count spam and inappropriate agreed flags in the last 100 days" do
|
||||
leader_requirements.num_flagged_posts.should == 2
|
||||
leader_requirements.num_flagged_by_users.should == 3
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue