RSS

(root)/bugzilla/4.2 : /editcomponents.cgi (revision 8010)

To get this branch, use:
bzr branch /bugzilla/4.2
Line Revision Contents
1 2616
#!/usr/bin/perl -wT
2 193
# -*- Mode: perl; indent-tabs-mode: nil -*-
3
#
4 371
# 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 mozilla.org code.
15
#
16
# The Initial Developer of the Original Code is Holger
17
# Schurig. Portions created by Holger Schurig are
18
# Copyright (C) 1999 Holger Schurig. All
19
# Rights Reserved.
20
#
21
# Contributor(s): Holger Schurig <holgerschurig@nikocity.de>
22 1265
#                 Terry Weissman <terry@mozilla.org>
23 3859
#                 Frédéric Buclin <LpSolit@gmail.com>
24 4567
#                 Akamai Technologies <bugzilla-dev@akamai.com>
25 193
26
use strict;
27 5304
use lib qw(. lib);
28 193
29 3966
use Bugzilla;
30 2537
use Bugzilla::Constants;
31 2770
use Bugzilla::Util;
32 4296
use Bugzilla::Error;
33 3138
use Bugzilla::User;
34 3668
use Bugzilla::Component;
35 4612
use Bugzilla::Token;
36 2188
37 2659
my $cgi = Bugzilla->cgi;
38 3762
my $template = Bugzilla->template;
39
my $vars = {};
40 5311
# There is only one section about components in the documentation,
41
# so all actions point to the same page.
42
$vars->{'doc_section'} = 'components.html';
43 353
44
#
45
# Preliminary checks:
46
#
47 193
48 3308
my $user = Bugzilla->login(LOGIN_REQUIRED);
49 193
50 3668
print $cgi->header();
51 193
52 3684
$user->in_group('editcomponents')
53 4674
  || scalar(@{$user->get_products_by_permission('editcomponents')})
54 3001
  || ThrowUserError("auth_failure", {group  => "editcomponents",
55
                                     action => "edit",
56
                                     object => "components"});
57 353
58
#
59
# often used variables
60
#
61 3668
my $product_name  = trim($cgi->param('product')     || '');
62
my $comp_name     = trim($cgi->param('component')   || '');
63
my $action        = trim($cgi->param('action')      || '');
64
my $showbugcounts = (defined $cgi->param('showbugcounts'));
65 4612
my $token         = $cgi->param('token');
66 353
67
#
68
# product = '' -> Show nice list of products
69
#
70
71 3668
unless ($product_name) {
72 4674
    my $selectable_products = $user->get_selectable_products;
73
    # If the user has editcomponents privs for some products only,
74
    # we have to restrict the list of products to display.
75
    unless ($user->in_group('editcomponents')) {
76
        $selectable_products = $user->get_products_by_permission('editcomponents');
77
    }
78
    $vars->{'products'} = $selectable_products;
79 2739
    $vars->{'showbugcounts'} = $showbugcounts;
80 3859
81
    $template->process("admin/components/select-product.html.tmpl", $vars)
82 2739
      || ThrowTemplateError($template->error());
83 353
    exit;
84
}
85
86 4674
my $product = $user->check_can_admin_product($product_name);
87 3859
88 353
#
89
# action='' -> Show nice list of components
90
#
91
92
unless ($action) {
93 2739
    $vars->{'showbugcounts'} = $showbugcounts;
94 4040
    $vars->{'product'} = $product;
95 3668
    $template->process("admin/components/list.html.tmpl", $vars)
96
        || ThrowTemplateError($template->error());
97 353
    exit;
98
}
99
100
#
101
# action='add' -> present form for parameters for new component
102
#
103
# (next action will be 'new')
104
#
105
106
if ($action eq 'add') {
107 4612
    $vars->{'token'} = issue_session_token('add_component');
108 4040
    $vars->{'product'} = $product;
109 3668
    $template->process("admin/components/create.html.tmpl", $vars)
110
        || ThrowTemplateError($template->error());
111 353
    exit;
112
}
113
114
#
115
# action='new' -> add component entered in the 'action=add' screen
116
#
117
118
if ($action eq 'new') {
119 4612
    check_token_data($token, 'add_component');
120 3668
    # Do the user matching
121 6943
    Bugzilla::User::match_field ({
122 3668
        'initialowner'     => { 'type' => 'single' },
123
        'initialqacontact' => { 'type' => 'single' },
124 4567
        'initialcc'        => { 'type' => 'multi'  },
125 3668
    });
126
127
    my $default_assignee   = trim($cgi->param('initialowner')     || '');
128
    my $default_qa_contact = trim($cgi->param('initialqacontact') || '');
129
    my $description        = trim($cgi->param('description')      || '');
130 4567
    my @initial_cc         = $cgi->param('initialcc');
131 7456
    my $isactive           = $cgi->param('isactive');
132 3668
133 6559
    my $component = Bugzilla::Component->create({
134
        name             => $comp_name,
135
        product          => $product,
136
        description      => $description,
137
        initialowner     => $default_assignee,
138
        initialqacontact => $default_qa_contact,
139
        initial_cc       => \@initial_cc,
140
        # XXX We should not be creating series for products that we
141
        # didn't create series for.
142
        create_series    => 1,
143
   });
144 2188
145 5441
    $vars->{'message'} = 'component_created';
146 4040
    $vars->{'comp'} = $component;
147
    $vars->{'product'} = $product;
148 4612
    delete_token($token);
149
150 5441
    $template->process("admin/components/list.html.tmpl", $vars)
151 2739
      || ThrowTemplateError($template->error());
152 353
    exit;
153
}
154
155
#
156
# action='del' -> ask if user really wants to delete
157
#
158
# (next action would be 'delete')
159
#
160
161
if ($action eq 'del') {
162 4612
    $vars->{'token'} = issue_session_token('delete_component');
163 3668
    $vars->{'comp'} =
164 5296
      Bugzilla::Component->check({ product => $product, name => $comp_name });
165 4040
    $vars->{'product'} = $product;
166 3668
167
    $template->process("admin/components/confirm-delete.html.tmpl", $vars)
168
        || ThrowTemplateError($template->error());
169 353
    exit;
170
}
171
172
#
173
# action='delete' -> really delete the component
174
#
175
176
if ($action eq 'delete') {
177 4612
    check_token_data($token, 'delete_component');
178 3668
    my $component =
179 5296
        Bugzilla::Component->check({ product => $product, name => $comp_name });
180
181
    $component->remove_from_db;
182 353
183 5441
    $vars->{'message'} = 'component_deleted';
184 4040
    $vars->{'comp'} = $component;
185
    $vars->{'product'} = $product;
186 5441
    $vars->{'no_edit_component_link'} = 1;
187 4612
    delete_token($token);
188
189 5441
    $template->process("admin/components/list.html.tmpl", $vars)
190 2739
      || ThrowTemplateError($template->error());
191 353
    exit;
192
}
193
194
#
195
# action='edit' -> present the edit component form
196
#
197
# (next action would be 'update')
198
#
199
200
if ($action eq 'edit') {
201 4612
    $vars->{'token'} = issue_session_token('edit_component');
202 4567
    my $component =
203 5296
        Bugzilla::Component->check({ product => $product, name => $comp_name });
204 4567
    $vars->{'comp'} = $component;
205
206
    $vars->{'initial_cc_names'} = 
207
        join(', ', map($_->login, @{$component->initial_cc}));
208 3668
209 4040
    $vars->{'product'} = $product;
210 2739
211 5296
    $template->process("admin/components/edit.html.tmpl", $vars)
212 2739
      || ThrowTemplateError($template->error());
213 353
    exit;
214
}
215
216
#
217
# action='update' -> update the component
218
#
219
220
if ($action eq 'update') {
221 4612
    check_token_data($token, 'edit_component');
222 3622
    # Do the user matching
223 6943
    Bugzilla::User::match_field ({
224 3622
        'initialowner'     => { 'type' => 'single' },
225
        'initialqacontact' => { 'type' => 'single' },
226 4567
        'initialcc'        => { 'type' => 'multi'  },
227 3622
    });
228
229 3668
    my $comp_old_name         = trim($cgi->param('componentold')     || '');
230
    my $default_assignee      = trim($cgi->param('initialowner')     || '');
231
    my $default_qa_contact    = trim($cgi->param('initialqacontact') || '');
232
    my $description           = trim($cgi->param('description')      || '');
233 4567
    my @initial_cc            = $cgi->param('initialcc');
234 7456
    my $isactive              = $cgi->param('isactive');
235
  
236 5296
    my $component =
237
        Bugzilla::Component->check({ product => $product, name => $comp_old_name });
238
239
    $component->set_name($comp_name);
240
    $component->set_description($description);
241
    $component->set_default_assignee($default_assignee);
242
    $component->set_default_qa_contact($default_qa_contact);
243
    $component->set_cc_list(\@initial_cc);
244 7456
    $component->set_is_active($isactive);
245 5296
    my $changes = $component->update();
246
247 5441
    $vars->{'message'} = 'component_updated';
248 4040
    $vars->{'comp'} = $component;
249
    $vars->{'product'} = $product;
250 5296
    $vars->{'changes'} = $changes;
251 4612
    delete_token($token);
252
253 5441
    $template->process("admin/components/list.html.tmpl", $vars)
254 2739
      || ThrowTemplateError($template->error());
255 353
    exit;
256
}
257
258
# No valid action found
259 7188
ThrowUserError('unknown_action', {action => $action});

Loggerhead 1.18.1 is a web-based interface for Bazaar branches