2003-03-27 03:07:02 +03:00
|
|
|
#!/usr/bin/perl -wT
|
2002-09-28 22:42:54 +04:00
|
|
|
# -*- Mode: perl; indent-tabs-mode: nil -*-
|
|
|
|
#
|
|
|
|
# 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 Netscape Communications
|
|
|
|
# Corporation. Portions created by Netscape are
|
|
|
|
# Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
# Rights Reserved.
|
|
|
|
#
|
|
|
|
# Contributor(s): Myk Melez <myk@mozilla.org>
|
2006-05-29 21:24:54 +04:00
|
|
|
# Frédéric Buclin <LpSolit@gmail.com>
|
2002-09-28 22:42:54 +04:00
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# Script Initialization
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
# Make it harder for us to do dangerous things in Perl.
|
|
|
|
use strict;
|
|
|
|
use lib ".";
|
|
|
|
|
|
|
|
# Use Bugzilla's flag modules for handling flag types.
|
2003-05-05 05:15:38 +04:00
|
|
|
use Bugzilla;
|
2004-03-27 06:51:44 +03:00
|
|
|
use Bugzilla::Constants;
|
2002-09-28 22:42:54 +04:00
|
|
|
use Bugzilla::Flag;
|
|
|
|
use Bugzilla::FlagType;
|
2005-08-30 20:47:33 +04:00
|
|
|
use Bugzilla::Group;
|
2005-07-21 01:24:19 +04:00
|
|
|
use Bugzilla::Util;
|
2006-06-21 04:44:48 +04:00
|
|
|
use Bugzilla::Error;
|
2006-03-16 00:51:35 +03:00
|
|
|
use Bugzilla::Product;
|
2006-05-29 21:24:54 +04:00
|
|
|
use Bugzilla::Component;
|
2006-06-19 02:46:50 +04:00
|
|
|
use Bugzilla::Bug;
|
|
|
|
use Bugzilla::Attachment;
|
2002-09-28 22:42:54 +04:00
|
|
|
|
2006-06-15 01:20:53 +04:00
|
|
|
use List::Util qw(reduce);
|
|
|
|
|
2005-10-25 03:11:56 +04:00
|
|
|
my $template = Bugzilla->template;
|
|
|
|
my $vars = {};
|
2002-09-28 22:42:54 +04:00
|
|
|
|
|
|
|
# Make sure the user is logged in and is an administrator.
|
2005-09-16 02:01:56 +04:00
|
|
|
my $user = Bugzilla->login(LOGIN_REQUIRED);
|
|
|
|
$user->in_group('editcomponents')
|
2005-01-16 17:07:31 +03:00
|
|
|
|| ThrowUserError("auth_failure", {group => "editcomponents",
|
|
|
|
action => "edit",
|
|
|
|
object => "flagtypes"});
|
2002-09-28 22:42:54 +04:00
|
|
|
|
2005-04-10 03:12:11 +04:00
|
|
|
my $cgi = Bugzilla->cgi;
|
2002-09-28 22:42:54 +04:00
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# Main Body Execution
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
# All calls to this script should contain an "action" variable whose value
|
|
|
|
# determines what the user wants to do. The code below checks the value of
|
|
|
|
# that variable and runs the appropriate code.
|
|
|
|
|
|
|
|
# Determine whether to use the action specified by the user or the default.
|
2005-04-10 03:12:11 +04:00
|
|
|
my $action = $cgi->param('action') || 'list';
|
2004-09-24 05:01:30 +04:00
|
|
|
my @categoryActions;
|
2002-09-28 22:42:54 +04:00
|
|
|
|
2005-04-10 03:12:11 +04:00
|
|
|
if (@categoryActions = grep(/^categoryAction-.+/, $cgi->param())) {
|
2004-09-24 05:01:30 +04:00
|
|
|
$categoryActions[0] =~ s/^categoryAction-//;
|
|
|
|
processCategoryChange($categoryActions[0]);
|
2002-09-28 22:42:54 +04:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($action eq 'list') { list(); }
|
|
|
|
elsif ($action eq 'enter') { edit(); }
|
|
|
|
elsif ($action eq 'copy') { edit(); }
|
|
|
|
elsif ($action eq 'edit') { edit(); }
|
|
|
|
elsif ($action eq 'insert') { insert(); }
|
|
|
|
elsif ($action eq 'update') { update(); }
|
|
|
|
elsif ($action eq 'confirmdelete') { confirmDelete(); }
|
2004-09-03 13:58:00 +04:00
|
|
|
elsif ($action eq 'delete') { deleteType(); }
|
2002-09-28 22:42:54 +04:00
|
|
|
elsif ($action eq 'deactivate') { deactivate(); }
|
|
|
|
else {
|
|
|
|
ThrowCodeError("action_unrecognized", { action => $action });
|
|
|
|
}
|
|
|
|
|
|
|
|
exit;
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# Functions
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
sub list {
|
2006-06-15 01:20:53 +04:00
|
|
|
# Restrict the list to the given product and component, if given.
|
|
|
|
$vars = get_products_and_components($vars);
|
|
|
|
|
|
|
|
my $product = validateProduct(scalar $cgi->param('product'));
|
|
|
|
my $component = validateComponent($product, scalar $cgi->param('component'));
|
|
|
|
my $product_id = $product ? $product->id : 0;
|
|
|
|
my $component_id = $component ? $component->id : 0;
|
|
|
|
|
2002-09-28 22:42:54 +04:00
|
|
|
# Define the variables and functions that will be passed to the UI template.
|
2006-06-15 01:20:53 +04:00
|
|
|
$vars->{'selected_product'} = $cgi->param('product');
|
|
|
|
$vars->{'selected_component'} = $cgi->param('component');
|
|
|
|
|
|
|
|
# If only a product was specified but no component, then we restrict
|
|
|
|
# the list to flag types available in ALL components of that product.
|
|
|
|
my @comp_ids = ($component_id);
|
|
|
|
if ($product_id && !$component_id) {
|
|
|
|
@comp_ids = map {$_->id} @{$product->components};
|
|
|
|
}
|
|
|
|
|
|
|
|
my @bug_flagtypes;
|
|
|
|
my @attach_flagtypes;
|
|
|
|
|
|
|
|
foreach my $comp_id (@comp_ids) {
|
|
|
|
my $bug_types =
|
|
|
|
Bugzilla::FlagType::match({ 'target_type' => 'bug',
|
|
|
|
'group' => scalar $cgi->param('group'),
|
|
|
|
'product_id' => $product_id,
|
|
|
|
'component_id' => $comp_id }, 1);
|
|
|
|
push(@bug_flagtypes, $bug_types);
|
|
|
|
|
|
|
|
my $attach_types =
|
|
|
|
Bugzilla::FlagType::match({ 'target_type' => 'attachment',
|
|
|
|
'group' => scalar $cgi->param('group'),
|
|
|
|
'product_id' => $product_id,
|
|
|
|
'component_id' => $comp_id }, 1);
|
|
|
|
push(@attach_flagtypes, $attach_types);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub intersection {
|
|
|
|
my ($aa, $bb) = @_;
|
|
|
|
my %union;
|
|
|
|
my %isect;
|
|
|
|
foreach my $e (@$aa, @$bb) { $union{$e->{'id'}}++ && ($isect{$e->{'id'}} ||= $e) };
|
|
|
|
return [sort { $a->{'sortkey'} <=> $b->{'sortkey'}
|
|
|
|
|| $a->{'name'} cmp $b->{'name'} } values %isect];
|
|
|
|
}
|
|
|
|
$vars->{'bug_types'} = reduce { intersection($a, $b) } @bug_flagtypes;
|
|
|
|
$vars->{'attachment_types'} = reduce { intersection($a, $b) } @attach_flagtypes;
|
2002-09-28 22:42:54 +04:00
|
|
|
|
2006-03-02 01:24:13 +03:00
|
|
|
# Users want to see group names, not IDs
|
|
|
|
# So get the group names
|
|
|
|
my %group_name_cache = ();
|
|
|
|
foreach my $flag_type_set ("bug_types", "attachment_types") {
|
|
|
|
foreach my $flag_type (@{$vars->{$flag_type_set}}) {
|
|
|
|
foreach my $group ("grant", "request") {
|
|
|
|
my $gid = $flag_type->{$group . "_gid"};
|
|
|
|
next if (!$gid);
|
|
|
|
$group_name_cache{$gid} ||= new Bugzilla::Group($gid)->name();
|
|
|
|
$flag_type->{$group . "_group_name"} = $group_name_cache{$gid};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-28 22:42:54 +04:00
|
|
|
# Return the appropriate HTTP response headers.
|
2005-04-10 03:12:11 +04:00
|
|
|
print $cgi->header();
|
2002-09-28 22:42:54 +04:00
|
|
|
|
|
|
|
# Generate and return the UI (HTML page) from the appropriate template.
|
|
|
|
$template->process("admin/flag-type/list.html.tmpl", $vars)
|
|
|
|
|| ThrowTemplateError($template->error());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub edit {
|
2005-04-10 03:12:11 +04:00
|
|
|
$action eq 'enter' ? validateTargetType() : (my $id = validateID());
|
2005-09-22 21:16:47 +04:00
|
|
|
my $dbh = Bugzilla->dbh;
|
2002-09-28 22:42:54 +04:00
|
|
|
|
2006-06-15 01:20:53 +04:00
|
|
|
# Fill $vars with products and components data.
|
|
|
|
$vars = get_products_and_components($vars);
|
2006-03-16 00:51:35 +03:00
|
|
|
|
2005-04-10 03:12:11 +04:00
|
|
|
$vars->{'last_action'} = $cgi->param('action');
|
|
|
|
if ($cgi->param('action') eq 'enter' || $cgi->param('action') eq 'copy') {
|
2002-09-28 22:42:54 +04:00
|
|
|
$vars->{'action'} = "insert";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$vars->{'action'} = "update";
|
|
|
|
}
|
|
|
|
|
|
|
|
# If copying or editing an existing flag type, retrieve it.
|
2005-04-10 03:12:11 +04:00
|
|
|
if ($cgi->param('action') eq 'copy' || $cgi->param('action') eq 'edit') {
|
|
|
|
$vars->{'type'} = Bugzilla::FlagType::get($id);
|
|
|
|
$vars->{'type'}->{'inclusions'} = Bugzilla::FlagType::get_inclusions($id);
|
|
|
|
$vars->{'type'}->{'exclusions'} = Bugzilla::FlagType::get_exclusions($id);
|
2004-11-24 01:41:44 +03:00
|
|
|
# Users want to see group names, not IDs
|
|
|
|
foreach my $group ("grant_gid", "request_gid") {
|
|
|
|
my $gid = $vars->{'type'}->{$group};
|
|
|
|
next if (!$gid);
|
2005-09-22 21:16:47 +04:00
|
|
|
($vars->{'type'}->{$group}) =
|
|
|
|
$dbh->selectrow_array('SELECT name FROM groups WHERE id = ?',
|
|
|
|
undef, $gid);
|
2004-11-24 01:41:44 +03:00
|
|
|
}
|
2002-09-28 22:42:54 +04:00
|
|
|
}
|
|
|
|
# Otherwise set the target type (the minimal information about the type
|
2002-11-06 02:45:56 +03:00
|
|
|
# that the template needs to know) from the URL parameter and default
|
|
|
|
# the list of inclusions to all categories.
|
2005-05-05 23:20:45 +04:00
|
|
|
else {
|
|
|
|
my %inclusions;
|
|
|
|
$inclusions{"__Any__:__Any__"} = "0:0";
|
2005-04-10 03:12:11 +04:00
|
|
|
$vars->{'type'} = { 'target_type' => scalar $cgi->param('target_type'),
|
2005-05-05 23:20:45 +04:00
|
|
|
'inclusions' => \%inclusions };
|
2002-09-28 22:42:54 +04:00
|
|
|
}
|
2005-08-30 20:47:33 +04:00
|
|
|
# Get a list of groups available to restrict this flag type against.
|
|
|
|
my @groups = Bugzilla::Group::get_all_groups();
|
|
|
|
$vars->{'groups'} = \@groups;
|
2002-09-28 22:42:54 +04:00
|
|
|
# Return the appropriate HTTP response headers.
|
2005-04-10 03:12:11 +04:00
|
|
|
print $cgi->header();
|
2002-09-28 22:42:54 +04:00
|
|
|
|
|
|
|
# Generate and return the UI (HTML page) from the appropriate template.
|
|
|
|
$template->process("admin/flag-type/edit.html.tmpl", $vars)
|
|
|
|
|| ThrowTemplateError($template->error());
|
|
|
|
}
|
|
|
|
|
|
|
|
sub processCategoryChange {
|
2004-09-24 05:01:30 +04:00
|
|
|
my $categoryAction = shift;
|
2002-09-28 22:42:54 +04:00
|
|
|
validateIsActive();
|
|
|
|
validateIsRequestable();
|
|
|
|
validateIsRequesteeble();
|
|
|
|
validateAllowMultiple();
|
|
|
|
|
2005-04-10 03:12:11 +04:00
|
|
|
my @inclusions = $cgi->param('inclusions');
|
|
|
|
my @exclusions = $cgi->param('exclusions');
|
2004-09-24 05:01:30 +04:00
|
|
|
if ($categoryAction eq 'include') {
|
2006-05-29 21:24:54 +04:00
|
|
|
my $product = validateProduct(scalar $cgi->param('product'));
|
|
|
|
my $component = validateComponent($product, scalar $cgi->param('component'));
|
|
|
|
my $category = ($product ? $product->id : 0) . ":" .
|
|
|
|
($component ? $component->id : 0);
|
2002-09-28 22:42:54 +04:00
|
|
|
push(@inclusions, $category) unless grep($_ eq $category, @inclusions);
|
|
|
|
}
|
2004-09-24 05:01:30 +04:00
|
|
|
elsif ($categoryAction eq 'exclude') {
|
2006-05-29 21:24:54 +04:00
|
|
|
my $product = validateProduct(scalar $cgi->param('product'));
|
|
|
|
my $component = validateComponent($product, scalar $cgi->param('component'));
|
|
|
|
my $category = ($product ? $product->id : 0) . ":" .
|
|
|
|
($component ? $component->id : 0);
|
2002-09-28 22:42:54 +04:00
|
|
|
push(@exclusions, $category) unless grep($_ eq $category, @exclusions);
|
|
|
|
}
|
2004-09-24 05:01:30 +04:00
|
|
|
elsif ($categoryAction eq 'removeInclusion') {
|
2006-01-11 16:16:39 +03:00
|
|
|
my @inclusion_to_remove = $cgi->param('inclusion_to_remove');
|
|
|
|
@inclusions = map {(lsearch(\@inclusion_to_remove, $_) < 0) ? $_ : ()} @inclusions;
|
2002-09-28 22:42:54 +04:00
|
|
|
}
|
2004-09-24 05:01:30 +04:00
|
|
|
elsif ($categoryAction eq 'removeExclusion') {
|
2006-01-11 16:16:39 +03:00
|
|
|
my @exclusion_to_remove = $cgi->param('exclusion_to_remove');
|
|
|
|
@exclusions = map {(lsearch(\@exclusion_to_remove, $_) < 0) ? $_ : ()} @exclusions;
|
2002-09-28 22:42:54 +04:00
|
|
|
}
|
|
|
|
|
2005-05-05 23:20:45 +04:00
|
|
|
# Convert the array @clusions('prod_ID:comp_ID') back to a hash of
|
|
|
|
# the form %clusions{'prod_name:comp_name'} = 'prod_ID:comp_ID'
|
|
|
|
my %inclusions = clusion_array_to_hash(\@inclusions);
|
|
|
|
my %exclusions = clusion_array_to_hash(\@exclusions);
|
|
|
|
|
2006-06-15 01:20:53 +04:00
|
|
|
# Fill $vars with products and components data.
|
|
|
|
$vars = get_products_and_components($vars);
|
2002-09-28 22:42:54 +04:00
|
|
|
|
2005-08-30 20:47:33 +04:00
|
|
|
my @groups = Bugzilla::Group::get_all_groups();
|
|
|
|
$vars->{'groups'} = \@groups;
|
2005-04-10 03:12:11 +04:00
|
|
|
$vars->{'action'} = $cgi->param('action');
|
2006-03-16 00:51:35 +03:00
|
|
|
|
2002-09-28 22:42:54 +04:00
|
|
|
my $type = {};
|
2005-04-10 03:12:11 +04:00
|
|
|
foreach my $key ($cgi->param()) { $type->{$key} = $cgi->param($key) }
|
2005-05-05 23:20:45 +04:00
|
|
|
$type->{'inclusions'} = \%inclusions;
|
|
|
|
$type->{'exclusions'} = \%exclusions;
|
2002-09-28 22:42:54 +04:00
|
|
|
$vars->{'type'} = $type;
|
|
|
|
|
|
|
|
# Return the appropriate HTTP response headers.
|
2005-04-10 03:12:11 +04:00
|
|
|
print $cgi->header();
|
2002-09-28 22:42:54 +04:00
|
|
|
|
|
|
|
# Generate and return the UI (HTML page) from the appropriate template.
|
|
|
|
$template->process("admin/flag-type/edit.html.tmpl", $vars)
|
|
|
|
|| ThrowTemplateError($template->error());
|
|
|
|
}
|
|
|
|
|
2005-05-05 23:20:45 +04:00
|
|
|
# Convert the array @clusions('prod_ID:comp_ID') back to a hash of
|
|
|
|
# the form %clusions{'prod_name:comp_name'} = 'prod_ID:comp_ID'
|
|
|
|
sub clusion_array_to_hash {
|
|
|
|
my $array = shift;
|
|
|
|
my %hash;
|
2006-06-18 03:12:36 +04:00
|
|
|
my %products;
|
2006-05-29 21:24:54 +04:00
|
|
|
my %components;
|
2005-05-05 23:20:45 +04:00
|
|
|
foreach my $ids (@$array) {
|
|
|
|
trick_taint($ids);
|
|
|
|
my ($product_id, $component_id) = split(":", $ids);
|
2006-06-18 03:12:36 +04:00
|
|
|
my $product_name = "__Any__";
|
|
|
|
if ($product_id) {
|
|
|
|
$products{$product_id} ||= new Bugzilla::Product($product_id);
|
|
|
|
$product_name = $products{$product_id}->name if $products{$product_id};
|
|
|
|
}
|
2006-05-29 21:24:54 +04:00
|
|
|
my $component_name = "__Any__";
|
|
|
|
if ($component_id) {
|
|
|
|
$components{$component_id} ||= new Bugzilla::Component($component_id);
|
2006-06-18 03:12:36 +04:00
|
|
|
$component_name = $components{$component_id}->name if $components{$component_id};
|
2006-05-29 21:24:54 +04:00
|
|
|
}
|
2005-05-05 23:20:45 +04:00
|
|
|
$hash{"$product_name:$component_name"} = $ids;
|
|
|
|
}
|
|
|
|
return %hash;
|
|
|
|
}
|
|
|
|
|
2002-09-28 22:42:54 +04:00
|
|
|
sub insert {
|
2005-09-22 21:16:47 +04:00
|
|
|
my $name = validateName();
|
|
|
|
my $description = validateDescription();
|
|
|
|
my $cc_list = validateCCList();
|
2002-09-28 22:42:54 +04:00
|
|
|
validateTargetType();
|
|
|
|
validateSortKey();
|
|
|
|
validateIsActive();
|
|
|
|
validateIsRequestable();
|
|
|
|
validateIsRequesteeble();
|
|
|
|
validateAllowMultiple();
|
2004-11-24 01:41:44 +03:00
|
|
|
validateGroups();
|
2005-02-18 00:57:27 +03:00
|
|
|
|
|
|
|
my $dbh = Bugzilla->dbh;
|
|
|
|
|
2005-04-10 03:12:11 +04:00
|
|
|
my $target_type = $cgi->param('target_type') eq "bug" ? "b" : "a";
|
2005-02-18 00:57:27 +03:00
|
|
|
|
|
|
|
$dbh->bz_lock_tables('flagtypes WRITE', 'products READ',
|
|
|
|
'components READ', 'flaginclusions WRITE',
|
|
|
|
'flagexclusions WRITE');
|
|
|
|
|
2002-09-28 22:42:54 +04:00
|
|
|
# Determine the new flag type's unique identifier.
|
2005-09-22 21:16:47 +04:00
|
|
|
my $id = $dbh->selectrow_array('SELECT MAX(id) FROM flagtypes') + 1;
|
|
|
|
|
2002-09-28 22:42:54 +04:00
|
|
|
# Insert a record for the new flag type into the database.
|
2005-09-22 21:16:47 +04:00
|
|
|
$dbh->do('INSERT INTO flagtypes
|
|
|
|
(id, name, description, cc_list, target_type,
|
|
|
|
sortkey, is_active, is_requestable,
|
|
|
|
is_requesteeble, is_multiplicable,
|
|
|
|
grant_group_id, request_group_id)
|
|
|
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
|
|
|
|
undef, ($id, $name, $description, $cc_list, $target_type,
|
|
|
|
$cgi->param('sortkey'), $cgi->param('is_active'),
|
|
|
|
$cgi->param('is_requestable'), $cgi->param('is_requesteeble'),
|
|
|
|
$cgi->param('is_multiplicable'), scalar($cgi->param('grant_gid')),
|
|
|
|
scalar($cgi->param('request_gid'))));
|
|
|
|
|
2002-09-28 22:42:54 +04:00
|
|
|
# Populate the list of inclusions/exclusions for this flag type.
|
2005-05-05 23:20:45 +04:00
|
|
|
validateAndSubmit($id);
|
2005-02-18 00:57:27 +03:00
|
|
|
|
|
|
|
$dbh->bz_unlock_tables();
|
2002-09-28 22:42:54 +04:00
|
|
|
|
2005-04-10 03:12:11 +04:00
|
|
|
$vars->{'name'} = $cgi->param('name');
|
2002-09-28 22:42:54 +04:00
|
|
|
$vars->{'message'} = "flag_type_created";
|
|
|
|
|
|
|
|
# Return the appropriate HTTP response headers.
|
2005-04-10 03:12:11 +04:00
|
|
|
print $cgi->header();
|
2002-09-28 22:42:54 +04:00
|
|
|
|
|
|
|
# Generate and return the UI (HTML page) from the appropriate template.
|
|
|
|
$template->process("global/message.html.tmpl", $vars)
|
|
|
|
|| ThrowTemplateError($template->error());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub update {
|
2005-04-10 03:12:11 +04:00
|
|
|
my $id = validateID();
|
2005-09-22 21:16:47 +04:00
|
|
|
my $name = validateName();
|
|
|
|
my $description = validateDescription();
|
|
|
|
my $cc_list = validateCCList();
|
2002-09-28 22:42:54 +04:00
|
|
|
validateTargetType();
|
|
|
|
validateSortKey();
|
|
|
|
validateIsActive();
|
|
|
|
validateIsRequestable();
|
|
|
|
validateIsRequesteeble();
|
|
|
|
validateAllowMultiple();
|
2004-11-24 01:41:44 +03:00
|
|
|
validateGroups();
|
2005-02-18 00:57:27 +03:00
|
|
|
|
|
|
|
my $dbh = Bugzilla->dbh;
|
|
|
|
$dbh->bz_lock_tables('flagtypes WRITE', 'products READ',
|
|
|
|
'components READ', 'flaginclusions WRITE',
|
|
|
|
'flagexclusions WRITE');
|
2005-09-22 21:16:47 +04:00
|
|
|
$dbh->do('UPDATE flagtypes
|
|
|
|
SET name = ?, description = ?, cc_list = ?,
|
|
|
|
sortkey = ?, is_active = ?, is_requestable = ?,
|
|
|
|
is_requesteeble = ?, is_multiplicable = ?,
|
|
|
|
grant_group_id = ?, request_group_id = ?
|
|
|
|
WHERE id = ?',
|
|
|
|
undef, ($name, $description, $cc_list, $cgi->param('sortkey'),
|
|
|
|
$cgi->param('is_active'), $cgi->param('is_requestable'),
|
|
|
|
$cgi->param('is_requesteeble'), $cgi->param('is_multiplicable'),
|
|
|
|
scalar($cgi->param('grant_gid')), scalar($cgi->param('request_gid')),
|
|
|
|
$id));
|
2002-09-28 22:42:54 +04:00
|
|
|
|
|
|
|
# Update the list of inclusions/exclusions for this flag type.
|
2005-05-05 23:20:45 +04:00
|
|
|
validateAndSubmit($id);
|
2002-09-28 22:42:54 +04:00
|
|
|
|
2005-02-18 00:57:27 +03:00
|
|
|
$dbh->bz_unlock_tables();
|
2006-06-19 02:46:50 +04:00
|
|
|
|
2002-09-28 22:42:54 +04:00
|
|
|
# Clear existing flags for bugs/attachments in categories no longer on
|
|
|
|
# the list of inclusions or that have been added to the list of exclusions.
|
2006-06-19 02:46:50 +04:00
|
|
|
my $flags = $dbh->selectall_arrayref('SELECT flags.id, flags.bug_id, flags.attach_id
|
2005-09-22 21:16:47 +04:00
|
|
|
FROM flags
|
|
|
|
INNER JOIN bugs
|
|
|
|
ON flags.bug_id = bugs.bug_id
|
|
|
|
LEFT OUTER JOIN flaginclusions AS i
|
|
|
|
ON (flags.type_id = i.type_id
|
|
|
|
AND (bugs.product_id = i.product_id
|
|
|
|
OR i.product_id IS NULL)
|
|
|
|
AND (bugs.component_id = i.component_id
|
|
|
|
OR i.component_id IS NULL))
|
|
|
|
WHERE flags.type_id = ?
|
|
|
|
AND i.type_id IS NULL',
|
|
|
|
undef, $id);
|
2006-06-19 02:46:50 +04:00
|
|
|
foreach my $flag (@$flags) {
|
|
|
|
my ($flag_id, $bug_id, $attach_id) = @$flag;
|
|
|
|
my $bug = new Bugzilla::Bug($bug_id, $user->id);
|
|
|
|
my $attachment = $attach_id ? Bugzilla::Attachment->get($attach_id) : undef;
|
|
|
|
Bugzilla::Flag::clear($flag_id, $bug, $attachment);
|
2005-09-22 21:16:47 +04:00
|
|
|
}
|
2006-06-19 02:46:50 +04:00
|
|
|
|
|
|
|
$flags = $dbh->selectall_arrayref('SELECT flags.id, flags.bug_id, flags.attach_id
|
2005-09-22 21:16:47 +04:00
|
|
|
FROM flags
|
|
|
|
INNER JOIN bugs
|
|
|
|
ON flags.bug_id = bugs.bug_id
|
|
|
|
INNER JOIN flagexclusions AS e
|
|
|
|
ON flags.type_id = e.type_id
|
|
|
|
WHERE flags.type_id = ?
|
|
|
|
AND (bugs.product_id = e.product_id
|
|
|
|
OR e.product_id IS NULL)
|
|
|
|
AND (bugs.component_id = e.component_id
|
|
|
|
OR e.component_id IS NULL)',
|
|
|
|
undef, $id);
|
2006-06-19 02:46:50 +04:00
|
|
|
foreach my $flag (@$flags) {
|
|
|
|
my ($flag_id, $bug_id, $attach_id) = @$flag;
|
|
|
|
my $bug = new Bugzilla::Bug($bug_id, $user->id);
|
|
|
|
my $attachment = $attach_id ? Bugzilla::Attachment->get($attach_id) : undef;
|
|
|
|
Bugzilla::Flag::clear($flag_id, $bug, $attachment);
|
2005-09-22 21:16:47 +04:00
|
|
|
}
|
2006-06-19 02:46:50 +04:00
|
|
|
|
2005-04-10 03:12:11 +04:00
|
|
|
$vars->{'name'} = $cgi->param('name');
|
2002-09-28 22:42:54 +04:00
|
|
|
$vars->{'message'} = "flag_type_changes_saved";
|
|
|
|
|
|
|
|
# Return the appropriate HTTP response headers.
|
2005-04-10 03:12:11 +04:00
|
|
|
print $cgi->header();
|
2002-09-28 22:42:54 +04:00
|
|
|
|
|
|
|
# Generate and return the UI (HTML page) from the appropriate template.
|
|
|
|
$template->process("global/message.html.tmpl", $vars)
|
|
|
|
|| ThrowTemplateError($template->error());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub confirmDelete
|
|
|
|
{
|
2005-04-10 03:12:11 +04:00
|
|
|
my $id = validateID();
|
|
|
|
|
2002-09-28 22:42:54 +04:00
|
|
|
# check if we need confirmation to delete:
|
|
|
|
|
2006-04-14 20:50:47 +04:00
|
|
|
my $count = Bugzilla::Flag::count({ 'type_id' => $id });
|
2002-09-28 22:42:54 +04:00
|
|
|
|
|
|
|
if ($count > 0) {
|
2005-04-10 03:12:11 +04:00
|
|
|
$vars->{'flag_type'} = Bugzilla::FlagType::get($id);
|
2002-09-28 22:42:54 +04:00
|
|
|
$vars->{'flag_count'} = scalar($count);
|
|
|
|
|
|
|
|
# Return the appropriate HTTP response headers.
|
2005-04-10 03:12:11 +04:00
|
|
|
print $cgi->header();
|
2002-09-28 22:42:54 +04:00
|
|
|
|
|
|
|
# Generate and return the UI (HTML page) from the appropriate template.
|
|
|
|
$template->process("admin/flag-type/confirm-delete.html.tmpl", $vars)
|
|
|
|
|| ThrowTemplateError($template->error());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
deleteType();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-09-03 13:58:00 +04:00
|
|
|
sub deleteType {
|
2005-04-10 03:12:11 +04:00
|
|
|
my $id = validateID();
|
2005-02-18 00:57:27 +03:00
|
|
|
my $dbh = Bugzilla->dbh;
|
|
|
|
|
|
|
|
$dbh->bz_lock_tables('flagtypes WRITE', 'flags WRITE',
|
|
|
|
'flaginclusions WRITE', 'flagexclusions WRITE');
|
2002-09-28 22:42:54 +04:00
|
|
|
|
|
|
|
# Get the name of the flag type so we can tell users
|
|
|
|
# what was deleted.
|
2005-09-22 21:16:47 +04:00
|
|
|
($vars->{'name'}) = $dbh->selectrow_array('SELECT name FROM flagtypes
|
|
|
|
WHERE id = ?', undef, $id);
|
|
|
|
|
|
|
|
$dbh->do('DELETE FROM flags WHERE type_id = ?', undef, $id);
|
|
|
|
$dbh->do('DELETE FROM flaginclusions WHERE type_id = ?', undef, $id);
|
|
|
|
$dbh->do('DELETE FROM flagexclusions WHERE type_id = ?', undef, $id);
|
|
|
|
$dbh->do('DELETE FROM flagtypes WHERE id = ?', undef, $id);
|
2005-02-18 00:57:27 +03:00
|
|
|
$dbh->bz_unlock_tables();
|
2002-09-28 22:42:54 +04:00
|
|
|
|
|
|
|
$vars->{'message'} = "flag_type_deleted";
|
|
|
|
|
|
|
|
# Return the appropriate HTTP response headers.
|
2005-04-10 03:12:11 +04:00
|
|
|
print $cgi->header();
|
2002-09-28 22:42:54 +04:00
|
|
|
|
|
|
|
# Generate and return the UI (HTML page) from the appropriate template.
|
|
|
|
$template->process("global/message.html.tmpl", $vars)
|
|
|
|
|| ThrowTemplateError($template->error());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub deactivate {
|
2005-04-10 03:12:11 +04:00
|
|
|
my $id = validateID();
|
2002-09-28 22:42:54 +04:00
|
|
|
validateIsActive();
|
2005-02-18 00:57:27 +03:00
|
|
|
|
|
|
|
my $dbh = Bugzilla->dbh;
|
|
|
|
|
|
|
|
$dbh->bz_lock_tables('flagtypes WRITE');
|
2005-09-22 21:16:47 +04:00
|
|
|
$dbh->do('UPDATE flagtypes SET is_active = 0 WHERE id = ?', undef, $id);
|
2005-02-18 00:57:27 +03:00
|
|
|
$dbh->bz_unlock_tables();
|
2002-09-28 22:42:54 +04:00
|
|
|
|
|
|
|
$vars->{'message'} = "flag_type_deactivated";
|
2005-04-10 03:12:11 +04:00
|
|
|
$vars->{'flag_type'} = Bugzilla::FlagType::get($id);
|
2002-09-28 22:42:54 +04:00
|
|
|
|
|
|
|
# Return the appropriate HTTP response headers.
|
2005-04-10 03:12:11 +04:00
|
|
|
print $cgi->header();
|
2002-09-28 22:42:54 +04:00
|
|
|
|
|
|
|
# Generate and return the UI (HTML page) from the appropriate template.
|
|
|
|
$template->process("global/message.html.tmpl", $vars)
|
|
|
|
|| ThrowTemplateError($template->error());
|
|
|
|
}
|
|
|
|
|
2006-06-15 01:20:53 +04:00
|
|
|
sub get_products_and_components {
|
|
|
|
my $vars = shift;
|
|
|
|
|
|
|
|
my @products = Bugzilla::Product::get_all_products();
|
|
|
|
# We require all unique component names.
|
|
|
|
my %components;
|
|
|
|
foreach my $product (@products) {
|
|
|
|
foreach my $component (@{$product->components}) {
|
|
|
|
$components{$component->name} = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$vars->{'products'} = \@products;
|
|
|
|
$vars->{'components'} = [sort(keys %components)];
|
|
|
|
return $vars;
|
|
|
|
}
|
2002-09-28 22:42:54 +04:00
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# Data Validation / Security Authorization
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
sub validateID {
|
2005-09-22 21:16:47 +04:00
|
|
|
my $dbh = Bugzilla->dbh;
|
2005-04-10 03:12:11 +04:00
|
|
|
# $flagtype_id is destroyed if detaint_natural fails.
|
|
|
|
my $flagtype_id = $cgi->param('id');
|
|
|
|
detaint_natural($flagtype_id)
|
|
|
|
|| ThrowCodeError("flag_type_id_invalid",
|
|
|
|
{ id => scalar $cgi->param('id') });
|
2002-09-28 22:42:54 +04:00
|
|
|
|
2005-09-22 21:16:47 +04:00
|
|
|
my $flagtype_exists =
|
|
|
|
$dbh->selectrow_array('SELECT 1 FROM flagtypes WHERE id = ?',
|
|
|
|
undef, $flagtype_id);
|
|
|
|
$flagtype_exists
|
2005-04-10 03:12:11 +04:00
|
|
|
|| ThrowCodeError("flag_type_nonexistent", { id => $flagtype_id });
|
|
|
|
|
|
|
|
return $flagtype_id;
|
2002-09-28 22:42:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
sub validateName {
|
2005-09-22 21:16:47 +04:00
|
|
|
my $name = $cgi->param('name');
|
|
|
|
($name && $name !~ /[ ,]/ && length($name) <= 50)
|
2005-04-10 03:12:11 +04:00
|
|
|
|| ThrowUserError("flag_type_name_invalid",
|
2005-09-22 21:16:47 +04:00
|
|
|
{ name => $name });
|
|
|
|
trick_taint($name);
|
|
|
|
return $name;
|
2002-09-28 22:42:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
sub validateDescription {
|
2005-09-22 21:16:47 +04:00
|
|
|
my $description = $cgi->param('description');
|
|
|
|
length($description) < 2**16-1
|
2002-09-28 22:42:54 +04:00
|
|
|
|| ThrowUserError("flag_type_description_invalid");
|
2005-09-22 21:16:47 +04:00
|
|
|
trick_taint($description);
|
|
|
|
return $description;
|
2002-09-28 22:42:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
sub validateCCList {
|
2005-09-22 21:16:47 +04:00
|
|
|
my $cc_list = $cgi->param('cc_list');
|
|
|
|
length($cc_list) <= 200
|
2002-09-28 22:42:54 +04:00
|
|
|
|| ThrowUserError("flag_type_cc_list_invalid",
|
2005-09-22 21:16:47 +04:00
|
|
|
{ cc_list => $cc_list });
|
|
|
|
|
|
|
|
my @addresses = split(/[, ]+/, $cc_list);
|
2005-12-14 00:32:51 +03:00
|
|
|
# We do not call Util::validate_email_syntax because these
|
|
|
|
# addresses do not require to match 'emailregexp' and do not
|
|
|
|
# depend on 'emailsuffix'. So we limit ourselves to a simple
|
|
|
|
# sanity check:
|
|
|
|
# - match the syntax of a fully qualified email address;
|
|
|
|
# - do not contain any illegal character.
|
2005-08-15 21:43:38 +04:00
|
|
|
foreach my $address (@addresses) {
|
2005-12-14 00:32:51 +03:00
|
|
|
($address =~ /^[\w\.\+\-=]+@[\w\.\-]+\.[\w\-]+$/
|
|
|
|
&& $address !~ /[\\\(\)<>&,;:"\[\] \t\r\n]/)
|
|
|
|
|| ThrowUserError('illegal_email_address',
|
|
|
|
{addr => $address, default => 1});
|
2005-08-15 21:43:38 +04:00
|
|
|
}
|
2005-09-22 21:16:47 +04:00
|
|
|
trick_taint($cc_list);
|
|
|
|
return $cc_list;
|
2002-09-28 22:42:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
sub validateProduct {
|
2006-05-29 21:24:54 +04:00
|
|
|
my $product_name = shift;
|
|
|
|
return unless $product_name;
|
|
|
|
|
|
|
|
my $product = Bugzilla::Product::check_product($product_name);
|
|
|
|
return $product;
|
2002-09-28 22:42:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
sub validateComponent {
|
2006-05-29 21:24:54 +04:00
|
|
|
my ($product, $component_name) = @_;
|
|
|
|
return unless $component_name;
|
|
|
|
|
|
|
|
($product && $product->id)
|
2006-06-15 01:20:53 +04:00
|
|
|
|| ThrowUserError("flag_type_component_without_product");
|
2002-09-28 22:42:54 +04:00
|
|
|
|
2006-05-29 21:24:54 +04:00
|
|
|
my $component = Bugzilla::Component::check_component($product, $component_name);
|
|
|
|
return $component;
|
2002-09-28 22:42:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
sub validateSortKey {
|
2005-04-10 03:12:11 +04:00
|
|
|
# $sortkey is destroyed if detaint_natural fails.
|
|
|
|
my $sortkey = $cgi->param('sortkey');
|
|
|
|
detaint_natural($sortkey)
|
|
|
|
&& $sortkey < 32768
|
2002-09-28 22:42:54 +04:00
|
|
|
|| ThrowUserError("flag_type_sortkey_invalid",
|
2005-04-10 03:12:11 +04:00
|
|
|
{ sortkey => scalar $cgi->param('sortkey') });
|
|
|
|
$cgi->param('sortkey', $sortkey);
|
2002-09-28 22:42:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
sub validateTargetType {
|
2005-04-10 03:12:11 +04:00
|
|
|
grep($cgi->param('target_type') eq $_, ("bug", "attachment"))
|
2002-09-28 22:42:54 +04:00
|
|
|
|| ThrowCodeError("flag_type_target_type_invalid",
|
2005-04-10 03:12:11 +04:00
|
|
|
{ target_type => scalar $cgi->param('target_type') });
|
2002-09-28 22:42:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
sub validateIsActive {
|
2005-04-10 03:12:11 +04:00
|
|
|
$cgi->param('is_active', $cgi->param('is_active') ? 1 : 0);
|
2002-09-28 22:42:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
sub validateIsRequestable {
|
2005-04-10 03:12:11 +04:00
|
|
|
$cgi->param('is_requestable', $cgi->param('is_requestable') ? 1 : 0);
|
2002-09-28 22:42:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
sub validateIsRequesteeble {
|
2005-04-10 03:12:11 +04:00
|
|
|
$cgi->param('is_requesteeble', $cgi->param('is_requesteeble') ? 1 : 0);
|
2002-09-28 22:42:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
sub validateAllowMultiple {
|
2005-04-10 03:12:11 +04:00
|
|
|
$cgi->param('is_multiplicable', $cgi->param('is_multiplicable') ? 1 : 0);
|
2002-09-28 22:42:54 +04:00
|
|
|
}
|
|
|
|
|
2004-11-24 01:41:44 +03:00
|
|
|
sub validateGroups {
|
2005-09-22 21:16:47 +04:00
|
|
|
my $dbh = Bugzilla->dbh;
|
2004-11-24 01:41:44 +03:00
|
|
|
# Convert group names to group IDs
|
|
|
|
foreach my $col ("grant_gid", "request_gid") {
|
2005-04-10 03:12:11 +04:00
|
|
|
my $name = $cgi->param($col);
|
2005-09-22 21:16:47 +04:00
|
|
|
if ($name) {
|
|
|
|
trick_taint($name);
|
|
|
|
my $gid = $dbh->selectrow_array('SELECT id FROM groups
|
|
|
|
WHERE name = ?', undef, $name);
|
|
|
|
$gid || ThrowUserError("group_unknown", { name => $name });
|
|
|
|
$cgi->param($col, $gid);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$cgi->delete($col);
|
2004-11-24 01:41:44 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-05-05 23:20:45 +04:00
|
|
|
|
|
|
|
# At this point, values either come the DB itself or have been recently
|
|
|
|
# added by the user and have passed all validation tests.
|
|
|
|
# The only way to have invalid product/component combinations is to
|
|
|
|
# hack the URL. So we silently ignore them, if any.
|
2005-08-13 16:27:04 +04:00
|
|
|
sub validateAndSubmit {
|
2005-05-05 23:20:45 +04:00
|
|
|
my ($id) = @_;
|
|
|
|
my $dbh = Bugzilla->dbh;
|
|
|
|
|
2006-06-18 03:12:36 +04:00
|
|
|
# Cache product objects.
|
|
|
|
my %products;
|
2005-05-05 23:20:45 +04:00
|
|
|
foreach my $category_type ("inclusions", "exclusions") {
|
|
|
|
# Will be used several times below.
|
|
|
|
my $sth = $dbh->prepare("INSERT INTO flag$category_type " .
|
|
|
|
"(type_id, product_id, component_id) " .
|
|
|
|
"VALUES (?, ?, ?)");
|
|
|
|
|
|
|
|
$dbh->do("DELETE FROM flag$category_type WHERE type_id = ?", undef, $id);
|
|
|
|
foreach my $category ($cgi->param($category_type)) {
|
|
|
|
trick_taint($category);
|
|
|
|
my ($product_id, $component_id) = split(":", $category);
|
2006-06-18 03:12:36 +04:00
|
|
|
# Does the product exist?
|
|
|
|
if ($product_id) {
|
|
|
|
$products{$product_id} ||= new Bugzilla::Product($product_id);
|
|
|
|
next unless defined $products{$product_id};
|
|
|
|
}
|
2005-05-05 23:20:45 +04:00
|
|
|
# A component was selected without a product being selected.
|
|
|
|
next if (!$product_id && $component_id);
|
2006-06-18 03:12:36 +04:00
|
|
|
# Does the component belong to this product?
|
|
|
|
if ($component_id) {
|
|
|
|
my @match = grep {$_->id == $component_id} @{$products{$product_id}->components};
|
|
|
|
next unless scalar(@match);
|
|
|
|
}
|
2005-05-05 23:20:45 +04:00
|
|
|
$product_id ||= undef;
|
|
|
|
$component_id ||= undef;
|
|
|
|
$sth->execute($id, $product_id, $component_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|