summaryrefslogtreecommitdiffstats
path: root/extensions/BMO/Extension.pm
diff options
context:
space:
mode:
authorByron Jones <bjones@mozilla.com>2014-02-25 07:31:55 +0100
committerByron Jones <bjones@mozilla.com>2014-02-25 07:31:55 +0100
commitab86aba0236ca96d58d75b839c003f093a12a297 (patch)
tree5b672f901931cce0dc02c402f2bb5c08e20d27d4 /extensions/BMO/Extension.pm
parent0e67941defa509229a33b3b20d2ff2660f8728cb (diff)
downloadbugzilla-ab86aba0236ca96d58d75b839c003f093a12a297.tar.gz
bugzilla-ab86aba0236ca96d58d75b839c003f093a12a297.tar.xz
Bug 975943: add special support for a "deleted" comment tag
Diffstat (limited to 'extensions/BMO/Extension.pm')
-rw-r--r--extensions/BMO/Extension.pm75
1 files changed, 75 insertions, 0 deletions
diff --git a/extensions/BMO/Extension.pm b/extensions/BMO/Extension.pm
index c0e8b084b..8d16e2e92 100644
--- a/extensions/BMO/Extension.pm
+++ b/extensions/BMO/Extension.pm
@@ -1342,4 +1342,79 @@ sub install_filesystem {
};
}
+# "deleted" comment tag
+
+sub config_modify_panels {
+ my ($self, $args) = @_;
+ push @{ $args->{panels}->{groupsecurity}->{params} }, {
+ name => 'delete_comments_group',
+ type => 's',
+ choices => \&Bugzilla::Config::GroupSecurity::_get_all_group_names,
+ default => 'admin',
+ checker => \&check_group
+ };
+}
+
+sub comment_after_add_tag {
+ my ($self, $args) = @_;
+ my $tag = $args->{tag};
+ return unless lc($tag) eq 'deleted';
+
+ my $group_name = Bugzilla->params->{delete_comments_group};
+ if (!$group_name || !Bugzilla->user->in_group($group_name)) {
+ ThrowUserError('auth_failure', { group => $group_name,
+ action => 'delete',
+ object => 'comments' });
+ }
+}
+
+sub comment_after_remove_tag {
+ my ($self, $args) = @_;
+ my $tag = $args->{tag};
+ return unless lc($tag) eq 'deleted';
+
+ my $group_name = Bugzilla->params->{delete_comments_group};
+ if (!$group_name || !Bugzilla->user->in_group($group_name)) {
+ ThrowUserError('auth_failure', { group => $group_name,
+ action => 'delete',
+ object => 'comments' });
+ }
+}
+
+BEGIN {
+ *Bugzilla::Comment::has_tag = \&_comment_has_tag;
+}
+
+sub _comment_has_tag {
+ my ($self, $test_tag) = @_;
+ $test_tag = lc($test_tag);
+ foreach my $tag (@{ $self->tags }) {
+ return 1 if lc($tag) eq $test_tag;
+ }
+ return 0;
+}
+
+sub bug_comments {
+ my ($self, $args) = @_;
+ my $can_delete = Bugzilla->user->in_group(Bugzilla->params->{delete_comments_group});
+ my $comments = $args->{comments};
+ my @deleted = grep { $_->has_tag('deleted') } @$comments;
+ while (my $comment = pop @deleted) {
+ for (my $i = scalar(@$comments) - 1; $i >= 0; $i--) {
+ if ($comment == $comments->[$i]) {
+ if ($can_delete) {
+ # don't remove comment from users who can "delete" them
+ # just collapse it instead
+ $comment->{collapsed} = 1;
+ }
+ else {
+ # otherwise, remove it from the array
+ splice(@$comments, $i, 1);
+ }
+ last;
+ }
+ }
+ }
+}
+
__PACKAGE__->NAME;