Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Nov 8, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -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
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.