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 --- Bugzilla/Bug.pm | 4 +- Bugzilla/Flag.pm | 6 ++ .../hook/bug/edit-after_custom_fields.html.tmpl | 112 ++++++++++++--------- 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 ++++++++++++ template/en/default/bug/comments.html.tmpl | 14 +-- template/en/default/bug/edit.html.tmpl | 29 ++++-- template/en/default/flag/list.html.tmpl | 2 +- 12 files changed, 363 insertions(+), 68 deletions(-) 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 diff --git a/Bugzilla/Bug.pm b/Bugzilla/Bug.pm index 0484ab8f4..3d3a92838 100644 --- a/Bugzilla/Bug.pm +++ b/Bugzilla/Bug.pm @@ -4029,8 +4029,8 @@ sub check_can_change_field { return 1; } - # Allow anyone to change comments. - if ($field =~ /^longdesc/) { + # Allow anyone to change comments, or set flags + if ($field =~ /^longdesc/ || $field eq 'flagtypes.name') { return 1; } diff --git a/Bugzilla/Flag.pm b/Bugzilla/Flag.pm index 0828ddc7c..2f6ee526f 100644 --- a/Bugzilla/Flag.pm +++ b/Bugzilla/Flag.pm @@ -312,6 +312,12 @@ sub set_flag { ThrowCodeError('flag_unexpected_object', { 'caller' => ref $obj }); } + # Make sure the user can change flags + my $privs; + $bug->check_can_change_field('flagtypes.name', 0, 1, \$privs) + || ThrowUserError('illegal_change', + { field => 'flagtypes.name', privs => $privs }); + # Update (or delete) an existing flag. if ($params->{id}) { my $flag = $class->check({ id => $params->{id} }); diff --git a/extensions/BMO/template/en/default/hook/bug/edit-after_custom_fields.html.tmpl b/extensions/BMO/template/en/default/hook/bug/edit-after_custom_fields.html.tmpl index de97706b0..f72267246 100644 --- a/extensions/BMO/template/en/default/hook/bug/edit-after_custom_fields.html.tmpl +++ b/extensions/BMO/template/en/default/hook/bug/edit-after_custom_fields.html.tmpl @@ -41,29 +41,36 @@ - - [% FOREACH field = project_flags %] - [% NEXT IF NOT user.id AND field.value == "---" %] - - - - - + [% IF bug.check_can_change_field('flagtypes.name', 0, 1) %] +
  - - - [% PROCESS bug/field.html.tmpl value = bug.${field.name} - editable = user.id - no_tds = 1 %] - [% IF user.id %] - - [% bug.${field.name} FILTER html %] - - [% END %] -
+ [% FOREACH field = project_flags %] + [% NEXT IF NOT user.id AND field.value == "---" %] + + + + + + [% END %] +
  + + + [% PROCESS bug/field.html.tmpl value = bug.${field.name} + editable = user.id + no_tds = 1 %] + [% IF user.id %] + + [% bug.${field.name} FILTER html %] + + [% END %] +
+ [% ELSE %] + [% FOREACH field = project_flags %] + [% NEXT IF bug.${field.name} == "---" %] + [% field_descs.${field.name} FILTER html %]: [% bug.${field.name} FILTER html %]
+ [% END %] [% END %] - [% END %] @@ -74,34 +81,41 @@ - [% IF user.id %] - - (edit) - + [% IF bug.check_can_change_field('flagtypes.name', 0, 1) %] + [% IF user.id %] + + (edit) + + [% END %] + + [% FOREACH field = tracking_flags %] + [% NEXT IF NOT user.id AND field.value == "---" %] + + + + + + [% END %] +
  + + + [% PROCESS bug/field.html.tmpl value = bug.${field.name} + editable = user.id + no_tds = 1 %] + [% IF user.id %] + + [% bug.${field.name} FILTER html %] + + [% END %] +
+ [% ELSE %] + [% FOREACH field = tracking_flags %] + [% NEXT IF bug.${field.name} == "---" %] + [% field_descs.${field.name} FILTER html %]: [% bug.${field.name} FILTER html %]
+ [% END %] [% END %] - - [% FOREACH field = tracking_flags %] - [% NEXT IF NOT user.id AND field.value == "---" %] - - - - - - [% END %] -
  - - - [% PROCESS bug/field.html.tmpl value = bug.${field.name} - editable = user.id - no_tds = 1 %] - [% IF user.id %] - - [% bug.${field.name} FILTER html %] - - [% END %] -
[% END %] - [% IF mode == "edit" && user.is_insider %] + [% IF mode == "edit" && user.is_insider && bug.check_can_change_field('longdesc', 0, 1) %]
diff --git a/template/en/default/bug/edit.html.tmpl b/template/en/default/bug/edit.html.tmpl index 52e5865b8..d57d9641c 100644 --- a/template/en/default/bug/edit.html.tmpl +++ b/template/en/default/bug/edit.html.tmpl @@ -903,7 +903,7 @@ flag_types = bug.flag_types any_flags_requesteeble = bug.any_flags_requesteeble %] [% END %] - [% IF show_more_flags %] + [% IF show_more_flags && bug.check_can_change_field('flagtypes.name', 0, 1) %] [% IF !bug_flags_set %]None yet set[% END %] ([% IF !bug_flags_set %]set[% ELSE %]more[% END %] flags) @@ -1090,7 +1090,7 @@ : - [% IF user.is_insider %] + [% IF user.is_insider && bug.check_can_change_field('longdesc', 0, 1) %] @@ -1102,14 +1102,23 @@
- [% INCLUDE global/textarea.html.tmpl - name = 'comment' - id = 'comment' - minrows = 10 - maxrows = 25 - cols = constants.COMMENT_COLS - %] - [% Hook.process("after_comment_textarea", 'bug/edit.html.tmpl') %] + [% IF bug.check_can_change_field('longdesc', 0, 1) %] + [% INCLUDE global/textarea.html.tmpl + name = 'comment' + id = 'comment' + minrows = 10 + maxrows = 25 + cols = constants.COMMENT_COLS + %] + [% Hook.process("after_comment_textarea", 'bug/edit.html.tmpl') %] + [% ELSE %] +
+
+ Note + You are unable to make an additional comment on this [% terms.bug %]. +
+
+ [% END %]
[% PROCESS commit_button id=""%] diff --git a/template/en/default/flag/list.html.tmpl b/template/en/default/flag/list.html.tmpl index e670515e0..16775c714 100644 --- a/template/en/default/flag/list.html.tmpl +++ b/template/en/default/flag/list.html.tmpl @@ -18,7 +18,7 @@ # Contributor(s): Myk Melez #%] -[% IF user.id AND !read_only_flags %] +[% IF user.id && !read_only_flags && bug.check_can_change_field('flagtypes.name', 0, 1) %] [%# We list flags by looping twice over the flag types relevant for the bug. # In the first loop, we display existing flags and then, for active types, -- cgit v1.2.3-24-g4f1b