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