ddkilzer@apple.com | f573e63 | 2009-07-03 02:14:39 +0000 | [diff] [blame] | 1 | #!/usr/bin/env perl -wT |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 2 | # -*- Mode: perl; indent-tabs-mode: nil -*- |
| 3 | # |
| 4 | # The contents of this file are subject to the Mozilla Public |
| 5 | # License Version 1.1 (the "License"); you may not use this file |
| 6 | # except in compliance with the License. You may obtain a copy of |
| 7 | # the License at http://www.mozilla.org/MPL/ |
| 8 | # |
| 9 | # Software distributed under the License is distributed on an "AS |
| 10 | # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or |
| 11 | # implied. See the License for the specific language governing |
| 12 | # rights and limitations under the License. |
| 13 | # |
| 14 | # The Original Code is the Bugzilla Bug Tracking System. |
| 15 | # |
| 16 | # The Initial Developer of the Original Code is Netscape Communications |
| 17 | # Corporation. Portions created by Netscape are |
| 18 | # Copyright (C) 1998 Netscape Communications Corporation. All |
| 19 | # Rights Reserved. |
| 20 | # |
| 21 | # Contributor(s): Terry Weissman <terry@mozilla.org> |
| 22 | # Dan Mosedale <dmose@mozilla.org> |
| 23 | # Dave Miller <justdave@syndicomm.com> |
| 24 | # Christopher Aillon <christopher@aillon.com> |
| 25 | # Myk Melez <myk@mozilla.org> |
| 26 | # Jeff Hedlund <jeff.hedlund@matrixsi.com> |
ddkilzer@apple.com | f3615fc | 2009-07-03 02:13:41 +0000 | [diff] [blame] | 27 | # Frédéric Buclin <LpSolit@gmail.com> |
| 28 | # Lance Larsh <lance.larsh@oracle.com> |
| 29 | # Akamai Technologies <bugzilla-dev@akamai.com> |
ddkilzer@apple.com | 097da08 | 2009-07-03 02:14:25 +0000 | [diff] [blame] | 30 | # Max Kanat-Alexander <mkanat@bugzilla.org> |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 31 | |
| 32 | # Implementation notes for this file: |
| 33 | # |
| 34 | # 1) the 'id' form parameter is validated early on, and if it is not a valid |
| 35 | # bugid an error will be reported, so it is OK for later code to simply check |
| 36 | # for a defined form 'id' value, and it can assume a valid bugid. |
| 37 | # |
| 38 | # 2) If the 'id' form parameter is not defined (after the initial validation), |
| 39 | # then we are processing multiple bugs, and @idlist will contain the ids. |
| 40 | # |
| 41 | # 3) If we are processing just the one id, then it is stored in @idlist for |
| 42 | # later processing. |
| 43 | |
| 44 | use strict; |
| 45 | |
ddkilzer@apple.com | 097da08 | 2009-07-03 02:14:25 +0000 | [diff] [blame] | 46 | use lib qw(. lib); |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 47 | |
| 48 | use Bugzilla; |
| 49 | use Bugzilla::Constants; |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 50 | use Bugzilla::Bug; |
ddkilzer@apple.com | f3615fc | 2009-07-03 02:13:41 +0000 | [diff] [blame] | 51 | use Bugzilla::BugMail; |
| 52 | use Bugzilla::Mailer; |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 53 | use Bugzilla::User; |
| 54 | use Bugzilla::Util; |
ddkilzer@apple.com | f3615fc | 2009-07-03 02:13:41 +0000 | [diff] [blame] | 55 | use Bugzilla::Error; |
| 56 | use Bugzilla::Field; |
| 57 | use Bugzilla::Product; |
| 58 | use Bugzilla::Component; |
| 59 | use Bugzilla::Keyword; |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 60 | use Bugzilla::Flag; |
ddkilzer@apple.com | 097da08 | 2009-07-03 02:14:25 +0000 | [diff] [blame] | 61 | use Bugzilla::Status; |
| 62 | use Bugzilla::Token; |
| 63 | |
| 64 | use Storable qw(dclone); |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 65 | |
| 66 | my $user = Bugzilla->login(LOGIN_REQUIRED); |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 67 | |
| 68 | my $cgi = Bugzilla->cgi; |
| 69 | my $dbh = Bugzilla->dbh; |
ddkilzer@apple.com | f3615fc | 2009-07-03 02:13:41 +0000 | [diff] [blame] | 70 | my $template = Bugzilla->template; |
ddkilzer@apple.com | 097da08 | 2009-07-03 02:14:25 +0000 | [diff] [blame] | 71 | my $vars = {}; |
ddkilzer@apple.com | f3615fc | 2009-07-03 02:13:41 +0000 | [diff] [blame] | 72 | $vars->{'use_keywords'} = 1 if Bugzilla::Keyword::keyword_count(); |
| 73 | |
ddkilzer@apple.com | f3615fc | 2009-07-03 02:13:41 +0000 | [diff] [blame] | 74 | ###################################################################### |
| 75 | # Subroutines |
| 76 | ###################################################################### |
| 77 | |
ddkilzer@apple.com | f3615fc | 2009-07-03 02:13:41 +0000 | [diff] [blame] | 78 | # Used to send email when an update is done. |
| 79 | sub send_results { |
| 80 | my ($bug_id, $vars) = @_; |
| 81 | my $template = Bugzilla->template; |
| 82 | if (Bugzilla->usage_mode == USAGE_MODE_EMAIL) { |
| 83 | Bugzilla::BugMail::Send($bug_id, $vars->{'mailrecipients'}); |
| 84 | } |
| 85 | else { |
| 86 | $template->process("bug/process/results.html.tmpl", $vars) |
| 87 | || ThrowTemplateError($template->error()); |
| 88 | } |
| 89 | $vars->{'header_done'} = 1; |
| 90 | } |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 91 | |
ddkilzer@apple.com | 097da08 | 2009-07-03 02:14:25 +0000 | [diff] [blame] | 92 | # Tells us whether or not a field should be changed by process_bug. |
| 93 | sub should_set { |
| 94 | # check_defined is used for fields where there's another field |
| 95 | # whose name starts with "defined_" and then the field name--it's used |
| 96 | # to know when we did things like empty a multi-select or deselect |
| 97 | # a checkbox. |
| 98 | my ($field, $check_defined) = @_; |
| 99 | my $cgi = Bugzilla->cgi; |
| 100 | if ( defined $cgi->param($field) |
| 101 | || ($check_defined && defined $cgi->param("defined_$field")) ) |
| 102 | { |
| 103 | return 1; |
| 104 | } |
| 105 | return 0; |
| 106 | } |
| 107 | |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 108 | ###################################################################### |
| 109 | # Begin Data/Security Validation |
| 110 | ###################################################################### |
| 111 | |
ddkilzer@apple.com | 097da08 | 2009-07-03 02:14:25 +0000 | [diff] [blame] | 112 | # Create a list of objects for all bugs being modified in this request. |
| 113 | my @bug_objects; |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 114 | if (defined $cgi->param('id')) { |
| 115 | my $id = $cgi->param('id'); |
| 116 | ValidateBugID($id); |
| 117 | |
| 118 | # Store the validated, and detainted id back in the cgi data, as |
| 119 | # lots of later code will need it, and will obtain it from there |
| 120 | $cgi->param('id', $id); |
ddkilzer@apple.com | 097da08 | 2009-07-03 02:14:25 +0000 | [diff] [blame] | 121 | push(@bug_objects, new Bugzilla::Bug($id)); |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 122 | } else { |
ddkilzer@apple.com | 097da08 | 2009-07-03 02:14:25 +0000 | [diff] [blame] | 123 | my @ids; |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 124 | foreach my $i ($cgi->param()) { |
| 125 | if ($i =~ /^id_([1-9][0-9]*)/) { |
| 126 | my $id = $1; |
| 127 | ValidateBugID($id); |
ddkilzer@apple.com | 097da08 | 2009-07-03 02:14:25 +0000 | [diff] [blame] | 128 | push(@ids, $id); |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 129 | } |
| 130 | } |
ddkilzer@apple.com | 097da08 | 2009-07-03 02:14:25 +0000 | [diff] [blame] | 131 | @bug_objects = @{Bugzilla::Bug->new_from_list(\@ids)}; |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | # Make sure there are bugs to process. |
ddkilzer@apple.com | 097da08 | 2009-07-03 02:14:25 +0000 | [diff] [blame] | 135 | scalar(@bug_objects) || ThrowUserError("no_bugs_chosen", {action => 'modify'}); |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 136 | |
ddkilzer@apple.com | 097da08 | 2009-07-03 02:14:25 +0000 | [diff] [blame] | 137 | my $first_bug = $bug_objects[0]; # Used when we're only updating a single bug. |
ddkilzer@apple.com | f3615fc | 2009-07-03 02:13:41 +0000 | [diff] [blame] | 138 | |
ddkilzer@apple.com | 097da08 | 2009-07-03 02:14:25 +0000 | [diff] [blame] | 139 | # Delete any parameter set to 'dontchange'. |
| 140 | if (defined $cgi->param('dontchange')) { |
| 141 | foreach my $name ($cgi->param) { |
| 142 | next if $name eq 'dontchange'; # But don't delete dontchange itself! |
| 143 | # Skip ones we've already deleted (such as "defined_$name"). |
| 144 | next if !defined $cgi->param($name); |
| 145 | if ($cgi->param($name) eq $cgi->param('dontchange')) { |
| 146 | $cgi->delete($name); |
| 147 | $cgi->delete("defined_$name"); |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 148 | } |
| 149 | } |
| 150 | } |
| 151 | |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 152 | # do a match on the fields if applicable |
| 153 | |
ddkilzer@apple.com | f3615fc | 2009-07-03 02:13:41 +0000 | [diff] [blame] | 154 | # The order of these function calls is important, as Flag::validate |
| 155 | # assumes User::match_field has ensured that the values |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 156 | # in the requestee fields are legitimate user email addresses. |
| 157 | &Bugzilla::User::match_field($cgi, { |
| 158 | 'qa_contact' => { 'type' => 'single' }, |
| 159 | 'newcc' => { 'type' => 'multi' }, |
| 160 | 'masscc' => { 'type' => 'multi' }, |
| 161 | 'assigned_to' => { 'type' => 'single' }, |
ddkilzer@apple.com | f3615fc | 2009-07-03 02:13:41 +0000 | [diff] [blame] | 162 | '^requestee(_type)?-(\d+)$' => { 'type' => 'multi' }, |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 163 | }); |
| 164 | |
| 165 | # Validate flags in all cases. validate() should not detect any |
| 166 | # reference to flags if $cgi->param('id') is undefined. |
ddkilzer@apple.com | 097da08 | 2009-07-03 02:14:25 +0000 | [diff] [blame] | 167 | Bugzilla::Flag::validate($cgi->param('id')); |
| 168 | |
| 169 | print $cgi->header() unless Bugzilla->usage_mode == USAGE_MODE_EMAIL; |
| 170 | |
| 171 | # Check for a mid-air collision. Currently this only works when updating |
| 172 | # an individual bug. |
| 173 | if (defined $cgi->param('delta_ts') |
| 174 | && $cgi->param('delta_ts') ne $first_bug->delta_ts) |
| 175 | { |
| 176 | ($vars->{'operations'}) = |
| 177 | Bugzilla::Bug::GetBugActivity($first_bug->id, undef, |
| 178 | scalar $cgi->param('delta_ts')); |
| 179 | |
| 180 | $vars->{'title_tag'} = "mid_air"; |
| 181 | |
| 182 | ThrowCodeError('undefined_field', { field => 'longdesclength' }) |
| 183 | if !defined $cgi->param('longdesclength'); |
| 184 | |
| 185 | $vars->{'start_at'} = $cgi->param('longdesclength'); |
| 186 | # Always sort midair collision comments oldest to newest, |
| 187 | # regardless of the user's personal preference. |
| 188 | $vars->{'comments'} = Bugzilla::Bug::GetComments($first_bug->id, |
| 189 | "oldest_to_newest"); |
| 190 | $vars->{'bug'} = $first_bug; |
| 191 | # The token contains the old delta_ts. We need a new one. |
| 192 | $cgi->param('token', issue_hash_token([$first_bug->id, $first_bug->delta_ts])); |
| 193 | |
| 194 | # Warn the user about the mid-air collision and ask them what to do. |
| 195 | $template->process("bug/process/midair.html.tmpl", $vars) |
| 196 | || ThrowTemplateError($template->error()); |
| 197 | exit; |
| 198 | } |
| 199 | |
| 200 | # We couldn't do this check earlier as we first had to validate bug IDs |
| 201 | # and display the mid-air collision page if delta_ts changed. |
| 202 | # If we do a mass-change, we use session tokens. |
| 203 | my $token = $cgi->param('token'); |
| 204 | |
| 205 | if ($cgi->param('id')) { |
| 206 | check_hash_token($token, [$first_bug->id, $first_bug->delta_ts]); |
| 207 | } |
| 208 | else { |
| 209 | check_token_data($token, 'buglist_mass_change', 'query.cgi'); |
| 210 | } |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 211 | |
| 212 | ###################################################################### |
| 213 | # End Data/Security Validation |
| 214 | ###################################################################### |
| 215 | |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 216 | $vars->{'title_tag'} = "bug_processed"; |
| 217 | |
ddkilzer@apple.com | f3615fc | 2009-07-03 02:13:41 +0000 | [diff] [blame] | 218 | # Set up the vars for navigational <link> elements |
| 219 | my @bug_list; |
ddkilzer@apple.com | 097da08 | 2009-07-03 02:14:25 +0000 | [diff] [blame] | 220 | if ($cgi->cookie("BUGLIST")) { |
ddkilzer@apple.com | f3615fc | 2009-07-03 02:13:41 +0000 | [diff] [blame] | 221 | @bug_list = split(/:/, $cgi->cookie("BUGLIST")); |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 222 | $vars->{'bug_list'} = \@bug_list; |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 223 | } |
| 224 | |
ddkilzer@apple.com | 097da08 | 2009-07-03 02:14:25 +0000 | [diff] [blame] | 225 | my ($action, $next_bug); |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 226 | if (defined $cgi->param('id')) { |
ddkilzer@apple.com | 097da08 | 2009-07-03 02:14:25 +0000 | [diff] [blame] | 227 | $action = Bugzilla->user->settings->{'post_bug_submit_action'}->{'value'}; |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 228 | |
ddkilzer@apple.com | 097da08 | 2009-07-03 02:14:25 +0000 | [diff] [blame] | 229 | if ($action eq 'next_bug') { |
| 230 | my $cur = lsearch(\@bug_list, $cgi->param('id')); |
| 231 | if ($cur >= 0 && $cur < $#bug_list) { |
| 232 | $next_bug = $bug_list[$cur + 1]; |
| 233 | # No need to check whether the user can see the bug or not. |
| 234 | # All we want is its ID. An error will be thrown later |
| 235 | # if the user cannot see it. |
| 236 | $vars->{'bug'} = {bug_id => $next_bug}; |
ddkilzer@apple.com | f3615fc | 2009-07-03 02:13:41 +0000 | [diff] [blame] | 237 | } |
| 238 | } |
ddkilzer@apple.com | 097da08 | 2009-07-03 02:14:25 +0000 | [diff] [blame] | 239 | # Include both action = 'same_bug' and 'nothing'. |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 240 | else { |
ddkilzer@apple.com | 097da08 | 2009-07-03 02:14:25 +0000 | [diff] [blame] | 241 | $vars->{'bug'} = {bug_id => $cgi->param('id')}; |
| 242 | } |
| 243 | } |
| 244 | else { |
| 245 | # param('id') is not defined when changing multiple bugs at once. |
| 246 | $action = 'nothing'; |
| 247 | } |
| 248 | |
| 249 | # For each bug, we have to check if the user can edit the bug the product |
| 250 | # is currently in, before we allow them to change anything. |
| 251 | foreach my $bug (@bug_objects) { |
| 252 | if (!Bugzilla->user->can_edit_product($bug->product_obj->id) ) { |
| 253 | ThrowUserError("product_edit_denied", |
| 254 | { product => $bug->product }); |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 255 | } |
| 256 | } |
| 257 | |
ddkilzer@apple.com | 097da08 | 2009-07-03 02:14:25 +0000 | [diff] [blame] | 258 | # For security purposes, and because lots of other checks depend on it, |
| 259 | # we set the product first before anything else. |
| 260 | my $product_change; # Used only for strict_isolation checks, right now. |
| 261 | if (should_set('product')) { |
| 262 | foreach my $b (@bug_objects) { |
| 263 | my $changed = $b->set_product(scalar $cgi->param('product'), |
| 264 | { component => scalar $cgi->param('component'), |
| 265 | version => scalar $cgi->param('version'), |
| 266 | target_milestone => scalar $cgi->param('target_milestone'), |
| 267 | change_confirmed => scalar $cgi->param('confirm_product_change'), |
| 268 | other_bugs => \@bug_objects, |
| 269 | }); |
| 270 | $product_change ||= $changed; |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 271 | } |
| 272 | } |
ddkilzer@apple.com | 097da08 | 2009-07-03 02:14:25 +0000 | [diff] [blame] | 273 | |
| 274 | # strict_isolation checks mean that we should set the groups |
| 275 | # immediately after changing the product. |
| 276 | foreach my $b (@bug_objects) { |
| 277 | foreach my $group (@{$b->product_obj->groups_valid}) { |
| 278 | my $gid = $group->id; |
| 279 | if (should_set("bit-$gid", 1)) { |
| 280 | # Check ! first to avoid having to check defined below. |
| 281 | if (!$cgi->param("bit-$gid")) { |
| 282 | $b->remove_group($gid); |
ddkilzer@apple.com | f3615fc | 2009-07-03 02:13:41 +0000 | [diff] [blame] | 283 | } |
ddkilzer@apple.com | 097da08 | 2009-07-03 02:14:25 +0000 | [diff] [blame] | 284 | # "== 1" is important because mass-change uses -1 to mean |
| 285 | # "don't change this restriction" |
| 286 | elsif ($cgi->param("bit-$gid") == 1) { |
| 287 | $b->add_group($gid); |
ddkilzer@apple.com | f3615fc | 2009-07-03 02:13:41 +0000 | [diff] [blame] | 288 | } |
| 289 | } |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 290 | } |
| 291 | } |
| 292 | |
ddkilzer@apple.com | 097da08 | 2009-07-03 02:14:25 +0000 | [diff] [blame] | 293 | if ($cgi->param('id') && (defined $cgi->param('dependson') |
| 294 | || defined $cgi->param('blocked')) ) |
ddkilzer@apple.com | f3615fc | 2009-07-03 02:13:41 +0000 | [diff] [blame] | 295 | { |
ddkilzer@apple.com | 097da08 | 2009-07-03 02:14:25 +0000 | [diff] [blame] | 296 | $first_bug->set_dependencies(scalar $cgi->param('dependson'), |
| 297 | scalar $cgi->param('blocked')); |
| 298 | } |
| 299 | # Right now, you can't modify dependencies on a mass change. |
| 300 | else { |
| 301 | $cgi->delete('dependson'); |
| 302 | $cgi->delete('blocked'); |
| 303 | } |
ddkilzer@apple.com | f3615fc | 2009-07-03 02:13:41 +0000 | [diff] [blame] | 304 | |
ddkilzer@apple.com | 097da08 | 2009-07-03 02:14:25 +0000 | [diff] [blame] | 305 | my $any_keyword_changes; |
| 306 | if (defined $cgi->param('keywords')) { |
| 307 | foreach my $b (@bug_objects) { |
| 308 | my $return = |
| 309 | $b->modify_keywords(scalar $cgi->param('keywords'), |
| 310 | scalar $cgi->param('keywordaction')); |
| 311 | $any_keyword_changes ||= $return; |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 312 | } |
| 313 | } |
| 314 | |
ddkilzer@apple.com | 097da08 | 2009-07-03 02:14:25 +0000 | [diff] [blame] | 315 | # Component, target_milestone, and version are in here just in case |
| 316 | # the 'product' field wasn't defined in the CGI. It doesn't hurt to set |
| 317 | # them twice. |
| 318 | my @set_fields = qw(op_sys rep_platform priority bug_severity |
| 319 | component target_milestone version |
| 320 | bug_file_loc status_whiteboard short_desc |
| 321 | deadline remaining_time estimated_time); |
| 322 | push(@set_fields, 'assigned_to') if !$cgi->param('set_default_assignee'); |
| 323 | push(@set_fields, 'qa_contact') if !$cgi->param('set_default_qa_contact'); |
| 324 | my @custom_fields = Bugzilla->active_custom_fields; |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 325 | |
ddkilzer@apple.com | 097da08 | 2009-07-03 02:14:25 +0000 | [diff] [blame] | 326 | my %methods = ( |
| 327 | bug_severity => 'set_severity', |
| 328 | rep_platform => 'set_platform', |
| 329 | short_desc => 'set_summary', |
| 330 | bug_file_loc => 'set_url', |
| 331 | ); |
| 332 | foreach my $b (@bug_objects) { |
| 333 | if (should_set('comment') || $cgi->param('work_time')) { |
| 334 | # Add a comment as needed to each bug. This is done early because |
| 335 | # there are lots of things that want to check if we added a comment. |
| 336 | $b->add_comment(scalar($cgi->param('comment')), |
| 337 | { isprivate => scalar $cgi->param('commentprivacy'), |
| 338 | work_time => scalar $cgi->param('work_time') }); |
| 339 | } |
| 340 | foreach my $field_name (@set_fields) { |
| 341 | if (should_set($field_name)) { |
| 342 | my $method = $methods{$field_name}; |
| 343 | $method ||= "set_" . $field_name; |
| 344 | $b->$method($cgi->param($field_name)); |
| 345 | } |
| 346 | } |
| 347 | $b->reset_assigned_to if $cgi->param('set_default_assignee'); |
| 348 | $b->reset_qa_contact if $cgi->param('set_default_qa_contact'); |
| 349 | |
| 350 | # And set custom fields. |
| 351 | foreach my $field (@custom_fields) { |
| 352 | my $fname = $field->name; |
| 353 | if (should_set($fname, 1)) { |
| 354 | $b->set_custom_field($field, [$cgi->param($fname)]); |
| 355 | } |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | # Certain changes can only happen on individual bugs, never on mass-changes. |
| 360 | if (defined $cgi->param('id')) { |
| 361 | # Since aliases are unique (like bug numbers), they can only be changed |
| 362 | # for one bug at a time. |
| 363 | if (Bugzilla->params->{"usebugaliases"} && defined $cgi->param('alias')) { |
| 364 | $first_bug->set_alias($cgi->param('alias')); |
| 365 | } |
| 366 | |
| 367 | # reporter_accessible and cclist_accessible--these are only set if |
| 368 | # the user can change them and they appear on the page. |
| 369 | if (should_set('cclist_accessible', 1)) { |
| 370 | $first_bug->set_cclist_accessible($cgi->param('cclist_accessible')) |
| 371 | } |
| 372 | if (should_set('reporter_accessible', 1)) { |
| 373 | $first_bug->set_reporter_accessible($cgi->param('reporter_accessible')) |
| 374 | } |
| 375 | |
| 376 | # You can only mark/unmark comments as private on single bugs. If |
| 377 | # you're not in the insider group, this code won't do anything. |
| 378 | foreach my $field (grep(/^defined_isprivate/, $cgi->param())) { |
| 379 | $field =~ /(\d+)$/; |
| 380 | my $comment_id = $1; |
| 381 | $first_bug->set_comment_is_private($comment_id, |
| 382 | $cgi->param("isprivate_$comment_id")); |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | # We need to check the addresses involved in a CC change before we touch |
| 387 | # any bugs. What we'll do here is formulate the CC data into two arrays of |
| 388 | # users involved in this CC change. Then those arrays can be used later |
| 389 | # on for the actual change. |
| 390 | my (@cc_add, @cc_remove); |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 391 | if (defined $cgi->param('newcc') |
| 392 | || defined $cgi->param('addselfcc') |
| 393 | || defined $cgi->param('removecc') |
| 394 | || defined $cgi->param('masscc')) { |
ddkilzer@apple.com | 097da08 | 2009-07-03 02:14:25 +0000 | [diff] [blame] | 395 | |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 396 | # If masscc is defined, then we came from buglist and need to either add or |
| 397 | # remove cc's... otherwise, we came from bugform and may need to do both. |
| 398 | my ($cc_add, $cc_remove) = ""; |
| 399 | if (defined $cgi->param('masscc')) { |
| 400 | if ($cgi->param('ccaction') eq 'add') { |
| 401 | $cc_add = join(' ',$cgi->param('masscc')); |
| 402 | } elsif ($cgi->param('ccaction') eq 'remove') { |
| 403 | $cc_remove = join(' ',$cgi->param('masscc')); |
| 404 | } |
| 405 | } else { |
| 406 | $cc_add = join(' ',$cgi->param('newcc')); |
| 407 | # We came from bug_form which uses a select box to determine what cc's |
| 408 | # need to be removed... |
| 409 | if (defined $cgi->param('removecc') && $cgi->param('cc')) { |
| 410 | $cc_remove = join (",", $cgi->param('cc')); |
| 411 | } |
| 412 | } |
| 413 | |
ddkilzer@apple.com | 097da08 | 2009-07-03 02:14:25 +0000 | [diff] [blame] | 414 | push(@cc_add, split(/[\s,]+/, $cc_add)) if $cc_add; |
| 415 | push(@cc_add, Bugzilla->user) if $cgi->param('addselfcc'); |
| 416 | |
| 417 | push(@cc_remove, split(/[\s,]+/, $cc_remove)) if $cc_remove; |
| 418 | } |
| 419 | |
| 420 | foreach my $b (@bug_objects) { |
| 421 | $b->remove_cc($_) foreach @cc_remove; |
| 422 | $b->add_cc($_) foreach @cc_add; |
| 423 | # Theoretically you could move a product without ever specifying |
| 424 | # a new assignee or qa_contact, or adding/removing any CCs. So, |
| 425 | # we have to check that the current assignee, qa, and CCs are still |
| 426 | # valid if we've switched products, under strict_isolation. We can only |
| 427 | # do that here. There ought to be some better way to do this, |
| 428 | # architecturally, but I haven't come up with it. |
| 429 | if ($product_change) { |
| 430 | $b->_check_strict_isolation(); |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 431 | } |
| 432 | } |
| 433 | |
ddkilzer@apple.com | 097da08 | 2009-07-03 02:14:25 +0000 | [diff] [blame] | 434 | my $move_action = $cgi->param('action') || ''; |
| 435 | if ($move_action eq Bugzilla->params->{'move-button-text'}) { |
| 436 | Bugzilla->params->{'move-enabled'} || ThrowUserError("move_bugs_disabled"); |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 437 | |
ddkilzer@apple.com | 097da08 | 2009-07-03 02:14:25 +0000 | [diff] [blame] | 438 | $user->is_mover || ThrowUserError("auth_failure", {action => 'move', |
| 439 | object => 'bugs'}); |
ddkilzer@apple.com | f3615fc | 2009-07-03 02:13:41 +0000 | [diff] [blame] | 440 | |
ddkilzer@apple.com | 097da08 | 2009-07-03 02:14:25 +0000 | [diff] [blame] | 441 | $dbh->bz_start_transaction(); |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 442 | |
ddkilzer@apple.com | 097da08 | 2009-07-03 02:14:25 +0000 | [diff] [blame] | 443 | # First update all moved bugs. |
| 444 | foreach my $bug (@bug_objects) { |
| 445 | $bug->add_comment('', { type => CMT_MOVED_TO, extra_data => $user->login }); |
| 446 | } |
| 447 | # Don't export the new status and resolution. We want the current ones. |
| 448 | local $Storable::forgive_me = 1; |
| 449 | my $bugs = dclone(\@bug_objects); |
| 450 | |
| 451 | my $new_status = Bugzilla->params->{'duplicate_or_move_bug_status'}; |
| 452 | foreach my $bug (@bug_objects) { |
| 453 | $bug->set_status($new_status, {resolution => 'MOVED', moving => 1}); |
| 454 | } |
| 455 | $_->update() foreach @bug_objects; |
| 456 | $dbh->bz_commit_transaction(); |
| 457 | |
| 458 | # Now send emails. |
| 459 | foreach my $bug (@bug_objects) { |
| 460 | $vars->{'mailrecipients'} = { 'changer' => $user->login }; |
| 461 | $vars->{'id'} = $bug->id; |
| 462 | $vars->{'type'} = "move"; |
| 463 | send_results($bug->id, $vars); |
| 464 | } |
| 465 | # Prepare and send all data about these bugs to the new database |
| 466 | my $to = Bugzilla->params->{'move-to-address'}; |
| 467 | $to =~ s/@/\@/; |
| 468 | my $from = Bugzilla->params->{'moved-from-address'}; |
| 469 | $from =~ s/@/\@/; |
| 470 | my $msg = "To: $to\n"; |
| 471 | $msg .= "From: Bugzilla <" . $from . ">\n"; |
| 472 | $msg .= "Subject: Moving bug(s) " . join(', ', map($_->id, @bug_objects)) |
| 473 | . "\n\n"; |
| 474 | |
| 475 | my @fieldlist = (Bugzilla::Bug->fields, 'group', 'long_desc', |
| 476 | 'attachment', 'attachmentdata'); |
| 477 | my %displayfields; |
| 478 | foreach (@fieldlist) { |
| 479 | $displayfields{$_} = 1; |
| 480 | } |
| 481 | |
| 482 | $template->process("bug/show.xml.tmpl", { bugs => $bugs, |
| 483 | displayfields => \%displayfields, |
| 484 | }, \$msg) |
| 485 | || ThrowTemplateError($template->error()); |
| 486 | |
| 487 | $msg .= "\n"; |
| 488 | MessageToMTA($msg); |
| 489 | |
| 490 | # End the response page. |
| 491 | unless (Bugzilla->usage_mode == USAGE_MODE_EMAIL) { |
| 492 | $template->process("bug/navigate.html.tmpl", $vars) |
| 493 | || ThrowTemplateError($template->error()); |
| 494 | $template->process("global/footer.html.tmpl", $vars) |
| 495 | || ThrowTemplateError($template->error()); |
| 496 | } |
| 497 | exit; |
| 498 | } |
| 499 | |
| 500 | |
| 501 | # You cannot mark bugs as duplicates when changing several bugs at once |
| 502 | # (because currently there is no way to check for duplicate loops in that |
| 503 | # situation). |
| 504 | if (!$cgi->param('id') && $cgi->param('dup_id')) { |
| 505 | ThrowUserError('dupe_not_allowed'); |
| 506 | } |
| 507 | |
| 508 | # Set the status, resolution, and dupe_of (if needed). This has to be done |
| 509 | # down here, because the validity of status changes depends on other fields, |
| 510 | # such as Target Milestone. |
| 511 | foreach my $b (@bug_objects) { |
| 512 | if (should_set('bug_status')) { |
| 513 | $b->set_status( |
| 514 | scalar $cgi->param('bug_status'), |
| 515 | {resolution => scalar $cgi->param('resolution'), |
| 516 | dupe_of => scalar $cgi->param('dup_id')} |
| 517 | ); |
| 518 | } |
| 519 | elsif (should_set('resolution')) { |
| 520 | $b->set_resolution(scalar $cgi->param('resolution'), |
| 521 | {dupe_of => scalar $cgi->param('dup_id')}); |
| 522 | } |
| 523 | elsif (should_set('dup_id')) { |
| 524 | $b->set_dup_id(scalar $cgi->param('dup_id')); |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 525 | } |
| 526 | } |
| 527 | |
ddkilzer@apple.com | 097da08 | 2009-07-03 02:14:25 +0000 | [diff] [blame] | 528 | ############################## |
| 529 | # Do Actual Database Updates # |
| 530 | ############################## |
| 531 | foreach my $bug (@bug_objects) { |
| 532 | $dbh->bz_start_transaction(); |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 533 | |
ddkilzer@apple.com | 097da08 | 2009-07-03 02:14:25 +0000 | [diff] [blame] | 534 | my $timestamp = $dbh->selectrow_array(q{SELECT NOW()}); |
| 535 | my $changes = $bug->update($timestamp); |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 536 | |
ddkilzer@apple.com | 097da08 | 2009-07-03 02:14:25 +0000 | [diff] [blame] | 537 | my %notify_deps; |
| 538 | if ($changes->{'bug_status'}) { |
| 539 | my ($old_status, $new_status) = @{ $changes->{'bug_status'} }; |
ddkilzer@apple.com | f3615fc | 2009-07-03 02:13:41 +0000 | [diff] [blame] | 540 | |
ddkilzer@apple.com | 097da08 | 2009-07-03 02:14:25 +0000 | [diff] [blame] | 541 | # If this bug has changed from opened to closed or vice-versa, |
| 542 | # then all of the bugs we block need to be notified. |
| 543 | if (is_open_state($old_status) ne is_open_state($new_status)) { |
| 544 | $notify_deps{$_} = 1 foreach (@{$bug->blocked}); |
ddkilzer@apple.com | f3615fc | 2009-07-03 02:13:41 +0000 | [diff] [blame] | 545 | } |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 546 | |
ddkilzer@apple.com | 097da08 | 2009-07-03 02:14:25 +0000 | [diff] [blame] | 547 | # We may have zeroed the remaining time, if we moved into a closed |
| 548 | # status, so we should inform the user about that. |
| 549 | if (!is_open_state($new_status) && $changes->{'remaining_time'}) { |
| 550 | $vars->{'message'} = "remaining_time_zeroed" |
| 551 | if Bugzilla->user->in_group(Bugzilla->params->{'timetrackinggroup'}); |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 552 | } |
| 553 | } |
| 554 | |
ddkilzer@apple.com | 097da08 | 2009-07-03 02:14:25 +0000 | [diff] [blame] | 555 | # To get a list of all changed dependencies, convert the "changes" arrays |
| 556 | # into a long string, then collapse that string into unique numbers in |
| 557 | # a hash. |
| 558 | my $all_changed_deps = join(', ', @{ $changes->{'dependson'} || [] }); |
| 559 | $all_changed_deps = join(', ', @{ $changes->{'blocked'} || [] }, |
| 560 | $all_changed_deps); |
| 561 | my %changed_deps = map { $_ => 1 } split(', ', $all_changed_deps); |
| 562 | # When clearning one field (say, blocks) and filling in the other |
| 563 | # (say, dependson), an empty string can get into the hash and cause |
| 564 | # an error later. |
| 565 | delete $changed_deps{''}; |
ddkilzer@apple.com | f3615fc | 2009-07-03 02:13:41 +0000 | [diff] [blame] | 566 | |
| 567 | # $msgs will store emails which have to be sent to voters, if any. |
| 568 | my $msgs; |
ddkilzer@apple.com | 097da08 | 2009-07-03 02:14:25 +0000 | [diff] [blame] | 569 | if ($changes->{'product'}) { |
| 570 | # If some votes have been removed, RemoveVotes() returns |
| 571 | # a list of messages to send to voters. |
| 572 | # We delay the sending of these messages till tables are unlocked. |
| 573 | $msgs = RemoveVotes($bug->id, 0, 'votes_bug_moved'); |
| 574 | CheckIfVotedConfirmed($bug->id, Bugzilla->user->id); |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 575 | } |
ddkilzer@apple.com | 097da08 | 2009-07-03 02:14:25 +0000 | [diff] [blame] | 576 | |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 577 | # Set and update flags. |
ddkilzer@apple.com | 097da08 | 2009-07-03 02:14:25 +0000 | [diff] [blame] | 578 | Bugzilla::Flag->process($bug, undef, $timestamp, $vars); |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 579 | |
ddkilzer@apple.com | 097da08 | 2009-07-03 02:14:25 +0000 | [diff] [blame] | 580 | $dbh->bz_commit_transaction(); |
| 581 | |
| 582 | ############### |
| 583 | # Send Emails # |
| 584 | ############### |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 585 | |
ddkilzer@apple.com | f3615fc | 2009-07-03 02:13:41 +0000 | [diff] [blame] | 586 | # Now is a good time to send email to voters. |
| 587 | foreach my $msg (@$msgs) { |
| 588 | MessageToMTA($msg); |
| 589 | } |
| 590 | |
ddkilzer@apple.com | 097da08 | 2009-07-03 02:14:25 +0000 | [diff] [blame] | 591 | my $old_qa = $changes->{'qa_contact'} ? $changes->{'qa_contact'}->[0] : ''; |
| 592 | my $old_own = $changes->{'assigned_to'} ? $changes->{'assigned_to'}->[0] : ''; |
| 593 | my $old_cc = $changes->{cc} ? $changes->{cc}->[0] : ''; |
| 594 | $vars->{'mailrecipients'} = { |
| 595 | cc => [split(/[\s,]+/, $old_cc)], |
| 596 | owner => $old_own, |
| 597 | qacontact => $old_qa, |
| 598 | changer => Bugzilla->user->login }; |
ddkilzer@apple.com | f3615fc | 2009-07-03 02:13:41 +0000 | [diff] [blame] | 599 | |
ddkilzer@apple.com | 097da08 | 2009-07-03 02:14:25 +0000 | [diff] [blame] | 600 | $vars->{'id'} = $bug->id; |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 601 | $vars->{'type'} = "bug"; |
| 602 | |
| 603 | # Let the user know the bug was changed and who did and didn't |
| 604 | # receive email about the change. |
ddkilzer@apple.com | 097da08 | 2009-07-03 02:14:25 +0000 | [diff] [blame] | 605 | send_results($bug->id, $vars); |
ddkilzer@apple.com | f3615fc | 2009-07-03 02:13:41 +0000 | [diff] [blame] | 606 | |
ddkilzer@apple.com | 097da08 | 2009-07-03 02:14:25 +0000 | [diff] [blame] | 607 | # If the bug was marked as a duplicate, we need to notify users on the |
| 608 | # other bug of any changes to that bug. |
| 609 | my $new_dup_id = $changes->{'dup_id'} ? $changes->{'dup_id'}->[1] : undef; |
| 610 | if ($new_dup_id) { |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 611 | $vars->{'mailrecipients'} = { 'changer' => Bugzilla->user->login }; |
| 612 | |
ddkilzer@apple.com | 097da08 | 2009-07-03 02:14:25 +0000 | [diff] [blame] | 613 | $vars->{'id'} = $new_dup_id; |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 614 | $vars->{'type'} = "dupe"; |
| 615 | |
ddkilzer@apple.com | f3615fc | 2009-07-03 02:13:41 +0000 | [diff] [blame] | 616 | # Let the user know a duplication notation was added to the |
| 617 | # original bug. |
ddkilzer@apple.com | 097da08 | 2009-07-03 02:14:25 +0000 | [diff] [blame] | 618 | send_results($new_dup_id, $vars); |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 619 | } |
| 620 | |
ddkilzer@apple.com | 097da08 | 2009-07-03 02:14:25 +0000 | [diff] [blame] | 621 | my %all_dep_changes = (%notify_deps, %changed_deps); |
| 622 | foreach my $id (sort { $a <=> $b } (keys %all_dep_changes)) { |
| 623 | $vars->{'mailrecipients'} = { 'changer' => Bugzilla->user->login }; |
| 624 | $vars->{'id'} = $id; |
| 625 | $vars->{'type'} = "dep"; |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 626 | |
ddkilzer@apple.com | 097da08 | 2009-07-03 02:14:25 +0000 | [diff] [blame] | 627 | # Let the user (if he is able to see the bug) know we checked to |
| 628 | # see if we should email notice of this change to users with a |
| 629 | # relationship to the dependent bug and who did and didn't |
| 630 | # receive email about it. |
| 631 | send_results($id, $vars); |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 632 | } |
| 633 | } |
| 634 | |
ddkilzer@apple.com | f3615fc | 2009-07-03 02:13:41 +0000 | [diff] [blame] | 635 | # Determine if Patch Viewer is installed, for Diff link |
| 636 | # (NB: Duplicate code with show_bug.cgi.) |
| 637 | eval { |
| 638 | require PatchReader; |
| 639 | $vars->{'patchviewerinstalled'} = 1; |
| 640 | }; |
| 641 | |
ddkilzer@apple.com | f3615fc | 2009-07-03 02:13:41 +0000 | [diff] [blame] | 642 | if (Bugzilla->usage_mode == USAGE_MODE_EMAIL) { |
| 643 | # Do nothing. |
| 644 | } |
| 645 | elsif ($action eq 'next_bug') { |
ddkilzer@apple.com | f3615fc | 2009-07-03 02:13:41 +0000 | [diff] [blame] | 646 | if ($next_bug) { |
| 647 | if (detaint_natural($next_bug) && Bugzilla->user->can_see_bug($next_bug)) { |
| 648 | my $bug = new Bugzilla::Bug($next_bug); |
| 649 | ThrowCodeError("bug_error", { bug => $bug }) if $bug->error; |
| 650 | |
| 651 | $vars->{'bugs'} = [$bug]; |
| 652 | $vars->{'nextbug'} = $bug->bug_id; |
| 653 | |
| 654 | $template->process("bug/show.html.tmpl", $vars) |
| 655 | || ThrowTemplateError($template->error()); |
| 656 | |
| 657 | exit; |
| 658 | } |
| 659 | } |
| 660 | } elsif ($action eq 'same_bug') { |
| 661 | if (Bugzilla->user->can_see_bug($cgi->param('id'))) { |
| 662 | my $bug = new Bugzilla::Bug($cgi->param('id')); |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 663 | ThrowCodeError("bug_error", { bug => $bug }) if $bug->error; |
| 664 | |
ddkilzer@apple.com | f3615fc | 2009-07-03 02:13:41 +0000 | [diff] [blame] | 665 | $vars->{'bugs'} = [$bug]; |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 666 | |
ddkilzer@apple.com | f3615fc | 2009-07-03 02:13:41 +0000 | [diff] [blame] | 667 | $template->process("bug/show.html.tmpl", $vars) |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 668 | || ThrowTemplateError($template->error()); |
| 669 | |
| 670 | exit; |
| 671 | } |
ddkilzer@apple.com | f3615fc | 2009-07-03 02:13:41 +0000 | [diff] [blame] | 672 | } elsif ($action ne 'nothing') { |
| 673 | ThrowCodeError("invalid_post_bug_submit_action"); |
timothy@apple.com | f42518d | 2008-02-06 20:19:16 +0000 | [diff] [blame] | 674 | } |
| 675 | |
| 676 | # End the response page. |
ddkilzer@apple.com | f3615fc | 2009-07-03 02:13:41 +0000 | [diff] [blame] | 677 | unless (Bugzilla->usage_mode == USAGE_MODE_EMAIL) { |
ddkilzer@apple.com | f3615fc | 2009-07-03 02:13:41 +0000 | [diff] [blame] | 678 | $template->process("bug/navigate.html.tmpl", $vars) |
| 679 | || ThrowTemplateError($template->error()); |
| 680 | $template->process("global/footer.html.tmpl", $vars) |
| 681 | || ThrowTemplateError($template->error()); |
| 682 | } |
| 683 | |
| 684 | 1; |