aboutsummaryrefslogtreecommitdiffstats
path: root/userdrake2
diff options
context:
space:
mode:
authorDaouda Lo <daouda@mandriva.com>2003-06-18 10:22:51 +0000
committerDaouda Lo <daouda@mandriva.com>2003-06-18 10:22:51 +0000
commitd28412cab3783fd16149a42e44a3ae17bebb6698 (patch)
tree31ca7df00aefa1caceb257adaf3401d9ac4369e6 /userdrake2
parent1cd3acd2c102d4c67e7efc217e84a0ce08442948 (diff)
downloaduserdrake-d28412cab3783fd16149a42e44a3ae17bebb6698.tar
userdrake-d28412cab3783fd16149a42e44a3ae17bebb6698.tar.gz
userdrake-d28412cab3783fd16149a42e44a3ae17bebb6698.tar.bz2
userdrake-d28412cab3783fd16149a42e44a3ae17bebb6698.tar.xz
userdrake-d28412cab3783fd16149a42e44a3ae17bebb6698.zip
- Primary group should be set in combo first.
- Append selected group in combo and grow the list
Diffstat (limited to 'userdrake2')
-rwxr-xr-xuserdrake297
1 files changed, 84 insertions, 13 deletions
diff --git a/userdrake2 b/userdrake2
index bd34bae..789e20a 100755
--- a/userdrake2
+++ b/userdrake2
@@ -110,7 +110,7 @@ map {
[ N("Add Group"), N("Add a group to the system"), 'group_add', \&AddGroup ],
[ N("Edit"), N("Edit selected row"), 'user_conf', \&Edit ],
[ N("Delete"), N("Delete selected row"), 'user_del', \&Delete ],
- [ N("Refresh"), N("Refresh the list"), 'refresh', \&Refresh ],
+ [ N("Refresh"), N("Refresh the list"), 'refresh', sub { Refresh($sysfilter) } ],
[ N("Help"), N("Generic help on userdrake"), 'help', \&HelpSystem ]
);
my ($tbuser, $tbgroup, $tbedit, $tbdel, $tbref, $tbhelp) = @toolbwg;
@@ -359,6 +359,14 @@ sub GetNameEntFromIter {
$iter->free;
$name
}
+sub FillUserInfo {
+ my $ent = shift;
+ $us->{o}->{fullname}->set_text($ent->UserName($GetValue));
+ $us->{o}->{passwd}->set_text(' ');
+ $us->{o}->{confpasswd}->set_text(' ');
+ $us->{o}->{shells}->entry->set_text($ent->LoginShell($GetValue));
+ $us->{o}->{homedir}->set_text($ent->HomeDir($GetValue))
+}
sub Delete {
my $page = $nb->get_current_page();
$us->{wnd}{rwindow}->set_sensitive(0);
@@ -455,7 +463,9 @@ sub BuildGui {
sub Edit {
my $w = ugtk2->new('userdrake', grab => 1);
my $model = Gtk2::ListStore->new(Gtk2::GType->OBJECT, Gtk2::GType->STRING, Gtk2::GType->INT);
- my $tree = Gtk2::TreeView->new_with_model($model); my %g; my %u; my $groupname;
+ my $tree = Gtk2::TreeView->new_with_model($model); my %g; my %u;
+ my ($groupname, $username, $groupEnt, $userEnt, $members);
+ my @primgroup;
my @pix = ($pixdir.'selected.png', $pixdir.'unselected.png');
$tree->get_selection->set_mode('browse');
$tree->append_column(my $check = Gtk2::TreeViewColumn->new_with_attributes(undef, Gtk2::CellRendererPixbuf->new, 'pixbuf' => 0));
@@ -501,8 +511,26 @@ sub Edit {
gtkappend_page($nbU,
gtkpack_(Gtk2::VBox->new(0, 2),
0, Gtk2::Label->new(N("Select the groups that the user will be a member of:")),
- 1, $tree
- ), gtkshow(Gtk2::Label->new(N("Account Info"))));
+ 1, create_scrolled_window($tree),
+ 0, gtkpack_( Gtk2::HBox->new(0, 1),
+ 0, Gtk2::Label->new(N("Primary Group")),
+ 1, $us->{o}->{primgroup} = Gtk2::Combo->new,
+ )
+ ), gtkshow(Gtk2::Label->new(N("Groups"))));
+ $username = GetNameEntFromIter($usertree, $utree_model,0); $us->{o}->{login}->set_text($username);
+ $userEnt = $ctx->LookupUserByName($username); FillUserInfo($userEnt);
+ my $grps = $ctx->GroupsEnumerate(); my @sgroups = sort(@$grps);
+ $members = $ctx->EnumerateGroupsByUser($username);
+ my $primgid = $userEnt->Gid($GetValue);
+ my $Gent = $ctx->LookupGroupById($primgid);
+ foreach my $group (@sgroups) {
+ if (any { $_ eq $group } @$members) {
+ $model->append_set([ 0 => gtkcreate_pixbuf($pix[0]), 1 => $group, 2 => 1]); push(@primgroup, $group);
+ } else { $model->append_set([ 0 => gtkcreate_pixbuf($pix[1]), 1 => $group, 2 => 0]); }
+ }
+ $us->{o}->{primgroup}->set_popdown_strings(@primgroup);
+ $Gent and $us->{o}->{primgroup}->entry->set_text($Gent->GroupName($GetValue));
+
} elsif ($p == 1) {
$nbG->set_size_request(300, 200);
gtkappend_page($nbG, gtkpack_(Gtk2::VBox->new(0, 2), 1, BuildGui()), gtkshow(Gtk2::Label->new(N("Group Data"))));
@@ -511,9 +539,11 @@ sub Edit {
0, Gtk2::Label->new(N("Select the users to join this group :")),
1, create_scrolled_window($tree)), gtkshow(Gtk2::Label->new(N("Group Users"))));
$groupname = GetNameEntFromIter($grouptree, $gtree_model, 0); $us->{o}->{groupname}->set_text($groupname);
- my $groupEnt = $ctx->LookupGroupByName($groupname);
+ # Don't allow change on group name since there is a bug in lu_user_modify group
+ $us->{o}->{groupname}->set_editable(0);
+ $groupEnt = $ctx->LookupGroupByName($groupname);
my $users = $ctx->UsersEnumerate(); my @susers = sort(@$users);
- my $members = $ctx->EnumerateUsersByGroup($groupname);
+ $members = $ctx->EnumerateUsersByGroup($groupname);
foreach my $user (@susers) {
if (any { $_ eq $user } @$members) {
$model->append_set([ 0 => gtkcreate_pixbuf($pix[0]), 1 => $user, 2 => 1]);
@@ -530,21 +560,46 @@ sub Edit {
gtksignal_connect(Gtk2::Button->new($_->[0]), clicked => sub {
if (!$retv) {
if ($p == 0) {
- $u{username} = $us->{o}->{log}->get_text();
+ $u{username} = $us->{o}->{login}->get_text();
} elsif ($p == 1) {
$g{groupname} = $us->{o}->{groupname}->get_text(); $error = 0;
if (!valid($g{groupname})) { raiseerror($us->{error}); $error = 1 };
- if (!$error && $groupname ne $g{groupname}) {$ctx->GroupName($g{groupname})}
- #my $members = $ctx->EnumerateUsersByGroup($g->groupname);
- my $ch; my $name;
+ printf("Old Groupname = $groupname \t\t New groupname = %s\n",$g{groupname});
+ if (!$error && $groupname ne $g{groupname}) {$groupEnt->GroupName($g{groupname})}
+ $groupname = $groupEnt->GroupName($GetValue);
+ $members = $ctx->EnumerateUsersByGroup($groupname);
+ my $gid = $groupEnt->Gid($GetValue);
+ my ($ch, $name, $userEnt, $ugid);
$model->foreach(sub {
my ($mod, $path, $iter) = @_;
$ch = $mod->get($iter, 2);
$name = $mod->get($iter, 1);
-
+ if ($ch == 1) {
+ if (!any { $_ eq $name } @$members) {
+ print "\n******* $name ****\n";
+ $userEnt = $ctx->LookupUserByName($name);
+ $ugid = $userEnt->Gid($GetValue);
+ $ugid != $gid and $groupEnt->MemberName($name,1);
+ }
+ } else {
+ if (any { $_ eq $name } @$members) {
+ $userEnt = $ctx->LookupUserByName($name);
+ if ($userEnt->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));
+ $error = 1;
+ }
+ !$error and $groupEnt->MemberName($name,2);
+ }
+ }
$iter->free;
return 0;
}, undef);
+ if (!$error) {
+ $ctx->GroupModify($groupEnt);
+ Refresh($sysfilter);
+ }
}
}
!$error and Gtk2->main_quit; $error = 0; })
@@ -553,9 +608,7 @@ sub Edit {
$tree->show;
$w->{rwindow}->show_all;
$tree->signal_connect(button_press_event => sub {
- printf "button pressed on treeview, coordinates x:%d y:%d\n", $_[1]->x, $_[1]->y;
my ($returns, $path, $column) = $tree->get_path_at_pos($_[1]->x, $_[1]->y);
- print "####### $returns ########";
if ($returns) {
my $eq = Gtk2->equals($check, $column);
if ($eq) {
@@ -563,8 +616,17 @@ sub Edit {
$iter = $model->get_iter($path);
if ($iter) {
my $cp = $model->get($iter, 2);
+ my $item = $model->get($iter, 1);
$model->set($iter, [0 => gtkcreate_pixbuf($pix[$cp])]);
$model->set($iter, [2 => !$cp]);
+ if ($p == 0) {
+ if (!$cp) {
+ !InArray($item, \@primgroup) and push(@primgroup, $item)
+ } else {
+ InArray($item, \@primgroup) and @primgroup = RemoveFromArray($item, \@primgroup)
+ }
+ $us->{o}->{primgroup}->set_popdown_strings(@primgroup);
+ }
$iter->free;
}
}
@@ -573,6 +635,15 @@ sub Edit {
});
$w->main
}
+sub InArray {
+ my ($item, $arr) = @_;
+ return any { $item eq $_} @$arr
+}
+sub RemoveFromArray {
+ my ($item, $arr) = @_;
+ my ($t, $s) = partition { $item ne $_ } @$arr;
+ return @$t;
+}
sub GrayBox {
my ($o, $v, $m) = @_;
$v->set_sensitive($m);