diff options
author | Angelo Naselli <anaselli@linux.it> | 2014-10-11 16:11:31 +0200 |
---|---|---|
committer | Angelo Naselli <anaselli@linux.it> | 2014-10-11 16:11:31 +0200 |
commit | d79e5d4de09d38882d111341ed17bdb1b181050b (patch) | |
tree | 267abcb03261835b52127491441546f6156cd086 /lib/AdminPanel | |
parent | 2552e8a2749d59d57db11d801d5cfdcf384f8c1b (diff) | |
download | manatools-d79e5d4de09d38882d111341ed17bdb1b181050b.tar manatools-d79e5d4de09d38882d111341ed17bdb1b181050b.tar.gz manatools-d79e5d4de09d38882d111341ed17bdb1b181050b.tar.bz2 manatools-d79e5d4de09d38882d111341ed17bdb1b181050b.tar.xz manatools-d79e5d4de09d38882d111341ed17bdb1b181050b.zip |
moved getGroupsInfo to Shared and updated RefreshGroup accordingly
Diffstat (limited to 'lib/AdminPanel')
-rw-r--r-- | lib/AdminPanel/Module/Users.pm | 41 | ||||
-rw-r--r-- | lib/AdminPanel/Shared/Users.pm | 85 |
2 files changed, 91 insertions, 35 deletions
diff --git a/lib/AdminPanel/Module/Users.pm b/lib/AdminPanel/Module/Users.pm index b32b9485..cf709426 100644 --- a/lib/AdminPanel/Module/Users.pm +++ b/lib/AdminPanel/Module/Users.pm @@ -1193,40 +1193,19 @@ sub _refreshGroups { # WA remove notification immediate $self->get_widget('table')->setImmediateMode(0); $self->get_widget('table')->deleteAllItems(); - my @GroupReal; - LOOP: foreach my $g (@$groups) { - next LOOP if $filtergroups && $g->Gid($self->sh_users->USER_GetValue) <= 499 || $g->Gid($self->sh_users->USER_GetValue) == 65534; - - if ($filtergroups && $g->Gid($self->sh_users->USER_GetValue) > 499 && $g->Gid($self->sh_users->USER_GetValue) < 1000) { - my $groupname = $g->GroupName($self->sh_users->USER_GetValue); - my $l = $self->sh_users->ctx->LookupUserByName($groupname); - if (!defined($l)) { - my $members = $self->sh_users->ctx->EnumerateUsersByGroup($groupname); - next LOOP if !scalar(@{$members}); - foreach my $username (@$members) { - my $userEnt = $self->sh_users->ctx->LookupUserByName($username); - next LOOP if $userEnt->HomeDir($self->sh_users->USER_GetValue) =~ /^\/($|var\/|run\/)/ || $userEnt->LoginShell($self->sh_users->USER_GetValue) =~ /(nologin|false)$/; - } - } - else { - next LOOP if $l->HomeDir($self->sh_users->USER_GetValue) =~ /^\/($|var\/|run\/)/ || $l->LoginShell($self->sh_users->USER_GetValue) =~ /(nologin|false)$/; - } - } - push @GroupReal, $g if $g->GroupName($self->sh_users->USER_GetValue) =~ /^\Q$strfilt/; - } + my $groupInfo = $self->sh_users->getGroupsInfo({ + groupname_filter => $strfilt, + filter_system => $filtergroups, + }); my $itemColl = new yui::YItemCollection; - foreach my $g (@GroupReal) { - my $a = $g->GroupName($self->sh_users->USER_GetValue); - #my $group = $ctx->LookupGroupById($a); - my $u_b_g = $a && $self->sh_users->ctx->EnumerateUsersByGroup($a); - my $listUbyG = join(',', @$u_b_g); - my $group_id = $g->Gid($self->sh_users->USER_GetValue); - my $groupname = $g->GroupName($self->sh_users->USER_GetValue); - my $item = new yui::YTableItem ("$groupname", - "$group_id", - "$listUbyG"); + foreach my $groupname (keys %{$groupInfo}) { + my $info = $groupInfo->{$groupname}; + my $listUbyG = join(',', @{$info->{members}}); + my $item = new yui::YTableItem ("$groupname", + "$info->{gid}", + "$listUbyG"); $item->setLabel( $groupname ); $itemColl->push($item); $item->DISOWN(); diff --git a/lib/AdminPanel/Shared/Users.pm b/lib/AdminPanel/Shared/Users.pm index c77fbeab..bfce0e7b 100644 --- a/lib/AdminPanel/Shared/Users.pm +++ b/lib/AdminPanel/Shared/Users.pm @@ -688,6 +688,83 @@ sub deleteGroup { return 1; } + +#============================================================= + +=head2 getGroupsInfo + +$options: HASH reference containing + groupname_filter => groupname search string + filter_system => hides system groups + +=head3 OUTPUT + + $groupsInfo: HASH reference containing + groupname-1 => { + gid => group identifier + members => ARRAY of username + } + groupname-2 => { + ... + } + +=head3 DESCRIPTION + + This method get group information (all groups or the + filtered ones) + + +=cut + +#============================================================= +sub getGroupsInfo { + my ($self, $options) = @_; + + my $groupsInfo = {}; + return $groupsInfo if !defined $self->ctx; + + my $strfilt = $options->{groupname_filter} if exists($options->{groupname_filter}); + my $filtergroups = $options->{filter_system} if exists($options->{filter_system}); + + my $groups = $self->ctx->GroupsEnumerateFull; + + my @GroupReal; + LOOP: foreach my $g (@$groups) { + next LOOP if $filtergroups && $g->Gid($self->USER_GetValue) <= 499 || $g->Gid($self->USER_GetValue) == 65534; + + if ($filtergroups && $g->Gid($self->USER_GetValue) > 499 && $g->Gid($self->USER_GetValue) < 1000) { + my $groupname = $g->GroupName($self->USER_GetValue); + my $l = $self->ctx->LookupUserByName($groupname); + if (!defined($l)) { + my $members = $self->ctx->EnumerateUsersByGroup($groupname); + next LOOP if !scalar(@{$members}); + foreach my $username (@$members) { + my $userEnt = $self->ctx->LookupUserByName($username); + next LOOP if $userEnt->HomeDir($self->USER_GetValue) =~ /^\/($|var\/|run\/)/ || $userEnt->LoginShell($self->USER_GetValue) =~ /(nologin|false)$/; + } + } + else { + next LOOP if $l->HomeDir($self->USER_GetValue) =~ /^\/($|var\/|run\/)/ || $l->LoginShell($self->USER_GetValue) =~ /(nologin|false)$/; + } + } + push @GroupReal, $g if $g->GroupName($self->USER_GetValue) =~ /^\Q$strfilt/; + } + + foreach my $g (@GroupReal) { + my $groupname = $g->GroupName($self->USER_GetValue); + my $u_b_g = $self->ctx->EnumerateUsersByGroup($groupname); + my $group_id = $g->Gid($self->USER_GetValue); + + $groupsInfo->{"$groupname"} = { + gid => $group_id, + members => $u_b_g, + }; + } + + return $groupsInfo; +} + + #============================================================= =head2 getUsersInfo @@ -700,7 +777,7 @@ $options: HASH reference containing =head3 OUTPUT -%users: HASH reference containing +$usersInfo: HASH reference containing username-1 => { uid => user identifier group => primary group name @@ -716,7 +793,7 @@ $options: HASH reference containing =head3 DESCRIPTION -This method get users information (all or by using a filter) +This method get user information (all users or filtered ones) =cut @@ -746,8 +823,8 @@ sub getUsersInfo { $i++; my $uid = $l->Uid($self->USER_GetValue); if (!defined $uid) { - warn "bogus user at line $i\n"; - next; + warn "bogus user at line $i\n"; + next; } my $gid = $l->Gid($self->USER_GetValue); $group = $self->ctx->LookupGroupById($gid); |