[Bps-public-commit] RT-BugTracker-Public branch, rt4, updated. eff9888e6a649d9c93a2ca373ebae96d31071728

Thomas Sibley trs at bestpractical.com
Fri Mar 8 14:02:05 EST 2013


The branch, rt4 has been updated
       via  eff9888e6a649d9c93a2ca373ebae96d31071728 (commit)
       via  e2f1c9321c836e02d5010eec1767364e27218a20 (commit)
      from  f09ecb95990e329f9c927511512f9019bcec5581 (commit)

Summary of changes:
 html/Callbacks/BugTracker-Public/autohandler/Auth  | 12 ++++----
 .../BugTracker-Public/autohandler/Default          | 35 +++++-----------------
 lib/RT/BugTracker/Public.pm                        | 32 ++++++++++++++++++++
 3 files changed, 45 insertions(+), 34 deletions(-)

- Log -----------------------------------------------------------------
commit e2f1c9321c836e02d5010eec1767364e27218a20
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Fri Mar 8 10:36:45 2013 -0800

    Refactor mapping of non-public url space to public url space
    
    This is a step towards fixing [rt.cpan.org #76301].

diff --git a/html/Callbacks/BugTracker-Public/autohandler/Default b/html/Callbacks/BugTracker-Public/autohandler/Default
index ecc083d..1d60416 100644
--- a/html/Callbacks/BugTracker-Public/autohandler/Default
+++ b/html/Callbacks/BugTracker-Public/autohandler/Default
@@ -48,33 +48,12 @@
 <%init>
 return unless RT::BugTracker::Public->IsPublicUser;
 
-# This is a public user, we only want them going to /Public/
+# This is a public user, we only want them going to /Public/ or other allowed paths.
 
-# The following logic is very similar to the priv/unpriv logic
-my $path = $m->request_path;
-
-# if the user is trying to access a ticket, redirect them
-if ( $path =~ '^(/+)Ticket/Display.html'
-        and $ARGS{'id'} )
-{
-    $m->redirect($RT::WebPath . "/Public/Bug/Display.html?id="
-                    . $m->interp->apply_escapes($ARGS{'id'}, 'u'));
-}
-elsif ( $path =~ '^(/+)Dist/Display.html' and ($ARGS{'Name'} or $ARGS{'Queue'}) ) {
-    $m->redirect($RT::WebPath . "/Public/Dist/Display.html?Name="
-                    . $m->interp->apply_escapes($ARGS{'Name'} || $ARGS{'Queue'}, 'u'));
-}
-elsif ( $path =~ '^(/+)Dist/ByMaintainer.html' and $ARGS{'Name'} ) {
-    $m->redirect($RT::WebPath . "/Public/Dist/ByMaintainer.html?Name="
-                    . $m->interp->apply_escapes($ARGS{'Name'}, 'u'));
-}
-
-# otherwise, drop the user at the Public default page
-elsif (    $path !~ '^(/+)Public/'
-       and $path !~ RT->Config->Get('WebNoAuthRegex')
-       and $path !~ '^(/+)Ticket/Attachment/'
-       and $path !~ '^/+Helpers/Autocomplete/Queues' ) {
-    $m->redirect($RT::WebPath . "/Public/");
-    $m->abort();
-}
+my $destination = RT::BugTracker::Public->RedirectToPublic(
+    Path => $m->request_path,
+    ARGS => \%ARGS,
+);
+$m->redirect( RT->Config->Get("WebPath") . $destination )
+    if $destination;
 </%init>
diff --git a/lib/RT/BugTracker/Public.pm b/lib/RT/BugTracker/Public.pm
index 4c6b179..37a6dc2 100644
--- a/lib/RT/BugTracker/Public.pm
+++ b/lib/RT/BugTracker/Public.pm
@@ -51,6 +51,7 @@ use strict;
 use warnings;
 
 package RT::BugTracker::Public;
+use URI::Escape qw/ uri_escape /;
 
 our $VERSION = '0.03_02';
 
@@ -99,6 +100,37 @@ sub IsPublicUser {
     return 0;
 }
 
+sub RedirectToPublic {
+    my $self = shift;
+    my %args = @_;
+    my ($path, $ARGS) = @args{"Path", "ARGS"};
+
+    # The following logic is very similar to the default priv/unpriv logic for
+    # self service, which is disabled.
+
+    if ( $path =~ '^(/+)Ticket/Display.html' and $ARGS->{'id'} ) {
+        return "/Public/Bug/Display.html?id="
+                    . uri_escape($ARGS->{'id'});
+    }
+    elsif ( $path =~ '^(/+)Dist/Display.html' and ($ARGS->{'Name'} or $ARGS->{'Queue'}) ) {
+        return "/Public/Dist/Display.html?Name="
+                    . uri_escape($ARGS->{'Name'} || $ARGS->{'Queue'});
+    }
+    elsif ( $path =~ '^(/+)Dist/ByMaintainer.html' and $ARGS->{'Name'} ) {
+        return "/Public/Dist/ByMaintainer.html?Name="
+                    . uri_escape($ARGS->{'Name'});
+    }
+
+    # otherwise, drop the user at the Public default page
+    elsif (    $path !~ '^(/+)Public/'
+           and $path !~ RT->Config->Get('WebNoAuthRegex')
+           and $path !~ '^(/+)Ticket/Attachment/'
+           and $path !~ '^/+Helpers/Autocomplete/Queues' ) {
+        return "/Public/";
+    }
+    return undef;
+}
+
 =head1 AUTHOR
 
 Thomas Sibley E<lt>trs at bestpractical.comE<gt>

commit eff9888e6a649d9c93a2ca373ebae96d31071728
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Fri Mar 8 10:53:37 2013 -0800

    Auto-login the public user if the requested non-public page has a public equivalent
    
    All of the non-public to public url space mapping now happens even if
    the request is not yet authed as the public user.  By checking if there
    is a public equivalent of the request and logging the client in if so,
    we allow our autohandler/Default callback do the redirecting later in
    the request handling.
    
    This resolves [rt.cpan.org #76301].

diff --git a/html/Callbacks/BugTracker-Public/autohandler/Auth b/html/Callbacks/BugTracker-Public/autohandler/Auth
index faea91e..bb6bca6 100644
--- a/html/Callbacks/BugTracker-Public/autohandler/Auth
+++ b/html/Callbacks/BugTracker-Public/autohandler/Auth
@@ -53,7 +53,12 @@ if (    not ($session{'CurrentUser'} and $session{'CurrentUser'}->id)
     and not defined $ARGS{user}
     and not defined $ARGS{pass} )
 {
-    if ( $m->request_comp->path =~ m{ ^/+Public/ }x ) {
+    my $path = $m->request_path;
+    my $has_public_equiv = RT::BugTracker::Public->RedirectToPublic(
+        Path => $path,
+        ARGS => \%ARGS,
+    );
+    if ( $path =~ m{ ^/+Public/ }x or $has_public_equiv ) {
         my $cu = new RT::CurrentUser;
         $cu->LoadByName( $RT::WebPublicUser );
         unless ( $cu->id ) {
@@ -63,10 +68,5 @@ if (    not ($session{'CurrentUser'} and $session{'CurrentUser'}->id)
             $session{'CurrentUser'} = $cu;
         }
     }
-    elsif ( $m->request_comp->path =~ '^(/+)Ticket/Display.html'
-                and $ARGS{'id'} )
-    {
-        $m->redirect( $RT::WebPath .'/Public/Bug/Display.html?id=' . $ARGS{'id'} );
-    }
 }
 </%init>

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



More information about the Bps-public-commit mailing list