From 8076cbac92c228d086e84ebedef01dfff106cd62 Mon Sep 17 00:00:00 2001 From: Byron Jones Date: Thu, 14 Feb 2013 00:23:29 +0800 Subject: Bug 690833: Add the ability to restrict who can add comments to a bug report --- extensions/RestrictComments/Config.pm | 16 ++++ extensions/RestrictComments/Extension.pm | 95 ++++++++++++++++++++++ extensions/RestrictComments/lib/Config.pm | 47 +++++++++++ .../admin/params/restrictcomments.html.tmpl | 23 ++++++ .../bug/edit-after_comment_commit_button.html.tmpl | 21 +++++ .../pages/restrict_comments_guidelines.html.tmpl | 62 ++++++++++++++ 6 files changed, 264 insertions(+) create mode 100644 extensions/RestrictComments/Config.pm create mode 100644 extensions/RestrictComments/Extension.pm create mode 100644 extensions/RestrictComments/lib/Config.pm create mode 100644 extensions/RestrictComments/template/en/default/admin/params/restrictcomments.html.tmpl create mode 100644 extensions/RestrictComments/template/en/default/hook/bug/edit-after_comment_commit_button.html.tmpl create mode 100644 extensions/RestrictComments/template/en/default/pages/restrict_comments_guidelines.html.tmpl (limited to 'extensions/RestrictComments') diff --git a/extensions/RestrictComments/Config.pm b/extensions/RestrictComments/Config.pm new file mode 100644 index 000000000..bef472cc1 --- /dev/null +++ b/extensions/RestrictComments/Config.pm @@ -0,0 +1,16 @@ +# 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. + +package Bugzilla::Extension::RestrictComments; + +use strict; + +use constant NAME => 'RestrictComments'; +use constant REQUIRED_MODULES => []; +use constant OPTIONAL_MODULES => []; + +__PACKAGE__->NAME; diff --git a/extensions/RestrictComments/Extension.pm b/extensions/RestrictComments/Extension.pm new file mode 100644 index 000000000..001332a8e --- /dev/null +++ b/extensions/RestrictComments/Extension.pm @@ -0,0 +1,95 @@ +# 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. + +package Bugzilla::Extension::RestrictComments; + +use strict; +use warnings; + +use base qw(Bugzilla::Extension); + +use Bugzilla::Constants; + +BEGIN { + *Bugzilla::Bug::restrict_comments = \&_bug_restrict_comments; +} + +sub _bug_restrict_comments { + my ($self) = @_; + return $self->{restrict_comments}; +} + +sub bug_check_can_change_field { + my ($self, $args) = @_; + my ($bug, $priv_results) = @$args{qw(bug priv_results)}; + my $user = Bugzilla->user; + + if ($user->id + && $bug->restrict_comments + && !$user->in_group(Bugzilla->params->{'restrict_comments_group'})) + { + push(@$priv_results, PRIVILEGES_REQUIRED_EMPOWERED); + return; + } +} + +sub _can_restrict_comments { + my ($self, $object) = @_; + return unless $object->isa('Bugzilla::Bug'); + $self->{setter_group} ||= Bugzilla->params->{'restrict_comments_enable_group'}; + return Bugzilla->user->in_group($self->{setter_group}); +} + +sub object_end_of_set_all { + my ($self, $args) = @_; + my $object = $args->{object}; + if ($self->_can_restrict_comments($object)) { + my $input = Bugzilla->input_params; + $object->set('restrict_comments', $input->{restrict_comments} ? 1 : undef); + } +} + +sub object_update_columns { + my ($self, $args) = @_; + my ($object, $columns) = @$args{qw(object columns)}; + if ($self->_can_restrict_comments($object)) { + push(@$columns, 'restrict_comments'); + } +} + +sub object_columns { + my ($self, $args) = @_; + my ($class, $columns) = @$args{qw(class columns)}; + if ($class->isa('Bugzilla::Bug')) { + push(@$columns, 'restrict_comments'); + } +} + +sub bug_fields { + my ($self, $args) = @_; + my $fields = $args->{'fields'}; + push (@$fields, 'restrict_comments') +} + +sub config_add_panels { + my ($self, $args) = @_; + my $modules = $args->{panel_modules}; + $modules->{RestrictComments} = "Bugzilla::Extension::RestrictComments::Config"; +} + +sub install_update_db { + my $dbh = Bugzilla->dbh; + + my $field = new Bugzilla::Field({ name => 'restrict_comments' }); + if (!$field) { + Bugzilla::Field->create({ name => 'restrict_comments', description => 'Restrict Comments' }); + } + + $dbh->bz_add_column('bugs', 'restrict_comments', { TYPE => 'BOOLEAN' }); +} + +__PACKAGE__->NAME; diff --git a/extensions/RestrictComments/lib/Config.pm b/extensions/RestrictComments/lib/Config.pm new file mode 100644 index 000000000..33607e680 --- /dev/null +++ b/extensions/RestrictComments/lib/Config.pm @@ -0,0 +1,47 @@ +# 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. + +package Bugzilla::Extension::RestrictComments::Config; + +use strict; +use warnings; + +use Bugzilla::Config::Common; +use Bugzilla::Group; + +our $sortkey = 510; + +sub get_param_list { + my ($class) = @_; + + my @param_list = ( + { + name => 'restrict_comments_group', + type => 's', + choices => \&_get_all_group_names, + default => '', + checker => \&check_group + }, + { + name => 'restrict_comments_enable_group', + type => 's', + choices => \&_get_all_group_names, + default => '', + checker => \&check_group + }, + ); + + return @param_list; +} + +sub _get_all_group_names { + my @group_names = map {$_->name} Bugzilla::Group->get_all; + unshift(@group_names, ''); + return \@group_names; +} + +1; diff --git a/extensions/RestrictComments/template/en/default/admin/params/restrictcomments.html.tmpl b/extensions/RestrictComments/template/en/default/admin/params/restrictcomments.html.tmpl new file mode 100644 index 000000000..d2a050563 --- /dev/null +++ b/extensions/RestrictComments/template/en/default/admin/params/restrictcomments.html.tmpl @@ -0,0 +1,23 @@ +[%# 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. + #%] + +[% + title = "Restrict Comments" + desc = "Edit Restrict Comments Configuration" +%] + +[% param_descs = +{ + restrict_comments_group => "Users must be a member of this group to " _ + "comment on bug with restricted commenting " _ + "enabled." + + restrict_comments_enable_group => "Members of this group can toggle " _ + "'restrict comments' on bugs." +} +%] diff --git a/extensions/RestrictComments/template/en/default/hook/bug/edit-after_comment_commit_button.html.tmpl b/extensions/RestrictComments/template/en/default/hook/bug/edit-after_comment_commit_button.html.tmpl new file mode 100644 index 000000000..0cc24e289 --- /dev/null +++ b/extensions/RestrictComments/template/en/default/hook/bug/edit-after_comment_commit_button.html.tmpl @@ -0,0 +1,21 @@ +[%# 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. + #%] + + +[% RETURN UNLESS user.in_group(Param('restrict_comments_enable_group')) %] + +
+ + + (guidelines) +
diff --git a/extensions/RestrictComments/template/en/default/pages/restrict_comments_guidelines.html.tmpl b/extensions/RestrictComments/template/en/default/pages/restrict_comments_guidelines.html.tmpl new file mode 100644 index 000000000..694681ad7 --- /dev/null +++ b/extensions/RestrictComments/template/en/default/pages/restrict_comments_guidelines.html.tmpl @@ -0,0 +1,62 @@ +[%# 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. + #%] + +[% USE Bugzilla %] + +[% PROCESS global/header.html.tmpl + title = "Restrict Comments - Guidelines" +%] + +

Restricting Comments

+ +

+ Some [% terms.bug %] reports are inundated with comments that make it + difficult for developers to conduct technical discussions. Restricting + comments provides the ability for users in the + [%+ Param('restrict_comments_enable_group') FILTER html %] group to prevent + users who are not in the [% Param('restrict_comments_group') FILTER html %] + from making additional comments. +

+ +

Guidelines

+ + + +

Impact

+ + + +[% PROCESS global/footer.html.tmpl %] -- cgit v1.2.3-24-g4f1b