[Rt-commit] rt branch, 4.4/attach-from-transactions, repushed
? sunnavy
sunnavy at bestpractical.com
Sun Aug 9 13:18:52 EDT 2015
The branch 4.4/attach-from-transactions was deleted and repushed:
was f54f1b6e56cb0dbbd347d037282c1e13c00e99f9
now bd700c1f1f2302217c9f974fb134732e1d53e65a
1: 0f43ef5 ! 1: a7bc597 Add the ability to include existing attachments when responding to a transaction
@@ -91,8 +91,8 @@
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@
- Sign => ( $args{ARGSRef}->{'Sign'} ? 1 : 0 ),
- Encrypt => ( $args{ARGSRef}->{'Encrypt'} ? 1 : 0 ),
+ Sign => $args{ARGSRef}->{'Sign'},
+ Encrypt => $args{ARGSRef}->{'Encrypt'},
MIMEObj => $Message,
- TimeTaken => $args{ARGSRef}->{'UpdateTimeWorked'}
+ TimeTaken => $args{ARGSRef}->{'UpdateTimeWorked'},
@@ -105,8 +105,8 @@
--- a/lib/RT/Ticket.pm
+++ b/lib/RT/Ticket.pm
@@
+ NoteType => 'Correspond',
TimeTaken => 0,
- CommitScrips => 1,
SquelchMailTo => undef,
+ AttachExisting => [],
@_
@@ -135,36 +135,44 @@
--- a/share/html/Ticket/Elements/AddAttachments
+++ b/share/html/Ticket/Elements/AddAttachments
@@
+
<tr><td class="label"><&|/l&>Attach</&>:</td><td><input name="Attach" type="file" /><input type="submit" class="button" name="AddMoreAttach" value="<&|/l&>Add More Files</&>" /><input type="hidden" class="hidden" name="UpdateAttach" value="1" />
</td></tr>
-
+% if (@quoted_attachments) {
+<tr>
-+ <td class="label"><&|/l&>Include attachments</&>:</td>
++ <td class="label" valign="top"><&|/l&>Include attachments</&>:</td>
+ <td>
+% for my $attach (@quoted_attachments) {
+ <label>
+ <input type="checkbox" class="checkbox" name="AttachExisting" value="<% $attach->Id %>" \
+ <% (grep { $attach->Id == $_ } @AttachExisting) ? 'checked' : '' %> />
+ <% $attach->Filename %>
-+ </label>
++ </label><br />
+% }
+ </td>
+</tr>
+% }
-+<%init>
+ % $m->callback( %ARGS, CallbackName => 'End' );
+ <%ARGS>
+ $Token => ''
++ at AttachExisting => ()
++$QuoteTransaction => ''
+ </%ARGS>
+ <%INIT>
+ my $attachments;
+ if ( exists $session{'Attachments'}{ $Token } && keys %{ $session{'Attachments'}{ $Token } } ) {
+ $attachments = $session{'Attachments'}{ $Token };
+ }
++
+my @quoted_attachments;
+if ($QuoteTransaction) {
+ my $txn = RT::Transaction->new( $session{'CurrentUser'} );
+ $txn->Load($QuoteTransaction);
+ if ($txn->Id and $txn->CurrentUserCanSee) {
-+ @quoted_attachments = grep { defined $_->Filename and length $_->Filename }
++ @quoted_attachments = sort { lc($a->Filename) cmp lc($b->Filename) }
++ grep { defined $_->Filename and length $_->Filename }
+ @{$txn->Attachments->ItemsArrayRef};
+ }
+}
-+</%init>
-+<%args>
-+ at AttachExisting => ()
-+$QuoteTransaction => ''
-+</%args>
+ </%INIT>
2: 7b0cb85 = 2: 0da0f88 Simplify the copying of RT-Attach headers from the txn into the mail
3: af0c0ad < --: ------- Each include attachment checkbox and filename gets its own line
4: ea61a55 ! 3: 01348d6 Display RT-Attach headers in history by linking the filename
@@ -7,13 +7,13 @@
future, but it's an acceptable edge case at the moment since we avoid
storing the attachment twice.
-diff --git a/share/html/Ticket/Elements/ShowMessageHeaders b/share/html/Ticket/Elements/ShowMessageHeaders
---- a/share/html/Ticket/Elements/ShowMessageHeaders
-+++ b/share/html/Ticket/Elements/ShowMessageHeaders
+diff --git a/share/html/Elements/ShowMessageHeaders b/share/html/Elements/ShowMessageHeaders
+--- a/share/html/Elements/ShowMessageHeaders
++++ b/share/html/Elements/ShowMessageHeaders
@@
- my $ticket = $Message->TransactionObj->TicketObj;
+ my $object = $Message->TransactionObj->Object;
foreach my $f (@headers) {
- $m->comp('/Elements/MakeClicky', content => \$f->{'Value'}, ticket => $ticket, %ARGS);
+ $m->comp('/Elements/MakeClicky', content => \$f->{'Value'}, object => $object, %ARGS);
+ if ($f->{'Tag'} eq 'RT-Attach') {
+ # Blat in the filename and linkify
+ my $att = RT::Attachment->new( $session{'CurrentUser'} );
@@ -27,11 +27,11 @@
+ }
}
- if ( $Localize ) {
+ unshift @headers, $m->comp( 'CryptStatus', Message => $Message, WarnUnsigned => $WarnUnsigned );
-diff --git a/share/html/Ticket/Elements/ShowTransactionAttachments b/share/html/Ticket/Elements/ShowTransactionAttachments
---- a/share/html/Ticket/Elements/ShowTransactionAttachments
-+++ b/share/html/Ticket/Elements/ShowTransactionAttachments
+diff --git a/share/html/Elements/ShowTransactionAttachments b/share/html/Elements/ShowTransactionAttachments
+--- a/share/html/Elements/ShowTransactionAttachments
++++ b/share/html/Elements/ShowTransactionAttachments
@@
# If the transaction has anything attached to it at all
5: d887781 < --: ------- Consistently order the existing attachment checkboxes by name
9: d164d13 ! 4: 1ef7d36 Headers often come with leading spaces, which make SQLite choke on comparisons
@@ -19,12 +19,12 @@
$attach->Load($id);
next unless $attach->Id
-diff --git a/share/html/Ticket/Elements/ShowMessageHeaders b/share/html/Ticket/Elements/ShowMessageHeaders
---- a/share/html/Ticket/Elements/ShowMessageHeaders
-+++ b/share/html/Ticket/Elements/ShowMessageHeaders
+diff --git a/share/html/Elements/ShowMessageHeaders b/share/html/Elements/ShowMessageHeaders
+--- a/share/html/Elements/ShowMessageHeaders
++++ b/share/html/Elements/ShowMessageHeaders
@@
foreach my $f (@headers) {
- $m->comp('/Elements/MakeClicky', content => \$f->{'Value'}, ticket => $ticket, %ARGS);
+ $m->comp('/Elements/MakeClicky', content => \$f->{'Value'}, object => $object, %ARGS);
if ($f->{'Tag'} eq 'RT-Attach') {
+ $f->{'Value'} =~ s/(?:^\s*|\s*$)//g;
+
--: ------- > 5: 66db6d3 Link to the download page for existing attachments
--: ------- > 6: d1982c2 Don't present transaction attachments when we don't have an existing ticket
13: 52dcce0 = 7: 216627f email could be multipart already before calling AddAttachmentsFromHeaders
6: 4ad6fdf ! 8: bd700c1 Tests for the new RT-Attach functionality
@@ -16,8 +16,9 @@
+++ b/t/web/attach-from-txn.t
@@
+use strict;
-+
-+use RT::Test tests => 46;
++use warnings;
++
++use RT::Test tests => 70;
+
+my $LogoName = 'image.png';
+my $ImageName = 'owls.jpg';
@@ -113,16 +114,49 @@
+like $mail, qr/RT-Attachment: \d+\/\d+\/\d+/, "found RT-Attachment header";
+like $mail, qr/filename=.?\Q$ImageName\E.?/, "found filename";
+
++# Reply to first correspondence, including an attachment with an uploaded one
++$m->follow_link_ok({text => 'Reply', n => 3}, "reply to the reply");
++$m->form_name('TicketUpdate');
++$m->current_form->find_input('AttachExisting', 'checkbox', 2)->check; # owls.jpg
++$m->field( 'UpdateContent', 'attachments from both list and upload' );
++$m->field('Attach', $LogoFile);
++$m->click('SubmitTicket');
++is($m->status, 200, "request successful");
++
++# yep, we got it and processed the header!
++$m->content_contains('attachments from both list and upload');
++$m->content_like(qr/(RT-Attach:.+?\Q$ImageName\E).*\1/s, 'found rt attach header');
++$m->content_like(qr/Subject:.+?\Q$LogoName\E/s, 'found rt attach header');
++
++# outgoing looks good
++$m->follow_link_ok({text => 'Show', n => 4}, "found show link");
++$m->content_like(qr/RT-Attach: \d+/, "found RT-Attach header");
++$m->content_like(qr/RT-Attachment: \d+\/\d+\/\d+/, "found RT-Attachment header");
++$m->content_lacks($ImageName);
++$m->content_lacks($LogoName);
++$m->back;
++
++# check that it got into mail
++ at mails = RT::Test->fetch_caught_mails;
++is scalar @mails, 1, "got one outgoing email";
++$mail = shift @mails;
++like $mail, qr/To: owls\@localhost/, 'got To';
++like $mail, qr/RT-Attach: \d+/, "found attachment we expected";
++like $mail, qr/RT-Attachment: \d+\/\d+\/\d+/, "found RT-Attachment header";
++like $mail, qr/filename=.?\Q$ImageName\E.?/, "found selected filename";
++like $mail, qr/filename=.?\Q$LogoName\E.?/, "found uploaded filename";
++
+# add header to template, make a normal reply, and see that it worked
+my $link = $m->find_link(text_regex => qr/\Q$LogoName\E/, url_regex => qr/Attachment/);
+ok $link;
-+my ($id) = $link->url =~ /Attachment\/\d+\/(\d+)/;
-+ok $id;
++my ($LogoId) = $link->url =~ /Attachment\/\d+\/(\d+)/;
++ok $LogoId;
+my $template = RT::Template->new( RT->SystemUser );
-+$template->LoadGlobalTemplate('Correspondence');
++$template->LoadGlobalTemplate('Correspondence in HTML');
+ok $template->Id;
-+$template->SetContent( "RT-Attach: $id\n" . $template->Content );
-+like $template->Content, qr/RT-Attach/, "updated template";
++my $old_template = $template->Content;
++$template->SetContent( "RT-Attach: $LogoId\n" . $template->Content );
++like $template->Content, qr/RT-Attach:/, "updated template";
+
+# reply...
+$m->follow_link_ok({text => 'Reply'}, "reply to the ticket");
@@ -133,11 +167,35 @@
+$m->content_contains('who gives a hoot');
+
+# then see if we got the right mail
-+my @mails = RT::Test->fetch_caught_mails;
-+is scalar @mails, 1, "got one outgoing email";
-+my $mail = shift @mails;
++ at mails = RT::Test->fetch_caught_mails;
++is scalar @mails, 1, "got one outgoing email";
++$mail = shift @mails;
+like $mail, qr/To: owls\@localhost/, 'got To';
-+like $mail, qr/RT-Attach: $id/, "found attachment we expected";
-+like $mail, qr/RT-Attachment: \d+\/\d+\/$id/, "found RT-Attachment header";
++like $mail, qr/RT-Attach: $LogoId/, "found attachment we expected";
++like $mail, qr/RT-Attachment: \d+\/\d+\/$LogoId/, "found RT-Attachment header";
+like $mail, qr/filename=.?\Q$LogoName\E.?/, "found filename";
-
++
++# create a new, privileged user who can't see this ticket but can reply
++$template->SetContent($old_template);
++unlike $template->Content, qr/RT-Attach:/, "no header in template anymore";
++
++my $peter = RT::Test->load_or_create_user(
++ Name => 'peter',
++ EmailAddress => 'peter at localhost',
++);
++ok( RT::Test->add_rights({ Principal => 'Everyone', Right => [qw(ReplyToTicket)] }), 'add ReplyToTicket rights');
++
++my $ticket = RT::Ticket->new($peter);
++$ticket->Load(1);
++ok $ticket->Id, "loaded ticket";
++
++my ($ok, $msg, $txn) = $ticket->Correspond( AttachExisting => $LogoId, Content => 'Hi' );
++ok $ok, $msg;
++
++# check mail that went out doesn't contain the logo
++ at mails = RT::Test->fetch_caught_mails;
++is scalar @mails, 1, "got one outgoing email";
++$mail = shift @mails;
++like $mail, qr/RT-Attach: $LogoId/, "found header we expected";
++unlike $mail, qr/RT-Attachment: \d+\/\d+\/$LogoId/, "lacks RT-Attachment header";
++unlike $mail, qr/filename=.?\Q$LogoName\E.?/, "lacks filename";
7: 9fe31d1 < --: ------- Test that users who can't see an attachment can't attach it
8: 2844b2a < --: ------- Avoid some "masks earlier declaration" warnings
10: ae16e97 < --: ------- Link to the download page for existing attachments
11: dbcab60 < --: ------- Move the link out of the label so clicking doesn't both open the attachment and select it for inclusion
12: 923d73c < --: ------- Don't present transaction attachments when we don't have an existing ticket
14: f54f1b6 < --: ------- test attachments selection with uploaded ones in the mean time
More information about the rt-commit
mailing list