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

View File

@ -357,7 +357,12 @@ describe TrustLevel3Requirements do
end
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)
end
@ -372,7 +377,12 @@ describe TrustLevel3Requirements do
end
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)
end
end