aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/AdminPanel/Module/Users.pm44
-rw-r--r--lib/AdminPanel/Shared/Users.pm78
2 files changed, 90 insertions, 32 deletions
diff --git a/lib/AdminPanel/Module/Users.pm b/lib/AdminPanel/Module/Users.pm
index c7913d1..4d735a2 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 9357fc9..9d8fca2 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