diff options
author | Byron Jones <glob@mozilla.com> | 2014-04-22 16:56:28 +0200 |
---|---|---|
committer | Byron Jones <glob@mozilla.com> | 2014-04-22 16:56:28 +0200 |
commit | 572c5819d656d63f6b87e8fc54d8f561d6c3b9e3 (patch) | |
tree | 7f50581c885fc11e9c04ad2aab31cc8fe2211dab /extensions/AntiSpam/Extension.pm | |
parent | f9c1b976d7b5b6ffb6bf0df58cacaaf640499005 (diff) | |
download | bugzilla-572c5819d656d63f6b87e8fc54d8f561d6c3b9e3.tar.gz bugzilla-572c5819d656d63f6b87e8fc54d8f561d6c3b9e3.tar.xz |
Bug 936509: Automatically disable accounts based on the number of comments tagged as spam
Diffstat (limited to 'extensions/AntiSpam/Extension.pm')
-rw-r--r-- | extensions/AntiSpam/Extension.pm | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/extensions/AntiSpam/Extension.pm b/extensions/AntiSpam/Extension.pm index ef31a0b2d..40a637adc 100644 --- a/extensions/AntiSpam/Extension.pm +++ b/extensions/AntiSpam/Extension.pm @@ -126,6 +126,73 @@ sub _ip_blocking { } # +# spam user disabling +# + +sub comment_after_add_tag { + my ($self, $args) = @_; + return unless lc($args->{tag}) eq 'spam'; + my $comment = $args->{comment}; + my $author = $comment->author; + + # exclude disabled users + return if !$author->is_enabled; + + # exclude users by group + return if $author->in_group(Bugzilla->params->{antispam_spammer_exclude_group}); + + # exclude users who are no longer new + 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; + + # get user's comments + 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' + WHERE longdescs.who = ? + ORDER BY longdescs.bug_when + ", undef, $author->id); + + # this comment is spam + my $comment_id = $comment->id; + foreach my $ra (@$comments) { + if ($ra->[0] == $comment_id) { + $ra->[1] = 1; + last; + } + } + + # throw away comment id and negate bool to make it a list of not-spam + $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 last N comments are spam + elsif (!scalar(grep { $_ } @$comments[-$spam_count..-1])) { + $reason = "last $spam_count comments are spam"; + } + + # disable + if ($reason) { + $author->set_disabledtext(Bugzilla->params->{antispam_spammer_disable_text}); + $author->set_disable_mail(1); + $author->update(); + _syslog(sprintf("[audit] antispam disabled <%s>: %s", $author->login, $reason)); + } +} + +# # hooks # @@ -171,6 +238,12 @@ sub editable_tables { }; } +sub config_add_panels { + my ($self, $args) = @_; + my $modules = $args->{panel_modules}; + $modules->{AntiSpam} = "Bugzilla::Extension::AntiSpam::Config"; +} + # # installation # |