Check if the product is "open" explicitly in editproducts.cgi until we have a single "save" method

beta
Vitaliy Filippov 2018-12-21 18:21:22 +03:00
parent d31c230159
commit d3257ad482
2 changed files with 42 additions and 29 deletions

View File

@ -168,6 +168,7 @@ sub update
my $self = shift; my $self = shift;
my $dbh = Bugzilla->dbh; my $dbh = Bugzilla->dbh;
# This is for future when we'll have a single "save" (create/update) method
my $is_new = !$self->id; my $is_new = !$self->id;
# Don't update the DB if something goes wrong below -> transaction. # Don't update the DB if something goes wrong below -> transaction.
@ -277,31 +278,7 @@ sub update
my $new_settings = $self->group_controls; my $new_settings = $self->group_controls;
my $timestamp = $dbh->selectrow_array('SELECT NOW()'); my $timestamp = $dbh->selectrow_array('SELECT NOW()');
if (Bugzilla->config->{forbid_open_products}) $self->check_open_product;
{
my $has_mandatory = 0;
my $has_entry = 0;
foreach my $gid (keys %$new_settings)
{
if ($new_settings->{$gid}->{entry})
{
$has_entry = 1;
}
if ($new_settings->{$gid}->{membercontrol} == CONTROLMAPMANDATORY &&
$new_settings->{$gid}->{othercontrol} == CONTROLMAPMANDATORY)
{
$has_mandatory = 1;
}
}
if (!$has_mandatory)
{
ThrowUserError('product_mandatory_group_required');
}
if (!$has_entry)
{
ThrowUserError('product_entry_group_required');
}
}
foreach my $gid (keys %$new_settings) foreach my $gid (keys %$new_settings)
{ {
@ -440,6 +417,37 @@ sub update
return $changes; return $changes;
} }
sub check_open_product
{
my $self = shift;
if (Bugzilla->params->{forbid_open_products})
{
my $new_settings = $self->group_controls;
my $has_mandatory = 0;
my $has_entry = 0;
foreach my $gid (keys %$new_settings)
{
if ($new_settings->{$gid}->{entry})
{
$has_entry = 1;
}
if ($new_settings->{$gid}->{membercontrol} == CONTROLMAPMANDATORY &&
$new_settings->{$gid}->{othercontrol} == CONTROLMAPMANDATORY)
{
$has_mandatory = 1;
}
}
if (!$has_mandatory)
{
ThrowUserError('product_mandatory_group_required');
}
if (!$has_entry)
{
ThrowUserError('product_entry_group_required');
}
}
}
sub remove_from_db sub remove_from_db
{ {
my ($self, $params) = @_; my ($self, $params) = @_;
@ -660,9 +668,9 @@ sub _create_bug_group
# Associate the new group and new product. # Associate the new group and new product.
$dbh->do( $dbh->do(
'INSERT INTO group_control_map (group_id, product_id, membercontrol, othercontrol, editcomponents)'. 'INSERT INTO group_control_map (group_id, product_id, membercontrol, othercontrol, editcomponents, entry)'.
' VALUES (?, ?, ?, ?, ?)', undef, $group->id, $self->id, ' VALUES (?, ?, ?, ?, ?, ?)', undef, $group->id, $self->id,
($create_admin_group ? (0, 0, 1) : (CONTROLMAPMANDATORY, CONTROLMAPMANDATORY, 0)) ($create_admin_group ? (0, 0, 1, 0) : (CONTROLMAPMANDATORY, CONTROLMAPMANDATORY, 0, 1))
); );
# Grant current user permission to edit the new group and include him in it # Grant current user permission to edit the new group and include him in it

View File

@ -189,6 +189,9 @@ if ($action eq 'new')
$create_params{maxvotesperbug} = $ARGS->{maxvotesperbug}; $create_params{maxvotesperbug} = $ARGS->{maxvotesperbug};
$create_params{votestoconfirm} = $ARGS->{votestoconfirm}; $create_params{votestoconfirm} = $ARGS->{votestoconfirm};
} }
Bugzilla->dbh->bz_start_transaction();
my $product = Bugzilla::Product->create(\%create_params); my $product = Bugzilla::Product->create(\%create_params);
# Create groups and series for the new product, if requested. # Create groups and series for the new product, if requested.
@ -200,9 +203,11 @@ if ($action eq 'new')
$product->_create_bug_group(1, $new_bug_group); $product->_create_bug_group(1, $new_bug_group);
} }
$product->_create_series() if $ARGS->{createseries}; $product->_create_series() if $ARGS->{createseries};
$product->check_open_product();
delete_token($token); delete_token($token);
Bugzilla->dbh->bz_commit_transaction();
$vars->{message} = 'product_created'; $vars->{message} = 'product_created';
$vars->{product} = $product; $vars->{product} = $product;
if ($useclassification) if ($useclassification)