From 4c9959f795182d3121676098c61ff3dc943bca86 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Mon, 12 Feb 2018 17:19:47 -0500 Subject: [PATCH] FIX: Don't allow silenced users to reach TL3 --- app/models/trust_level3_requirements.rb | 54 ++++++++++--------- spec/models/trust_level3_requirements_spec.rb | 14 ++++- 2 files changed, 41 insertions(+), 27 deletions(-) diff --git a/app/models/trust_level3_requirements.rb b/app/models/trust_level3_requirements.rb index 6307e563b07..37785e32a37 100644 --- a/app/models/trust_level3_requirements.rb +++ b/app/models/trust_level3_requirements.rb @@ -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 diff --git a/spec/models/trust_level3_requirements_spec.rb b/spec/models/trust_level3_requirements_spec.rb index 1c99fd9ee9b..b98641a3258 100644 --- a/spec/models/trust_level3_requirements_spec.rb +++ b/spec/models/trust_level3_requirements_spec.rb @@ -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