diff options
author | Angelo Naselli <anaselli@linux.it> | 2014-10-12 15:57:47 +0200 |
---|---|---|
committer | Angelo Naselli <anaselli@linux.it> | 2014-10-12 15:57:47 +0200 |
commit | 87b62edabda2799dcb324b8f6a91e31fd70f7e3e (patch) | |
tree | 520aad307fb9ce7a8cd32966a7ea9bf19fe84ee2 /lib/AdminPanel | |
parent | 9fcb30e55a7f191fbe0c25e16d24547da94a1af3 (diff) | |
download | manatools-87b62edabda2799dcb324b8f6a91e31fd70f7e3e.tar manatools-87b62edabda2799dcb324b8f6a91e31fd70f7e3e.tar.gz manatools-87b62edabda2799dcb324b8f6a91e31fd70f7e3e.tar.bz2 manatools-87b62edabda2799dcb324b8f6a91e31fd70f7e3e.tar.xz manatools-87b62edabda2799dcb324b8f6a91e31fd70f7e3e.zip |
moved modifyGroup to Shared::Users and changed Module::Users accordingly
Diffstat (limited to 'lib/AdminPanel')
-rw-r--r-- | lib/AdminPanel/Module/Users.pm | 44 | ||||
-rw-r--r-- | lib/AdminPanel/Shared/Users.pm | 78 |
2 files changed, 90 insertions, 32 deletions
diff --git a/lib/AdminPanel/Module/Users.pm b/lib/AdminPanel/Module/Users.pm index c7913d19..4d735a29 100644 --- a/lib/AdminPanel/Module/Users.pm +++ b/lib/AdminPanel/Module/Users.pm @@ -1820,43 +1820,23 @@ sub _groupEdit_Ok { $self->sh_gui->msgBox({text => $errorString}) if ($errorString); return $continue; } - my $groupEnt = $self->sh_users->ctx->LookupGroupByName($groupData{start_groupname}); + $DB::single = 1; + + my $groupInfo = { + groupname => $groupData{groupname}, + members => $groupData{members}, + }; + if ($groupData{start_groupname} ne $groupData{groupname}) { - $groupEnt->GroupName($groupData{groupname}); + $groupInfo->{old_groupname} = $groupData{start_groupname}; } - my $members = $groupData{members}; - my $gid = $groupEnt->Gid($self->sh_users->USER_GetValue); - my $users = $self->sh_users->getUsers(); - my @susers = sort(@$users); + my $retval = $self->sh_users->modifyGroup($groupInfo); - foreach my $user (@susers) { - my $uEnt = $self->sh_users->ctx->LookupGroupByName($user); - if ($uEnt) { - my $ugid = $uEnt->Gid($self->sh_users->USER_GetValue); - my $m = $self->sh_users->ctx->EnumerateUsersByGroup($groupData{start_groupname}); - if (MDK::Common::DataStructure::member($user, @$members)) { - if (!AdminPanel::Shared::inArray($user, $m)) { - if ($ugid != $gid) { - eval { $groupEnt->MemberName($user,1) }; - } - } - } - else { - if (AdminPanel::Shared::inArray($user, $m)) { - if ($ugid == $gid) { - $self->sh_gui->msgBox({text => $self->loc->N("You cannot remove user '%s' from their primary group", $user)}); - return 0; - } - else { - eval { $groupEnt->MemberName($user,2) }; - } - } - } - } - } + if (!$retval->{status}) { + $self->sh_gui->msgBox({text => $retval->{error}} ); + } - $self->sh_users->ctx->GroupModify($groupEnt); $self->_refresh(); return 1; diff --git a/lib/AdminPanel/Shared/Users.pm b/lib/AdminPanel/Shared/Users.pm index 9357fc91..9d8fca2f 100644 --- a/lib/AdminPanel/Shared/Users.pm +++ b/lib/AdminPanel/Shared/Users.pm @@ -749,6 +749,84 @@ sub deleteGroup { } + +#============================================================= + +=head2 modifyGroup + +=head3 INPUT + + $groupInfo: HASH reference containing: + old_groupname => old name of the group (if renaming) + groupname => group name + members => users belonging to the group + +=head3 INPUT + $retval => HASH reference + status => 1 (ok) 0 (error) + error => error message if status is 0 + +=head3 DESCRIPTION + + This method modifies the group groupname + +=cut + +#============================================================= +sub modifyGroup { + my ($self, $groupInfo) = @_; + + die "group name is mandatory" if !defined($groupInfo->{groupname}); + + my $groupEnt = defined($groupInfo->{old_groupname}) ? + $self->ctx->LookupGroupByName($groupInfo->{old_groupname}) : + $self->ctx->LookupGroupByName($groupInfo->{groupname}); + + my $orig_groupname = $groupInfo->{groupname}; + if (defined($groupInfo->{old_groupname}) && + $groupInfo->{old_groupname} ne $groupInfo->{groupname}) { + $groupEnt->GroupName($groupInfo->{groupname}); + $orig_groupname = $groupInfo->{old_groupname}; + } + + my $members = $groupInfo->{members}; + my $gid = $groupEnt->Gid($self->USER_GetValue); + my $users = $self->getUsers(); + my @susers = sort(@{$users}); + + foreach my $user (@susers) { + my $uEnt = $self->ctx->LookupGroupByName($user); + if ($uEnt) { + my $ugid = $uEnt->Gid($self->USER_GetValue); + my $m = $self->ctx->EnumerateUsersByGroup($orig_groupname); + if (MDK::Common::DataStructure::member($user, @{$members})) { + if (!AdminPanel::Shared::inArray($user, $m)) { + if ($ugid != $gid) { + eval { $groupEnt->MemberName($user, 1) }; + } + } + } + else { + if (AdminPanel::Shared::inArray($user, $m)) { + if ($ugid == $gid) { + return { + status => 0, + error =>$self->loc->N("You cannot remove user <%s> from their primary group", $user) + }; + } + else { + eval { $groupEnt->MemberName($user, 2) }; + } + } + } + } + } + + $self->ctx->GroupModify($groupEnt); + + return {status => 1,}; +} + #============================================================= =head2 getGroupsInfo |