diff options
author | Byron Jones <bjones@mozilla.com> | 2014-02-25 07:31:55 +0100 |
---|---|---|
committer | Byron Jones <bjones@mozilla.com> | 2014-02-25 07:31:55 +0100 |
commit | ab86aba0236ca96d58d75b839c003f093a12a297 (patch) | |
tree | 5b672f901931cce0dc02c402f2bb5c08e20d27d4 /extensions/BMO | |
parent | 0e67941defa509229a33b3b20d2ff2660f8728cb (diff) | |
download | bugzilla-ab86aba0236ca96d58d75b839c003f093a12a297.tar.gz bugzilla-ab86aba0236ca96d58d75b839c003f093a12a297.tar.xz |
Bug 975943: add special support for a "deleted" comment tag
Diffstat (limited to 'extensions/BMO')
3 files changed, 98 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; diff --git a/extensions/BMO/template/en/default/hook/admin/params/editparams-current_panel.html.tmpl b/extensions/BMO/template/en/default/hook/admin/params/editparams-current_panel.html.tmpl new file mode 100644 index 000000000..39f063464 --- /dev/null +++ b/extensions/BMO/template/en/default/hook/admin/params/editparams-current_panel.html.tmpl @@ -0,0 +1,13 @@ +[%# This Source Code Form is subject to the terms of the Mozilla Public + # License, v. 2.0. If a copy of the MPL was not distributed with this + # file, You can obtain one at http://mozilla.org/MPL/2.0/. + # + # This Source Code Form is "Incompatible With Secondary Licenses", as + # defined by the Mozilla Public License, v. 2.0. + #%] + +[% IF panel.name == "groupsecurity" %] + [% panel.param_descs.delete_comments_group = + 'The name of the group of users who can delete comments by using the "deleted" comment tag.' + %] +[% END -%] diff --git a/extensions/BMO/template/en/default/hook/global/user-error-auth_failure_object.html.tmpl b/extensions/BMO/template/en/default/hook/global/user-error-auth_failure_object.html.tmpl index ce855ad97..bf46ed895 100644 --- a/extensions/BMO/template/en/default/hook/global/user-error-auth_failure_object.html.tmpl +++ b/extensions/BMO/template/en/default/hook/global/user-error-auth_failure_object.html.tmpl @@ -1,7 +1,17 @@ +[%# This Source Code Form is subject to the terms of the Mozilla Public + # License, v. 2.0. If a copy of the MPL was not distributed with this + # file, You can obtain one at http://mozilla.org/MPL/2.0/. + # + # This Source Code Form is "Incompatible With Secondary Licenses", as + # defined by the Mozilla Public License, v. 2.0. + #%] + [% IF object == 'group_admins' %] the group administrators report [% ELSIF object == 'email_queue' %] the email queue status report [% ELSIF object == 'product_security' %] the product security report +[% ELSIF object == 'comments' %] + comments [% END %] |