X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2Fstemmaweb%2FController%2FRoot.pm;h=5decf721576d0ae6a407806e3c4a122a3b603fdf;hb=2bfac19751089df74b9382ef3d06180560cdca7f;hp=d4184aae4b12fbb446530a00acc99a9a24c9a29f;hpb=4f849eeaee482cf1fd222d90e1d9db8c91a12fed;p=scpubgit%2Fstemmaweb.git diff --git a/lib/stemmaweb/Controller/Root.pm b/lib/stemmaweb/Controller/Root.pm index d4184aa..5decf72 100644 --- a/lib/stemmaweb/Controller/Root.pm +++ b/lib/stemmaweb/Controller/Root.pm @@ -33,6 +33,10 @@ components will be loaded. sub index :Path :Args(0) { my ( $self, $c ) = @_; + # Are we being asked to load a text immediately? If so + if( $c->req->param('withtradition') ) { + $c->stash->{'withtradition'} = $c->req->param('withtradition'); + } $c->stash->{template} = 'index.tt'; } @@ -137,7 +141,7 @@ sub newtradition :Local :Args(0) { } } else { # Error unless we have a recognized filename extension - return _json_error( $c, 500, "Unrecognized file type extension $ext" ); + return _json_error( $c, 403, "Unrecognized file type extension $ext" ); } # Save the tradition if we have it, and return its data or else the @@ -173,7 +177,7 @@ sub textinfo :Local :Args(1) { my( $self, $c, $textid ) = @_; my $tradition = $c->model('Directory')->tradition( $textid ); unless( $tradition ) { - return _json_error( $c, 500, "No tradition with ID $textid" ); + return _json_error( $c, 404, "No tradition with ID $textid" ); } my $ok = _check_permission( $c, $tradition ); return unless $ok; @@ -275,7 +279,7 @@ sub variantgraph :Local :Args(1) { my( $self, $c, $textid ) = @_; my $tradition = $c->model('Directory')->tradition( $textid ); unless( $tradition ) { - return _json_error( $c, 500, "No tradition with ID $textid" ); + return _json_error( $c, 404, "No tradition with ID $textid" ); } my $ok = _check_permission( $c, $tradition ); return unless $ok; @@ -302,7 +306,7 @@ sub stemma :Local :Args(2) { my $m = $c->model('Directory'); my $tradition = $m->tradition( $textid ); unless( $tradition ) { - return _json_error( $c, 500, "No tradition with ID $textid" ); + return _json_error( $c, 404, "No tradition with ID $textid" ); } my $ok = _check_permission( $c, $tradition ); return unless $ok; @@ -317,13 +321,15 @@ sub stemma :Local :Args(2) { # We are adding a new stemma. $stemma = $tradition->add_stemma( 'dot' => $dot ); $stemmaid = $tradition->stemma_count - 1; + } elsif( $stemmaid !~ /^\d+$/ ) { + return _json_error( $c, 403, "Invalid stemma ID specification $stemmaid" ); } elsif( $stemmaid < $tradition->stemma_count ) { # We are updating an existing stemma. $stemma = $tradition->stemma( $stemmaid ); $stemma->alter_graph( $dot ); } else { # Unrecognized stemma ID - return _json_error( $c, 500, "No stemma at index $stemmaid, cannot update" ); + return _json_error( $c, 404, "No stemma at index $stemmaid, cannot update" ); } } catch ( Text::Tradition::Error $e ) { return _json_error( $c, 500, $e->message ); @@ -379,13 +385,13 @@ sub stemmadot :Local :Args(2) { my $m = $c->model('Directory'); my $tradition = $m->tradition( $textid ); unless( $tradition ) { - return _json_error( $c, 500, "No tradition with ID $textid" ); + return _json_error( $c, 404, "No tradition with ID $textid" ); } my $ok = _check_permission( $c, $tradition ); return unless $ok; my $stemma = $tradition->stemma( $stemmaid ); unless( $stemma ) { - return _json_error( $c, 500, "Tradition $textid has no stemma ID $stemmaid" ); + return _json_error( $c, 404, "Tradition $textid has no stemma ID $stemmaid" ); } # Get the dot and transmute its line breaks to literal '|n' $c->stash->{'result'} = { 'dot' => $stemma->editable( { linesep => '|n' } ) };