← Back to team overview

mvhub-dev team mailing list archive

[Merge] lp:~priya/mvhub/move_prerun into lp:mvhub

 

Priya Ravindran has proposed merging lp:~priya/mvhub/move_prerun into lp:mvhub.

Requested reviews:
  MVHub devs with commit rights (mvhub-commit)


MOved cgiapp_prerun() from CGIAppBase  to AgencyAccount.pm
-- 
https://code.launchpad.net/~priya/mvhub/move_prerun/+merge/28441
Your team MVHub Developers is subscribed to branch lp:mvhub.
=== modified file 'lib-mvhub/lib/MVHub/AgencyAccount.pm'
--- lib-mvhub/lib/MVHub/AgencyAccount.pm	2010-05-24 19:44:00 +0000
+++ lib-mvhub/lib/MVHub/AgencyAccount.pm	2010-06-24 18:29:24 +0000
@@ -82,6 +82,86 @@
     $self->mode_param('rm');
 }
 
+sub cgiapp_prerun {
+    my $self           = shift;
+    my $cgi            = $self->query();
+    my $requested_mode = $self->get_current_runmode();
+
+    # Modes that require the user to first be logged in:
+    my @LOGIN_ONLY_MODES = qw(display_agency_home remove_agency);
+
+    MVHub::Utils::clean_cgi_params($cgi);
+
+    $self->header_add( -Cache_Control => 'no-store' );
+
+    my $cookie_name = $self->get_config_param('COOKIES.auth_cookie_name');
+
+    my $session_id = $cgi->cookie($cookie_name);
+
+    my $cgi_agency_id = $cgi->param('agency_id');
+
+    # TODO put Directory in config file [PATH].session_dir
+    my $session
+        = new CGI::Session( "driver:File", $session_id,
+        { Directory => '/tmp/' } )
+        or croak CGI::Session->erstr();
+
+    if ( !defined $session_id || $session_id ne $session->id() ) {
+
+        if ( grep /$requested_mode/, @LOGIN_ONLY_MODES ) {
+            $self->param(
+                login_error => 'You must log in to access this page.' );
+            $self->prerun_mode('show_login_page');
+        }
+    }
+    else {
+        my $caller_id = $session->param('caller_id');
+        assert( $caller_id,
+            "Session object does not have a caller_id value" );
+        my $agency_id;
+
+        # If the caller is not an admin, their caller_id is their agency_id.
+        # TODO: better error message if a bad agency_id is passed in
+        if ( $caller_id != $MVHub::Common::ADMIN_ID ) {
+
+            $agency_id = $caller_id;
+
+            if ( defined $cgi_agency_id && $cgi_agency_id != $agency_id ) {
+                if ( grep /$requested_mode/, @LOGIN_ONLY_MODES ) {
+                    $self->param( login_error =>
+                            'You must log in to access this page.' );
+                    $self->prerun_mode('show_login_page');
+                }
+            }
+        }
+        else {
+
+            $agency_id = $cgi->param('agency_id');
+
+            # If we don't get an agency id, it's either a programming error or
+            # possibly the user is currently logged in as admin, goes back
+            # to the home/search page, and then clicks on agency log-in.
+            # We'll optimistically assume the latter, and just redirect the
+            # user to the admin site.
+            if ( !$agency_id ) {
+                $self->redirect( absolute_path => '/html/admin/' );
+            }
+        }
+
+        # If they requested the show_login_page, send them to their
+        # agency home page (if they aren't an admin)
+        if (   $requested_mode eq 'show_login_page'
+            && $caller_id != $MVHub::Common::ADMIN_ID )
+        {
+            $self->prerun_mode('display_agency_home');
+        }
+
+        # They are logged in, set the caller_id and agency_id params
+        $self->param( agency_id => $agency_id );
+        $self->param( caller_id => $caller_id );
+    }
+}
+
 sub cgiapp_postrun {
     my $self       = shift;
     my $output_ref = shift;

=== modified file 'lib-mvhub/lib/MVHub/CGIAppBase.pm'
--- lib-mvhub/lib/MVHub/CGIAppBase.pm	2010-06-10 18:14:35 +0000
+++ lib-mvhub/lib/MVHub/CGIAppBase.pm	2010-06-24 18:29:24 +0000
@@ -56,86 +56,6 @@
     return;
 }
 
-sub cgiapp_prerun {
-    my $self           = shift;
-    my $cgi            = $self->query();
-    my $requested_mode = $self->get_current_runmode();
-
-    # Modes that require the user to first be logged in:
-    my @LOGIN_ONLY_MODES = qw(display_agency_home remove_agency);
-
-    MVHub::Utils::clean_cgi_params($cgi);
-
-    $self->header_add( -Cache_Control => 'no-store' );
-
-    my $cookie_name = $self->get_config_param('COOKIES.auth_cookie_name');
-
-    my $session_id = $cgi->cookie($cookie_name);
-
-    my $cgi_agency_id = $cgi->param('agency_id');
-
-    # TODO put Directory in config file [PATH].session_dir
-    my $session
-        = new CGI::Session( "driver:File", $session_id,
-        { Directory => '/tmp/' } )
-        or croak CGI::Session->erstr();
-
-    if ( !defined $session_id || $session_id ne $session->id() ) {
-
-        if ( grep /$requested_mode/, @LOGIN_ONLY_MODES ) {
-            $self->param(
-                login_error => 'You must log in to access this page.' );
-            $self->prerun_mode('show_login_page');
-        }
-    }
-    else {
-        my $caller_id = $session->param('caller_id');
-        assert( $caller_id,
-            "Session object does not have a caller_id value" );
-        my $agency_id;
-
-        # If the caller is not an admin, their caller_id is their agency_id.
-        # TODO: better error message if a bad agency_id is passed in
-        if ( $caller_id != $MVHub::Common::ADMIN_ID ) {
-
-            $agency_id = $caller_id;
-
-            if ( defined $cgi_agency_id && $cgi_agency_id != $agency_id ) {
-                if ( grep /$requested_mode/, @LOGIN_ONLY_MODES ) {
-                    $self->param( login_error =>
-                            'You must log in to access this page.' );
-                    $self->prerun_mode('show_login_page');
-                }
-            }
-        }
-        else {
-
-            $agency_id = $cgi->param('agency_id');
-
-            # If we don't get an agency id, it's either a programming error or
-            # possibly the user is currently logged in as admin, goes back
-            # to the home/search page, and then clicks on agency log-in.
-            # We'll optimistically assume the latter, and just redirect the
-            # user to the admin site.
-            if ( !$agency_id ) {
-                $self->redirect( absolute_path => '/html/admin/' );
-            }
-        }
-
-        # If they requested the show_login_page, send them to their
-        # agency home page (if they aren't an admin)
-        if (   $requested_mode eq 'show_login_page'
-            && $caller_id != $MVHub::Common::ADMIN_ID )
-        {
-            $self->prerun_mode('display_agency_home');
-        }
-
-        # They are logged in, set the caller_id and agency_id params
-        $self->param( agency_id => $agency_id );
-        $self->param( caller_id => $caller_id );
-    }
-}
-
 # end all modules with 1
 1;
 __END__


Follow ups