REGRESSION (r243153): [iOS] TestWebKitAPI.FocusPreservationTests.ChangingFocusedNodeR...
[WebKit-https.git] / Websites / bugs.webkit.org / editmilestones.cgi
1 #!/usr/bin/perl -T
2 # This Source Code Form is subject to the terms of the Mozilla Public
3 # License, v. 2.0. If a copy of the MPL was not distributed with this
4 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 #
6 # This Source Code Form is "Incompatible With Secondary Licenses", as
7 # defined by the Mozilla Public License, v. 2.0.
8
9 use 5.10.1;
10 use strict;
11 use warnings;
12
13 use lib qw(. lib);
14
15 use Bugzilla;
16 use Bugzilla::Constants;
17 use Bugzilla::Util;
18 use Bugzilla::Error;
19 use Bugzilla::Milestone;
20 use Bugzilla::Token;
21
22 my $cgi = Bugzilla->cgi;
23 my $dbh = Bugzilla->dbh;
24 my $template = Bugzilla->template;
25 my $vars = {};
26 # There is only one section about milestones in the documentation,
27 # so all actions point to the same page.
28 $vars->{'doc_section'} = 'administering/categorization.html#milestones';
29
30 #
31 # Preliminary checks:
32 #
33
34 my $user = Bugzilla->login(LOGIN_REQUIRED);
35
36 print $cgi->header();
37
38 $user->in_group('editcomponents')
39   || scalar(@{$user->get_products_by_permission('editcomponents')})
40   || ThrowUserError("auth_failure", {group  => "editcomponents",
41                                      action => "edit",
42                                      object => "milestones"});
43
44 #
45 # often used variables
46 #
47 my $product_name   = trim($cgi->param('product')     || '');
48 my $milestone_name = trim($cgi->param('milestone')   || '');
49 my $sortkey        = trim($cgi->param('sortkey')     || 0);
50 my $action         = trim($cgi->param('action')      || '');
51 my $showbugcounts = (defined $cgi->param('showbugcounts'));
52 my $token          = $cgi->param('token');
53 my $isactive       = $cgi->param('isactive');
54
55 #
56 # product = '' -> Show nice list of products
57 #
58
59 unless ($product_name) {
60     my $selectable_products = $user->get_selectable_products;
61     # If the user has editcomponents privs for some products only,
62     # we have to restrict the list of products to display.
63     unless ($user->in_group('editcomponents')) {
64         $selectable_products = $user->get_products_by_permission('editcomponents');
65     }
66     $vars->{'products'} = $selectable_products;
67     $vars->{'showbugcounts'} = $showbugcounts;
68
69     $template->process("admin/milestones/select-product.html.tmpl", $vars)
70       || ThrowTemplateError($template->error());
71     exit;
72 }
73
74 my $product = $user->check_can_admin_product($product_name);
75
76 #
77 # action='' -> Show nice list of milestones
78 #
79
80 unless ($action) {
81
82     $vars->{'showbugcounts'} = $showbugcounts;
83     $vars->{'product'} = $product;
84     $template->process("admin/milestones/list.html.tmpl", $vars)
85       || ThrowTemplateError($template->error());
86     exit;
87 }
88
89 #
90 # action='add' -> present form for parameters for new milestone
91 #
92 # (next action will be 'new')
93 #
94
95 if ($action eq 'add') {
96     $vars->{'token'} = issue_session_token('add_milestone');
97     $vars->{'product'} = $product;
98     $template->process("admin/milestones/create.html.tmpl", $vars)
99       || ThrowTemplateError($template->error());
100     exit;
101 }
102
103 #
104 # action='new' -> add milestone entered in the 'action=add' screen
105 #
106
107 if ($action eq 'new') {
108     check_token_data($token, 'add_milestone');
109
110     my $milestone = Bugzilla::Milestone->create({ value    => $milestone_name,
111                                                   product  => $product,
112                                                   sortkey  => $sortkey });
113
114     delete_token($token);
115
116     $vars->{'message'} = 'milestone_created';
117     $vars->{'milestone'} = $milestone;
118     $vars->{'product'} = $product;
119     $template->process("admin/milestones/list.html.tmpl", $vars)
120       || ThrowTemplateError($template->error());
121     exit;
122 }
123
124 #
125 # action='del' -> ask if user really wants to delete
126 #
127 # (next action would be 'delete')
128 #
129
130 if ($action eq 'del') {
131     my $milestone = Bugzilla::Milestone->check({ product => $product,
132                                                  name    => $milestone_name });
133     
134     $vars->{'milestone'} = $milestone;
135     $vars->{'product'} = $product;
136
137     # The default milestone cannot be deleted.
138     if ($product->default_milestone eq $milestone->name) {
139         ThrowUserError("milestone_is_default", { milestone => $milestone });
140     }
141     $vars->{'token'} = issue_session_token('delete_milestone');
142
143     $template->process("admin/milestones/confirm-delete.html.tmpl", $vars)
144       || ThrowTemplateError($template->error());
145     exit;
146 }
147
148 #
149 # action='delete' -> really delete the milestone
150 #
151
152 if ($action eq 'delete') {
153     check_token_data($token, 'delete_milestone');
154     my $milestone = Bugzilla::Milestone->check({ product => $product,
155                                                  name    => $milestone_name });
156     $milestone->remove_from_db;
157     delete_token($token);
158
159     $vars->{'message'} = 'milestone_deleted';
160     $vars->{'milestone'} = $milestone;
161     $vars->{'product'} = $product;
162     $vars->{'no_edit_milestone_link'} = 1;
163
164     $template->process("admin/milestones/list.html.tmpl", $vars)
165       || ThrowTemplateError($template->error());
166     exit;
167 }
168
169 #
170 # action='edit' -> present the edit milestone form
171 #
172 # (next action would be 'update')
173 #
174
175 if ($action eq 'edit') {
176
177     my $milestone = Bugzilla::Milestone->check({ product => $product,
178                                                  name    => $milestone_name });
179
180     $vars->{'milestone'} = $milestone;
181     $vars->{'product'} = $product;
182     $vars->{'token'} = issue_session_token('edit_milestone');
183
184     $template->process("admin/milestones/edit.html.tmpl", $vars)
185       || ThrowTemplateError($template->error());
186     exit;
187 }
188
189 #
190 # action='update' -> update the milestone
191 #
192
193 if ($action eq 'update') {
194     check_token_data($token, 'edit_milestone');
195     my $milestone_old_name = trim($cgi->param('milestoneold') || '');
196     my $milestone = Bugzilla::Milestone->check({ product => $product,
197                                                  name    => $milestone_old_name });
198
199     $milestone->set_name($milestone_name);
200     $milestone->set_sortkey($sortkey);
201     $milestone->set_is_active($isactive);
202     my $changes = $milestone->update();
203     # Reloading the product since the default milestone name
204     # could have been changed.
205     $product = new Bugzilla::Product({ name => $product_name });
206
207     delete_token($token);
208
209     $vars->{'message'} = 'milestone_updated';
210     $vars->{'milestone'} = $milestone;
211     $vars->{'product'} = $product;
212     $vars->{'changes'} = $changes;
213     $template->process("admin/milestones/list.html.tmpl", $vars)
214       || ThrowTemplateError($template->error());
215     exit;
216 }
217
218 # No valid action found
219 ThrowUserError('unknown_action', {action => $action});