2004-08-21 01:49:20 +04:00
|
|
|
#!/usr/bin/perl -wT
|
|
|
|
# -*- Mode: perl; indent-tabs-mode: nil; cperl-indent-level: 4 -*-
|
|
|
|
#
|
|
|
|
# The contents of this file are subject to the Mozilla Public
|
|
|
|
# License Version 1.1 (the "License"); you may not use this file
|
|
|
|
# except in compliance with the License. You may obtain a copy of
|
|
|
|
# the License at http://www.mozilla.org/MPL/
|
|
|
|
#
|
|
|
|
# Software distributed under the License is distributed on an "AS
|
|
|
|
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
# implied. See the License for the specific language governing
|
|
|
|
# rights and limitations under the License.
|
|
|
|
#
|
|
|
|
# The Original Code is the Bugzilla Bug Tracking System.
|
|
|
|
#
|
|
|
|
# The Initial Developer of the Original Code is Albert Ting
|
|
|
|
#
|
|
|
|
# Contributor(s): Albert Ting <alt@sonic.net>
|
2005-06-15 07:55:00 +04:00
|
|
|
# Max Kanat-Alexander <mkanat@bugzilla.org>
|
2008-01-28 02:14:26 +03:00
|
|
|
# Frédéric Buclin <LpSolit@gmail.com>
|
|
|
|
|
2004-08-21 01:49:20 +04:00
|
|
|
|
|
|
|
use strict;
|
2007-10-19 10:46:19 +04:00
|
|
|
use lib qw(. lib);
|
2004-08-21 01:49:20 +04:00
|
|
|
|
|
|
|
use Bugzilla;
|
|
|
|
use Bugzilla::Constants;
|
2005-02-20 13:14:14 +03:00
|
|
|
use Bugzilla::Util;
|
|
|
|
use Bugzilla::Error;
|
2005-07-29 18:14:42 +04:00
|
|
|
use Bugzilla::Classification;
|
2006-10-15 02:02:13 +04:00
|
|
|
use Bugzilla::Token;
|
2004-08-21 01:49:20 +04:00
|
|
|
|
|
|
|
my $dbh = Bugzilla->dbh;
|
2006-07-06 10:12:05 +04:00
|
|
|
my $cgi = Bugzilla->cgi;
|
2005-02-20 13:14:14 +03:00
|
|
|
my $template = Bugzilla->template;
|
2006-07-06 10:12:05 +04:00
|
|
|
local our $vars = {};
|
2004-08-21 01:49:20 +04:00
|
|
|
|
2005-08-13 16:27:04 +04:00
|
|
|
sub LoadTemplate {
|
2004-08-21 01:49:20 +04:00
|
|
|
my $action = shift;
|
2006-07-06 10:12:05 +04:00
|
|
|
my $cgi = Bugzilla->cgi;
|
|
|
|
my $template = Bugzilla->template;
|
2008-01-28 02:14:26 +03:00
|
|
|
|
|
|
|
$vars->{'classifications'} = [Bugzilla::Classification::get_all_classifications()]
|
|
|
|
if ($action eq 'select');
|
2007-10-23 01:42:01 +04:00
|
|
|
# There is currently only one section about classifications,
|
|
|
|
# so all pages point to it. Let's define it here.
|
|
|
|
$vars->{'doc_section'} = 'classifications.html';
|
2004-08-21 01:49:20 +04:00
|
|
|
|
|
|
|
$action =~ /(\w+)/;
|
|
|
|
$action = $1;
|
|
|
|
print $cgi->header();
|
|
|
|
$template->process("admin/classifications/$action.html.tmpl", $vars)
|
|
|
|
|| ThrowTemplateError($template->error());
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Preliminary checks:
|
|
|
|
#
|
|
|
|
|
|
|
|
Bugzilla->login(LOGIN_REQUIRED);
|
|
|
|
|
|
|
|
print $cgi->header();
|
|
|
|
|
2005-02-20 13:14:14 +03:00
|
|
|
exists Bugzilla->user->groups->{'editclassifications'}
|
2005-01-16 17:07:31 +03:00
|
|
|
|| ThrowUserError("auth_failure", {group => "editclassifications",
|
|
|
|
action => "edit",
|
|
|
|
object => "classifications"});
|
|
|
|
|
2006-07-04 01:26:22 +04:00
|
|
|
ThrowUserError("auth_classification_not_enabled")
|
|
|
|
unless Bugzilla->params->{"useclassification"};
|
2004-08-21 01:49:20 +04:00
|
|
|
|
|
|
|
#
|
|
|
|
# often used variables
|
|
|
|
#
|
2005-07-29 18:14:42 +04:00
|
|
|
my $action = trim($cgi->param('action') || '');
|
|
|
|
my $class_name = trim($cgi->param('classification') || '');
|
2006-10-15 02:02:13 +04:00
|
|
|
my $token = $cgi->param('token');
|
|
|
|
|
2004-08-21 01:49:20 +04:00
|
|
|
#
|
|
|
|
# action='' -> Show nice list of classifications
|
|
|
|
#
|
2008-01-28 02:14:26 +03:00
|
|
|
LoadTemplate('select') unless $action;
|
2004-08-21 01:49:20 +04:00
|
|
|
|
|
|
|
#
|
|
|
|
# action='add' -> present form for parameters for new classification
|
|
|
|
#
|
|
|
|
# (next action will be 'new')
|
|
|
|
#
|
|
|
|
|
|
|
|
if ($action eq 'add') {
|
2006-10-15 02:02:13 +04:00
|
|
|
$vars->{'token'} = issue_session_token('add_classification');
|
2004-08-21 01:49:20 +04:00
|
|
|
LoadTemplate($action);
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# action='new' -> add classification entered in the 'action=add' screen
|
|
|
|
#
|
|
|
|
|
|
|
|
if ($action eq 'new') {
|
2006-10-15 02:02:13 +04:00
|
|
|
check_token_data($token, 'add_classification');
|
2005-07-29 18:14:42 +04:00
|
|
|
|
|
|
|
$class_name || ThrowUserError("classification_not_specified");
|
|
|
|
|
|
|
|
my $classification =
|
|
|
|
new Bugzilla::Classification({name => $class_name});
|
|
|
|
|
|
|
|
if ($classification) {
|
|
|
|
ThrowUserError("classification_already_exists",
|
|
|
|
{ name => $classification->name });
|
2004-08-21 01:49:20 +04:00
|
|
|
}
|
2006-08-06 03:32:36 +04:00
|
|
|
|
2004-08-21 01:49:20 +04:00
|
|
|
my $description = trim($cgi->param('description') || '');
|
2006-08-06 03:32:36 +04:00
|
|
|
|
2006-07-17 03:23:33 +04:00
|
|
|
my $sortkey = trim($cgi->param('sortkey') || 0);
|
2006-08-06 03:32:36 +04:00
|
|
|
my $stored_sortkey = $sortkey;
|
|
|
|
detaint_natural($sortkey)
|
|
|
|
|| ThrowUserError('classification_invalid_sortkey', {'name' => $class_name,
|
|
|
|
'sortkey' => $stored_sortkey});
|
2006-07-17 03:23:33 +04:00
|
|
|
|
2004-08-21 01:49:20 +04:00
|
|
|
trick_taint($description);
|
2005-07-29 18:14:42 +04:00
|
|
|
trick_taint($class_name);
|
2004-08-21 01:49:20 +04:00
|
|
|
|
|
|
|
# Add the new classification.
|
2006-07-17 03:23:33 +04:00
|
|
|
$dbh->do("INSERT INTO classifications (name, description, sortkey)
|
|
|
|
VALUES (?, ?, ?)", undef, ($class_name, $description, $sortkey));
|
2004-08-21 01:49:20 +04:00
|
|
|
|
2006-10-15 02:02:13 +04:00
|
|
|
delete_token($token);
|
2008-01-28 02:14:26 +03:00
|
|
|
|
|
|
|
$vars->{'message'} = 'classification_created';
|
|
|
|
$vars->{'classification'} = new Bugzilla::Classification({name => $class_name});
|
|
|
|
$vars->{'classifications'} = [Bugzilla::Classification::get_all_classifications];
|
|
|
|
$vars->{'token'} = issue_session_token('reclassify_classifications');
|
|
|
|
LoadTemplate('reclassify');
|
2004-08-21 01:49:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# action='del' -> ask if user really wants to delete
|
|
|
|
#
|
|
|
|
# (next action would be 'delete')
|
|
|
|
#
|
|
|
|
|
|
|
|
if ($action eq 'del') {
|
|
|
|
|
2005-07-29 18:14:42 +04:00
|
|
|
my $classification =
|
|
|
|
Bugzilla::Classification::check_classification($class_name);
|
2004-08-21 01:49:20 +04:00
|
|
|
|
2005-07-29 18:14:42 +04:00
|
|
|
if ($classification->id == 1) {
|
|
|
|
ThrowUserError("classification_not_deletable");
|
|
|
|
}
|
2004-08-21 01:49:20 +04:00
|
|
|
|
2005-07-29 18:14:42 +04:00
|
|
|
if ($classification->product_count()) {
|
|
|
|
ThrowUserError("classification_has_products");
|
|
|
|
}
|
2004-08-21 01:49:20 +04:00
|
|
|
|
2005-10-14 03:42:43 +04:00
|
|
|
$vars->{'classification'} = $classification;
|
2006-10-15 02:02:13 +04:00
|
|
|
$vars->{'token'} = issue_session_token('delete_classification');
|
2004-08-21 01:49:20 +04:00
|
|
|
|
|
|
|
LoadTemplate($action);
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# action='delete' -> really delete the classification
|
|
|
|
#
|
|
|
|
|
|
|
|
if ($action eq 'delete') {
|
2006-10-15 02:02:13 +04:00
|
|
|
check_token_data($token, 'delete_classification');
|
2004-08-21 01:49:20 +04:00
|
|
|
|
2005-07-29 18:14:42 +04:00
|
|
|
my $classification =
|
|
|
|
Bugzilla::Classification::check_classification($class_name);
|
2004-08-21 01:49:20 +04:00
|
|
|
|
2005-07-29 18:14:42 +04:00
|
|
|
if ($classification->id == 1) {
|
|
|
|
ThrowUserError("classification_not_deletable");
|
2004-08-21 01:49:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
# lock the tables before we start to change everything:
|
2007-10-10 03:21:49 +04:00
|
|
|
$dbh->bz_start_transaction();
|
2004-08-21 01:49:20 +04:00
|
|
|
|
|
|
|
# update products just in case
|
2005-07-29 18:14:42 +04:00
|
|
|
$dbh->do("UPDATE products SET classification_id = 1
|
|
|
|
WHERE classification_id = ?", undef, $classification->id);
|
2004-08-21 01:49:20 +04:00
|
|
|
|
2008-01-28 02:14:26 +03:00
|
|
|
# delete
|
|
|
|
$dbh->do("DELETE FROM classifications WHERE id = ?", undef,
|
|
|
|
$classification->id);
|
2004-08-21 01:49:20 +04:00
|
|
|
|
2008-01-28 02:14:26 +03:00
|
|
|
$dbh->bz_commit_transaction();
|
2005-07-29 18:14:42 +04:00
|
|
|
|
2008-01-28 02:14:26 +03:00
|
|
|
$vars->{'message'} = 'classification_deleted';
|
|
|
|
$vars->{'classification'} = $class_name;
|
2006-10-15 02:02:13 +04:00
|
|
|
delete_token($token);
|
2008-01-28 02:14:26 +03:00
|
|
|
LoadTemplate('select');
|
2004-08-21 01:49:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# action='edit' -> present the edit classifications from
|
|
|
|
#
|
|
|
|
# (next action would be 'update')
|
|
|
|
#
|
|
|
|
|
|
|
|
if ($action eq 'edit') {
|
|
|
|
|
2005-07-29 18:14:42 +04:00
|
|
|
my $classification =
|
|
|
|
Bugzilla::Classification::check_classification($class_name);
|
2004-08-21 01:49:20 +04:00
|
|
|
|
2005-10-14 03:42:43 +04:00
|
|
|
$vars->{'classification'} = $classification;
|
2006-10-15 02:02:13 +04:00
|
|
|
$vars->{'token'} = issue_session_token('edit_classification');
|
2004-08-21 01:49:20 +04:00
|
|
|
|
|
|
|
LoadTemplate($action);
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# action='update' -> update the classification
|
|
|
|
#
|
|
|
|
|
|
|
|
if ($action eq 'update') {
|
2006-10-15 02:02:13 +04:00
|
|
|
check_token_data($token, 'edit_classification');
|
2004-08-21 01:49:20 +04:00
|
|
|
|
2005-07-29 18:14:42 +04:00
|
|
|
$class_name || ThrowUserError("classification_not_specified");
|
2004-08-21 01:49:20 +04:00
|
|
|
|
2005-07-29 18:14:42 +04:00
|
|
|
my $class_old_name = trim($cgi->param('classificationold') || '');
|
2004-08-21 01:49:20 +04:00
|
|
|
|
2005-07-29 18:14:42 +04:00
|
|
|
my $class_old =
|
|
|
|
Bugzilla::Classification::check_classification($class_old_name);
|
2004-08-21 01:49:20 +04:00
|
|
|
|
2006-08-06 03:32:36 +04:00
|
|
|
my $description = trim($cgi->param('description') || '');
|
|
|
|
|
|
|
|
my $sortkey = trim($cgi->param('sortkey') || 0);
|
|
|
|
my $stored_sortkey = $sortkey;
|
|
|
|
detaint_natural($sortkey)
|
|
|
|
|| ThrowUserError('classification_invalid_sortkey', {'name' => $class_old->name,
|
|
|
|
'sortkey' => $stored_sortkey});
|
|
|
|
|
2007-10-10 03:21:49 +04:00
|
|
|
$dbh->bz_start_transaction();
|
2004-08-21 01:49:20 +04:00
|
|
|
|
2005-07-29 18:14:42 +04:00
|
|
|
if ($class_name ne $class_old->name) {
|
|
|
|
|
|
|
|
my $class = new Bugzilla::Classification({name => $class_name});
|
|
|
|
if ($class) {
|
|
|
|
ThrowUserError("classification_already_exists",
|
|
|
|
{ name => $class->name });
|
2004-08-21 01:49:20 +04:00
|
|
|
}
|
2005-07-29 18:14:42 +04:00
|
|
|
trick_taint($class_name);
|
|
|
|
$dbh->do("UPDATE classifications SET name = ? WHERE id = ?",
|
|
|
|
undef, ($class_name, $class_old->id));
|
2005-07-19 18:52:59 +04:00
|
|
|
|
2006-06-20 00:15:18 +04:00
|
|
|
$vars->{'updated_classification'} = 1;
|
2004-08-21 01:49:20 +04:00
|
|
|
}
|
2005-03-16 02:56:18 +03:00
|
|
|
|
2005-07-29 18:14:42 +04:00
|
|
|
if ($description ne $class_old->description) {
|
|
|
|
trick_taint($description);
|
|
|
|
$dbh->do("UPDATE classifications SET description = ?
|
|
|
|
WHERE id = ?", undef,
|
|
|
|
($description, $class_old->id));
|
|
|
|
|
2005-03-16 02:56:18 +03:00
|
|
|
$vars->{'updated_description'} = 1;
|
|
|
|
}
|
|
|
|
|
2006-07-17 03:23:33 +04:00
|
|
|
if ($sortkey ne $class_old->sortkey) {
|
|
|
|
$dbh->do("UPDATE classifications SET sortkey = ?
|
|
|
|
WHERE id = ?", undef,
|
|
|
|
($sortkey, $class_old->id));
|
|
|
|
|
|
|
|
$vars->{'updated_sortkey'} = 1;
|
|
|
|
}
|
|
|
|
|
2007-10-10 03:21:49 +04:00
|
|
|
$dbh->bz_commit_transaction();
|
2004-08-21 01:49:20 +04:00
|
|
|
|
2008-01-28 02:14:26 +03:00
|
|
|
$vars->{'message'} = 'classification_updated';
|
|
|
|
$vars->{'classification'} = $class_name;
|
2006-10-15 02:02:13 +04:00
|
|
|
delete_token($token);
|
2008-01-28 02:14:26 +03:00
|
|
|
LoadTemplate('select');
|
2004-08-21 01:49:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# action='reclassify' -> reclassify products for the classification
|
|
|
|
#
|
|
|
|
|
|
|
|
if ($action eq 'reclassify') {
|
|
|
|
|
2005-07-29 18:14:42 +04:00
|
|
|
my $classification =
|
|
|
|
Bugzilla::Classification::check_classification($class_name);
|
|
|
|
|
|
|
|
my $sth = $dbh->prepare("UPDATE products SET classification_id = ?
|
|
|
|
WHERE name = ?");
|
2004-08-21 01:49:20 +04:00
|
|
|
|
|
|
|
if (defined $cgi->param('add_products')) {
|
2006-10-15 02:02:13 +04:00
|
|
|
check_token_data($token, 'reclassify_classifications');
|
2004-08-21 01:49:20 +04:00
|
|
|
if (defined $cgi->param('prodlist')) {
|
|
|
|
foreach my $prod ($cgi->param("prodlist")) {
|
|
|
|
trick_taint($prod);
|
2005-07-29 18:14:42 +04:00
|
|
|
$sth->execute($classification->id, $prod);
|
2004-08-21 01:49:20 +04:00
|
|
|
}
|
|
|
|
}
|
2006-10-15 02:02:13 +04:00
|
|
|
delete_token($token);
|
2004-08-21 01:49:20 +04:00
|
|
|
} elsif (defined $cgi->param('remove_products')) {
|
2006-10-15 02:02:13 +04:00
|
|
|
check_token_data($token, 'reclassify_classifications');
|
2004-08-21 01:49:20 +04:00
|
|
|
if (defined $cgi->param('myprodlist')) {
|
|
|
|
foreach my $prod ($cgi->param("myprodlist")) {
|
|
|
|
trick_taint($prod);
|
|
|
|
$sth->execute(1,$prod);
|
|
|
|
}
|
|
|
|
}
|
2006-10-15 02:02:13 +04:00
|
|
|
delete_token($token);
|
2004-08-21 01:49:20 +04:00
|
|
|
}
|
|
|
|
|
2005-10-14 03:42:43 +04:00
|
|
|
my @classifications =
|
|
|
|
Bugzilla::Classification::get_all_classifications;
|
|
|
|
$vars->{'classifications'} = \@classifications;
|
|
|
|
$vars->{'classification'} = $classification;
|
2006-10-15 02:02:13 +04:00
|
|
|
$vars->{'token'} = issue_session_token('reclassify_classifications');
|
2004-08-21 01:49:20 +04:00
|
|
|
|
|
|
|
LoadTemplate($action);
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# No valid action found
|
|
|
|
#
|
|
|
|
|
2005-07-29 18:14:42 +04:00
|
|
|
ThrowCodeError("action_unrecognized", {action => $action});
|