FIX: Don't allow silenced users to reach TL3

This commit is contained in:
Robin Ward 2018-02-12 17:19:47 -05:00
parent 1bafbc8c5c
commit 4c9959f795
2 changed files with 41 additions and 27 deletions

View File

@ -26,36 +26,40 @@ class TrustLevel3Requirements
def requirements_met? def requirements_met?
return false if trust_level_locked return false if trust_level_locked
!@user.suspended? &&
days_visited >= min_days_visited && (!@user.suspended?) &&
num_topics_replied_to >= min_topics_replied_to && (!@user.silenced?) &&
topics_viewed >= min_topics_viewed && days_visited >= min_days_visited &&
posts_read >= min_posts_read && num_topics_replied_to >= min_topics_replied_to &&
num_flagged_posts <= max_flagged_posts && topics_viewed >= min_topics_viewed &&
num_flagged_by_users <= max_flagged_by_users && posts_read >= min_posts_read &&
topics_viewed_all_time >= min_topics_viewed_all_time && num_flagged_posts <= max_flagged_posts &&
posts_read_all_time >= min_posts_read_all_time && num_flagged_by_users <= max_flagged_by_users &&
num_likes_given >= min_likes_given && topics_viewed_all_time >= min_topics_viewed_all_time &&
num_likes_received >= min_likes_received && posts_read_all_time >= min_posts_read_all_time &&
num_likes_received_users >= min_likes_received_users && num_likes_given >= min_likes_given &&
num_likes_received_days >= min_likes_received_days num_likes_received >= min_likes_received &&
num_likes_received_users >= min_likes_received_users &&
num_likes_received_days >= min_likes_received_days
end end
def requirements_lost? def requirements_lost?
return false if trust_level_locked return false if trust_level_locked
@user.suspended? || @user.suspended? ||
days_visited < min_days_visited * LOW_WATER_MARK || @user.silenced? ||
num_topics_replied_to < min_topics_replied_to * LOW_WATER_MARK || days_visited < min_days_visited * LOW_WATER_MARK ||
topics_viewed < min_topics_viewed * LOW_WATER_MARK || num_topics_replied_to < min_topics_replied_to * LOW_WATER_MARK ||
posts_read < min_posts_read * LOW_WATER_MARK || topics_viewed < min_topics_viewed * LOW_WATER_MARK ||
num_flagged_posts > max_flagged_posts || posts_read < min_posts_read * LOW_WATER_MARK ||
num_flagged_by_users > max_flagged_by_users || num_flagged_posts > max_flagged_posts ||
topics_viewed_all_time < min_topics_viewed_all_time || num_flagged_by_users > max_flagged_by_users ||
posts_read_all_time < min_posts_read_all_time || topics_viewed_all_time < min_topics_viewed_all_time ||
num_likes_given < min_likes_given * LOW_WATER_MARK || posts_read_all_time < min_posts_read_all_time ||
num_likes_received < min_likes_received * LOW_WATER_MARK || num_likes_given < min_likes_given * LOW_WATER_MARK ||
num_likes_received_users < min_likes_received_users * LOW_WATER_MARK || num_likes_received < min_likes_received * LOW_WATER_MARK ||
num_likes_received_days < min_likes_received_days * LOW_WATER_MARK num_likes_received_users < min_likes_received_users * LOW_WATER_MARK ||
num_likes_received_days < min_likes_received_days * LOW_WATER_MARK
end end
def time_period def time_period

View File

@ -357,7 +357,12 @@ describe TrustLevel3Requirements do
end end
it "are not met if suspended" do it "are not met if suspended" do
user.stubs(:suspended?).returns(true) user.suspended_till = 3.weeks.from_now
expect(tl3_requirements.requirements_met?).to eq(false)
end
it "are not met if silenced" do
user.silenced_till = 3.weeks.from_now
expect(tl3_requirements.requirements_met?).to eq(false) expect(tl3_requirements.requirements_met?).to eq(false)
end end
@ -372,7 +377,12 @@ describe TrustLevel3Requirements do
end end
it "are lost if suspended" do it "are lost if suspended" do
user.stubs(:suspended?).returns(true) user.suspended_till = 4.weeks.from_now
expect(tl3_requirements.requirements_lost?).to eq(true)
end
it "are lost if silenced" do
user.silenced_till = 4.weeks.from_now
expect(tl3_requirements.requirements_lost?).to eq(true) expect(tl3_requirements.requirements_lost?).to eq(true)
end end
end end