[vhffs-dev] [997] When a user left its last group, its mailuser is deleted as well if groupneed is set to yes |
[ Thread Index |
Date Index
| More vhffs.org/vhffs-dev Archives
]
Revision: 997
Author: gradator
Date: 2007-10-16 15:00:08 +0000 (Tue, 16 Oct 2007)
Log Message:
-----------
When a user left its last group, its mailuser is deleted as well if groupneed is set to yes
Modified Paths:
--------------
trunk/vhffs-api/src/Vhffs/Group.pm
trunk/vhffs-api/src/Vhffs/Services/MailGroup.pm
trunk/vhffs-api/src/Vhffs/Services/MailUser.pm
Modified: trunk/vhffs-api/src/Vhffs/Group.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Group.pm 2007-10-16 14:22:53 UTC (rev 996)
+++ trunk/vhffs-api/src/Vhffs/Group.pm 2007-10-16 15:00:08 UTC (rev 997)
@@ -34,7 +34,9 @@
use strict;
use DBI;
+use Vhffs::Constants;
+
=head1 NAME
Vhffs::Object - Handle a group in VHFFS
@@ -142,13 +144,38 @@
sub remove_user
{
- use Vhffs::Constants;
+ use Vhffs::User;
my $self = shift;
my $uid = shift;
+ my $user = Vhffs::User::get_by_uid( $self->{'main'} , $uid );
+ return -1 unless defined $user;
- my $sql = 'UPDATE vhffs_user_group SET state=? WHERE gid=? AND uid=?';
- return $self->{db}->do( $sql, {}, Vhffs::Constants::TO_DELETE, $self->{gid}, $uid ) > 0;
+ # delete mail user if mail user is enabled, and if a group is needed to have a mail user, and if this is the last group of this user
+ if( $self->{'main'}->get_config->get_service_availability('mailuser') == 1 && $self->{'main'}->get_config->get_service('mailuser')->{groupneeded} eq 'yes' )
+ {
+ use Vhffs::Services::Mail;
+ use Vhffs::Services::MailUser;
+ my $mu = init Vhffs::Services::MailUser( $self->{'main'} , $user );
+
+ if( defined $mu ) {
+
+ my $sql = 'SELECT COUNT(*) FROM vhffs_user_group WHERE uid=?';
+ my $request = $self->{'db'}->prepare( $sql );
+ if( $request->execute( $uid ) ) {
+ my $row = $request->fetchrow_arrayref;
+ if( $row ) {
+ if( $row->[0] <= 1 ) {
+ $mu->delbox;
+ $mu->delforward;
+ }
+ }
+ }
+ }
+ }
+
+ my $sql = 'UPDATE vhffs_user_group SET state=? WHERE gid=? AND uid=?';
+ return $self->{db}->do( $sql, {}, Vhffs::Constants::TO_DELETE, $self->{gid}, $uid ) > 0;
}
Modified: trunk/vhffs-api/src/Vhffs/Services/MailGroup.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Services/MailGroup.pm 2007-10-16 14:22:53 UTC (rev 996)
+++ trunk/vhffs-api/src/Vhffs/Services/MailGroup.pm 2007-10-16 15:00:08 UTC (rev 997)
@@ -120,7 +120,7 @@
my $remote = shift;
$self->{mail_service}->delforward( $self->{localpart} ) if( $self->exists_forward == 1 );
- $self->{mail_service}->delbox( $self->{localpart} ) if( $self->exists_box == 1 );
+ $self->{mail_service}->set_box_status( $self->{localpart} , Vhffs::Constants::TO_DELETE ) if( $self->exists_box == 1 );
return -1 if ( $self->{mail_service}->addforward( $self->{localpart} , $remote ) < 0);
}
@@ -140,7 +140,7 @@
sub delbox
{
my $self = shift;
- $self->{mail_service}->delbox( $self->{localpart} );
+ $self->{mail_service}->set_box_status( $self->{localpart} , Vhffs::Constants::TO_DELETE );
}
sub addbox
Modified: trunk/vhffs-api/src/Vhffs/Services/MailUser.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Services/MailUser.pm 2007-10-16 14:22:53 UTC (rev 996)
+++ trunk/vhffs-api/src/Vhffs/Services/MailUser.pm 2007-10-16 15:00:08 UTC (rev 997)
@@ -122,7 +122,7 @@
my $remote = shift;
$self->{mail_service}->delforward( $self->{localpart} ) if( $self->exists_forward == 1 );
- $self->{mail_service}->delbox( $self->{localpart} ) if( $self->exists_box == 1 );
+ $self->{mail_service}->set_box_status( $self->{localpart} , Vhffs::Constants::TO_DELETE ) if( $self->exists_box == 1 );
return -1 if ( $self->{mail_service}->addforward( $self->{localpart} , $remote ) < 0);
}
@@ -142,7 +142,7 @@
sub delbox
{
my $self = shift;
- $self->{mail_service}->delbox( $self->{localpart} );
+ $self->{mail_service}->set_box_status( $self->{localpart} , Vhffs::Constants::TO_DELETE );
}
sub addbox