Skip to content
Permalink
Browse files

Added "--delete userId [userId ...]" option to the "user" command

Added "--delete userId [userId ...]" option to the "user" command
to delete user(s) by their userId.
  • Loading branch information...
pbmarklf authored and haarg committed Jul 13, 2012
1 parent 0d53d61 commit 94018b64912d3f66f43ad6640cb20b3517d45dcd
Showing with 51 additions and 1 deletion.
  1. +37 −1 lib/WGDev/Command/User.pm
  2. +14 −0 lib/WGDev/X.pm
@@ -10,6 +10,7 @@ use WGDev::X ();

sub config_options {
return qw(
delete
findByPassword=s
findByDictionary=s
);
@@ -28,6 +29,33 @@ sub process {
if ( my $dictionary = $self->option('findByDictionary') ) {
return $self->find_by_dictionary($dictionary);
}

if ( $self->option('delete') ) {
return $self->delete_user();
}
}

# this is named 'delete_user()' because 'delete' is a built-in function in Perl
sub delete_user {
my $self = shift;
my $user = undef;
my $wgd = $self->wgd;
my $session = $wgd->session();

if ( !$self->arguments ) {
WGDev::X->throw("No user to delete!\n");
}

foreach my $userId ( $self->arguments ) {
eval {
$user = new WebGUI::User($session, $userId);
};
if ($@ || !$user->validUserId($session, $userId)) {
WGDev::X::UserNotFound->throw(userId => $userId);
}

$user->delete();
}
}

sub find_by_password {
@@ -89,7 +117,7 @@ sub find_by_dictionary {

=head1 SYNOPSIS
wgd user [--findByPassword <password>] [--findByDictionary <dictionary>]
wgd user [--delete userId [userId ...]] [--findByPassword <password>] [--findByDictionary <dictionary>]
=head1 DESCRIPTION
@@ -99,6 +127,10 @@ Utilities for manipulating WebGUI Users
=over 8
=item C<--delete>
Delete the specified user(s) by their userId.
=item C<--findByPassword>
Return a list of users that are using the given password (assumes
@@ -113,6 +145,10 @@ file in C</usr/share/dict/> or C</var/lib/dict/>
=back
=method delete_user
Deletes the specified user(s), given a list of userIds on the command line.
=method find_by_password
Hashes the given password and sees if any user IDs in the C<authentication> table
@@ -66,6 +66,11 @@ use Exception::Class (
description => 'Bad asset class specified',
fields => ['class'],
},
'WGDev::X::UserNotFound' => {
isa => 'WGDev::X',
description => 'Specified user not found',
fields => ['userId'],
},
'WGDev::X::Module' => {
isa => 'WGDev::X',
description => 'Error loading module',
@@ -232,6 +237,15 @@ sub WGDev::X::AssetNotFound::full_message {
return $message;
}

sub WGDev::X::UserNotFound::full_message {
my $self = shift;
my $message = $self->SUPER::full_message;
if ( $self->userId ) {
$message .= ' FATAL ERROR: User not found - ' . $self->userId;
}
return $message;
}

sub WGDev::X::Module::full_message {
my $self = shift;
my $message = $self->description . q{ } . $self->module

0 comments on commit 94018b6

Please sign in to comment.
You can’t perform that action at this time.