FIX: Count current penalty if it started more than 6 months ago (#8313)
This commit is contained in:
parent
edec922803
commit
dfc002d331
|
@ -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 @@ class TrustLevel3Requirements
|
|||
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 @@ describe TrustLevel3Requirements do
|
|||
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
|
||||
|
|
Loading…
Reference in New Issue