...and apply first ACL bugfix to relater/stexaminer
[scpubgit/stemmaweb.git] / lib / stemmaweb / Controller / Stexaminer.pm
index 16c515f..36679ee 100644 (file)
@@ -23,16 +23,19 @@ 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 $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 ] } );
@@ -47,7 +50,9 @@ sub index :Path :Args(1) {
                $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 = ( 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' ) {
@@ -92,6 +97,27 @@ sub _stringify_element {
        }
 }
 
+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->has_user && $tradition->user->id eq $user->id ) );
+       return 1;
+    } 
+    # Is it public?
+    if( $tradition->public ) {
+       $c->stash->{'permission'} = 'readonly';
+       return 1;
+    } 
+       # 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