From: Jess Robinson Date: Mon, 21 May 2012 14:48:08 +0000 (+0000) Subject: Add 'list' to admin X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=df8c12f0adaa60f133ba1ac752e619d29fb8d19e;p=scpubgit%2Fstemmatology.git Add 'list' to admin Only return user from find (used by login) if user is admin Fix tests to match --- diff --git a/lib/Text/Tradition/Directory.pm b/lib/Text/Tradition/Directory.pm index 29bf0f9..1f69d94 100644 --- a/lib/Text/Tradition/Directory.pm +++ b/lib/Text/Tradition/Directory.pm @@ -400,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; } @@ -484,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; diff --git a/script/admin_users.pl b/script/admin_users.pl index 59e326a..e327395 100644 --- a/script/admin_users.pl +++ b/script/admin_users.pl @@ -23,7 +23,7 @@ GetOptions( 't|tradition:s' => \$tradition_id, ) or usage(); -if(!$command || !($command ~~ [qw/add modify delete deactivate reactivate/])) { +if(!$command || !($command ~~ [qw/add modify delete deactivate reactivate list/])) { print "No command supplied, chickening out ... \n\n"; usage(); } @@ -85,6 +85,22 @@ given ($command) { } } + when ('list') { + my $user = $userstore->find_user({ username => $username }); + if(!$user) { + print "Can't find user '$username'\n"; + break; + } + my $traditions = $user->traditions; + + print "User: $username\n"; + print "Has traditions: \n"; + foreach my $t (@$traditions) { + print " ", $t->name, "\n"; + } + print "OK.\n"; + } + when ('deactivate') { my $user = $userstore->deactivate_user({ username => $username}); if(!$user) { @@ -139,6 +155,8 @@ admin_users.pl - add / modify / etc users admin_user.pl -c modify -u jimbob -t "mytradition" + admin_user.pl -c list -u jimbob + admin_user.pl -c delete -u jimbob =head1 OPTIONS @@ -147,7 +165,37 @@ admin_users.pl - add / modify / etc users =item -c | --command -The action to take, can be one of: add, modify, deactivate, reactivate, delete. +The action to take, can be one of: add, modify, deactivate, reactivate, delete, list. + +=over + +=item add + +Create a new user and store it in the Directory + +=item modify + +Change an existing stored user, with a -p this will change the user's +password, with a -t will add or remove the named tradition from the +user. + +=item list + +List the given user's traditions. + +=item deactivate + +Deactivate this user. + +=item reactivate + +Re-activate this user. + +=item delete + +Delete the user permanently. + +=back =item -u | --username diff --git a/t/text_tradition_user.t b/t/text_tradition_user.t index ac54b05..f93e5e7 100644 --- a/t/text_tradition_user.t +++ b/t/text_tradition_user.t @@ -49,6 +49,7 @@ ok($changed->check_password('passbloggs'), 'Modified & retrieved with correct ne my $d_user = $user_store->deactivate_user({ username => 'testactive' }); is($d_user->active, 0, 'Deactivated user'); + is($user_store->find_user({ username => 'testactive' }), undef, 'Deactivated user not returned by find_user'); ## TODO - add test where user has traditions to start with } @@ -59,11 +60,12 @@ ok($changed->check_password('passbloggs'), 'Modified & retrieved with correct ne my $user = $user_store->add_user({ username => 'testinactive', password => 'imaninactiveuser' }); - my $d_user = $user_store->deactivate_user({ username => 'testactive' }); + my $d_user = $user_store->deactivate_user({ username => 'testinactive' }); ok(!$d_user->active, 'Deactivate test user starts active'); my $a_user = $user_store->reactivate_user({ username => 'testinactive' }); is($a_user->active, 1, 'Re-activated user'); + ok($user_store->find_user({ username => 'testinactive' }), 'Re-activated user returned by find_user again'); } {