Commit a589e55a authored by lpsolit%gmail.com's avatar lpsolit%gmail.com

Bug 487769: checksetup.pl can no longer create versions in TestProduct due to…

Bug 487769: checksetup.pl can no longer create versions in TestProduct due to insufficient privileges (checksetup.pl fails) - Patch by Max Kanat-Alexander <mkanat@bugzilla.org> r/a=LpSolit
parent 0e4b2ce5
...@@ -60,6 +60,7 @@ use constant UPDATE_COLUMNS => qw( ...@@ -60,6 +60,7 @@ use constant UPDATE_COLUMNS => qw(
); );
use constant VALIDATORS => { use constant VALIDATORS => {
create_series => \&Bugzilla::Object::check_boolean,
product => \&_check_product, product => \&_check_product,
initialowner => \&_check_initialowner, initialowner => \&_check_initialowner,
initialqacontact => \&_check_initialqacontact, initialqacontact => \&_check_initialqacontact,
...@@ -114,14 +115,15 @@ sub create { ...@@ -114,14 +115,15 @@ sub create {
$class->check_required_create_fields(@_); $class->check_required_create_fields(@_);
my $params = $class->run_create_validators(@_); my $params = $class->run_create_validators(@_);
my $cc_list = delete $params->{initial_cc}; my $cc_list = delete $params->{initial_cc};
my $create_series = delete $params->{create_series};
my $component = $class->insert_create_data($params); my $component = $class->insert_create_data($params);
# We still have to fill the component_cc table. # We still have to fill the component_cc table.
$component->_update_cc_list($cc_list); $component->_update_cc_list($cc_list) if $cc_list;
# Create series for the new component. # Create series for the new component.
$component->_create_series(); $component->_create_series() if $create_series;
$dbh->bz_commit_transaction(); $dbh->bz_commit_transaction();
return $component; return $component;
......
...@@ -79,6 +79,7 @@ use File::Basename; ...@@ -79,6 +79,7 @@ use File::Basename;
DEFAULT_COLUMN_LIST DEFAULT_COLUMN_LIST
DEFAULT_QUERY_NAME DEFAULT_QUERY_NAME
DEFAULT_MILESTONE
QUERY_LIST QUERY_LIST
LIST_OF_BUGS LIST_OF_BUGS
...@@ -257,6 +258,9 @@ use constant DEFAULT_COLUMN_LIST => ( ...@@ -257,6 +258,9 @@ use constant DEFAULT_COLUMN_LIST => (
# for the default settings. # for the default settings.
use constant DEFAULT_QUERY_NAME => '(Default query)'; use constant DEFAULT_QUERY_NAME => '(Default query)';
# The default "defaultmilestone" created for products.
use constant DEFAULT_MILESTONE => '---';
# The possible types for saved searches. # The possible types for saved searches.
use constant QUERY_LIST => 0; use constant QUERY_LIST => 0;
use constant LIST_OF_BUGS => 1; use constant LIST_OF_BUGS => 1;
......
...@@ -26,6 +26,7 @@ package Bugzilla::Install; ...@@ -26,6 +26,7 @@ package Bugzilla::Install;
use strict; use strict;
use Bugzilla::Component;
use Bugzilla::Constants; use Bugzilla::Constants;
use Bugzilla::Error; use Bugzilla::Error;
use Bugzilla::Group; use Bugzilla::Group;
...@@ -126,7 +127,10 @@ use constant DEFAULT_PRODUCT => { ...@@ -126,7 +127,10 @@ use constant DEFAULT_PRODUCT => {
name => 'TestProduct', name => 'TestProduct',
description => 'This is a test product.' description => 'This is a test product.'
. ' This ought to be blown away and replaced with real stuff in a' . ' This ought to be blown away and replaced with real stuff in a'
. ' finished installation of bugzilla.' . ' finished installation of bugzilla.',
version => Bugzilla::Version::DEFAULT_VERSION,
classification => 'Unclassified',
defaultmilestone => DEFAULT_MILESTONE,
}; };
use constant DEFAULT_COMPONENT => { use constant DEFAULT_COMPONENT => {
...@@ -216,54 +220,33 @@ sub update_system_groups { ...@@ -216,54 +220,33 @@ sub update_system_groups {
# This function should be called only after creating the admin user. # This function should be called only after creating the admin user.
sub create_default_product { sub create_default_product {
my $dbh = Bugzilla->dbh; my $dbh = Bugzilla->dbh;
# Make the default Classification if it doesn't already exist. # Make the default Classification if it doesn't already exist.
if (!$dbh->selectrow_array('SELECT 1 FROM classifications')) { if (!$dbh->selectrow_array('SELECT 1 FROM classifications')) {
my $class = DEFAULT_CLASSIFICATION;
print get_text('install_default_classification', print get_text('install_default_classification',
{ name => $class->{name} }) . "\n"; { name => DEFAULT_CLASSIFICATION->{name} }) . "\n";
$dbh->do('INSERT INTO classifications (name, description) Bugzilla::Classification->create(DEFAULT_CLASSIFICATION);
VALUES (?, ?)',
undef, $class->{name}, $class->{description});
} }
# And same for the default product/component. # And same for the default product/component.
if (!$dbh->selectrow_array('SELECT 1 FROM products')) { if (!$dbh->selectrow_array('SELECT 1 FROM products')) {
my $default_prod = DEFAULT_PRODUCT;
print get_text('install_default_product', print get_text('install_default_product',
{ name => $default_prod->{name} }) . "\n"; { name => DEFAULT_PRODUCT->{name} }) . "\n";
$dbh->do(q{INSERT INTO products (name, description)
VALUES (?,?)},
undef, $default_prod->{name}, $default_prod->{description});
my $product = new Bugzilla::Product({name => $default_prod->{name}});
# The default version. my $product = Bugzilla::Product->create(DEFAULT_PRODUCT);
Bugzilla::Version->create({name => Bugzilla::Version::DEFAULT_VERSION,
product => $product});
# And we automatically insert the default milestone. # Get the user who will be the owner of the Component.
$dbh->do(q{INSERT INTO milestones (product_id, value, sortkey) # We pick the admin with the lowest id, which is probably the
SELECT id, defaultmilestone, 0 # admin checksetup.pl just created.
FROM products});
# Get the user who will be the owner of the Product.
# We pick the admin with the lowest id, or we insert
# an invalid "0" into the database, just so that we can
# create the component.
my $admin_group = new Bugzilla::Group({name => 'admin'}); my $admin_group = new Bugzilla::Group({name => 'admin'});
my ($admin_id) = $dbh->selectrow_array( my ($admin_id) = $dbh->selectrow_array(
'SELECT user_id FROM user_group_map WHERE group_id = ? 'SELECT user_id FROM user_group_map WHERE group_id = ?
ORDER BY user_id ' . $dbh->sql_limit(1), ORDER BY user_id ' . $dbh->sql_limit(1),
undef, $admin_group->id) || 0; undef, $admin_group->id);
my $admin = Bugzilla::User->new($admin_id);
my $default_comp = DEFAULT_COMPONENT;
Bugzilla::Component->create({
$dbh->do("INSERT INTO components (name, product_id, description, %{ DEFAULT_COMPONENT() }, product => $product,
initialowner) initialowner => $admin->login });
VALUES (?, ?, ?, ?)", undef, $default_comp->{name},
$product->id, $default_comp->{description}, $admin_id);
} }
} }
......
...@@ -50,8 +50,9 @@ use Bugzilla::Classification; ...@@ -50,8 +50,9 @@ use Bugzilla::Classification;
use Bugzilla::Field; use Bugzilla::Field;
use Bugzilla::Group; use Bugzilla::Group;
use Scalar::Util qw(blessed);
use DateTime::TimeZone; use DateTime::TimeZone;
use Scalar::Util qw(blessed);
use Storable qw(dclone);
use base qw(Bugzilla::Object Exporter); use base qw(Bugzilla::Object Exporter);
@Bugzilla::User::EXPORT = qw(is_available_username @Bugzilla::User::EXPORT = qw(is_available_username
...@@ -135,6 +136,18 @@ sub new { ...@@ -135,6 +136,18 @@ sub new {
return $class->SUPER::new(@_); return $class->SUPER::new(@_);
} }
sub super_user {
my $invocant = shift;
my $class = ref($invocant) || $invocant;
my ($param) = @_;
my $user = dclone(DEFAULT_USER);
$user->{groups} = [Bugzilla::Group->get_all];
$user->{bless_groups} = [Bugzilla::Group->get_all];
bless $user, $class;
return $user;
}
sub update { sub update {
my $self = shift; my $self = shift;
my $changes = $self->SUPER::update(@_); my $changes = $self->SUPER::update(@_);
...@@ -1762,6 +1775,18 @@ confirmation screen. ...@@ -1762,6 +1775,18 @@ confirmation screen.
=head1 METHODS =head1 METHODS
=head2 Constructors
=over
=item C<super_user>
Returns a user who is in all groups, but who does not really exist in the
database. Used for non-web scripts like L<checksetup> that need to make
database changes and so on.
=back
=head2 Saved and Shared Queries =head2 Saved and Shared Queries
=over =over
......
...@@ -96,6 +96,7 @@ exit if $switch{'check-modules'}; ...@@ -96,6 +96,7 @@ exit if $switch{'check-modules'};
# get a cryptic perl error about the missing module. # get a cryptic perl error about the missing module.
require Bugzilla; require Bugzilla;
require Bugzilla::User;
require Bugzilla::Config; require Bugzilla::Config;
import Bugzilla::Config qw(:admin); import Bugzilla::Config qw(:admin);
...@@ -196,6 +197,9 @@ Bugzilla::Install::DB::update_table_definitions(\%old_params); ...@@ -196,6 +197,9 @@ Bugzilla::Install::DB::update_table_definitions(\%old_params);
Bugzilla::Install::update_system_groups(); Bugzilla::Install::update_system_groups();
# "Log In" as the fake superuser who can do everything.
Bugzilla->set_user(Bugzilla::User->super_user);
########################################################################### ###########################################################################
# Create --SETTINGS-- users can adjust # Create --SETTINGS-- users can adjust
########################################################################### ###########################################################################
......
...@@ -129,13 +129,17 @@ if ($action eq 'new') { ...@@ -129,13 +129,17 @@ if ($action eq 'new') {
my $description = trim($cgi->param('description') || ''); my $description = trim($cgi->param('description') || '');
my @initial_cc = $cgi->param('initialcc'); my @initial_cc = $cgi->param('initialcc');
my $component = my $component = Bugzilla::Component->create({
Bugzilla::Component->create({ name => $comp_name, name => $comp_name,
product => $product, product => $product,
description => $description, description => $description,
initialowner => $default_assignee, initialowner => $default_assignee,
initialqacontact => $default_qa_contact, initialqacontact => $default_qa_contact,
initial_cc => \@initial_cc }); initial_cc => \@initial_cc,
# XXX We should not be creating series for products that we
# didn't create series for.
create_series => 1,
});
$vars->{'message'} = 'component_created'; $vars->{'message'} = 'component_created';
$vars->{'comp'} = $component; $vars->{'comp'} = $component;
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
product.maxvotesperbug = "10000", product.maxvotesperbug = "10000",
product.votestoconfirm = "0", product.votestoconfirm = "0",
version = "unspecified", version = "unspecified",
product.defaultmilestone = "---" product.defaultmilestone = constants.DEFAULT_MILESTONE
%] %]
<form method="post" action="editproducts.cgi"> <form method="post" action="editproducts.cgi">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment