[Rt-commit] rt branch, 4.2/extract-rss-dhandler, created. rt-4.2.3-85-ge41fd8b

Alex Vandiver alexmv at bestpractical.com
Tue Apr 15 18:42:38 EDT 2014


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

- Log -----------------------------------------------------------------
commit 728d3286cb5180b4b262742cea866d44aa7e0aed
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 4bc69ab..3e77033 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_utf8($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 b6a766f..1c7efd1 100644
--- a/share/html/Search/Elements/ResultsRSSView
+++ b/share/html/Search/Elements/ResultsRSSView
@@ -46,44 +46,6 @@
 %#
 %# END BPS TAGGED BLOCK }}}
 <%INIT>
-use Encode ();
-
-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;
-
-    # convert to perl strings
-    $name = Encode::decode_utf8($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 =~ /\|/) {
@@ -142,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 e41fd8bb74edd13b610816b3d633e8907cb70a00
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 1c7efd1..edb5989 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();

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


More information about the rt-commit mailing list