Merge branch 'master' of github.com:tla/stemmatology
Tara L Andrews [Tue, 11 Sep 2012 08:10:13 +0000 (10:10 +0200)]
Conflicts:
stemmaweb/lib/stemmaweb/Controller/Root.pm

1  2 
lib/stemmaweb/Controller/Root.pm

@@@ -141,7 -141,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
@@@ -177,7 -177,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;
@@@ -279,7 -279,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;
@@@ -306,7 -306,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;
                        try {
                                if( $stemmaid eq 'n' ) {
                                        # We are adding a new stemma.
+                                       $stemmaid = $tradition->stemma_count;
                                        $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 );
@@@ -385,13 -383,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' } ) };