Add 'list' to admin
[scpubgit/stemmatology.git] / lib / Text / Tradition / Directory.pm
index b697f7c..1f69d94 100644 (file)
@@ -274,11 +274,39 @@ sub tradition {
        return $obj;
 }
 
+sub user_traditionlist {
+    my ($self, $user) = @_;
+
+    my @tlist;
+    if(ref $user) {
+        ## We have a user object already, so just fetch its traditions and use tose
+        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
+    ## When they exist!
+    # $self->search({ public => 1 });
+    
+    ## For now, just fetch all
+    ## (could use all_objects or grep down there?)
+    return $self->traditionlist();
+}
+
 sub traditionlist {
        my $self = shift;
+    my ($user) = @_;
+
+    return $self->user_traditionlist($user) if($user);
+
+       my @tlist;
        # If we are using DBI, we can do it the easy way; if not, the hard way.
        # Easy way still involves making a separate DBI connection. Ew.
-       my @tlist;
        if( $self->dsn =~ /^dbi:(\w+):/ ) {
                my $dbtype = $1;
                my @connection = @{$self->directory->backend->connect_info};
@@ -372,7 +400,11 @@ sub find_user {
     # 'url' => 'http://castaway.myopenid.com/',
     my $username = $userinfo->{url} || $userinfo->{username};
 
-    return $self->lookup(Text::Tradition::User->id_for_user($username));
+    ## No logins if user is deactivated (use lookup to fetch to re-activate)
+    my $user = $self->lookup(Text::Tradition::User->id_for_user($username));
+    return if($user && !$user->active);
+
+    return $user;
     
 }
 
@@ -456,7 +488,7 @@ sub reactivate_user {
 
     return if !$username;
 
-    my $user = $self->find_user({ username => $username });
+    my $user = $self->lookup(Text::Tradition::User->id_for_user($username));
     return if !$user;
 
     return $user if $user->active;