my( $self, $c, $textid ) = @_;
my $m = $c->model('Directory');
my $tradition = $m->tradition( $textid );
+ my $ok = _check_permission( $c, $tradition );
+ return unless $ok;
if( $tradition->stemma_count ) {
my $stemma = $tradition->stemma(0);
$c->stash->{svg} = $stemma->as_svg( { size => [ 600, 350 ] } );
# 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;
- $analysis_options{'exclude_type1'} = !$use_type1;
+ my %analysis_options = ( 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'}} ) {
foreach my $rhash ( @{$loc->{'readings'}} ) {
my $gst = wit_stringify( $rhash->{'group'} );
$rhash->{'group'} = $gst;
- my $roots = join( ', ', @{$rhash->{'independent_occurrence'}} );
- $rhash->{'independent_occurrence'} = $roots;
+ _stringify_element( $rhash, 'independent_occurrence' );
+ _stringify_element( $rhash, 'reversions' );
unless( $rhash->{'text'} ) {
$rhash->{'text'} = $rhash->{'readingid'};
}
}
}
+sub _stringify_element {
+ my( $hash, $key ) = @_;
+ return undef unless exists $hash->{$key};
+ if( ref( $hash->{$key} ) eq 'ARRAY' ) {
+ my $str = join( ', ', @{$hash->{$key}} );
+ $hash->{$key} = $str;
+ }
+}
+
+sub _check_permission {
+ my( $c, $tradition ) = @_;
+ my $user = $c->user_exists ? $c->user->get_object : undef;
+ if( $user ) {
+ $c->stash->{'permission'} = 'full'
+ if( $user->is_admin || $tradition->user->id eq $user->id );
+ return 1;
+ } elsif( $tradition->public ) {
+ $c->stash->{'permission'} = 'readonly';
+ return 1;
+ } else {
+ # Forbidden!
+ $c->response->status( 403 );
+ $c->response->body( 'You do not have permission to view this tradition.' );
+ $c->detach( 'View::Plain' );
+ return 0;
+ }
+}
+
=head2 graphsvg
POST stexaminer/graphsvg