editcomponents.cgi: remove CGI usage, code style

hinted-selects
Vitaliy Filippov 2014-08-27 16:01:51 +04:00
parent 16a1c9d3f7
commit de967fa5c8
2 changed files with 113 additions and 175 deletions

View File

@ -1,6 +1,4 @@
#!/usr/bin/perl -wT #!/usr/bin/perl -wT
# -*- Mode: perl; indent-tabs-mode: nil -*-
#
# The contents of this file are subject to the Mozilla Public # The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the "License"); you may not use this file # License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of # except in compliance with the License. You may obtain a copy of
@ -34,222 +32,163 @@ use Bugzilla::User;
use Bugzilla::Component; use Bugzilla::Component;
use Bugzilla::Token; use Bugzilla::Token;
my $cgi = Bugzilla->cgi; my $ARGS = Bugzilla->input_params;
my $template = Bugzilla->template; my $template = Bugzilla->template;
my $vars = {}; my $vars = {};
# There is only one section about components in the documentation, $vars->{doc_section} = 'components.html';
# so all actions point to the same page.
$vars->{'doc_section'} = 'components.html';
my $ARGS = Bugzilla->input_params;
#
# Preliminary checks:
#
my $user = Bugzilla->login(LOGIN_REQUIRED); my $user = Bugzilla->login(LOGIN_REQUIRED);
$user->in_group('editcomponents') $user->in_group('editcomponents')
|| scalar(@{$user->get_editable_products}) || scalar(@{$user->get_editable_products})
|| ThrowUserError("auth_failure", {group => "editcomponents", || ThrowUserError('auth_failure', {
action => "edit", group => 'editcomponents',
object => "components"}); action => 'edit',
object => 'components'
#
# often used variables
#
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');
#
# product = '' -> Show nice list of products
#
unless ($product_name) {
$vars->{'products'} = $user->get_editable_products;
$vars->{'showbugcounts'} = $showbugcounts;
$template->process("admin/components/select-product.html.tmpl", $vars)
|| ThrowTemplateError($template->error());
exit;
}
my $product = $user->check_can_admin_product($product_name);
#
# action='' -> Show nice list of components
#
unless ($action) {
$vars->{'showbugcounts'} = $showbugcounts;
$vars->{'product'} = $product;
$template->process("admin/components/list.html.tmpl", $vars)
|| ThrowTemplateError($template->error());
exit;
}
#
# action='add' -> present form for parameters for new component
#
# (next action will be 'new')
#
if ($action eq 'add') {
$vars->{'token'} = issue_session_token('add_component');
$vars->{'product'} = $product;
$template->process("admin/components/edit.html.tmpl", $vars)
|| ThrowTemplateError($template->error());
exit;
}
#
# action='new' -> add component entered in the 'action=add' screen
#
if ($action eq 'new') {
check_token_data($token, 'add_component');
# Do the user matching
Bugzilla::User::match_field ({
'initialowner' => { 'type' => 'single' },
'initialqacontact' => { 'type' => 'single' },
'initialcc' => { 'type' => 'multi' },
}); });
my $default_assignee = trim($cgi->param('initialowner') || ''); my $comp_name = trim($ARGS->{component} || '');
my $default_qa_contact = trim($cgi->param('initialqacontact') || ''); my $action = trim($ARGS->{action} || '');
my $description = trim($cgi->param('description') || ''); my $showbugcounts = defined $ARGS->{showbugcounts};
my $wiki_url = trim($cgi->param('wiki_url') || ''); my $token = $ARGS->{token};
my @initial_cc = $cgi->param('initialcc');
unless ($ARGS->{product})
{
# Select product
$vars->{products} = $user->get_editable_products;
$vars->{showbugcounts} = $showbugcounts;
$template->process('admin/components/select-product.html.tmpl', $vars)
|| ThrowTemplateError($template->error());
exit;
}
# Check product admin permission
my $product = $user->check_can_admin_product($ARGS->{product});
if (!$action)
{
# Show nice list of components
$vars->{showbugcounts} = $showbugcounts;
$vars->{product} = $product;
$template->process('admin/components/list.html.tmpl', $vars)
|| ThrowTemplateError($template->error());
exit;
}
elsif ($action eq 'add')
{
# Present form for parameters for new component (next action will be 'new')
$vars->{token} = issue_session_token('add_component');
$vars->{product} = $product;
$template->process('admin/components/edit.html.tmpl', $vars)
|| ThrowTemplateError($template->error());
exit;
}
elsif ($action eq 'new')
{
# Add component entered in the 'action=add' screen
check_token_data($token, 'add_component');
# Do the user matching
Bugzilla::User::match_field({
initialowner => { 'type' => 'single' },
initialqacontact => { 'type' => 'single' },
initialcc => { 'type' => 'multi' },
});
my $component = Bugzilla::Component->create({ my $component = Bugzilla::Component->create({
name => $comp_name, name => $comp_name,
product => $product, product => $product,
description => $description, description => $ARGS->{description},
initialowner => $default_assignee, initialowner => trim($ARGS->{initialowner} || ''),
initialqacontact => $default_qa_contact, initialqacontact => trim($ARGS->{initialqacontact} || ''),
wiki_url => $wiki_url, wiki_url => $ARGS->{wiki_url},
initial_cc => \@initial_cc, initial_cc => [ list $ARGS->{initialcc} ],
isactive => scalar $cgi->param('is_active'), isactive => $ARGS->{isactive},
# XXX We should not be creating series for products that we # XXX We should not be creating series for products that we
# didn't create series for. # didn't create series for.
create_series => 1, create_series => 1,
}); });
$vars->{'message'} = 'component_created'; $vars->{message} = 'component_created';
$vars->{'comp'} = $component; $vars->{comp} = $component;
$vars->{'product'} = $product; $vars->{product} = $product;
delete_token($token); delete_token($token);
$template->process("admin/components/list.html.tmpl", $vars) $template->process('admin/components/list.html.tmpl', $vars)
|| ThrowTemplateError($template->error()); || ThrowTemplateError($template->error());
exit; exit;
} }
elsif ($action eq 'del')
{
# Ask if user really wants to delete (next action would be 'delete')
$vars->{token} = issue_session_token('delete_component');
$vars->{comp} = Bugzilla::Component->check({ product => $product, name => $comp_name });
$vars->{product} = $product;
# $template->process('admin/components/confirm-delete.html.tmpl', $vars)
# action='del' -> ask if user really wants to delete
#
# (next action would be 'delete')
#
if ($action eq 'del') {
$vars->{'token'} = issue_session_token('delete_component');
$vars->{'comp'} =
Bugzilla::Component->check({ product => $product, name => $comp_name });
$vars->{'product'} = $product;
$template->process("admin/components/confirm-delete.html.tmpl", $vars)
|| ThrowTemplateError($template->error()); || ThrowTemplateError($template->error());
exit; exit;
} }
elsif ($action eq 'delete')
# {
# action='delete' -> really delete the component # Really delete the component
#
if ($action eq 'delete') {
check_token_data($token, 'delete_component'); check_token_data($token, 'delete_component');
my $component = my $component = Bugzilla::Component->check({ product => $product, name => $comp_name });
Bugzilla::Component->check({ product => $product, name => $comp_name });
$component->remove_from_db; $component->remove_from_db;
$vars->{'message'} = 'component_deleted'; $vars->{message} = 'component_deleted';
$vars->{'comp'} = $component; $vars->{comp} = $component;
$vars->{'product'} = $product; $vars->{product} = $product;
$vars->{'no_edit_component_link'} = 1; $vars->{no_edit_component_link} = 1;
delete_token($token); delete_token($token);
$template->process("admin/components/list.html.tmpl", $vars) $template->process('admin/components/list.html.tmpl', $vars)
|| ThrowTemplateError($template->error()); || ThrowTemplateError($template->error());
exit; exit;
} }
elsif ($action eq 'edit')
# {
# action='edit' -> present the edit component form # Present the edit component form (next action would be 'update')
# $vars->{token} = issue_session_token('edit_component');
# (next action would be 'update') my $component = Bugzilla::Component->check({ product => $product, name => $comp_name });
# $vars->{comp} = $component;
$vars->{initial_cc_names} = join(', ', map($_->login, @{$component->initial_cc}));
if ($action eq 'edit') { $vars->{product} = $product;
$vars->{'token'} = issue_session_token('edit_component'); $template->process('admin/components/edit.html.tmpl', $vars)
my $component = || ThrowTemplateError($template->error());
Bugzilla::Component->check({ product => $product, name => $comp_name });
$vars->{'comp'} = $component;
$vars->{'initial_cc_names'} =
join(', ', map($_->login, @{$component->initial_cc}));
$vars->{'product'} = $product;
$template->process("admin/components/edit.html.tmpl", $vars)
|| ThrowTemplateError($template->error());
exit; exit;
} }
elsif ($action eq 'update')
# {
# action='update' -> update the component # Update the component
#
if ($action eq 'update') {
check_token_data($token, 'edit_component'); check_token_data($token, 'edit_component');
# Do the user matching # Do the user matching
Bugzilla::User::match_field ({ Bugzilla::User::match_field({
'initialowner' => { 'type' => 'single' }, initialowner => { 'type' => 'single' },
'initialqacontact' => { 'type' => 'single' }, initialqacontact => { 'type' => 'single' },
'initialcc' => { 'type' => 'multi' }, initialcc => { 'type' => 'multi' },
}); });
my $comp_old_name = trim($cgi->param('componentold') || ''); my $component = Bugzilla::Component->check({ product => $product, name => $ARGS->{componentold} });
my $default_assignee = trim($cgi->param('initialowner') || '');
my $default_qa_contact = trim($cgi->param('initialqacontact') || '');
my $description = trim($cgi->param('description') || '');
my $wiki_url = trim($cgi->param('wiki_url') || '');
my @initial_cc = $cgi->param('initialcc');
my $component =
Bugzilla::Component->check({ product => $product, name => $comp_old_name });
$component->set_name($comp_name); $component->set_name($comp_name);
$component->set_description($description); $component->set_description($ARGS->{description});
$component->set_default_assignee($default_assignee); $component->set_default_assignee($ARGS->{initialowner});
$component->set_default_qa_contact($default_qa_contact); $component->set_default_qa_contact($ARGS->{initialqacontact});
$component->set_wiki_url($wiki_url); $component->set_wiki_url($ARGS->{wiki_url});
$component->set_cc_list(\@initial_cc); $component->set_cc_list([ list $ARGS->{initialcc} ]);
$component->set_is_active(scalar $cgi->param('is_active')); $component->set_is_active($ARGS->{isactive});
my $changes = $component->update(); my $changes = $component->update();
$changes->{control_lists} = 1 if $component->field->update_control_lists($component->id, $ARGS); $changes->{control_lists} = 1 if $component->field->update_control_lists($component->id, $ARGS);
$vars->{'message'} = 'component_updated'; $vars->{message} = 'component_updated';
$vars->{'comp'} = $component; $vars->{comp} = $component;
$vars->{'product'} = $product; $vars->{product} = $product;
$vars->{'changes'} = $changes; $vars->{changes} = $changes;
delete_token($token); delete_token($token);
$template->process("admin/components/list.html.tmpl", $vars) $template->process('admin/components/list.html.tmpl', $vars)
|| ThrowTemplateError($template->error()); || ThrowTemplateError($template->error());
exit; exit;
} }
@ -257,4 +196,4 @@ if ($action eq 'update') {
# #
# No valid action found # No valid action found
# #
ThrowUserError('no_valid_action', {'field' => "component"}); ThrowUserError('no_valid_action', { field => 'component' });

View File

@ -102,8 +102,7 @@
</tr> </tr>
<tr> <tr>
<th align="left">Open for [% terms.bug %] entry:</th> <th align="left">Open for [% terms.bug %] entry:</th>
<td><input type="checkbox" name="is_active" value="1" <td><input type="checkbox" name="isactive" value="1" [% ' checked="checked"' IF comp.isactive OR !comp.id %] />
[% ' checked="checked"' IF comp.isactive OR !comp.id %]>
</td> </td>
</tr> </tr>
<tr> <tr>