Commit 1afb5b3b authored by lpsolit%gmail.com's avatar lpsolit%gmail.com

Bug 376497: validateID() should return an attachment object - Patch by…

Bug 376497: validateID() should return an attachment object - Patch by Fré©ric Buclin <LpSolit@gmail.com> a=LpSolit
parent 52c8d09d
...@@ -728,8 +728,8 @@ sub insert_attachment_for_bug { ...@@ -728,8 +728,8 @@ sub insert_attachment_for_bug {
my $filename; my $filename;
my $contenttype; my $contenttype;
my $isurl; my $isurl;
$class->validate_is_patch($throw_error) || return 0; $class->validate_is_patch($throw_error) || return;
$class->validate_description($throw_error) || return 0; $class->validate_description($throw_error) || return;
if (Bugzilla->params->{'allow_attach_url'} if (Bugzilla->params->{'allow_attach_url'}
&& ($attachurl =~ /^(http|https|ftp):\/\/\S+/) && ($attachurl =~ /^(http|https|ftp):\/\/\S+/)
...@@ -743,16 +743,16 @@ sub insert_attachment_for_bug { ...@@ -743,16 +743,16 @@ sub insert_attachment_for_bug {
$cgi->delete('bigfile'); $cgi->delete('bigfile');
} }
else { else {
$filename = _validate_filename($throw_error) || return 0; $filename = _validate_filename($throw_error) || return;
# need to validate content type before data as # need to validate content type before data as
# we now check the content type for image/bmp in _validate_data() # we now check the content type for image/bmp in _validate_data()
unless ($cgi->param('ispatch')) { unless ($cgi->param('ispatch')) {
$class->validate_content_type($throw_error) || return 0; $class->validate_content_type($throw_error) || return;
} }
$data = _validate_data($throw_error, $hr_vars); $data = _validate_data($throw_error, $hr_vars);
# If the attachment is stored locally, $data eq ''. # If the attachment is stored locally, $data eq ''.
# If an error is thrown, $data eq '0'. # If an error is thrown, $data eq '0'.
($data ne '0') || return 0; ($data ne '0') || return;
$contenttype = $cgi->param('contenttype'); $contenttype = $cgi->param('contenttype');
# These are inserted using placeholders so no need to panic # These are inserted using placeholders so no need to panic
...@@ -826,7 +826,7 @@ sub insert_attachment_for_bug { ...@@ -826,7 +826,7 @@ sub insert_attachment_for_bug {
close AH; close AH;
close $fh; close $fh;
unlink "$attachdir/$hash/attachment.$attachid"; unlink "$attachdir/$hash/attachment.$attachid";
$throw_error ? ThrowUserError("local_file_too_large") : return 0; $throw_error ? ThrowUserError("local_file_too_large") : return;
} }
} }
close AH; close AH;
...@@ -874,8 +874,8 @@ sub insert_attachment_for_bug { ...@@ -874,8 +874,8 @@ sub insert_attachment_for_bug {
$$hr_vars->{'flag_creation_error'} = $@; $$hr_vars->{'flag_creation_error'} = $@;
} }
# Return the ID of the new attachment. # Return the new attachment object.
return $attachid; return $attachment;
} }
1; 1;
...@@ -187,15 +187,15 @@ if (defined $cgi->param('version')) { ...@@ -187,15 +187,15 @@ if (defined $cgi->param('version')) {
# Add an attachment if requested. # Add an attachment if requested.
if (defined($cgi->upload('data')) || $cgi->param('attachurl')) { if (defined($cgi->upload('data')) || $cgi->param('attachurl')) {
$cgi->param('isprivate', $cgi->param('commentprivacy')); $cgi->param('isprivate', $cgi->param('commentprivacy'));
my $attach_id = Bugzilla::Attachment->insert_attachment_for_bug(!THROW_ERROR, my $attachment = Bugzilla::Attachment->insert_attachment_for_bug(!THROW_ERROR,
$bug, $user, $timestamp, \$vars); $bug, $user, $timestamp, \$vars);
if ($attach_id) { if ($attachment) {
# Update the comment to include the new attachment ID. # Update the comment to include the new attachment ID.
# This string is hardcoded here because Template::quoteUrls() # This string is hardcoded here because Template::quoteUrls()
# expects to find this exact string. # expects to find this exact string.
my $new_comment = "Created an attachment (id=$attach_id)\n" . my $new_comment = "Created an attachment (id=" . $attachment->id . ")\n" .
$cgi->param('description') . "\n"; $attachment->description . "\n";
# We can use $bug->longdescs here because we are sure that the bug # We can use $bug->longdescs here because we are sure that the bug
# description is of type CMT_NORMAL. No need to include it if it's # description is of type CMT_NORMAL. No need to include it if it's
# empty, though. # empty, though.
......
...@@ -20,10 +20,7 @@ ...@@ -20,10 +20,7 @@
#%] #%]
[%# INTERFACE: [%# INTERFACE:
# bugid: integer. ID of the bug we just attached an attachment to. # attachment: object of the attachment just created.
# attachid: integer. ID of the attachment just created.
# description: string. Description of the attachment just created.
# contenttype: string. The Content Type we attached it as.
# contenttypemethod: string. How we got the content type of the attachment. # contenttypemethod: string. How we got the content type of the attachment.
# Possible values: autodetect, list, manual. # Possible values: autodetect, list, manual.
#%] #%]
...@@ -36,11 +33,12 @@ ...@@ -36,11 +33,12 @@
<dl> <dl>
<dt> <dt>
<a title="[% description FILTER html %]" href="attachment.cgi?id=[% attachid %]&amp;action=edit">Attachment #[% attachid %]</a> <a title="[% attachment.description FILTER html %]"
to [% "$terms.bug $bugid" FILTER bug_link(bugid) %] created href="attachment.cgi?id=[% attachment.id %]&amp;action=edit">Attachment #[% attachment.id %]</a>
to [% "$terms.bug $attachment.bug_id" FILTER bug_link(attachment.bug_id) FILTER none %] created
</dt> </dt>
<dd> <dd>
[% PROCESS "bug/process/bugmail.html.tmpl" mailing_bugid = bugid %] [% PROCESS "bug/process/bugmail.html.tmpl" mailing_bugid = attachment.bug_id %]
[% IF convertedbmp %] [% IF convertedbmp %]
<p> <p>
<b>Note:</b> [% terms.Bugzilla %] automatically converted your BMP image file to a <b>Note:</b> [% terms.Bugzilla %] automatically converted your BMP image file to a
...@@ -50,9 +48,9 @@ ...@@ -50,9 +48,9 @@
[% IF contenttypemethod == 'autodetect' %] [% IF contenttypemethod == 'autodetect' %]
<p> <p>
<b>Note:</b> [% terms.Bugzilla %] automatically detected the content type <b>Note:</b> [% terms.Bugzilla %] automatically detected the content type
<em>[% contenttype %]</em> for this attachment. If this is <em>[% attachment.contenttype FILTER html %]</em> for this attachment. If this is
incorrect, correct the value by incorrect, correct the value by editing the attachment's
editing the attachment's <a href="attachment.cgi?id=[% attachid %]&amp;action=edit">details</a>. <a href="attachment.cgi?id=[% attachment.id %]&amp;action=edit">details</a>.
</p> </p>
[% END %] [% END %]
...@@ -62,8 +60,8 @@ ...@@ -62,8 +60,8 @@
</dl> </dl>
<p> <p>
<a href="attachment.cgi?bugid=[% bugid %]&amp;action=enter">Create <a href="attachment.cgi?bugid=[% attachment.bug_id %]&amp;action=enter">Create
Another Attachment to [% terms.Bug %] #[% bugid %]</a> Another Attachment to [% terms.Bug %] #[% attachment.bug_id %]</a>
</p> </p>
[% PROCESS global/footer.html.tmpl %] [% PROCESS global/footer.html.tmpl %]
...@@ -15,12 +15,12 @@ ...@@ -15,12 +15,12 @@
#%] #%]
[%# INTERFACE: [%# INTERFACE:
# attachid: ID of the attachment the user wants to delete. # attachment: object of the attachment the user wants to delete.
# reason: string; The reason provided by the user. # reason: string; The reason provided by the user.
# date: the date when the request to delete the attachment was made. # date: the date when the request to delete the attachment was made.
#%] #%]
The content of attachment [% attachid %] has been deleted by The content of attachment [% attachment.id %] has been deleted by
[%+ user.identity %] [%+ user.identity %]
[% IF reason %] [% IF reason %]
who provided the following reason: who provided the following reason:
......
...@@ -21,8 +21,7 @@ ...@@ -21,8 +21,7 @@
#%] #%]
[%# INTERFACE: [%# INTERFACE:
# bugid: integer. ID of the bug we are updating. # attachment: object of the attachment we just attached.
# attachid: integer. ID of the attachment we just attached.
#%] #%]
[% PROCESS global/variables.none.tmpl %] [% PROCESS global/variables.none.tmpl %]
...@@ -33,11 +32,11 @@ ...@@ -33,11 +32,11 @@
<dl> <dl>
<dt>Changes to <dt>Changes to
<a href="attachment.cgi?id=[% attachid %]&amp;action=edit">attachment [% attachid %]</a> <a href="attachment.cgi?id=[% attachment.id %]&amp;action=edit">attachment [% attachment.id %]</a>
of [% "$terms.bug $bugid" FILTER bug_link(bugid) %] submitted of [% "$terms.bug $attachment.bug_id" FILTER bug_link(attachment.bug_id) FILTER none %] submitted
</dt> </dt>
<dd> <dd>
[% PROCESS "bug/process/bugmail.html.tmpl" mailing_bugid = bugid %] [% PROCESS "bug/process/bugmail.html.tmpl" mailing_bugid = attachment.bug_id %]
[%# Links to more information about the changed bug. %] [%# Links to more information about the changed bug. %]
[% Hook.process("links") %] [% Hook.process("links") %]
</dd> </dd>
......
...@@ -414,10 +414,8 @@ ...@@ -414,10 +414,8 @@
], ],
'attachment/created.html.tmpl' => [ 'attachment/created.html.tmpl' => [
'attachid', 'attachment.id',
'bugid', 'attachment.bug_id',
'contenttype',
'"$terms.bug $bugid" FILTER bug_link(bugid)',
], ],
'attachment/edit.html.tmpl' => [ 'attachment/edit.html.tmpl' => [
...@@ -439,8 +437,7 @@ ...@@ -439,8 +437,7 @@
], ],
'attachment/updated.html.tmpl' => [ 'attachment/updated.html.tmpl' => [
'attachid', 'attachment.id',
'"$terms.bug $bugid" FILTER bug_link(bugid)',
], ],
'attachment/diff-header.html.tmpl' => [ 'attachment/diff-header.html.tmpl' => [
......
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