aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThierry Vignaud <tv@mandriva.org>2010-02-02 08:43:47 +0000
committerThierry Vignaud <tv@mandriva.org>2010-02-02 08:43:47 +0000
commit77ce41c13500604fc16e659eaaea04b0a8289570 (patch)
treee26a80d030e49196c3ca661d28928355e8e8a7c2
parentc0d9470f7a2c338363109840ea6e5db37b6a5e77 (diff)
downloaduserdrake-77ce41c13500604fc16e659eaaea04b0a8289570.tar
userdrake-77ce41c13500604fc16e659eaaea04b0a8289570.tar.gz
userdrake-77ce41c13500604fc16e659eaaea04b0a8289570.tar.bz2
userdrake-77ce41c13500604fc16e659eaaea04b0a8289570.tar.xz
userdrake-77ce41c13500604fc16e659eaaea04b0a8289570.zip
(GroupEdit_valid) split it out of Edit()
-rwxr-xr-xuserdrake90
1 files changed, 48 insertions, 42 deletions
diff --git a/userdrake b/userdrake
index 396b75f..5b1fd92 100755
--- a/userdrake
+++ b/userdrake
@@ -838,11 +838,54 @@ sub UserEdit_valid {
}
}
+sub GroupEdit_valid {
+ my ($groupEnt, $model, $groupname) = @_;
+ my %g;
+ my ($uEnt);
+ $g{groupname} = $us->{o}{groupname}->get_text; $error = 0;
+ if (!valid_groupname($g{groupname})) { RaiseError($us->{error}) }
+ if (!$error && $groupname ne $g{groupname}) { $groupEnt->GroupName($g{groupname}) }
+ $groupname = $groupEnt->GroupName($GetValue);
+ my $members = $ctx->EnumerateUsersByGroup($groupname);
+ my $gid = $groupEnt->Gid($GetValue);
+ !$error and $model->foreach(sub {
+ my ($mod, $_path, $iter) = @_;
+ my $ch = $mod->get($iter, 2);
+ my $name = $mod->get($iter, 1);
+ if ($ch == 1) {
+ if (!InArray($name, $members)) {
+ $uEnt = $ctx->LookupUserByName($name);
+ my $ugid = $uEnt->Gid($GetValue);
+ if ($ugid != $gid) {
+ eval { $groupEnt->MemberName($name,1) };
+ }
+ }
+ } else {
+ if (InArray($name, $members)) {
+ $uEnt = $ctx->LookupUserByName($name);
+ if ($uEnt->Gid($GetValue) == $groupEnt->Gid($GetValue)) {
+ $model->set($iter, 0 => gtkcreate_pixbuf($pix[0]));
+ $model->set($iter, 2 => 1);
+ RaiseError(N("You cannot remove user '%s' from their primary group", $name));
+ }
+ if (!$error) {
+ eval { $groupEnt->MemberName($name,2) };
+ }
+ }
+ }
+ return 0;
+ }, undef);
+ if (!$error) {
+ $ctx->GroupModify($groupEnt);
+ Refresh($sysfilter, $stringsearch);
+ }
+}
+
sub Edit() {
my $w = NewWindow(N("Edit Groups / Users"));
my $model = Gtk2::ListStore->new("Gtk2::Gdk::Pixbuf", "Glib::String", "Glib::Int");
- my $tree = Gtk2::TreeView->new_with_model($model); my %g;
- my ($groupname, $groupEnt, $userEnt, $members, $times, $min, $max, $warn, $inact, $primgid, $Gent);
+ my $tree = Gtk2::TreeView->new_with_model($model);
+ my ($groupname, $groupEnt, $userEnt, $times, $min, $max, $warn, $inact, $primgid, $Gent);
my @primgroup;
$tree->get_selection->set_mode('browse');
$tree->append_column(my $check = Gtk2::TreeViewColumn->new_with_attributes(undef, Gtk2::CellRendererPixbuf->new, 'pixbuf' => 0));
@@ -922,7 +965,7 @@ sub Edit() {
$min && $min != -1 and $us->{o}{dbca}->set_text($min); $max && $max != -1 and $us->{o}{dbcr}->set_text($max);
$warn && $warn != -1 and $us->{o}{bwbc}->set_text($warn); $inact && $inact != -1 and $us->{o}{dbai}->set_text($inact);
my $grps = $ctx->GroupsEnumerate; my @sgroups = sort(@$grps);
- $members = $ctx->EnumerateGroupsByUser($username);
+ my $members = $ctx->EnumerateGroupsByUser($username);
$primgid = $userEnt->Gid($GetValue);
$Gent = $ctx->LookupGroupById($primgid);
foreach my $group (@sgroups) {
@@ -945,14 +988,13 @@ sub Edit() {
$us->{o}{groupname}->set_editable(0);
$groupEnt = $ctx->LookupGroupByName($groupname);
my $users = $ctx->UsersEnumerate; my @susers = sort(@$users);
- $members = $ctx->EnumerateUsersByGroup($groupname);
+ my $members = $ctx->EnumerateUsersByGroup($groupname);
foreach my $user (@susers) {
if (member($user, @$members)) {
$model->append_set([ 0 => gtkcreate_pixbuf($pix[0]), 1 => $user, 2 => 1 ]);
} else { $model->append_set([ 0 => gtkcreate_pixbuf($pix[1]), 1 => $user, 2 => 0 ]) }
}
}
- my ($uEnt);
gtkpack_($w->vbox,
1, !$p ? $nbU : $nbG);
gtkadd($w->action_area,
@@ -963,43 +1005,7 @@ sub Edit() {
if ($p <= 0) {
UserEdit_valid($userEnt, $model, $primgid);
} elsif ($p == 1) {
- $g{groupname} = $us->{o}{groupname}->get_text; $error = 0;
- if (!valid_groupname($g{groupname})) { RaiseError($us->{error}) }
- if (!$error && $groupname ne $g{groupname}) { $groupEnt->GroupName($g{groupname}) }
- $groupname = $groupEnt->GroupName($GetValue);
- $members = $ctx->EnumerateUsersByGroup($groupname);
- my $gid = $groupEnt->Gid($GetValue);
- !$error and $model->foreach(sub {
- my ($mod, $_path, $iter) = @_;
- my $ch = $mod->get($iter, 2);
- my $name = $mod->get($iter, 1);
- if ($ch == 1) {
- if (!InArray($name, $members)) {
- $uEnt = $ctx->LookupUserByName($name);
- my $ugid = $uEnt->Gid($GetValue);
- if ($ugid != $gid) {
- eval { $groupEnt->MemberName($name,1) };
- }
- }
- } else {
- if (InArray($name, $members)) {
- $uEnt = $ctx->LookupUserByName($name);
- if ($uEnt->Gid($GetValue) == $groupEnt->Gid($GetValue)) {
- $model->set($iter, 0 => gtkcreate_pixbuf($pix[0]));
- $model->set($iter, 2 => 1);
- RaiseError(N("You cannot remove user '%s' from their primary group", $name));
- }
- if (!$error) {
- eval { $groupEnt->MemberName($name,2) };
- }
- }
- }
- return 0;
- }, undef);
- if (!$error) {
- $ctx->GroupModify($groupEnt);
- Refresh($sysfilter, $stringsearch);
- }
+ GroupEdit_valid($groupEnt, $model, $groupname);
}
}
!$error and $w->destroy; $error = 0 });