From: Tara L Andrews Date: Wed, 29 Aug 2012 14:24:13 +0000 (+0200) Subject: distinguish between user, admin, and public traditions; add preliminary app test X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=27a20fbe904bd17be91d224ce4e30287c3a0696b;p=scpubgit%2Fstemmatology.git distinguish between user, admin, and public traditions; add preliminary app test --- diff --git a/script/admin_users.pl b/script/admin_users.pl old mode 100644 new mode 100755 diff --git a/stemmaweb/Makefile.PL b/stemmaweb/Makefile.PL index 4581143..0fba228 100644 --- a/stemmaweb/Makefile.PL +++ b/stemmaweb/Makefile.PL @@ -15,6 +15,7 @@ requires 'Catalyst::Plugin::StackTrace'; requires 'Catalyst::Plugin::Static::Simple'; requires 'Catalyst::Plugin::Unicode::Encoding'; requires 'Catalyst::Action::RenderView'; +requires 'Catalyst::Authentication::Credential::OpenID'; requires 'Catalyst::Model::KiokuDB'; requires 'Catalyst::View::Download::Plain'; requires 'Catalyst::View::JSON'; diff --git a/stemmaweb/lib/stemmaweb/Controller/Root.pm b/stemmaweb/lib/stemmaweb/Controller/Root.pm index 84288ea..cf3086e 100644 --- a/stemmaweb/lib/stemmaweb/Controller/Root.pm +++ b/stemmaweb/lib/stemmaweb/Controller/Root.pm @@ -48,9 +48,16 @@ Serves a snippet of HTML that lists the available texts. This returns texts bel sub directory :Local :Args(0) { my( $self, $c ) = @_; my $m = $c->model('Directory'); - my $user = $c->user_exists ? $c->user->get_object : 'public'; - my @textlist = $m->traditionlist($user); - $c->stash->{texts} = \@textlist; + # Is someone logged in? + if( $c->user_exists ) { + my $user = $c->user->get_object; + $c->stash->{usertexts} = [ $m->traditionlist( $user ) ]; + $c->stash->{is_admin} = 1 if $user->is_admin; + } + # Unless we have an admin user, list public texts separately from + # any user texts that exist. + $c->stash->{publictexts} = [ $m->traditionlist('public') ] + unless $c->stash->{is_admin}; $c->stash->{template} = 'directory.tt'; } diff --git a/stemmaweb/root/src/directory.tt b/stemmaweb/root/src/directory.tt index a8030e4..d4f3084 100644 --- a/stemmaweb/root/src/directory.tt +++ b/stemmaweb/root/src/directory.tt @@ -1,10 +1,26 @@ -

Choose a text to examine

-
+[% IF usertexts.size -%] + +

[% IF is_admin %]All[% ELSE %]My[% END %] text traditions

+
    [% SET i = 0 -%] -[% FOREACH t IN texts -%] +[% FOREACH t IN usertexts -%]
  • [% t.name %]
  • [% i = i + 1 -%] [% END -%] - +
+[% END -%] +[% IF publictexts.size -%] + +

Public text traditions

+
+
    +[% SET i = 0 -%] +[% FOREACH t IN publictexts -%] +
  • [% t.name %]
  • +[% i = i + 1 -%] +[% END -%] +
+
+[% END -%] \ No newline at end of file diff --git a/stemmaweb/root/src/index.tt b/stemmaweb/root/src/index.tt index 4131aeb..569968a 100644 --- a/stemmaweb/root/src/index.tt +++ b/stemmaweb/root/src/index.tt @@ -6,15 +6,21 @@ var selectedTextID; $(document).ready(function() { // call out to load the directory div - $('#directory').load( "[% c.uri_for( 'directory' ) %]" ); -}); + $('#directory').load( "[% c.uri_for( 'directory' ) %]", + function(response, status, xhr) { + if (status == "error") { + var msg = "An error occurred: "; + $("#directory").html(msg + xhr.status + " " + xhr.statusText); + } + }); + }); [% END %]

Stemmaweb - a collection of tools for analysis of collated texts

- [% IF c.user_exists %]Hello! [% c.user.get_object.email %] Sign out | [% ELSE %]Login | Register | [% END %]About + [% IF c.user_exists %]Hello! [% c.user.get_object.email %] Sign out | [% ELSE %]Login | Register | [% END %]About

Text directory

@@ -23,21 +29,7 @@ $(document).ready(function() {
-
-

Stemma for selected text

-
-
-
- Examine variants against this stemma -
-
-
-
- Run relationship mapper -
-
-
-
-
+
+
[% PROCESS footer.tt %] \ No newline at end of file diff --git a/stemmaweb/t/01app.t b/stemmaweb/t/01app.t index 5d544b9..ac0b4f2 100644 --- a/stemmaweb/t/01app.t +++ b/stemmaweb/t/01app.t @@ -1,10 +1,73 @@ #!/usr/bin/env perl use strict; use warnings; +use File::Temp; use Test::More; +use Text::Tradition::Directory; use Catalyst::Test 'stemmaweb'; -ok( request('/')->is_success, 'Request should succeed' ); +use vars qw( $orig_db, $was_link ); +my $textids; +my $dbfile = 'db/traditions.db'; +( $orig_db, $was_link, $textids ) = _make_testing_database(); + +ok( request('/')->is_success, 'Got root HTML' ); +ok( request('/directory')->is_success, 'Got the text directory' ); +ok( request('/text/' . $textids->{'public'} . '/info')->is_success, + 'Got information listing for public text' ); +is( request('/text/' . $textids->{'public'} . '/info')->code, 403, + 'Denied information listing for public text' ); + done_testing(); + + +sub _make_testing_database { + my $fh = File::Temp->new(); + my $file = $fh->filename; + $fh->unlink_on_destroy( 0 ); + $fh->close; + my $dsn = 'dbi:SQLite:dbname=' . $file; + my $dir = Text::Tradition::Directory->new( 'dsn' => $dsn, + 'extra_args' => { 'create' => 1 } ); + my $scope = $dir->new_scope; + + my $textids = {}; + # Create a (public) tradition + my $pubtrad = Text::Tradition->new( input => 'Self', file => 't/data/john.xml' ); + $textids->{'public'} = $dir->store( $pubtrad ); + + # Create a user + my $userobj = $dir->add_user( { username => 'swtest', password => 'swtestpass' } ); + # Create a tradition for the user + my $privtrad = Text::Tradition->new( input => 'Tabular', sep_char => ',' + file => 't/data/florilegium.csv', user => $userobj ); + $privtrad->add_stemma( dotfile => 't/data/florilegium.dot' ); + $textids->{'private'} = $dir->store( $privtrad ); + + ## Now replace the existing traditions database with the test one + my( $orig, $was_link ); + if( -l $dbfile ) { + $was_link = 1; + $orig = readlink( $dbfile ); + unlink( $dbfile ) or die "Could not replace database file $dbfile"; + } else { + my $suffix = '.backup.' . time(); + $orig = $dbfile.$suffix; + rename( $dbfile, $orig ) or die "Could not move database file $dbfile"; + } + link( $file, $dbfile ); + return( $orig, $was_link, $textids ); +} + +END { + # Restore the original database + unlink( readlink( $dbfile ) ); + unlink( $dbfile ); + if( $was_link ) { + link( $orig_db, $dbfile ); + } else { + rename( $orig_db, $dbfile ); + } +}