2017-03-21 16:27:49 +00:00
|
|
|
#!/usr/bin/perl -T
|
|
|
|
# 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/.
|
2008-02-06 20:19:16 +00:00
|
|
|
#
|
2017-03-21 16:27:49 +00:00
|
|
|
# This Source Code Form is "Incompatible With Secondary Licenses", as
|
|
|
|
# defined by the Mozilla Public License, v. 2.0.
|
2008-02-06 20:19:16 +00:00
|
|
|
|
2017-03-21 16:27:49 +00:00
|
|
|
use 5.10.1;
|
2008-02-06 20:19:16 +00:00
|
|
|
use strict;
|
2017-03-21 16:27:49 +00:00
|
|
|
use warnings;
|
|
|
|
|
2009-07-03 02:14:25 +00:00
|
|
|
use lib qw(. lib);
|
2008-02-06 20:19:16 +00:00
|
|
|
|
2009-07-03 02:13:41 +00:00
|
|
|
use Bugzilla;
|
2008-02-06 20:19:16 +00:00
|
|
|
use Bugzilla::Constants;
|
|
|
|
use Bugzilla::Util;
|
2009-07-03 02:13:41 +00:00
|
|
|
use Bugzilla::Error;
|
2008-02-06 20:19:16 +00:00
|
|
|
use Bugzilla::User;
|
2009-07-03 02:13:41 +00:00
|
|
|
use Bugzilla::Component;
|
|
|
|
use Bugzilla::Token;
|
|
|
|
|
|
|
|
my $cgi = Bugzilla->cgi;
|
|
|
|
my $template = Bugzilla->template;
|
|
|
|
my $vars = {};
|
2009-07-03 02:14:25 +00:00
|
|
|
# There is only one section about components in the documentation,
|
|
|
|
# so all actions point to the same page.
|
2017-03-21 16:27:49 +00:00
|
|
|
$vars->{'doc_section'} = 'administering/categorization.html#components';
|
2008-02-06 20:19:16 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# Preliminary checks:
|
|
|
|
#
|
|
|
|
|
|
|
|
my $user = Bugzilla->login(LOGIN_REQUIRED);
|
|
|
|
|
2009-07-03 02:13:41 +00:00
|
|
|
print $cgi->header();
|
2008-02-06 20:19:16 +00:00
|
|
|
|
2009-07-03 02:13:41 +00:00
|
|
|
$user->in_group('editcomponents')
|
|
|
|
|| scalar(@{$user->get_products_by_permission('editcomponents')})
|
2008-02-06 20:19:16 +00:00
|
|
|
|| ThrowUserError("auth_failure", {group => "editcomponents",
|
|
|
|
action => "edit",
|
|
|
|
object => "components"});
|
|
|
|
|
|
|
|
#
|
|
|
|
# often used variables
|
|
|
|
#
|
2009-07-03 02:13:41 +00:00
|
|
|
my $product_name = trim($cgi->param('product') || '');
|
|
|
|
my $comp_name = trim($cgi->param('component') || '');
|
|
|
|
my $action = trim($cgi->param('action') || '');
|
|
|
|
my $showbugcounts = (defined $cgi->param('showbugcounts'));
|
|
|
|
my $token = $cgi->param('token');
|
2008-02-06 20:19:16 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# product = '' -> Show nice list of products
|
|
|
|
#
|
|
|
|
|
2009-07-03 02:13:41 +00:00
|
|
|
unless ($product_name) {
|
|
|
|
my $selectable_products = $user->get_selectable_products;
|
|
|
|
# If the user has editcomponents privs for some products only,
|
|
|
|
# we have to restrict the list of products to display.
|
|
|
|
unless ($user->in_group('editcomponents')) {
|
|
|
|
$selectable_products = $user->get_products_by_permission('editcomponents');
|
2008-02-06 20:19:16 +00:00
|
|
|
}
|
2009-07-03 02:13:41 +00:00
|
|
|
$vars->{'products'} = $selectable_products;
|
2008-02-06 20:19:16 +00:00
|
|
|
$vars->{'showbugcounts'} = $showbugcounts;
|
|
|
|
|
2009-07-03 02:13:41 +00:00
|
|
|
$template->process("admin/components/select-product.html.tmpl", $vars)
|
|
|
|
|| ThrowTemplateError($template->error());
|
2008-02-06 20:19:16 +00:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2009-07-03 02:13:41 +00:00
|
|
|
my $product = $user->check_can_admin_product($product_name);
|
2008-02-06 20:19:16 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# action='' -> Show nice list of components
|
|
|
|
#
|
|
|
|
|
|
|
|
unless ($action) {
|
|
|
|
$vars->{'showbugcounts'} = $showbugcounts;
|
|
|
|
$vars->{'product'} = $product;
|
2009-07-03 02:13:41 +00:00
|
|
|
$template->process("admin/components/list.html.tmpl", $vars)
|
|
|
|
|| ThrowTemplateError($template->error());
|
2008-02-06 20:19:16 +00:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# action='add' -> present form for parameters for new component
|
|
|
|
#
|
|
|
|
# (next action will be 'new')
|
|
|
|
#
|
|
|
|
|
|
|
|
if ($action eq 'add') {
|
2009-07-03 02:13:41 +00:00
|
|
|
$vars->{'token'} = issue_session_token('add_component');
|
2008-02-06 20:19:16 +00:00
|
|
|
$vars->{'product'} = $product;
|
2009-07-03 02:13:41 +00:00
|
|
|
$template->process("admin/components/create.html.tmpl", $vars)
|
|
|
|
|| ThrowTemplateError($template->error());
|
2008-02-06 20:19:16 +00:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# action='new' -> add component entered in the 'action=add' screen
|
|
|
|
#
|
|
|
|
|
|
|
|
if ($action eq 'new') {
|
2009-07-03 02:13:41 +00:00
|
|
|
check_token_data($token, 'add_component');
|
|
|
|
# Do the user matching
|
2014-10-16 16:00:58 +00:00
|
|
|
Bugzilla::User::match_field ({
|
2009-07-03 02:13:41 +00:00
|
|
|
'initialowner' => { 'type' => 'single' },
|
|
|
|
'initialqacontact' => { 'type' => 'single' },
|
|
|
|
'initialcc' => { 'type' => 'multi' },
|
|
|
|
});
|
|
|
|
|
|
|
|
my $default_assignee = trim($cgi->param('initialowner') || '');
|
|
|
|
my $default_qa_contact = trim($cgi->param('initialqacontact') || '');
|
|
|
|
my $description = trim($cgi->param('description') || '');
|
|
|
|
my @initial_cc = $cgi->param('initialcc');
|
2014-10-16 16:00:58 +00:00
|
|
|
my $isactive = $cgi->param('isactive');
|
|
|
|
|
|
|
|
my $component = Bugzilla::Component->create({
|
|
|
|
name => $comp_name,
|
|
|
|
product => $product,
|
|
|
|
description => $description,
|
|
|
|
initialowner => $default_assignee,
|
|
|
|
initialqacontact => $default_qa_contact,
|
|
|
|
initial_cc => \@initial_cc,
|
|
|
|
# XXX We should not be creating series for products that we
|
|
|
|
# didn't create series for.
|
|
|
|
create_series => 1,
|
|
|
|
});
|
2009-07-03 02:14:25 +00:00
|
|
|
|
|
|
|
$vars->{'message'} = 'component_created';
|
2009-07-03 02:13:41 +00:00
|
|
|
$vars->{'comp'} = $component;
|
2008-02-06 20:19:16 +00:00
|
|
|
$vars->{'product'} = $product;
|
2009-07-03 02:13:41 +00:00
|
|
|
delete_token($token);
|
|
|
|
|
2009-07-03 02:14:25 +00:00
|
|
|
$template->process("admin/components/list.html.tmpl", $vars)
|
2008-02-06 20:19:16 +00:00
|
|
|
|| ThrowTemplateError($template->error());
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# action='del' -> ask if user really wants to delete
|
|
|
|
#
|
|
|
|
# (next action would be 'delete')
|
|
|
|
#
|
|
|
|
|
|
|
|
if ($action eq 'del') {
|
2009-07-03 02:13:41 +00:00
|
|
|
$vars->{'token'} = issue_session_token('delete_component');
|
|
|
|
$vars->{'comp'} =
|
2009-07-03 02:14:25 +00:00
|
|
|
Bugzilla::Component->check({ product => $product, name => $comp_name });
|
2008-02-06 20:19:16 +00:00
|
|
|
$vars->{'product'} = $product;
|
2009-07-03 02:13:41 +00:00
|
|
|
|
|
|
|
$template->process("admin/components/confirm-delete.html.tmpl", $vars)
|
|
|
|
|| ThrowTemplateError($template->error());
|
2008-02-06 20:19:16 +00:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# action='delete' -> really delete the component
|
|
|
|
#
|
|
|
|
|
|
|
|
if ($action eq 'delete') {
|
2009-07-03 02:13:41 +00:00
|
|
|
check_token_data($token, 'delete_component');
|
|
|
|
my $component =
|
2009-07-03 02:14:25 +00:00
|
|
|
Bugzilla::Component->check({ product => $product, name => $comp_name });
|
2008-02-06 20:19:16 +00:00
|
|
|
|
2009-07-03 02:14:25 +00:00
|
|
|
$component->remove_from_db;
|
2008-02-06 20:19:16 +00:00
|
|
|
|
2009-07-03 02:14:25 +00:00
|
|
|
$vars->{'message'} = 'component_deleted';
|
2009-07-03 02:13:41 +00:00
|
|
|
$vars->{'comp'} = $component;
|
2008-02-06 20:19:16 +00:00
|
|
|
$vars->{'product'} = $product;
|
2009-07-03 02:14:25 +00:00
|
|
|
$vars->{'no_edit_component_link'} = 1;
|
2009-07-03 02:13:41 +00:00
|
|
|
delete_token($token);
|
|
|
|
|
2009-07-03 02:14:25 +00:00
|
|
|
$template->process("admin/components/list.html.tmpl", $vars)
|
2008-02-06 20:19:16 +00:00
|
|
|
|| ThrowTemplateError($template->error());
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# action='edit' -> present the edit component form
|
|
|
|
#
|
|
|
|
# (next action would be 'update')
|
|
|
|
#
|
|
|
|
|
|
|
|
if ($action eq 'edit') {
|
2009-07-03 02:13:41 +00:00
|
|
|
$vars->{'token'} = issue_session_token('edit_component');
|
|
|
|
my $component =
|
2009-07-03 02:14:25 +00:00
|
|
|
Bugzilla::Component->check({ product => $product, name => $comp_name });
|
2009-07-03 02:13:41 +00:00
|
|
|
$vars->{'comp'} = $component;
|
2008-02-06 20:19:16 +00:00
|
|
|
|
2009-07-03 02:13:41 +00:00
|
|
|
$vars->{'initial_cc_names'} =
|
|
|
|
join(', ', map($_->login, @{$component->initial_cc}));
|
2008-02-06 20:19:16 +00:00
|
|
|
|
|
|
|
$vars->{'product'} = $product;
|
|
|
|
|
2009-07-03 02:14:25 +00:00
|
|
|
$template->process("admin/components/edit.html.tmpl", $vars)
|
2008-02-06 20:19:16 +00:00
|
|
|
|| ThrowTemplateError($template->error());
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# action='update' -> update the component
|
|
|
|
#
|
|
|
|
|
|
|
|
if ($action eq 'update') {
|
2009-07-03 02:13:41 +00:00
|
|
|
check_token_data($token, 'edit_component');
|
|
|
|
# Do the user matching
|
2014-10-16 16:00:58 +00:00
|
|
|
Bugzilla::User::match_field ({
|
2009-07-03 02:13:41 +00:00
|
|
|
'initialowner' => { 'type' => 'single' },
|
|
|
|
'initialqacontact' => { 'type' => 'single' },
|
|
|
|
'initialcc' => { 'type' => 'multi' },
|
|
|
|
});
|
|
|
|
|
|
|
|
my $comp_old_name = trim($cgi->param('componentold') || '');
|
|
|
|
my $default_assignee = trim($cgi->param('initialowner') || '');
|
|
|
|
my $default_qa_contact = trim($cgi->param('initialqacontact') || '');
|
|
|
|
my $description = trim($cgi->param('description') || '');
|
|
|
|
my @initial_cc = $cgi->param('initialcc');
|
2014-10-16 16:00:58 +00:00
|
|
|
my $isactive = $cgi->param('isactive');
|
|
|
|
|
2009-07-03 02:14:25 +00:00
|
|
|
my $component =
|
|
|
|
Bugzilla::Component->check({ product => $product, name => $comp_old_name });
|
2008-02-06 20:19:16 +00:00
|
|
|
|
2009-07-03 02:14:25 +00:00
|
|
|
$component->set_name($comp_name);
|
|
|
|
$component->set_description($description);
|
|
|
|
$component->set_default_assignee($default_assignee);
|
|
|
|
$component->set_default_qa_contact($default_qa_contact);
|
|
|
|
$component->set_cc_list(\@initial_cc);
|
2014-10-16 16:00:58 +00:00
|
|
|
$component->set_is_active($isactive);
|
2009-07-03 02:14:25 +00:00
|
|
|
my $changes = $component->update();
|
2008-02-06 20:19:16 +00:00
|
|
|
|
2009-07-03 02:14:25 +00:00
|
|
|
$vars->{'message'} = 'component_updated';
|
2009-07-03 02:13:41 +00:00
|
|
|
$vars->{'comp'} = $component;
|
2008-02-06 20:19:16 +00:00
|
|
|
$vars->{'product'} = $product;
|
2009-07-03 02:14:25 +00:00
|
|
|
$vars->{'changes'} = $changes;
|
2009-07-03 02:13:41 +00:00
|
|
|
delete_token($token);
|
|
|
|
|
2009-07-03 02:14:25 +00:00
|
|
|
$template->process("admin/components/list.html.tmpl", $vars)
|
2008-02-06 20:19:16 +00:00
|
|
|
|| ThrowTemplateError($template->error());
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
# No valid action found
|
2014-10-16 16:00:58 +00:00
|
|
|
ThrowUserError('unknown_action', {action => $action});
|