[vhffs-dev] [2123] fixed primary user (owner) adding in new groups, as well as users deletion in deleted groups

[ Thread Index | Date Index | More vhffs.org/vhffs-dev Archives ]


Revision: 2123
Author:   gradator
Date:     2012-03-05 23:49:59 +0100 (Mon, 05 Mar 2012)
Log Message:
-----------
fixed primary user (owner) adding in new groups, as well as users deletion in deleted groups

Modified Paths:
--------------
    branches/vhffs-4.4/vhffs-api/src/Vhffs/Robots/Group.pm
    branches/vhffs-4.4/vhffs-api/src/Vhffs/UserGroup.pm
    trunk/vhffs-api/src/Vhffs/Robots/Group.pm
    trunk/vhffs-api/src/Vhffs/UserGroup.pm

Modified: branches/vhffs-4.4/vhffs-api/src/Vhffs/Robots/Group.pm
===================================================================
--- branches/vhffs-4.4/vhffs-api/src/Vhffs/Robots/Group.pm	2012-03-05 15:06:29 UTC (rev 2122)
+++ branches/vhffs-4.4/vhffs-api/src/Vhffs/Robots/Group.pm	2012-03-05 22:49:59 UTC (rev 2123)
@@ -41,6 +41,8 @@
 use Vhffs::Functions;
 use Vhffs::Constants;
 use Vhffs::Robots;
+use Vhffs::UserGroup;
+use Vhffs::Robots::UserGroup;
 
 package Vhffs::Robots::Group;
 
@@ -66,11 +68,15 @@
 		return undef;
 	}
 
-	chown $group->get_owner_uid, $group->get_gid, $dir;
+	chown $group->get_owner->get_uid, $group->get_gid, $dir;
 	chmod 02770, $dir;
 
-	# TODO: Rework that
-	#add_user( $group->get_owner, $group, $vhffs );
+	my $usergroup = Vhffs::UserGroup::get_by_user_group( $vhffs, $group->get_owner, $group );
+	unless( Vhffs::Robots::UserGroup::create( $usergroup ) ) {
+		$group->set_status( Vhffs::Constants::CREATION_ERROR );
+		$group->commit;
+		return undef;
+	}
 
 	Vhffs::Robots::vhffs_log( $vhffs, 'Created group '.$group->get_groupname );
 	$group->set_status( Vhffs::Constants::ACTIVATED );
@@ -90,9 +96,14 @@
 	Vhffs::Robots::archive_targz( $group, $dir );
 
 	# Remove users from group
-	# TODO: Rework that
 	foreach( @{$group->get_users} ) {
-		del_user( $_, $group, $vhffs );
+		my $usergroup = Vhffs::UserGroup::get_by_user_group( $vhffs, $_, $group );
+		$usergroup->set_status( Vhffs::Constants::WAITING_FOR_DELETION );
+		unless( Vhffs::Robots::UserGroup::delete( $usergroup ) ) {
+			$group->set_status( Vhffs::Constants::DELETION_ERROR );
+			$group->commit;
+			return undef;
+		}
 	}
 
 	# Recursively delete group objects, do not delete the group until this is done

Modified: branches/vhffs-4.4/vhffs-api/src/Vhffs/UserGroup.pm
===================================================================
--- branches/vhffs-4.4/vhffs-api/src/Vhffs/UserGroup.pm	2012-03-05 15:06:29 UTC (rev 2122)
+++ branches/vhffs-4.4/vhffs-api/src/Vhffs/UserGroup.pm	2012-03-05 22:49:59 UTC (rev 2123)
@@ -120,6 +120,28 @@
 }
 
 =pod
+
+=head2 get_by_user_group
+
+	my $usergroup = Vhffs::Group::get_by_user_group($vhffs, $user, $group;
+	die('UserGroup not found') unless(defined $usergroup);
+
+Fetches the user group whose group is a C:<Vhffs::Group> and user is a C<Vhffs::User>
+
+=cut
+sub get_by_user_group {
+	my ($vhffs, $user, $group) = @_;
+	return undef unless defined $vhffs and defined $user and defined $group;
+	my $query = 'SELECT state FROM vhffs_user_group WHERE uid=? and gid=?';
+
+	my $dbh = $vhffs->get_db;
+	my @params = $dbh->selectrow_array($query, undef, $user->get_uid, $group->get_gid);
+	return undef unless(@params);
+	my $usergroup = _new Vhffs::UserGroup($vhffs, $user, $group, @params);
+	return $usergroup;
+}
+
+=pod
 =head1 INSTANCE METHODS
 =cut
 

Modified: trunk/vhffs-api/src/Vhffs/Robots/Group.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Robots/Group.pm	2012-03-05 15:06:29 UTC (rev 2122)
+++ trunk/vhffs-api/src/Vhffs/Robots/Group.pm	2012-03-05 22:49:59 UTC (rev 2123)
@@ -41,6 +41,8 @@
 use Vhffs::Functions;
 use Vhffs::Constants;
 use Vhffs::Robots;
+use Vhffs::UserGroup;
+use Vhffs::Robots::UserGroup;
 
 package Vhffs::Robots::Group;
 
@@ -66,11 +68,15 @@
 		return undef;
 	}
 
-	chown $group->get_owner_uid, $group->get_gid, $dir;
+	chown $group->get_owner->get_uid, $group->get_gid, $dir;
 	chmod 02770, $dir;
 
-	# TODO: Rework that
-	#add_user( $group->get_owner, $group, $vhffs );
+	my $usergroup = Vhffs::UserGroup::get_by_user_group( $vhffs, $group->get_owner, $group );
+	unless( Vhffs::Robots::UserGroup::create( $usergroup ) ) {
+		$group->set_status( Vhffs::Constants::CREATION_ERROR );
+		$group->commit;
+		return undef;
+	}
 
 	Vhffs::Robots::vhffs_log( $vhffs, 'Created group '.$group->get_groupname );
 	$group->set_status( Vhffs::Constants::ACTIVATED );
@@ -90,9 +96,14 @@
 	Vhffs::Robots::archive_targz( $group, $dir );
 
 	# Remove users from group
-	# TODO: Rework that
 	foreach( @{$group->get_users} ) {
-		del_user( $_, $group, $vhffs );
+		my $usergroup = Vhffs::UserGroup::get_by_user_group( $vhffs, $_, $group );
+		$usergroup->set_status( Vhffs::Constants::WAITING_FOR_DELETION );
+		unless( Vhffs::Robots::UserGroup::delete( $usergroup ) ) {
+			$group->set_status( Vhffs::Constants::DELETION_ERROR );
+			$group->commit;
+			return undef;
+		}
 	}
 
 	# Recursively delete group objects, do not delete the group until this is done

Modified: trunk/vhffs-api/src/Vhffs/UserGroup.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/UserGroup.pm	2012-03-05 15:06:29 UTC (rev 2122)
+++ trunk/vhffs-api/src/Vhffs/UserGroup.pm	2012-03-05 22:49:59 UTC (rev 2123)
@@ -120,6 +120,28 @@
 }
 
 =pod
+
+=head2 get_by_user_group
+
+	my $usergroup = Vhffs::Group::get_by_user_group($vhffs, $user, $group;
+	die('UserGroup not found') unless(defined $usergroup);
+
+Fetches the user group whose group is a C:<Vhffs::Group> and user is a C<Vhffs::User>
+
+=cut
+sub get_by_user_group {
+	my ($vhffs, $user, $group) = @_;
+	return undef unless defined $vhffs and defined $user and defined $group;
+	my $query = 'SELECT state FROM vhffs_user_group WHERE uid=? and gid=?';
+
+	my $dbh = $vhffs->get_db;
+	my @params = $dbh->selectrow_array($query, undef, $user->get_uid, $group->get_gid);
+	return undef unless(@params);
+	my $usergroup = _new Vhffs::UserGroup($vhffs, $user, $group, @params);
+	return $usergroup;
+}
+
+=pod
 =head1 INSTANCE METHODS
 =cut
 


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/