Skip to content
Permalink
Browse files

FIX: Count current penalty if it started more than 6 months ago (#8313)

  • Loading branch information...
udan11 committed Nov 8, 2019
1 parent edec922 commit dfc002d331a61225c4a9697f32e6cd1b120e15b3
Showing with 19 additions and 2 deletions.
  1. +7 −2 app/models/trust_level3_requirements.rb
  2. +12 −0 spec/models/trust_level3_requirements_spec.rb
@@ -7,9 +7,14 @@ class TrustLevel3Requirements
class PenaltyCounts
attr_reader :silenced, :suspended

def initialize(row)
def initialize(user, row)
@silenced = row['silence_count'] || 0
@suspended = row['suspend_count'] || 0

# If penalty started more than 6 months ago and still continues, it will
# not be selected by the query from 'penalty_counts'.
@silenced += 1 if @silenced == 0 && user.silenced?
@suspended += 1 if @suspended == 0 && user.suspended?
end

def total
@@ -114,7 +119,7 @@ def penalty_counts
AND uh.created_at > :since
SQL

PenaltyCounts.new(DB.query_hash(sql, args).first)
PenaltyCounts.new(@user, DB.query_hash(sql, args).first)
end

def min_days_visited
@@ -78,6 +78,18 @@ def like_at(created_by, post, created_at)
expect(tl3_requirements.penalty_counts.suspended).to eq(1)
expect(tl3_requirements.penalty_counts.total).to eq(2)
end

it "does return if the user has been silenced or suspended over 6 months ago and continues" do
freeze_time 1.year.ago do
UserSilencer.new(user, moderator, silenced_till: 10.years.from_now).silence
UserHistory.create!(target_user_id: user.id, action: UserHistory.actions[:suspend_user])
user.update(suspended_till: 10.years.from_now)
end

expect(tl3_requirements.penalty_counts.silenced).to eq(1)
expect(tl3_requirements.penalty_counts.suspended).to eq(1)
expect(tl3_requirements.penalty_counts.total).to eq(2)
end
end

it "time_period uses site setting" do

2 comments on commit dfc002d

@discoursereviewbot

This comment has been minimized.

Copy link

discoursereviewbot replied Nov 8, 2019

Régis Hanol posted:

Where is this 6 months delay coming from?

@discoursereviewbot

This comment has been minimized.

Please sign in to comment.
You can’t perform that action at this time.