X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2Fstemmaweb%2FController%2FStexaminer.pm;h=80d8827529ac977ecb31b33a76c6e9d8aa685cb7;hb=847e1ac6bbf676c2a7c9356918ba95f6e98cea60;hp=309f8d6240e2c0193d66e89f78bdadb18bad3ef6;hpb=8603127ad78e554759b5d2c2a844371a04db4673;p=scpubgit%2Fstemmaweb.git diff --git a/lib/stemmaweb/Controller/Stexaminer.pm b/lib/stemmaweb/Controller/Stexaminer.pm index 309f8d6..80d8827 100644 --- a/lib/stemmaweb/Controller/Stexaminer.pm +++ b/lib/stemmaweb/Controller/Stexaminer.pm @@ -23,19 +23,21 @@ The stemma analysis tool with the pretty colored table. =head2 index - GET stexaminer/$textid + GET stexaminer/$textid/$stemmaid -Renders the application for the text identified by $textid. +Renders the application for the text identified by $textid, using the stemma +graph identified by $stemmaid. =cut -sub index :Path :Args(1) { - my( $self, $c, $textid ) = @_; +sub index :Path :Args(2) { + my( $self, $c, $textid, $stemid ) = @_; my $m = $c->model('Directory'); - my $am = $c->model('Analysis'); my $tradition = $m->tradition( $textid ); + my $ok = _check_permission( $c, $tradition ); + return unless $ok; if( $tradition->stemma_count ) { - my $stemma = $tradition->stemma(0); + my $stemma = $tradition->stemma( $stemid ); $c->stash->{svg} = $stemma->as_svg( { size => [ 600, 350 ] } ); $c->stash->{graphdot} = $stemma->editable({ linesep => ' ' }); $c->stash->{text_title} = $tradition->name; @@ -43,21 +45,21 @@ sub index :Path :Args(1) { # Get the analysis options my( $use_type1, $ignore_sort ) = ( 0, 'none' ); - if( $c->req->method eq 'POST' ) { - $use_type1 = $c->req->param( 'show_type1' ) ? 1 : 0; - $ignore_sort = $c->req->param( 'ignore_variant' ); - } + $use_type1 = $c->req->param( 'show_type1' ) ? 1 : 0; + $ignore_sort = $c->req->param( 'ignore_variant' ) || ''; $c->stash->{'show_type1'} = $use_type1; $c->stash->{'ignore_variant'} = $ignore_sort; # TODO Run the analysis as AJAX from the loaded page. - my %analysis_options = ( calcdir => $am ); - $analysis_options{'exclude_type1'} = !$use_type1; + my %analysis_options = ( + stemma_id => $stemid, + exclude_type1 => !$use_type1 ); if( $ignore_sort eq 'spelling' ) { $analysis_options{'merge_types'} = [ qw/ spelling orthographic / ]; } elsif( $ignore_sort eq 'orthographic' ) { $analysis_options{'merge_types'} = 'orthographic'; } - + + # Do the deed my $t = run_analysis( $tradition, %analysis_options ); # Stringify the reading groups foreach my $loc ( @{$t->{'variants'}} ) { @@ -95,6 +97,23 @@ sub _stringify_element { } } +sub _check_permission { + my( $c, $tradition ) = @_; + my $user = $c->user_exists ? $c->user->get_object : undef; + if( $user ) { + return 'full' if ( $user->is_admin || + ( $tradition->has_user && $tradition->user->id eq $user->id ) ); + } + # Text doesn't belong to us, so maybe it's public? + return 'readonly' if $tradition->public; + + # ...nope. Forbidden! + $c->response->status( 403 ); + $c->response->body( 'You do not have permission to view this tradition' ); + $c->forward('View::Plain'); + return 0; +} + =head2 graphsvg POST stexaminer/graphsvg