[Rt-commit] rt branch, 4.4/signature-spacing, created. rt-4.4.0-88-g0d14b71

Alex Vandiver alexmv at bestpractical.com
Fri May 6 04:59:54 EDT 2016


The branch, 4.4/signature-spacing has been created
        at  0d14b71228af2cbcea312c88cc9a89da2c622541 (commit)

- Log -----------------------------------------------------------------
commit 6329df1ac01288a3dc949418c87bb0f18a864e74
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Wed Oct 24 23:24:36 2012 +0800

    remove the unnecessary "\" because browsers ignore the first newline
    
    see also #21152

diff --git a/share/html/Elements/MessageBox b/share/html/Elements/MessageBox
index df858b1..9e98f8b 100644
--- a/share/html/Elements/MessageBox
+++ b/share/html/Elements/MessageBox
@@ -45,7 +45,7 @@
 %# those contributions and any derivatives thereof.
 %#
 %# END BPS TAGGED BLOCK }}}
-<textarea autocomplete="off" class="messagebox <% $Type eq 'text/html' ? 'richtext' : '' %>" <% $width_attr %>="<% $Width %>" rows="<% $Height %>" <% $wrap_type |n %> name="<% $Name %>" id="<% $Name %>">\
+<textarea autocomplete="off" class="messagebox <% $Type eq 'text/html' ? 'richtext' : '' %>" <% $width_attr %>="<% $Width %>" rows="<% $Height %>" <% $wrap_type |n %> name="<% $Name %>" id="<% $Name %>">
 % $m->comp('/Articles/Elements/IncludeArticle', %ARGS) if $IncludeArticle;
 % $m->callback( %ARGS, SignatureRef => \$signature, DefaultRef => \$Default, MessageRef => $message );
 % if (RT->Config->Get("SignatureAboveQuote", $session{'CurrentUser'})) {

commit 0d14b71228af2cbcea312c88cc9a89da2c622541
Author: Alex Vandiver <alex at chmrr.net>
Date:   Fri May 6 01:59:27 2016 -0700

    Tweak spaces around signature to provide useful default whitespace
    
    Most signatures don't have trailing newlines, additional newlines are
    necessary after the signature to give whitespace before showing the
    quote.  Additionally, having a blank line (or two) before the "-- \n"
    means there's an obvious place to click and start typing.  With
    signature-before-quote, this now gives (all examples use "." for a blank
    line):
        .
        .
         --
         Foo
         Bar
        .
         On Oct 18, you wrote:
         > ...
    
    This provides a blank line to click on and begin to type, as well as a
    blank line thereafter to separate the quote from the signature.
    
    With the standard signature-after setting, this now gives:
         On Oct 18, you wrote:
         > ...
        .
        .
        .
         --
         Foo
         Bar
    
    ...providing three blank lines in the middle.  This allows the user to
    click on the second one and start typing, but leave whitespace before
    and after their response.  Finally, if there's nothing to quote,
    regardless of the preference:
        .
        .
         --
         Foo
         Bar
    
    ..with a similar click-on-the-first-line use case as described above.
    All of the same behavior is preserved when HTML editing is enabled.

diff --git a/lib/RT/Transaction.pm b/lib/RT/Transaction.pm
index 372deeb..774fbe3 100644
--- a/lib/RT/Transaction.pm
+++ b/lib/RT/Transaction.pm
@@ -400,12 +400,12 @@ sub Content {
                 . $self->QuoteHeader
                 . '<br /><blockquote class="gmail_quote" type="cite">'
                 . $content
-                . '</blockquote></div><br /><br />';
+                . '</blockquote></div>';
         } else {
             $content = $self->ApplyQuoteWrap(content => $content,
                                              cols    => $args{'Wrap'} );
 
-            $content = $self->QuoteHeader . "\n$content\n\n";
+            $content = $self->QuoteHeader . "\n$content";
         }
     }
 
diff --git a/share/html/Elements/MessageBox b/share/html/Elements/MessageBox
index 9e98f8b..6b65c2a 100644
--- a/share/html/Elements/MessageBox
+++ b/share/html/Elements/MessageBox
@@ -74,9 +74,10 @@ if ( $QuoteTransaction ) {
     $message = $transaction->Content( Quote => 1, Type  => $Type );
 }
 
-my $signature = '';
-if ( $IncludeSignature and my $text = $session{'CurrentUser'}->UserObj->Signature ) {
-    $signature = "-- \n". $text;
+my $signature = $session{'CurrentUser'}->UserObj->Signature;
+if ( $IncludeSignature and defined $signature and $signature =~ /\S/ ) {
+    $signature =~ s/\n*$//;
+
     if ($Type eq 'text/html') {
         $signature =~ s/&/&/g;
         $signature =~ s/</</g;
@@ -84,7 +85,17 @@ if ( $IncludeSignature and my $text = $session{'CurrentUser'}->UserObj->Signatur
         $signature =~ s/"/"/g;  # "//;
         $signature =~ s/'/'/g;   # '//;
         $signature =~ s{\n}{<br />}g;
-        $signature = "<p>$signature</p>";
+        $signature = "<br /><p>-- <br />$signature</p>";
+    } else {
+        $signature = "\n\n-- \n". $signature . "\n";
+    }
+
+    if ($message =~ /\S/) {
+        if (RT->Config->Get('SignatureAboveQuote', $session{CurrentUser})) {
+            $signature .= $Type eq 'text/html' ? "<br />" : "\n";
+        } else {
+            $signature = ($Type eq 'text/html' ? "" : "\n") . $signature;
+        }
     }
 }
 
diff --git a/t/web/search_bulk_update_links.t b/t/web/search_bulk_update_links.t
index d9b477e..c272345 100644
--- a/t/web/search_bulk_update_links.t
+++ b/t/web/search_bulk_update_links.t
@@ -79,11 +79,13 @@ $m->content_lacks( 'DeleteLink--', 'no delete link stuff' );
 $m->form_name('BulkUpdate');
 my @fields = qw/Owner AddRequestor DeleteRequestor AddCc DeleteCc AddAdminCc
 DeleteAdminCc Subject Priority Queue Status Starts_Date Told_Date Due_Date
-UpdateSubject UpdateContent/;
+UpdateSubject/;
 for my $field ( @fields ) {
     is( $m->value($field), '', "default $field is empty" );
 }
 
+like( $m->value('UpdateContent'), qr/^\s*$/, "default UpdateContent is effectively empty" );
+
 # test DependsOn, MemberOf and RefersTo
 $m->submit_form(
     form_name => 'BulkUpdate',
diff --git a/t/web/signatures.t b/t/web/signatures.t
new file mode 100644
index 0000000..becc1f9
--- /dev/null
+++ b/t/web/signatures.t
@@ -0,0 +1,162 @@
+use strict;
+use warnings;
+
+use RT::Test tests => undef;
+use HTML::Entities qw/decode_entities/;
+
+# Remove the timestamp from the quote header
+{
+    no warnings 'redefine';
+    *RT::Transaction::QuoteHeader = sub { "Someone wrote:" };
+}
+
+my ($baseurl, $m) = RT::Test->started_ok;
+ok( $m->login, 'logged in' );
+
+my $root = RT::Test->load_or_create_user( Name => 'root' );
+my ($ok) = $root->SetSignature("Signature one\nSignature two\n");
+ok($ok, "Set signature");
+
+my $t = RT::Test->create_ticket(
+    Queue   => 'General',
+    Subject => 'Signature quoting',
+    Content => "First\nSecond\nThird\n",
+);
+
+my $initial = $t->Transactions->First->id;
+
+sub template_is {
+    my (%args) = (
+        HTML        => 0,
+        Quote       => 0,
+        BeforeQuote => 0,
+    );
+    my $expected = pop(@_);
+    $args{$_}++ for @_;
+
+    my $prefs = $root->Preferences($RT::System);
+    $prefs->{SignatureAboveQuote} = $args{BeforeQuote};
+    $prefs->{MessageBoxRichText}  = $args{HTML};
+    ($ok) = $root->SetPreferences($RT::System, $prefs);
+    ok($ok, "Preferences updated");
+
+    my $url = "/Ticket/Update.html?id=" . $t->id;
+    $url .= "&QuoteTransaction=$initial" if $args{Quote};
+    $m->get_ok($url);
+
+    $m->form_name('TicketUpdate');
+    my $value = $m->value("UpdateContent");
+
+    # Work around a bug in Mechanize, wherein it thinks newlines
+    # following textareas are significant -- browsers do not.
+    $value =~ s/^\n//;
+
+    # For ease of interpretation, replace blank lines with dots, and
+    # put a $ after trailing whitespace.
+    my $display = $value;
+    $display =~ s/^$/./mg;
+    $display =~ s/([ ]+)$/$1\$/mg;
+
+    is($display, $expected, "Content matches expected");
+
+    my $trim = RT::Interface::Web::StripContent(
+        CurrentUser    => RT::CurrentUser->new($root),
+        Content        => $value,
+        ContentType    => $args{HTML} ? "text/html" : "text/plain",
+        StripSignature => 1,
+    );
+    if ($args{Quote}) {
+        ok($trim, "Counts as not empty");
+    } else {
+        is($trim, '', "Counts as empty");
+    }
+}
+
+
+### Text
+
+subtest "Non-HTML, no reply" => sub {
+    template_is(<<'EOT') };
+.
+.
+-- $
+Signature one
+Signature two
+EOT
+
+
+subtest "Non-HTML, no reply, before quote (which is irrelevant)" => sub {
+    template_is(qw/BeforeQuote/, <<'EOT') };
+.
+.
+-- $
+Signature one
+Signature two
+EOT
+
+subtest "Non-HTML, reply" => sub {
+    template_is(qw/Quote/, <<'EOT') };
+Someone wrote:
+> First
+> Second
+> Third
+.
+.
+.
+-- $
+Signature one
+Signature two
+EOT
+
+subtest "Non-HTML, reply, before quote" => sub {
+    template_is(qw/Quote BeforeQuote/, <<'EOT') };
+.
+.
+-- $
+Signature one
+Signature two
+.
+Someone wrote:
+> First
+> Second
+> Third
+EOT
+
+
+
+### HTML
+
+my $quote = '<div class="gmail_quote">Someone wrote:<br />'
+    .'<blockquote class="gmail_quote" type="cite">'
+    .'<pre style="white-space: pre-wrap; font-family: monospace;">'
+    ."First\nSecond\nThird\n"
+    .'</pre></blockquote></div>';
+
+subtest "HTML, no reply" => sub {
+    template_is(
+        qw/HTML/,
+        '<br /><p>-- <br />Signature one<br />Signature two</p>',
+    ) };
+
+subtest "HTML, no reply, before quote (which is irrelevant)" => sub {
+    template_is(
+        qw/HTML BeforeQuote/,
+        '<br /><p>-- <br />Signature one<br />Signature two</p>',
+    ) };
+
+subtest "HTML, reply" => sub {
+    template_is(
+        qw/HTML Quote/,
+        $quote.'<br /><p>-- <br />Signature one<br />Signature two</p>',
+    ) };
+
+subtest "HTML, reply, before quote" => sub {
+    template_is(
+        qw/HTML Quote BeforeQuote/,
+        '<br /><p>-- <br />Signature one<br />Signature two</p>'
+            . "<br />" . $quote,
+    ) };
+
+
+undef $m;
+done_testing;

-----------------------------------------------------------------------


More information about the rt-commit mailing list