Commit cc3a19cb authored by mkanat%bugzilla.org's avatar mkanat%bugzilla.org

Bug 351888: Move comment creation out of post_bug.cgi and into Bugzilla::Bug

Patch By Max Kanat-Alexander <mkanat@bugzilla.org> r=mkanat, a=myk
parent 4d734cd3
...@@ -116,6 +116,8 @@ sub VALIDATORS { ...@@ -116,6 +116,8 @@ sub VALIDATORS {
bug_file_loc => \&_check_bug_file_loc, bug_file_loc => \&_check_bug_file_loc,
bug_severity => \&_check_bug_severity, bug_severity => \&_check_bug_severity,
cc => \&_check_cc, cc => \&_check_cc,
comment => \&_check_comment,
commentprivacy => \&_check_commentprivacy,
deadline => \&_check_deadline, deadline => \&_check_deadline,
estimated_time => \&_check_estimated_time, estimated_time => \&_check_estimated_time,
keywords => \&_check_keywords, keywords => \&_check_keywords,
...@@ -253,6 +255,9 @@ sub create { ...@@ -253,6 +255,9 @@ sub create {
delete $params->{dependson}; delete $params->{dependson};
my $blocked = $params->{blocked}; my $blocked = $params->{blocked};
delete $params->{blocked}; delete $params->{blocked};
my ($comment, $privacy) = ($params->{comment}, $params->{commentprivacy});
delete $params->{comment};
delete $params->{commentprivacy};
# Set up the keyword cache for bug creation. # Set up the keyword cache for bug creation.
my $keywords = $params->{keywords}; my $keywords = $params->{keywords};
...@@ -264,6 +269,10 @@ sub create { ...@@ -264,6 +269,10 @@ sub create {
my $timestamp = $params->{creation_ts}; my $timestamp = $params->{creation_ts};
delete $params->{creation_ts}; delete $params->{creation_ts};
$dbh->bz_lock_tables('bugs WRITE', 'bug_group_map WRITE',
'longdescs WRITE', 'cc WRITE', 'keywords WRITE', 'dependencies WRITE',
'bugs_activity WRITE', 'fielddefs READ');
my $bug = $class->insert_create_data($params); my $bug = $class->insert_create_data($params);
# Add the group restrictions # Add the group restrictions
...@@ -296,15 +305,23 @@ sub create { ...@@ -296,15 +305,23 @@ sub create {
$sth_deps->execute($bug->bug_id, $depends_on_id); $sth_deps->execute($bug->bug_id, $depends_on_id);
# Log the reverse action on the other bug. # Log the reverse action on the other bug.
LogActivityEntry($depends_on_id, 'blocked', '', $bug->bug_id, LogActivityEntry($depends_on_id, 'blocked', '', $bug->bug_id,
$bug->reporter->id, $timestamp); $bug->{reporter_id}, $timestamp);
} }
foreach my $blocked_id (@$blocked) { foreach my $blocked_id (@$blocked) {
$sth_deps->execute($blocked_id, $bug->bug_id); $sth_deps->execute($blocked_id, $bug->bug_id);
# Log the reverse action on the other bug. # Log the reverse action on the other bug.
LogActivityEntry($blocked_id, 'dependson', '', $bug->bug_id, LogActivityEntry($blocked_id, 'dependson', '', $bug->bug_id,
$bug->reporter->id, $timestamp); $bug->{reporter_id}, $timestamp);
} }
# And insert the comment. We always insert a comment on bug creation,
# but sometimes it's blank.
$dbh->do('INSERT INTO longdescs (bug_id, who, bug_when, thetext, isprivate)
VALUES (?, ?, ?, ?, ?)', undef,
$bug->bug_id, $bug->{reporter_id}, $timestamp, $comment, $privacy);
$dbh->bz_unlock_tables();
return $bug; return $bug;
} }
...@@ -504,9 +521,7 @@ sub _check_cc { ...@@ -504,9 +521,7 @@ sub _check_cc {
sub _check_comment { sub _check_comment {
my ($invocant, $comment) = @_; my ($invocant, $comment) = @_;
if (!defined $comment) { $comment = '' unless defined $comment;
ThrowCodeError('undefined_field', { field => 'comment' });
}
# Remove any trailing whitespace. Leading whitespace could be # Remove any trailing whitespace. Leading whitespace could be
# a valid part of the comment. # a valid part of the comment.
...@@ -519,9 +534,20 @@ sub _check_comment { ...@@ -519,9 +534,20 @@ sub _check_comment {
ThrowUserError("description_required"); ThrowUserError("description_required");
} }
# On creation only, there must be a single-space comment, or
# email will be supressed.
$comment = ' ' if $comment eq '' && !ref($invocant);
return $comment; return $comment;
} }
sub _check_commentprivacy {
my ($invocant, $comment_privacy) = @_;
my $insider_group = Bugzilla->params->{"insidergroup"};
return ($insider_group && Bugzilla->user->in_group($insider_group)
&& $comment_privacy) ? 1 : 0;
}
sub _check_component { sub _check_component {
my ($invocant, $product, $name) = @_; my ($invocant, $product, $name) = @_;
$name = trim($name); $name = trim($name);
......
...@@ -270,7 +270,7 @@ use constant ABSTRACT_SCHEMA => { ...@@ -270,7 +270,7 @@ use constant ABSTRACT_SCHEMA => {
bug_when => {TYPE => 'DATETIME', NOTNULL => 1}, bug_when => {TYPE => 'DATETIME', NOTNULL => 1},
work_time => {TYPE => 'decimal(5,2)', NOTNULL => 1, work_time => {TYPE => 'decimal(5,2)', NOTNULL => 1,
DEFAULT => '0'}, DEFAULT => '0'},
thetext => {TYPE => 'MEDIUMTEXT'}, thetext => {TYPE => 'MEDIUMTEXT', NOTNULL => 1},
isprivate => {TYPE => 'BOOLEAN', NOTNULL => 1, isprivate => {TYPE => 'BOOLEAN', NOTNULL => 1,
DEFAULT => 'FALSE'}, DEFAULT => 'FALSE'},
already_wrapped => {TYPE => 'BOOLEAN', NOTNULL => 1, already_wrapped => {TYPE => 'BOOLEAN', NOTNULL => 1,
......
...@@ -493,6 +493,9 @@ sub update_table_definitions { ...@@ -493,6 +493,9 @@ sub update_table_definitions {
$dbh->bz_add_column('setting', 'subclass', {TYPE => 'varchar(32)'}); $dbh->bz_add_column('setting', 'subclass', {TYPE => 'varchar(32)'});
$dbh->bz_alter_column('longdescs', 'thetext',
{ TYPE => 'MEDIUMTEXT', NOTNULL => 1 }, '');
################################################################ ################################################################
# New --TABLE-- changes should go *** A B O V E *** this point # # New --TABLE-- changes should go *** A B O V E *** this point #
################################################################ ################################################################
......
...@@ -88,29 +88,6 @@ if ($token) { ...@@ -88,29 +88,6 @@ if ($token) {
'^requestee_type-(\d+)$' => { 'type' => 'multi' }, '^requestee_type-(\d+)$' => { 'type' => 'multi' },
}); });
# The format of the initial comment can be structured by adding fields to the
# enter_bug template and then referencing them in the comment template.
my $comment;
my $format = $template->get_format("bug/create/comment",
scalar($cgi->param('format')), "txt");
$template->process($format->{'template'}, $vars, \$comment)
|| ThrowTemplateError($template->error());
# Check that the product exists and that the user
# is allowed to enter bugs into this product.
my $product = Bugzilla::Bug->_check_product($cgi->param('product'));
# Set cookies
if (defined $cgi->param('product')) {
if (defined $cgi->param('version')) {
$cgi->send_cookie(-name => "VERSION-" . $product->name,
-value => $cgi->param('version'),
-expires => "Fri, 01-Jan-2038 00:00:00 GMT");
}
}
if (defined $cgi->param('maketemplate')) { if (defined $cgi->param('maketemplate')) {
$vars->{'url'} = $cgi->query_string(); $vars->{'url'} = $cgi->query_string();
$vars->{'short_desc'} = $cgi->param('short_desc'); $vars->{'short_desc'} = $cgi->param('short_desc');
...@@ -123,13 +100,6 @@ if (defined $cgi->param('maketemplate')) { ...@@ -123,13 +100,6 @@ if (defined $cgi->param('maketemplate')) {
umask 0; umask 0;
# This has to go somewhere after 'maketemplate'
# or it breaks bookmarks with no comments.
$comment = Bugzilla::Bug->_check_comment($cgi->param('comment'));
# If comment is all whitespace, it'll be null at this point. That's
# OK except for the fact that it causes e-mail to be suppressed.
$comment = $comment ? $comment : " ";
# get current time # get current time
my $timestamp = $dbh->selectrow_array(q{SELECT NOW()}); my $timestamp = $dbh->selectrow_array(q{SELECT NOW()});
...@@ -140,6 +110,14 @@ foreach my $group (grep(/^bit-\d+$/, $cgi->param())) { ...@@ -140,6 +110,14 @@ foreach my $group (grep(/^bit-\d+$/, $cgi->param())) {
push(@selected_groups, $1); push(@selected_groups, $1);
} }
# The format of the initial comment can be structured by adding fields to the
# enter_bug template and then referencing them in the comment template.
my $comment;
my $format = $template->get_format("bug/create/comment",
scalar($cgi->param('format')), "txt");
$template->process($format->{'template'}, $vars, \$comment)
|| ThrowTemplateError($template->error());
# Include custom fields editable on bug creation. # Include custom fields editable on bug creation.
my @custom_bug_fields = Bugzilla->get_fields( my @custom_bug_fields = Bugzilla->get_fields(
{ custom => 1, obsolete => 0, enter_bug => 1 }); { custom => 1, obsolete => 0, enter_bug => 1 });
...@@ -159,6 +137,7 @@ push(@bug_fields, qw( ...@@ -159,6 +137,7 @@ push(@bug_fields, qw(
alias alias
blocked blocked
commentprivacy
bug_file_loc bug_file_loc
bug_severity bug_severity
bug_status bug_status
...@@ -182,43 +161,21 @@ foreach my $field (@bug_fields) { ...@@ -182,43 +161,21 @@ foreach my $field (@bug_fields) {
$bug_params{'creation_ts'} = $timestamp; $bug_params{'creation_ts'} = $timestamp;
$bug_params{'cc'} = [$cgi->param('cc')]; $bug_params{'cc'} = [$cgi->param('cc')];
$bug_params{'groups'} = \@selected_groups; $bug_params{'groups'} = \@selected_groups;
$bug_params{'comment'} = $comment;
# Add the bug report to the DB.
$dbh->bz_lock_tables('bugs WRITE', 'bug_group_map WRITE', 'longdescs WRITE',
'cc WRITE', 'keywords WRITE', 'dependencies WRITE',
'bugs_activity WRITE', 'groups READ',
'user_group_map READ', 'group_group_map READ',
'keyworddefs READ', 'fielddefs READ',
'products READ', 'versions READ', 'milestones READ',
'components READ', 'profiles READ', 'bug_severity READ',
'op_sys READ', 'priority READ', 'rep_platform READ',
'group_control_map READ', @custom_tables);
my $bug = Bugzilla::Bug->create(\%bug_params); my $bug = Bugzilla::Bug->create(\%bug_params);
# Get the bug ID back. # Get the bug ID back.
my $id = $bug->bug_id; my $id = $bug->bug_id;
# Add the initial comment, allowing for the fact that it may be private # Set Version cookie, but only if the user actually selected
my $privacy = 0; # a version on the page.
if (Bugzilla->params->{"insidergroup"} if (defined $cgi->param('version')) {
&& Bugzilla->user->in_group(Bugzilla->params->{"insidergroup"})) $cgi->send_cookie(-name => "VERSION-" . $bug->product,
{ -value => $bug->version,
$privacy = $cgi->param('commentprivacy') ? 1 : 0; -expires => "Fri, 01-Jan-2038 00:00:00 GMT");
} }
trick_taint($comment);
$dbh->do(q{INSERT INTO longdescs (bug_id, who, bug_when, thetext,isprivate)
VALUES (?, ?, ?, ?, ?)}, undef, ($id, $user->id, $timestamp,
$comment, $privacy));
# All fields related to the newly created bug are set.
# The bug can now be made accessible.
$dbh->do("UPDATE bugs SET creation_ts = ? WHERE bug_id = ?",
undef, ($timestamp, $id));
$dbh->bz_unlock_tables();
# We don't have to check if the user can see the bug, because a user filing # We don't have to check if the user can see the bug, because a user filing
# a bug can always see it. You can't change reporter_accessible until # a bug can always see it. You can't change reporter_accessible until
# after the bug is filed. # after the bug is filed.
......
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