From: dkl%redhat.com <> Date: Sat, 28 Jun 2008 00:47:15 +0000 (+0000) Subject: Bug 422691 – Attachment gets added twice after hitting "Back" and "Refresh" X-Git-Tag: bugzilla-3.2rc1~48 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d7f29d0fa0f3914e17082383a91194d6569c12d8;p=thirdparty%2Fbugzilla.git Bug 422691 – Attachment gets added twice after hitting "Back" and "Refresh" Patch by David Lawrence - r/a=LpSolit --- diff --git a/attachment.cgi b/attachment.cgi index 937087a519..2520c00320 100755 --- a/attachment.cgi +++ b/attachment.cgi @@ -327,6 +327,7 @@ sub enter { 'component_id' => $bug->component_id}); $vars->{'flag_types'} = $flag_types; $vars->{'any_flags_requesteeble'} = grep($_->is_requesteeble, @$flag_types); + $vars->{'token'} = issue_session_token('createattachment:'); print $cgi->header(); @@ -348,6 +349,30 @@ sub insert { validateCanChangeBug($bugid); my ($timestamp) = Bugzilla->dbh->selectrow_array("SELECT NOW()"); + # Detect if the user already used the same form to submit an attachment + my $token = trim($cgi->param('token')); + if ($token) { + my ($creator_id, $date, $old_attach_id) = Bugzilla::Token::GetTokenData($token); + unless ($creator_id + && ($creator_id == $user->id) + && ($old_attach_id =~ "^createattachment:")) + { + # The token is invalid. + ThrowUserError('token_does_not_exist'); + } + + $old_attach_id =~ s/^createattachment://; + + if ($old_attach_id) { + $vars->{'bugid'} = $bugid; + $vars->{'attachid'} = $old_attach_id; + print $cgi->header(); + $template->process("attachment/cancel-create-dupe.html.tmpl", $vars) + || ThrowTemplateError($template->error()); + exit; + } + } + my $bug = new Bugzilla::Bug($bugid); my $attachment = Bugzilla::Attachment->insert_attachment_for_bug(THROW_ERROR, $bug, $user, @@ -379,6 +404,12 @@ sub insert { } $bug->update($timestamp); + if ($token) { + trick_taint($token); + $dbh->do('UPDATE tokens SET eventdata = ? WHERE token = ?', undef, + ("createattachment:" . $attachment->id, $token)); + } + $dbh->bz_commit_transaction; # Define the variables and functions that will be passed to the UI template. diff --git a/template/en/default/attachment/cancel-create-dupe.html.tmpl b/template/en/default/attachment/cancel-create-dupe.html.tmpl new file mode 100644 index 0000000000..f838955bca --- /dev/null +++ b/template/en/default/attachment/cancel-create-dupe.html.tmpl @@ -0,0 +1,48 @@ +[%# The contents of this file are subject to the Mozilla Public + # License Version 1.1 (the "License"); you may not use this file + # except in compliance with the License. You may obtain a copy of + # the License at http://www.mozilla.org/MPL/ + # + # Software distributed under the License is distributed on an "AS + # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + # implied. See the License for the specific language governing + # rights and limitations under the License. + # + # The Original Code is the Bugzilla Bug Tracking System. + # + # The Initial Developer of the Original Code is Olav Vitters. + # + # Contributor(s): Olav Vitters + # David Lawrence + #%] + +[%# INTERFACE: + # bugid: integer. ID of the bug report that this attachment relates to. + # attachid: integer. ID of the previous attachment recently created. + #%] + +[% PROCESS "global/field-descs.none.tmpl" %] + +[% PROCESS global/header.html.tmpl + title = "Already filed attachment" +%] + +[% USE Bugzilla %] + + + + + +
+ + You already used the form to file + attachment [% attachid FILTER url_quote %]. + +
+ +

+ You can either + create a new attachment or [% "go back to $terms.bug $bugid" FILTER bug_link(bugid) FILTER none %]. +

+ +[% PROCESS global/footer.html.tmpl %] diff --git a/template/en/default/attachment/create.html.tmpl b/template/en/default/attachment/create.html.tmpl index 7944228f37..10648159b8 100644 --- a/template/en/default/attachment/create.html.tmpl +++ b/template/en/default/attachment/create.html.tmpl @@ -42,6 +42,7 @@

+ [% PROCESS attachment/createformcontents.html.tmpl %]