[Rt-commit] rt branch, 4.2/extract-rss-dhandler, created. rt-4.2.9-79-g3da742f

Alex Vandiver alexmv at bestpractical.com
Fri Jan 30 17:48:21 EST 2015


The branch, 4.2/extract-rss-dhandler has been created
        at  3da742f823c950e059520b420e1d763f61626d58 (commit)

- Log -----------------------------------------------------------------
commit 67ea3d53876495b45d592efa26dbb9d5c570697e
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Tue Apr 15 18:37:36 2014 -0400

    Move dhandler-specific code into the dhandler
    
    ResultsRSSView is used in two places -- and uses a regex to determine
    which, hardcoding currentuser lookup logic.  Move said logic into the
    dhandler where it is used; this brings it into parallel with the ical
    endpoint.  `local` is used to temporarily override the currentuser.
    
    Fixes I#16974

diff --git a/share/html/NoAuth/rss/dhandler b/share/html/NoAuth/rss/dhandler
index 1446e6c..cdeae81 100644
--- a/share/html/NoAuth/rss/dhandler
+++ b/share/html/NoAuth/rss/dhandler
@@ -45,4 +45,37 @@
 %# those contributions and any derivatives thereof.
 %#
 %# END BPS TAGGED BLOCK }}}
-<& /Search/Elements/ResultsRSSView, %ARGS &>
+<%init>
+my $path = $m->dhandler_arg;
+
+my $notfound = sub {
+    my $mesg = shift;
+    $r->headers_out->{'Status'} = '404 Not Found';
+    $RT::Logger->info("Error encountered in rss generation: $mesg");
+    $m->clear_and_abort;
+};
+
+$notfound->("Invalid path: $path") unless $path =~ m!^([^/]+)/([^/]+)/?!;
+
+my ( $name, $auth ) = ( $1, $2 );
+
+# Unescape parts
+$name =~ s/\%([0-9a-z]{2})/chr(hex($1))/gei;
+
+# convert to perl strings
+$name = Encode::decode( "UTF-8", $name);
+
+my $user = RT::User->new(RT->SystemUser);
+$user->Load($name);
+$notfound->("Invalid user: $user") unless $user->id;
+
+$notfound->("Invalid authstring")
+  unless $user->ValidateAuthString( $auth,
+          $ARGS{Query} . $ARGS{Order} . $ARGS{OrderBy} );
+
+my $cu = RT::CurrentUser->new;
+$cu->Load($user);
+local $session{'CurrentUser'} = $cu;
+
+$m->comp("/Search/Elements/ResultsRSSView", %ARGS);
+</%init>
diff --git a/share/html/Search/Elements/ResultsRSSView b/share/html/Search/Elements/ResultsRSSView
index 1b1e853..85c0417 100644
--- a/share/html/Search/Elements/ResultsRSSView
+++ b/share/html/Search/Elements/ResultsRSSView
@@ -46,42 +46,6 @@
 %#
 %# END BPS TAGGED BLOCK }}}
 <%INIT>
-my $old_current_user;
-
-if ( $m->request_comp->path =~ RT->Config->Get('WebNoAuthRegex') ) {
-    my $path = $m->dhandler_arg;
-
-    my $notfound = sub {
-        my $mesg = shift;
-        $r->headers_out->{'Status'} = '404 Not Found';
-        $RT::Logger->info("Error encountered in rss generation: $mesg");
-        $m->clear_and_abort;
-    };
-
-    $notfound->("Invalid path: $path") unless $path =~ m!^([^/]+)/([^/]+)/?!;
-
-    my ( $name, $auth ) = ( $1, $2 );
-
-    # Unescape parts
-    $name =~ s/\%([0-9a-z]{2})/chr(hex($1))/gei;
-
-    # Decode from bytes to characters
-    $name = Encode::decode( "UTF-8", $name );
-
-    my $user = RT::User->new(RT->SystemUser);
-    $user->Load($name);
-    $notfound->("Invalid user: $user") unless $user->id;
-
-    $notfound->("Invalid authstring")
-      unless $user->ValidateAuthString( $auth,
-              $ARGS{Query} . $ARGS{Order} . $ARGS{OrderBy} );
-
-    $old_current_user = $session{'CurrentUser'};
-    my $cu               = RT::CurrentUser->new;
-    $cu->Load($user);
-    $session{'CurrentUser'} = $cu;
-}
-
 my $Tickets = RT::Tickets->new($session{'CurrentUser'});
 $Tickets->FromSQL($ARGS{'Query'});
 if ($OrderBy =~ /\|/) {
@@ -140,7 +104,6 @@ $r->content_type('application/rss+xml; charset=utf-8');
     }
 
 $m->out($rss->as_string);
-$session{'CurrentUser'} = $old_current_user if $old_current_user;
 $m->abort();
 </%INIT>
 <%ARGS>

commit c37194f6691968b93a8b1ab88ea8597d5ec454f6
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Tue Apr 15 18:42:29 2014 -0400

    Re-indent code; whitespace-only changes

diff --git a/share/html/Search/Elements/ResultsRSSView b/share/html/Search/Elements/ResultsRSSView
index 85c0417..7dc82f8 100644
--- a/share/html/Search/Elements/ResultsRSSView
+++ b/share/html/Search/Elements/ResultsRSSView
@@ -60,48 +60,45 @@ if ($OrderBy =~ /\|/) {
 }
 $r->content_type('application/rss+xml; charset=utf-8');
 
+# create an RSS 1.0 file (http://purl.org/rss/1.0/)
+use XML::RSS;
+my $rss = XML::RSS->new(version => '1.0');
 
+my $url;
+if ( RT->Config->Get('CanonicalizeURLsInFeeds') ) {
+    $url = RT->Config->Get('WebURL');
+} else {
+    $url = RT::Interface::Web::GetWebURLFromRequest();
+}
 
-        # create an RSS 1.0 file (http://purl.org/rss/1.0/)
-        use XML::RSS;
-        my $rss = XML::RSS->new(version => '1.0');
-
-        my $url;
-        if ( RT->Config->Get('CanonicalizeURLsInFeeds') ) {
-            $url = RT->Config->Get('WebURL');
-        }
-        else {
-            $url = RT::Interface::Web::GetWebURLFromRequest();
-        }
-
-        $rss->channel(
-          title        => RT->Config->Get('rtname').": Search " . $ARGS{'Query'},
-          link         => $url,
-          description  => "",
-          dc => {
-          },
-          generator    => "RT v" . $RT::VERSION,
-          syn => {
-            updatePeriod     => "hourly",
-            updateFrequency  => "1",
-            updateBase       => "1901-01-01T00:00+00:00",
-          },
-        );
+$rss->channel(
+    title        => RT->Config->Get('rtname').": Search " . $ARGS{'Query'},
+    link         => $url,
+    description  => "",
+    dc           => { },
+    generator    => "RT v" . $RT::VERSION,
+    syn => {
+        updatePeriod     => "hourly",
+        updateFrequency  => "1",
+        updateBase       => "1901-01-01T00:00+00:00",
+    },
+);
 
 
-    while ( my $Ticket = $Tickets->Next()) {
-        my $creator_str = $Ticket->CreatorObj->Format;
-        $creator_str =~ s/[\r\n]//g;
-        $rss->add_item(
-          title       =>  $Ticket->Subject || loc('No Subject'),
-          link        => $url . "Ticket/Display.html?id=".$Ticket->id,
-          description => $Ticket->Transactions->First->Content,
-          dc          => { creator => $creator_str,
-                           date => $Ticket->CreatedObj->RFC2822,
-                         },
-          guid        => $Ticket->Queue . '_' . $Ticket->id,
-        );
-    }
+while ( my $Ticket = $Tickets->Next()) {
+    my $creator_str = $Ticket->CreatorObj->Format;
+    $creator_str =~ s/[\r\n]//g;
+    $rss->add_item(
+        title       => $Ticket->Subject || loc('No Subject'),
+        link        => $url . "Ticket/Display.html?id=".$Ticket->id,
+        description => $Ticket->Transactions->First->Content,
+        dc          => {
+            creator => $creator_str,
+            date    => $Ticket->CreatedObj->RFC2822,
+        },
+        guid        => $Ticket->Queue . '_' . $Ticket->id,
+    );
+}
 
 $m->out($rss->as_string);
 $m->abort();

commit 68d705972392e3a90550fb0914189fe5a6e563b8
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Fri Jan 30 17:29:35 2015 -0500

    RSS specifies the W3CDTF format, not RFC2822
    
    The RSS 1.0 specification[1] says the the format for dates is W3CDTF[2],
    not RFC2822.  Switch to using the right formatter in items; the "syn"
    syndication information section already uses W3CDTF.
    
    [1] http://web.resource.org/rss/1.0/modules/dc/#model
    [2] http://www.w3.org/TR/NOTE-datetime
    
    Fixes I#29712

diff --git a/share/html/Search/Elements/ResultsRSSView b/share/html/Search/Elements/ResultsRSSView
index 7dc82f8..fdf3b3c 100644
--- a/share/html/Search/Elements/ResultsRSSView
+++ b/share/html/Search/Elements/ResultsRSSView
@@ -94,7 +94,7 @@ while ( my $Ticket = $Tickets->Next()) {
         description => $Ticket->Transactions->First->Content,
         dc          => {
             creator => $creator_str,
-            date    => $Ticket->CreatedObj->RFC2822,
+            date    => $Ticket->CreatedObj->W3CDTF,
         },
         guid        => $Ticket->Queue . '_' . $Ticket->id,
     );

commit 3da742f823c950e059520b420e1d763f61626d58
Author: Alex Vandiver <alexmv at bestpractical.com>
Date:   Fri Jan 30 17:38:31 2015 -0500

    Send a more believable value for the syndication base date
    
    The W3C feed validator[1] takes issue with a 1901 start date for
    syndication; certainly, being before the UNIX epoch may cause problems
    on some RSS implementations.
    
    Switch to using "the last midnight" as the base time.  As the provided
    frequency is "every hour", any timestamp which is on-the-hour should be
    sufficient.  While midnight does not historically exist for _every_ day,
    it has for all recent days in the current calendar system -- and, more
    importantly, most probably will exist for all future days in the current
    calendar system.  Unlike "truncate to the last hour," it is also unique
    even at DST boundaries.
    
    [1] http://validator.w3.org/feed/

diff --git a/share/html/Search/Elements/ResultsRSSView b/share/html/Search/Elements/ResultsRSSView
index fdf3b3c..44d6c97 100644
--- a/share/html/Search/Elements/ResultsRSSView
+++ b/share/html/Search/Elements/ResultsRSSView
@@ -71,6 +71,11 @@ if ( RT->Config->Get('CanonicalizeURLsInFeeds') ) {
     $url = RT::Interface::Web::GetWebURLFromRequest();
 }
 
+
+my $base_date = RT::Date->new( RT->SystemUser );
+$base_date->SetToNow;
+$base_date->SetToMidnight;
+
 $rss->channel(
     title        => RT->Config->Get('rtname').": Search " . $ARGS{'Query'},
     link         => $url,
@@ -80,7 +85,7 @@ $rss->channel(
     syn => {
         updatePeriod     => "hourly",
         updateFrequency  => "1",
-        updateBase       => "1901-01-01T00:00+00:00",
+        updateBase       => $base_date->W3CDTF,
     },
 );
 

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


More information about the rt-commit mailing list