aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThierry Vignaud <tv@mandriva.org>2010-02-02 08:43:44 +0000
committerThierry Vignaud <tv@mandriva.org>2010-02-02 08:43:44 +0000
commit01d18959aad4a6ea23f39bc9ea4a61e114cd8f9f (patch)
tree75599632398a4960b2ee36b0a19be4eea6faa65a
parenta32c150bd658ce6a4eb6e9930787bf1a508e52e2 (diff)
downloaduserdrake-01d18959aad4a6ea23f39bc9ea4a61e114cd8f9f.tar
userdrake-01d18959aad4a6ea23f39bc9ea4a61e114cd8f9f.tar.gz
userdrake-01d18959aad4a6ea23f39bc9ea4a61e114cd8f9f.tar.bz2
userdrake-01d18959aad4a6ea23f39bc9ea4a61e114cd8f9f.tar.xz
userdrake-01d18959aad4a6ea23f39bc9ea4a61e114cd8f9f.zip
(UserDelete,GroupDelete) split them out of Delete()
-rwxr-xr-xuserdrake157
1 files changed, 84 insertions, 73 deletions
diff --git a/userdrake b/userdrake
index 8f181d7..33a7955 100755
--- a/userdrake
+++ b/userdrake
@@ -546,85 +546,96 @@ sub FillUserInfo {
$us->{o}{homedir}->set_text($ent->HomeDir($GetValue));
}
+sub UserDelete() {
+ my ($checkhome, $checkspool);
+ my $username = GetNameEntFromIter($usertree, $utree_model, 0);
+ my $userEnt = $ctx->LookupUserByName($username);
+ # Old Delete version
+ #my $removehome = GimmeChoice(N(" Remove Home Directory"), N("Do you want to delete the user's home directory and mail spool?"));
+ #$removehome and $ctx->Clean($userEnt);
+ # New version
+ my $w = NewWindow(N("Delete files or not?"));
+ my $hd = $userEnt->HomeDir($GetValue);
+ gtkpack_($w->vbox,
+ 0, Gtk2::Label->new(N("Deleting user %s\n Also perform the following actions\n", $username)),
+ 0, $checkhome = Gtk2::CheckButton->new(N("Delete Home Directory: %s", $hd)),
+ 0, $checkspool = Gtk2::CheckButton->new(N("Delete Mailbox: /var/spool/mail/%s", $username)),
+ );
+ gtkadd($w->action_area,
+ map {
+ my $r = $_->[1];
+ gtksignal_connect(Gtk2::Button->new($_->[0]), clicked =>
+ sub {
+ if (!$r) {
+ log::explanations(N("Removing user: %s", $username));
+ $ctx->UserDel($userEnt);
+ UpdateOrDelUsersInGroup($username, 1);
+ #Let's check out the user's primary group
+ my $usergid = $userEnt->Gid($GetValue);
+ my $groupEnt = $ctx->LookupGroupById($usergid);
+ if ($groupEnt) {
+ my $member = $groupEnt->MemberName(1, 0);
+ if (scalar(@$member) == 0 && $groupEnt->Gid($GetValue) > 499) {
+ $ctx->GroupDel($groupEnt);
+ }
+ }
+ if ($checkhome->get_active) {
+ eval { $ctx->CleanHome($userEnt) };
+ $@ and RaiseError($@);
+ }
+ if ($checkspool->get_active) {
+ eval { $ctx->CleanSpool($userEnt) };
+ $@ and RaiseError($@);
+ }
+ Refresh($sysfilter, $stringsearch);
+ }
+ !$error and $w->destroy; $error = 0 });
+ } ([ N("Cancel"), 1 ], [ N("Delete"), 0 ]),
+ );
+ if ($hd !~ m!(?:/home|/var/spool)!) { $checkhome->set_sensitive(0); $checkspool->set_sensitive(0) }
+ $w->show_all;
+}
+
+sub GroupDelete() {
+ my $groupname = GetNameEntFromIter($grouptree, $gtree_model, 0);
+ my $wg = NewWindow(translate("Warning"));
+ gtkadd($wg->vbox,
+ Gtk2::Label->new(N("Do you really want to delete the group %s?", $groupname)),
+ );
+ gtkadd($wg->action_area,
+ map {
+ my $r = $_->[1];
+ gtksignal_connect(Gtk2::Button->new($_->[0]), clicked =>
+ sub {
+ if (!$r) {
+ my $groupEnt = $ctx->LookupGroupByName($groupname);
+ my $members = $ctx->EnumerateUsersByGroup($groupname);
+ GLOOP: foreach my $username (@$members) {
+ my $userEnt = $ctx->LookupUserByName($username);
+ if ($userEnt && $userEnt->Gid($GetValue) == $groupEnt->Gid($GetValue)) {
+ RaiseError(N("%s is a primary group for user %s\n Remove the user first", $groupname, $username));
+ last GLOOP;
+ }
+ }
+ if (!$error) {
+ log::explanations(N("Removing group: %s", $groupname));
+ eval { $ctx->GroupDel($groupEnt) }; Refresh($sysfilter, $stringsearch);
+ }
+ }
+ !$error and $wg->destroy; $error = 0 });
+ } ([ N("Cancel"), 1 ], [ N("Delete"), 0 ]),
+ );
+ $wg->show_all;
+}
+
sub Delete() {
my $page = $nb->get_current_page;
$us->{wnd}{rwindow}->set_sensitive(0);
gtkset_mousecursor_wait(); $error = 0;
if ($page <= 0) {
- my ($checkhome, $checkspool);
- my $username = GetNameEntFromIter($usertree, $utree_model, 0);
- my $userEnt = $ctx->LookupUserByName($username);
-# Old Delete version
- #my $removehome = GimmeChoice(N(" Remove Home Directory"), N("Do you want to delete the user's home directory and mail spool?"));
- #$removehome and $ctx->Clean($userEnt);
-# New version
- my $w = NewWindow(N("Delete files or not?"));
- my $hd = $userEnt->HomeDir($GetValue);
- gtkpack_($w->vbox,
- 0, Gtk2::Label->new(N("Deleting user %s\n Also perform the following actions\n", $username)),
- 0, $checkhome = Gtk2::CheckButton->new(N("Delete Home Directory: %s", $hd)),
- 0, $checkspool = Gtk2::CheckButton->new(N("Delete Mailbox: /var/spool/mail/%s", $username)),
- );
- gtkadd($w->action_area,
- map {
- my $r = $_->[1];
- gtksignal_connect(Gtk2::Button->new($_->[0]), clicked => sub {
- if (!$r) {
- log::explanations(N("Removing user: %s", $username));
- $ctx->UserDel($userEnt);
- UpdateOrDelUsersInGroup($username, 1);
- #Let's check out the user's primary group
- my $usergid = $userEnt->Gid($GetValue);
- my $groupEnt = $ctx->LookupGroupById($usergid);
- if ($groupEnt) {
- my $member = $groupEnt->MemberName(1, 0);
- if (scalar(@$member) == 0 && $groupEnt->Gid($GetValue) > 499) {
- $ctx->GroupDel($groupEnt);
- }
- }
- if ($checkhome->get_active) {
- eval { $ctx->CleanHome($userEnt) };
- $@ and RaiseError($@);
- }
- if ($checkspool->get_active) {
- eval { $ctx->CleanSpool($userEnt) };
- $@ and RaiseError($@);
- }
- Refresh($sysfilter, $stringsearch);
- }
- !$error and $w->destroy; $error = 0 });
- } ([ N("Cancel"), 1 ], [ N("Delete"), 0 ]),
- );
- if ($hd !~ m!(?:/home|/var/spool)!) { $checkhome->set_sensitive(0); $checkspool->set_sensitive(0) }
- $w->show_all;
+ UserDelete();
} elsif ($page == 1) {
- my $groupname = GetNameEntFromIter($grouptree, $gtree_model, 0);
- my $wg = NewWindow(translate("Warning"));
- gtkadd($wg->vbox,
- Gtk2::Label->new(N("Do you really want to delete the group %s?", $groupname)),
- );
- gtkadd($wg->action_area,
- map {
- my $r = $_->[1];
- gtksignal_connect(Gtk2::Button->new($_->[0]), clicked => sub {
- if (!$r) {
- my $groupEnt = $ctx->LookupGroupByName($groupname);
- my $members = $ctx->EnumerateUsersByGroup($groupname);
- GLOOP: foreach my $username (@$members) {
- my $userEnt = $ctx->LookupUserByName($username);
- if ($userEnt && $userEnt->Gid($GetValue) == $groupEnt->Gid($GetValue)) {
- RaiseError(N("%s is a primary group for user %s\n Remove the user first", $groupname, $username));
- last GLOOP;
- }
- }
- if (!$error) {
- log::explanations(N("Removing group: %s", $groupname));
- eval { $ctx->GroupDel($groupEnt) }; Refresh($sysfilter, $stringsearch) }
- }
- !$error and $wg->destroy; $error = 0 });
- } ([ N("Cancel"), 1 ], [ N("Delete"), 0 ]),
- );
- $wg->show_all;
+ GroupDelete();
}
$us->{wnd}{rwindow}->set_sensitive(1);
gtkset_mousecursor_normal();