diff options
author | Byron Jones <glob@mozilla.com> | 2014-05-22 07:31:14 +0200 |
---|---|---|
committer | Byron Jones <glob@mozilla.com> | 2014-05-22 07:31:14 +0200 |
commit | 54cc754a164f2ee7249b716239b53ca42cc0650a (patch) | |
tree | b8d4d27c2e6279371e2c51b8d1436656d03814c1 /extensions/AntiSpam | |
parent | e1aea961a9dd83d6d14b4e45cbf4a70b00fbe18c (diff) | |
download | bugzilla-54cc754a164f2ee7249b716239b53ca42cc0650a.tar.gz bugzilla-54cc754a164f2ee7249b716239b53ca42cc0650a.tar.xz |
Bug 1003950: automatically disable accounts based on the number of comments tagged as "abusive"
Diffstat (limited to 'extensions/AntiSpam')
-rw-r--r-- | extensions/AntiSpam/Extension.pm | 36 | ||||
-rw-r--r-- | extensions/AntiSpam/lib/Config.pm | 27 | ||||
-rw-r--r-- | extensions/AntiSpam/template/en/default/admin/params/antispam.html.tmpl | 11 |
3 files changed, 56 insertions, 18 deletions
diff --git a/extensions/AntiSpam/Extension.pm b/extensions/AntiSpam/Extension.pm index 40a637adc..7a0f27b31 100644 --- a/extensions/AntiSpam/Extension.pm +++ b/extensions/AntiSpam/Extension.pm @@ -131,7 +131,8 @@ sub _ip_blocking { sub comment_after_add_tag { my ($self, $args) = @_; - return unless lc($args->{tag}) eq 'spam'; + my $tag = lc($args->{tag}); + return unless $tag eq 'spam' or $tag eq 'abusive'; my $comment = $args->{comment}; my $author = $comment->author; @@ -145,21 +146,24 @@ sub comment_after_add_tag { return if !$author->is_new; # exclude users who haven't made enough comments - my $spam_count = Bugzilla->params->{antispam_spammer_comment_count}; - return if $author->comment_count < $spam_count; + my $count = $tag eq 'spam' + ? Bugzilla->params->{antispam_spammer_comment_count} + : Bugzilla->params->{antispam_abusive_comment_count}; + return if $author->comment_count < $count; # get user's comments + trick_taint($tag); my $comments = Bugzilla->dbh->selectall_arrayref(" SELECT longdescs.comment_id,longdescs_tags.id FROM longdescs LEFT JOIN longdescs_tags ON longdescs_tags.comment_id = longdescs.comment_id - AND longdescs_tags.tag = 'spam' + AND longdescs_tags.tag = ? WHERE longdescs.who = ? ORDER BY longdescs.bug_when - ", undef, $author->id); + ", undef, $tag, $author->id); - # this comment is spam + # this comment needs to be counted too my $comment_id = $comment->id; foreach my $ra (@$comments) { if ($ra->[0] == $comment_id) { @@ -168,24 +172,28 @@ sub comment_after_add_tag { } } - # throw away comment id and negate bool to make it a list of not-spam + # throw away comment id and negate bool to make it a list of not-spam/abuse $comments = [ map { $_->[1] ? 0 : 1 } @$comments ]; my $reason; - # check if the first N comments are spam - if (!scalar(grep { $_ } @$comments[0..($spam_count - 1)])) { - $reason = "first $spam_count comments are spam"; + # check if the first N comments are spam/abuse + if (!scalar(grep { $_ } @$comments[0..($count - 1)])) { + $reason = "first $count comments are $tag"; } - # check if the last N comments are spam - elsif (!scalar(grep { $_ } @$comments[-$spam_count..-1])) { - $reason = "last $spam_count comments are spam"; + # check if the last N comments are spam/abuse + elsif (!scalar(grep { $_ } @$comments[-$count..-1])) { + $reason = "last $count comments are $tag"; } # disable if ($reason) { - $author->set_disabledtext(Bugzilla->params->{antispam_spammer_disable_text}); + $author->set_disabledtext( + $tag eq 'spam' + ? Bugzilla->params->{antispam_spammer_disable_text} + : Bugzilla->params->{antispam_abusive_disable_text} + ); $author->set_disable_mail(1); $author->update(); _syslog(sprintf("[audit] antispam disabled <%s>: %s", $author->login, $reason)); diff --git a/extensions/AntiSpam/lib/Config.pm b/extensions/AntiSpam/lib/Config.pm index dc3e2820f..c8e1255c2 100644 --- a/extensions/AntiSpam/lib/Config.pm +++ b/extensions/AntiSpam/lib/Config.pm @@ -36,9 +36,30 @@ sub get_param_list { name => 'antispam_spammer_disable_text', type => 'l', default => - "This account has been automatically disabled as a result of a " . - "high number of spam comments.\n\nPlease contact the address at ". - "the end of this message if you believe this to be an error." + "This account has been automatically disabled as a result of " . + "a high number of spam comments.<br>\n<br>\n" . + "Please contact the address at the end of this message if " . + "you believe this to be an error." + }, + { + name => 'antispam_abusive_comment_count', + type => 't', + default => '5', + checker => \&check_numeric + }, + { + name => 'antispam_abusive_disable_text', + type => 'l', + default => + "This account has been automatically disabled as a result of " . + "a high number of comments tagged as abusive.<br>\n<br>\n" . + "All interactions on Bugzilla should follow our " . + "<a href=\"https://bugzilla.mozilla.org/page.cgi?id=etiquette.html\">" . + "etiquette guidelines</a>.<br>\n<br>\n" . + "Please contact the address at the end of this message if you " . + "believe this to be an error, or if you would like your account " . + "reactivated in order to interact within our etiquette " . + "guidelines." }, ); diff --git a/extensions/AntiSpam/template/en/default/admin/params/antispam.html.tmpl b/extensions/AntiSpam/template/en/default/admin/params/antispam.html.tmpl index 45dae623a..76299f546 100644 --- a/extensions/AntiSpam/template/en/default/admin/params/antispam.html.tmpl +++ b/extensions/AntiSpam/template/en/default/admin/params/antispam.html.tmpl @@ -23,6 +23,15 @@ antispam_spammer_disable_text => "This message will be displayed to the user when they try to log " _ - "in after their account is disabled." + "in after their account is disabled due to spam." + + antispam_abusive_comment_count => + "If a user has made at least this many comments, and either their first " _ + "NNN comments or their last NNN comments have been tagged as abusive, their " _ + "account will be automatically disabled." + + antispam_abusive_disable_text => + "This message will be displayed to the user when they try to log " _ + "in after their account is disabled due to abuse." } %] |