Changeset 1127


Ignore:
Timestamp:
12/02/08 12:49:15 (3 years ago)
Author:
CrawfordCurrie
Message:

Item139: removed oops redirect for error reports. Fixed status header in HTTP responses.

Location:
trunk
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/EditTablePlugin/lib/Foswiki/Plugins/EditTablePlugin/Core.pm

    r1086 r1127  
    14411441        # user has no permission to change the topic 
    14421442        throw Foswiki::OopsException( 
    1443             'accessdenied', 
     1443            'accessdenied', status => 403, 
    14441444            def    => 'topic_access', 
    14451445            web    => $theWeb, 
  • trunk/TWikiCompatibilityPlugin/lib/TWiki/OopsException.pm

    r1038 r1127  
    11package TWiki::OopsException; 
    2 use Error; 
    3 use Assert; 
    4 use base 'Error'; 
    5  
    6 use Foswiki::OopsException; 
     2use base 'Foswiki::OopsException'; 
    73 
    84sub new { 
    9     shift; 
    10     return new Foswiki::OopsException(@_); 
     5    my $class = shift; 
     6    return $class->SUPER::new(@_); 
    117} 
    128 
  • trunk/UnitTestContrib/test/unit/ExceptionTests.pm

    r816 r1127  
    11package ExceptionTests; 
    2 use base FoswikiTestCase; 
     2use base 'FoswikiTestCase'; 
    33 
    44use strict; 
     
    66use Error qw( :try ); 
    77use Foswiki::OopsException; 
     8use Foswiki::AccessControlException; 
    89use Foswiki::UI::Oops; 
    910 
     
    6465} 
    6566 
     67# Test for DEPRECATED redirect 
    6668sub test_redirectOopsException { 
    6769    my $this = shift; 
  • trunk/WorkflowPlugin/data/Sandbox/ControlledDocument.txt

    r580 r1127  
     1%META:TOPICINFO{author="SimianApe" date="1228219811" format="1.1" version="1.3"}% 
    12%WORKFLOWNOTICE% 
    23 
     
    1213 
    1314Workflow history: %WORKFLOWHISTORY% 
     15 
     16%META:FORM{name="InProcessForm"}% 
     17%META:WORKFLOWHISTORY{value="<br>WAITINGFORQM -- 02 Dec 2008 - 12:10"}% 
     18%META:WORKFLOW{name="WAITINGFORQM" LASTTIME_WAITINGFORQM="02 Dec 2008 - 12:10" LASTVERSION_WAITINGFORQM=""}% 
  • trunk/WorkflowPlugin/data/Sandbox/DocumentApprovalWorkflow.txt

    r440 r1127  
    3030| WAITINGFORCTO | nobody       | This document is waiting for approval by the CTO.| 
    3131---++ Transitions 
    32 | *State*        | *Action* | *Next State*  | *Allowed*                        | *Form*        | 
    33 | APPROVED       | revise   | UNDERREVISION |                      | ApprovedForm  | 
    34 | UNDERREVISION  | ready for approval | WAITINGFORQM  |                      | InProcessForm | 
    35 | WAITINGFORQM   | approve  | WAITINGFORCTO |       |               | 
    36 | WAITINGFORQM   | reject   | UNDERREVISION |       |               | 
    37 | WAITINGFORCTO  | approve  | APPROVED      |       | ApprovedForm  | 
    38 | WAITINGFORCTO  | reject   | UNDERREVISION |       |               | 
     32| *State*        | *Action* | *Next State*  | *Allowed* | *Form*        | 
     33| APPROVED       | revise   | UNDERREVISION |           | ApprovedForm  | 
     34| UNDERREVISION  | ready for approval | WAITINGFORQM  | | InProcessForm | 
     35| WAITINGFORQM   | approve  | WAITINGFORCTO |           |               | 
     36| WAITINGFORQM   | reject   | UNDERREVISION |           |               | 
     37| WAITINGFORCTO  | approve  | APPROVED      |           | ApprovedForm  | 
     38| WAITINGFORCTO  | reject   | UNDERREVISION |           |               | 
  • trunk/WorkflowPlugin/lib/TWiki/Plugins/WorkflowPlugin.pm

    r1090 r1127  
    241241    if ( !$query->param('INWORKFLOWSEQUENCE') && !$TOPIC->canEdit() ) { 
    242242        throw TWiki::OopsException( 
    243             'accessdenied', 
     243            'accessdenied', status => 403, 
    244244            def   => 'topic_access', 
    245245            web   => $_[2], 
     
    285285 
    286286        try { 
    287             $query->param('INWORKFLOWSEQUENCE' => 1); 
    288             $TOPIC->changeState($action); 
    289             if ($newForm) { 
    290  
    291                 # If there is a form with the new state, and it's not the same 
    292                 # form as previously, we need to kick into edit mode to support 
    293                 # form field changes. 
    294                 $url = TWiki::Func::getScriptUrl( 
    295                     $web, $topic, 'edit', 
    296                     INWORKFLOWSEQUENCE => time()); 
     287            try { 
     288                $query->param('INWORKFLOWSEQUENCE' => 1); 
     289                if ($newForm) { 
     290                    # If there is a form with the new state, and it's not 
     291                    # the same form as previously, we need to kick into edit 
     292                    # mode to support form field changes. 
     293                    $url = TWiki::Func::getScriptUrl( 
     294                        $web, $topic, 'edit', 
     295                        INWORKFLOWSEQUENCE => time()); 
     296                } 
     297                else { 
     298                    $url = TWiki::Func::getScriptUrl( $web, $topic, 'view' ); 
     299                } 
     300                # SMELL: don't do this until the edit is over 
     301                $TOPIC->changeState($action); 
     302                TWiki::Func::redirectCgiQuery( undef, $url ); 
     303            } catch Error::Simple with { 
     304                my $error = shift; 
     305                throw TWiki::OopsException( 
     306                    'oopssaveerr', 
     307                    web => $web, topic => $topic, 
     308                    params => [ $error || '?' ]); 
     309            }; 
     310        } catch TWiki::OopsException with { 
     311            my $e = shift; 
     312            if ($e->can('generate')) { 
     313                $e->generate( $session ); 
     314            } else { 
     315                # Deprecated, TWiki compatibility only 
     316                $e->redirect( $session ); 
    297317            } 
    298             else { 
    299                 $url = TWiki::Func::getScriptUrl( $web, $topic, 'view' ); 
    300             } 
    301         } 
    302         catch Error::Simple with { 
    303             my $error = shift; 
    304             $url = TWiki::Func::getScriptUrl( 
    305                 $web, $topic, 'oops', 
    306                 template => "oopssaveerr", 
    307                 param1   => $error 
    308             ); 
    309         } 
    310         catch TWiki::OopsException with { 
    311             shift->redirect( $session ); 
    312318 
    313319        }; 
    314320    } 
    315     TWiki::Func::redirectCgiQuery( undef, $url ); 
    316321    return undef; 
    317322} 
  • trunk/core/lib/Foswiki.pm

    r1115 r1127  
    723723    # add cookie(s) 
    724724    $this->{users}->{loginManager}->modifyHeader($hopts); 
    725  
    726725    $this->{response}->headers($hopts); 
    727726} 
  • trunk/core/lib/Foswiki/Engine/CGI.pm

    r1078 r1127  
    177177 
    178178    $this->SUPER::finalizeHeaders( $res, $req ); 
     179    # make sure we always generate a status for the response 
     180    print 'Status: '.$res->status() 
     181      if ($res->status() && !defined($res->headers->{status})); 
    179182    foreach my $header ( keys %{ $res->headers } ) { 
    180183        print $header . ': ' . $_ . $this->CRLF 
  • trunk/core/lib/Foswiki/OopsException.pm

    r1050 r1127  
    2424 
    2525throw Foswiki::OopsException( 'bathplugin', 
     26                            status => 418, 
    2627                            def => 'toestuck', 
    2728                            web => $web, 
     
    8485    my $class    = shift; 
    8586    my $template = shift; 
    86     my $this     = bless( $class->SUPER::new(), $class ); 
     87    my $this     = $class->SUPER::new(); 
    8788    $this->{template} = $template; 
    8889    ASSERT( scalar(@_) % 2 == 0, join( ";", map { $_ || 'undef' } @_ ) ) 
     
    146147} 
    147148 
    148 =begin TML 
    149  
    150 ---++ ObjectMethod redirect( $twiki ) 
    151  
    152 Generate a redirect to an 'oops' script for this exception. 
    153  
    154 If the 'keep' parameter is set in the 
    155 exception, it saves parameter values into the query as well. This is needed 
    156 if the query string might get lost during a passthrough, due to a POST 
    157 being redirected to a GET. 
    158  
    159 =cut 
    160  
     149# Generate a redirect to an 'oops' script for this exception. 
     150# 
     151# If the 'keep' parameter is set in the 
     152# exception, it saves parameter values into the query as well. This is needed 
     153# if the query string might get lost during a passthrough, due to a POST 
     154# being redirected to a GET. 
     155# This redirect has been replaced by the generate function below and should 
     156# not be called in new code. 
    161157sub redirect { 
    162158    my ( $this, $session ) = @_; 
    163  
     159    my @p = $this->_prepareResponse($session); 
     160    my $url = 
     161      $session->getScriptUrl( 1, 'oops', $this->{web}, $this->{topic}, @p ); 
     162    $session->redirect( $url, 1 ); 
     163} 
     164 
     165=begin TML 
     166 
     167---++ ObjectMethod generate( $session ) 
     168 
     169Generate an error page for the exception. This will output the error page 
     170to the browser. The default HTTP Status for an Oops exception is 500. This 
     171can be overridden using the 'status => ' parameter to the constructor. 
     172 
     173=cut 
     174 
     175sub generate { 
     176    my ($this, $session ) = @_; 
     177 
     178    my @p = $this->_prepareResponse( $session ); 
     179    $session->{response}->status( $this->{status} || 500 ); 
     180    require Foswiki::UI::Oops; 
     181    Foswiki::UI::Oops::oops($session, $this->{web}, $this->{topic}, 
     182                            $session->{request}, 0); 
     183} 
     184 
     185sub _prepareResponse { 
     186    my ($this, $session ) = @_; 
    164187    my @p = (); 
    165188 
     
    170193    my $n = 1; 
    171194    push( @p, map { 'param' . ( $n++ ) => $_ } @{ $this->{params} } ); 
    172     my $url = 
    173       $session->getScriptUrl( 1, 'oops', $this->{web}, $this->{topic}, @p ); 
    174195    while ( my $p = shift(@p) ) { 
    175196        $session->{request}->param( -name => $p, -value => shift(@p) ); 
    176197    } 
    177     $session->redirect( $url, 1 ); 
     198    return @p; 
    178199} 
    179200 
  • trunk/core/lib/Foswiki/Store.pm

    r1050 r1127  
    14041404    $web =~ s#\.#/#go; 
    14051405    ASSERT( defined($topic) ) if DEBUG; 
    1406     if (DEBUG) { 
    1407         my ( $webTest, $topicTest ) = 
    1408           $this->{session}->normalizeWebTopicName( $web, $topic ); 
    1409         ASSERT( $topic eq $topicTest ); 
    1410         ASSERT( $web   eq $webTest ); 
    1411     } 
     1406    # This test is invalid. This intent is good, but this function may 
     1407    # be called with a deliberately undef web or topic. 
     1408    #if (DEBUG) { 
     1409    #    my ( $webTest, $topicTest ) = 
     1410    #      $this->{session}->normalizeWebTopicName( $web, $topic ); 
     1411    #    ASSERT( $topic eq $topicTest ); 
     1412    #    ASSERT( $web   eq $webTest ); 
     1413    #} 
    14121414    return 0 unless $topic; 
    14131415 
  • trunk/core/lib/Foswiki/UI.pm

    r1078 r1127  
    183183                # we are already authenticated. 
    184184                my $exception = new Foswiki::OopsException( 
    185                     'accessdenied', 
     185                    'accessdenied', status => 403, 
    186186                    web    => $e->{web}, 
    187187                    topic  => $e->{topic}, 
     
    190190                ); 
    191191 
    192                 $exception->redirect($session); 
     192                $exception->generate($session); 
    193193            } 
    194194        } 
    195195        catch Foswiki::OopsException with { 
    196             shift->redirect($session); 
     196            shift->generate($session); 
    197197        } 
    198198        catch Error::Simple with { 
     
    277277    unless ( $session->{store}->webExists($webName) ) { 
    278278        throw Foswiki::OopsException( 
    279             'accessdenied', 
     279            'accessdenied', status => 403, 
    280280            def    => 'no_such_web', 
    281281            web    => $webName, 
     
    301301    unless ( $session->{store}->topicExists( $webName, $topic ) ) { 
    302302        throw Foswiki::OopsException( 
    303             'accessdenied', 
     303            'accessdenied', status => 403, 
    304304            def    => 'no_such_topic', 
    305305            web    => $webName, 
     
    352352    { 
    353353        throw Foswiki::OopsException( 
    354             'accessdenied', 
     354            'accessdenied', status => 403, 
    355355            def    => 'topic_access', 
    356356            web    => $web, 
  • trunk/core/lib/Foswiki/UI/Edit.pm

    r1050 r1127  
    183183    if ( $saveCmd && !$session->{users}->isAdmin( $session->{user} ) ) { 
    184184        throw Foswiki::OopsException( 
    185             'accessdenied', 
     185            'accessdenied', status => 403, 
    186186            def    => 'only_group', 
    187187            web    => $webName, 
     
    236236            unless ( $store->topicExists( $templateWeb, $templateTopic ) ) { 
    237237                throw Foswiki::OopsException( 
    238                     'accessdenied', 
     238                    'accessdenied', status => 403, 
    239239                    def   => 'no_such_topic_template', 
    240240                    web   => $templateWeb, 
  • trunk/core/lib/Foswiki/UI/Manage.pm

    r1090 r1127  
    137137 
    138138    throw Foswiki::OopsException( 
    139         'attention', 
     139        'attention', status => 200, 
    140140        def    => 'remove_user_done', 
    141141        web    => $webName, 
     
    238238    # everything OK, redirect to last message 
    239239    throw Foswiki::OopsException( 
    240         'attention', 
     240        'attention', status => 200, 
    241241        web   => $newWeb, 
    242242        topic => $newTopic, 
     
    313313        { 
    314314            throw Foswiki::OopsException( 
    315                 'accessdenied', 
     315                'accessdenied', status => 403, 
    316316                def   => 'no_such_topic_rename', 
    317317                web   => $oldWeb, 
     
    16251625        # user has no permission to change the topic 
    16261626        throw Foswiki::OopsException( 
    1627             'accessdenied', 
     1627            'accessdenied', status => 403, 
    16281628            def    => 'topic_access', 
    16291629            web    => $web, 
  • trunk/core/lib/Foswiki/UI/Register.pm

    r1050 r1127  
    136136    unless ( $session->{users}->isAdmin($user) ) { 
    137137        throw Foswiki::OopsException( 
    138             'accessdenied', 
     138            'accessdenied', status => 403, 
    139139            def    => 'only_group', 
    140140            web    => $web, 
     
    421421    throw Foswiki::OopsException( 
    422422        'attention', 
     423        status => 200, 
    423424        def    => 'confirm', 
    424425        web    => $data->{webName}, 
     
    470471        unless ( $session->{users}->isAdmin($user) ) { 
    471472            throw Foswiki::OopsException( 
    472                 'accessdenied', 
     473                'accessdenied', status => 403, 
    473474                def    => 'only_group', 
    474475                web    => $web, 
     
    508509        throw Foswiki::OopsException( 
    509510            'attention', 
     511            status => 200, 
    510512            topic  => $Foswiki::cfg{HomeTopicName}, 
    511513            def    => 'reset_ok', 
     
    737739        throw Foswiki::OopsException( 
    738740            'attention', 
     741            status => 200, 
    739742            web   => $webName, 
    740743            topic => $topic, 
     
    746749    throw Foswiki::OopsException( 
    747750        'attention', 
     751        status => 200, 
    748752        web    => $webName, 
    749753        topic  => $topic, 
     
    894898    throw Foswiki::OopsException( 
    895899        'attention', 
     900        status => 200, 
    896901        web    => $Foswiki::cfg{UsersWebName}, 
    897902        topic  => $data->{WikiName}, 
  • trunk/core/lib/Foswiki/UI/Save.pm

    r1050 r1127  
    521521    if ( $saveCmd && !$session->{users}->isAdmin( $session->{user} ) ) { 
    522522        throw Foswiki::OopsException( 
    523             'accessdenied', 
     523            'accessdenied', status => 403, 
    524524            def    => 'only_group', 
    525525            web    => $web, 
     
    612612    if ($merged) { 
    613613        throw Foswiki::OopsException( 
    614             'attention', 
     614            'attention', status => 200, 
    615615            def    => 'merge_notice', 
    616616            web    => $web, 
  • trunk/core/lib/Foswiki/UI/Search.pm

    r1050 r1127  
    5959        require Foswiki::OopsException; 
    6060        throw Foswiki::OopsException( 
    61             'accessdenied', 
     61            'accessdenied', status => 403, 
    6262            def    => 'no_such_web', 
    6363            web    => $webName, 
  • trunk/core/lib/Foswiki/UI/Upload.pm

    r1050 r1127  
    259259        throw Foswiki::OopsException( 
    260260            'attention', 
     261            status => 200, 
    261262            def    => 'upload_name_changed', 
    262263            web    => $webName, 
Note: See TracChangeset for help on using the changeset viewer.