From: Jess Robinson Date: Mon, 21 May 2012 13:19:41 +0000 (+0000) Subject: Pass user object to traditions as we have one already usually. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7d52d62bf8c4d9aeaad0a03df1de896f2c91b611;p=scpubgit%2Fstemmatology.git Pass user object to traditions as we have one already usually. --- diff --git a/lib/Text/Tradition/Directory.pm b/lib/Text/Tradition/Directory.pm index 55b7986..29bf0f9 100644 --- a/lib/Text/Tradition/Directory.pm +++ b/lib/Text/Tradition/Directory.pm @@ -278,13 +278,15 @@ sub user_traditionlist { my ($self, $user) = @_; my @tlist; - if($user && $user ne 'public') { + if(ref $user) { ## We have a user object already, so just fetch its traditions and use tose - foreach my $t (@{ $self->lookup($user)->traditions }) { + foreach my $t (@{ $user->traditions }) { push( @tlist, { 'id' => $self->object_to_id( $t ), 'name' => $t->name } ); } return @tlist; + } elsif($user ne 'public') { + die "Passed neither a user object nor 'public' to user_traditionlist"; } ## Search for all traditions which allow public viewing diff --git a/stemmaweb/lib/stemmaweb/Controller/Root.pm b/stemmaweb/lib/stemmaweb/Controller/Root.pm index a3505f5..b8238dc 100644 --- a/stemmaweb/lib/stemmaweb/Controller/Root.pm +++ b/stemmaweb/lib/stemmaweb/Controller/Root.pm @@ -49,7 +49,7 @@ sub directory :Local :Args(0) { my( $self, $c ) = @_; my $m = $c->model('Directory'); # TODO not used yet, will load user texts later - my $user = $c->user_exists ? $c->user->id : 'public'; + my $user = $c->user_exists ? $c->user->get_object : 'public'; # my $user = $c->request->param( 'user' ) || 'ALL'; my @textlist = $m->traditionlist($user); $c->stash->{texts} = \@textlist; diff --git a/t/text_tradition_user.t b/t/text_tradition_user.t index 62520de..ac54b05 100644 --- a/t/text_tradition_user.t +++ b/t/text_tradition_user.t @@ -92,11 +92,11 @@ ok($changed->check_password('passbloggs'), 'Modified & retrieved with correct ne password => 'testingtraditions' }); $user->add_tradition($t); $user_store->update($user); -# $userstore->update($t); is( scalar @{$user->traditions}, 1, 'Added one tradition'); - my @tlist = $user_store->traditionlist($user->kiokudb_object_id); - is($tlist[0]->name, $t->name, 'Traditionlist returns stored user->tradition'); + my @tlist = $user_store->traditionlist($user); + is($tlist[0]->{name}, $t->name, 'Traditionlist returns same named user->tradition'); + is($tlist[0]->{id}, $uuid, 'Traditionlist returns actual tradition with same uuid we put in earlier'); }