diff options
author | Angelo Naselli <anaselli@linux.it> | 2014-10-06 23:04:13 +0200 |
---|---|---|
committer | Angelo Naselli <anaselli@linux.it> | 2014-10-06 23:04:13 +0200 |
commit | 0ebbb4d0eb180c6b95da35667ea70d740085a2dd (patch) | |
tree | a20f30dfb50e5635e28a63ac05e3570ba2cb3cdd | |
parent | f4ac24e95ef87873b9ba8d05d359a60db0166913 (diff) | |
download | colin-keep-0ebbb4d0eb180c6b95da35667ea70d740085a2dd.tar colin-keep-0ebbb4d0eb180c6b95da35667ea70d740085a2dd.tar.gz colin-keep-0ebbb4d0eb180c6b95da35667ea70d740085a2dd.tar.bz2 colin-keep-0ebbb4d0eb180c6b95da35667ea70d740085a2dd.tar.xz colin-keep-0ebbb4d0eb180c6b95da35667ea70d740085a2dd.zip |
moved getUsersInfo to Shared::Users and updated
_refreshUsers accordingly
-rw-r--r-- | lib/AdminPanel/Module/Users.pm | 69 | ||||
-rw-r--r-- | lib/AdminPanel/Shared/Users.pm | 92 |
2 files changed, 114 insertions, 47 deletions
diff --git a/lib/AdminPanel/Module/Users.pm b/lib/AdminPanel/Module/Users.pm index 753b79e..f7815f4 100644 --- a/lib/AdminPanel/Module/Users.pm +++ b/lib/AdminPanel/Module/Users.pm @@ -123,14 +123,6 @@ has 'action_menu' => ( ); -## min UID was 500 now is 1000, let's change in a single point -has 'min_UID' => ( - default => 1000, - is => 'ro', - isa => 'Int', - init_arg => undef, -); - has 'edit_tab_widgets' => ( traits => ['Hash'], default => sub { {} }, @@ -845,7 +837,7 @@ sub addUserDialog { $hbox = $factory->createHBox($align); my $uidManually = $factory->createCheckBox($hbox, $self->loc->N("Specify user ID manually"), 0); $factory->createHSpacing($hbox, 2.0); - my $UID = $factory->createIntField($hbox, $self->loc->N("UID"), 1, 65000, $self->min_UID); + my $UID = $factory->createIntField($hbox, $self->loc->N("UID"), 1, 65000, $self->sh_users->min_UID); $UID->setEnabled($uidManually->value()); $uidManually->setNotify(1); # $uidManually->setWeight($yui::YD_HORIZ, 2); @@ -932,10 +924,10 @@ sub addUserDialog { } my $uid = -1; if ($continue && $uidManually->value()) { - if (($uid = $UID->value()) < $self->min_UID) { + if (($uid = $UID->value()) < $self->sh_users->min_UID) { $errorString = ""; - my $uidchoice = $self->sh_gui->ask_YesOrNo({title => $self->loc->N("User Uid is < %d", $self->min_UID), - text => $self->loc->N("Creating a user with a UID less than %d is not recommended.\nAre you sure you want to do this?\n\n", $self->min_UID)}); + my $uidchoice = $self->sh_gui->ask_YesOrNo({title => $self->loc->N("User Uid is < %d", $self->sh_users->min_UID), + text => $self->loc->N("Creating a user with a UID less than %d is not recommended.\nAre you sure you want to do this?\n\n", $self->sh_users->min_UID)}); $continue = $uidchoice; } } @@ -1130,8 +1122,11 @@ sub _refreshUsers { my $strfilt = $self->get_widget('filter')->value(); my $filterusers = $self->get_widget('filter_system')->isChecked(); - my ($users, $group, $groupnm, $expr); - defined $self->sh_users->ctx and $users = $self->sh_users->ctx->UsersEnumerateFull; + my $usersInfo = $self->sh_users->getUsersInfo({ + username_filter => $strfilt, + filter_system => $filterusers, + }); + $self->dialog->startMultipleChanges(); #for some reasons QT send an event using table->selectItem() @@ -1139,46 +1134,26 @@ sub _refreshUsers { $self->get_widget('table')->setImmediateMode(0); $self->get_widget('table')->deleteAllItems(); - my @UserReal; - LOOP: foreach my $l (@$users) { - next LOOP if $filterusers && $l->Uid($self->sh_users->USER_GetValue) <= 499 || $l->Uid($self->sh_users->USER_GetValue) == 65534; - next LOOP if $filterusers && $l->Uid($self->sh_users->USER_GetValue) > 499 && $l->Uid($self->sh_users->USER_GetValue) < $self->min_UID && - ($l->HomeDir($self->sh_users->USER_GetValue) =~ /^\/($|var\/|run\/)/ || $l->LoginShell($self->sh_users->USER_GetValue) =~ /(nologin|false)$/); - push @UserReal, $l if $l->UserName($self->sh_users->USER_GetValue) =~ /^\Q$strfilt/; - } - my $i; my $itemColl = new yui::YItemCollection; - foreach my $l (@UserReal) { - $i++; - my $uid = $l->Uid($self->sh_users->USER_GetValue); - if (!defined $uid) { - warn "bogus user at line $i\n"; - next; - } - my $a = $l->Gid($self->sh_users->USER_GetValue); - $group = $self->sh_users->ctx->LookupGroupById($a); - $groupnm = ''; - $expr = $self->sh_users->computeLockExpire($l); - $group and $groupnm = $group->GroupName($self->sh_users->USER_GetValue); - my $fulln = $l->Gecos($self->sh_users->USER_GetValue); - utf8::decode($fulln); - my $username = $l->UserName($self->sh_users->USER_GetValue); - my $Uid = $l->Uid($self->sh_users->USER_GetValue); - my $shell = $l->LoginShell($self->sh_users->USER_GetValue); - my $homedir = $l->HomeDir($self->sh_users->USER_GetValue); - my $item = new yui::YTableItem ("$username", - "$Uid", - "$groupnm", - "$fulln", - "$shell", - "$homedir", - "$expr"); + foreach my $username (keys %{$usersInfo}) { + my $info = $usersInfo->{$username}; + my $item = new yui::YTableItem ( + "$username", + "$info->{uid}", + "$info->{group}", + "$info->{fullname}", + "$info->{shell}", + "$info->{home}", + "$info->{status}" + ); + # TODO workaround to get first cell at least until we don't # a cast from YItem $item->setLabel( $username ); $itemColl->push($item); $item->DISOWN(); } + $self->get_widget('table')->addItems($itemColl); my $item = $self->get_widget('table')->selectedItem(); $self->get_widget('table')->selectItem($item, 0) if $item; diff --git a/lib/AdminPanel/Shared/Users.pm b/lib/AdminPanel/Shared/Users.pm index ce6f41a..0c23cc2 100644 --- a/lib/AdminPanel/Shared/Users.pm +++ b/lib/AdminPanel/Shared/Users.pm @@ -149,6 +149,13 @@ sub _USERInitialize { return undef; } +## min UID was 500 now is 1000, let's change in a single point +has 'min_UID' => ( + default => 1000, + is => 'ro', + isa => 'Int', + init_arg => undef, +); #============================================================= @@ -684,6 +691,91 @@ sub deleteGroup { #============================================================= +=head2 getUsersInfo + +=head3 INPUT + +$options: HASH reference containing + username_filter => username search string + filter_system => hides system users + +=head3 OUTPUT + +%users: HASH reference containing + username-1 => { + uid => user identifier + group => primary group name + gid => group identifier + fullname => user full name + home => home directory + shell => user shell + status => login status (locked, expired, etc) + } + username-2 => { + ... + } + +=head3 DESCRIPTION + +This method get users information (all or by using a filter) + +=cut + +#============================================================= +sub getUsersInfo { + my ($self, $options) = @_; + + my $usersInfo = {}; + return $usersInfo if !defined $self->ctx; + + my $strfilt = $options->{username_filter} if exists($options->{username_filter}); + my $filterusers = $options->{filter_system} if exists($options->{filter_system}); + + my ($users, $group, $groupnm, $expr); + $users = $self->ctx->UsersEnumerateFull; + + my @UserReal; + LOOP: foreach my $l (@$users) { + next LOOP if $filterusers && $l->Uid($self->USER_GetValue) <= 499 || $l->Uid($self->USER_GetValue) == 65534; + next LOOP if $filterusers && $l->Uid($self->USER_GetValue) > 499 && $l->Uid($self->USER_GetValue) < $self->min_UID && + ($l->HomeDir($self->USER_GetValue) =~ /^\/($|var\/|run\/)/ || $l->LoginShell($self->USER_GetValue) =~ /(nologin|false)$/); + push @UserReal, $l if $l->UserName($self->USER_GetValue) =~ /^\Q$strfilt/; + } + my $i; + my $itemColl = new yui::YItemCollection; + foreach my $l (@UserReal) { + $i++; + my $uid = $l->Uid($self->USER_GetValue); + if (!defined $uid) { + warn "bogus user at line $i\n"; + next; + } + my $gid = $l->Gid($self->USER_GetValue); + $group = $self->ctx->LookupGroupById($gid); + $groupnm = ''; + $expr = $self->computeLockExpire($l); + $group and $groupnm = $group->GroupName($self->USER_GetValue); + my $fulln = $l->Gecos($self->USER_GetValue); + utf8::decode($fulln); + my $username = $l->UserName($self->USER_GetValue); + my $shell = $l->LoginShell($self->USER_GetValue); + my $homedir = $l->HomeDir($self->USER_GetValue); + $usersInfo->{"$username"} = { + uid => $uid, + group => $groupnm, + gid => $gid, + fullname => $fulln, + home => $homedir, + status => $expr, + shell => $shell, + }; + } + + return $usersInfo; +} + +#============================================================= + =head2 getUserHome =head3 INPUT |