[vhffs-dev] [2134] clean fix for user<>group glitch bug ( yeah this involve some design changes)

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


Revision: 2134
Author:   gradator
Date:     2012-03-10 17:09:42 +0100 (Sat, 10 Mar 2012)
Log Message:
-----------
clean fix for user<>group glitch bug (yeah this involve some design changes)

Modified Paths:
--------------
    branches/vhffs-4.4/vhffs-api/examples/create_group.pl
    branches/vhffs-4.4/vhffs-api/examples/join_group.pl
    branches/vhffs-4.4/vhffs-api/src/Vhffs/Group.pm
    branches/vhffs-4.4/vhffs-api/src/Vhffs/Panel/Group.pm
    branches/vhffs-4.4/vhffs-api/src/Vhffs/Robots/Group.pm
    branches/vhffs-4.4/vhffs-api/src/Vhffs/Robots/UserGroup.pm
    branches/vhffs-4.4/vhffs-api/src/Vhffs/UserGroup.pm
    branches/vhffs-4.4/vhffs-panel/templates/group/prefs.tt
    trunk/vhffs-api/examples/create_group.pl
    trunk/vhffs-api/examples/join_group.pl
    trunk/vhffs-api/src/Vhffs/Group.pm
    trunk/vhffs-api/src/Vhffs/Panel/Group.pm
    trunk/vhffs-api/src/Vhffs/Robots/Group.pm
    trunk/vhffs-api/src/Vhffs/Robots/UserGroup.pm
    trunk/vhffs-api/src/Vhffs/UserGroup.pm
    trunk/vhffs-panel/templates/group/prefs.tt

Modified: branches/vhffs-4.4/vhffs-api/examples/create_group.pl
===================================================================
--- branches/vhffs-4.4/vhffs-api/examples/create_group.pl	2012-03-10 01:39:56 UTC (rev 2133)
+++ branches/vhffs-4.4/vhffs-api/examples/create_group.pl	2012-03-10 16:09:42 UTC (rev 2134)
@@ -28,6 +28,3 @@
 {
 	print "Group $groupname created!\n";
 }
-
-$group->add_user( $user->get_uid );
-

Modified: branches/vhffs-4.4/vhffs-api/examples/join_group.pl
===================================================================
--- branches/vhffs-4.4/vhffs-api/examples/join_group.pl	2012-03-10 01:39:56 UTC (rev 2133)
+++ branches/vhffs-4.4/vhffs-api/examples/join_group.pl	2012-03-10 16:09:42 UTC (rev 2134)
@@ -19,4 +19,4 @@
 my $group = Vhffs::Group::get_by_groupname($vhffs, $groupname);
 die("Group not found\n") unless(defined $group);
 
-die("Unable to add $username to group $groupname\n") unless($group->add_user($user->get_uid) > 0);
+die("Unable to add $username to group $groupname\n") unless($group->add_user($user) > 0);

Modified: branches/vhffs-4.4/vhffs-api/src/Vhffs/Group.pm
===================================================================
--- branches/vhffs-4.4/vhffs-api/src/Vhffs/Group.pm	2012-03-10 01:39:56 UTC (rev 2133)
+++ branches/vhffs-4.4/vhffs-api/src/Vhffs/Group.pm	2012-03-10 16:09:42 UTC (rev 2134)
@@ -361,35 +361,35 @@
 
 =head2 add_user
 
-	$group->add_user($uid);
+	$group->add_user($user);
 
-Adds an user to a group. Returns false if user doesn't exists or if there was an error.
+Adds a C<Vhffs::User> to a C<Vhffs::Group>.
+Returns a C<Vhffs::UserGroup> on success, otherwise returns false.
 
 =cut
 sub add_user {
-	my( $self , $uid ) = @_;
-
-	my $sql = 'INSERT INTO vhffs_user_group(uid, gid, state) VALUES(?, ?, ?)';
-	my $res = $self->get_db->do( $sql, {}, $uid, $self->{gid}, Vhffs::Constants::WAITING_FOR_CREATION );
-	return ( defined $res and $res > 0 );
+	my( $self, $user ) = @_;
+	use Vhffs::UserGroup;
+	return Vhffs::UserGroup::create( $user, $self );
 }
 
 =pod
 
 =head2 remove_user
 
-	$group->remove_user( $uid );
+	$group->remove_user($user);
 
-Remove an user from a given group.
+Remove a C<Vhffs::User> from a C<Vhffs::Group>.
 Return false if an error occurs or if the user wasn't in the group.
 
 =cut
 sub remove_user {
-	my $self = shift;
-	my $uid = shift;
-
-	my $sql = 'UPDATE vhffs_user_group SET state=? WHERE gid=? AND uid=?';
-	return $self->get_db->do( $sql, {}, Vhffs::Constants::WAITING_FOR_DELETION, $self->{gid}, $uid ) > 0;
+	my( $self, $user ) = @_;
+	use Vhffs::UserGroup;
+	my $usergroup = Vhffs::UserGroup::get_by_user_group( $user, $self );
+	return undef unless $usergroup;
+	$usergroup->set_status( Vhffs::Constants::WAITING_FOR_DELETION );
+	return $usergroup->commit;
 }
 
 =pod

Modified: branches/vhffs-4.4/vhffs-api/src/Vhffs/Panel/Group.pm
===================================================================
--- branches/vhffs-4.4/vhffs-api/src/Vhffs/Panel/Group.pm	2012-03-10 01:39:56 UTC (rev 2133)
+++ branches/vhffs-4.4/vhffs-api/src/Vhffs/Panel/Group.pm	2012-03-10 16:09:42 UTC (rev 2134)
@@ -194,17 +194,9 @@
 
 =cut
 
-sub create_group
-{
-	my( $groupname , $realname, $user , $vhffs, $description ) = @_;
-
-	my $group = Vhffs::Group::create($vhffs, $groupname, $realname, $user->get_uid, undef, $description);
-	return undef unless defined $group;
-
-	# TODO: rework that, this is ridiculous that the panel add the primary user to the recently created group
-	return undef unless $group->add_user( $user->get_uid );
-
-	return $group;
+sub create_group {
+	my( $groupname , $realname, $user, $vhffs, $description ) = @_;
+	return Vhffs::Group::create($vhffs, $groupname, $realname, $user->get_uid, undef, $description);
 }
 
 sub get_groups_starting_with {
@@ -450,21 +442,27 @@
 		}
 
 	} elsif( defined( $cgi->param( 'remove_user_submit' ) ) ) {
-		# User removal
-		my $uid = $cgi->param( 'uid' );
-		unless( defined $uid and $uid =~ /^\d+$/ ) {
-			$panel->add_error( gettext('CGI Error !') );
+		unless( $user->can_modify( $group ) ) {
+			$panel->add_error( gettext( 'You\'re not allowed to do this (ACL rights)' ) );
+		} elsif( not $user->is_admin ) {
+			$panel->add_error( gettext('Only an administrator can remove someone from a group, please contact the administration team') );
 		} else {
-			unless( $uid == $user->get_uid or $user->can_modify( $group ) )  {
-				$panel->add_error( gettext( 'You\'re not allowed to do this (ACL rights)' ) );
-			} elsif( $uid == $group->get_owner_uid ) {
-				$panel->add_error( gettext('You cannot remove the owner of the group') );
-			} elsif( not $user->is_admin ) {
-				$panel->add_error( gettext('Only an administrator can remove someone from a group, please contact the administration team') );
-			} elsif( $group->remove_user($uid) ) {
-				$panel->add_info( gettext('This user will be removed from this group as soon as possible') );
+			my $username = $cgi->param( 'username' );
+			unless( defined $username ) {
+				$panel->add_error( gettext('CGI Error !') );
+			} elsif( $username =~ /^\s*$/ ) {
+				$vars->{add_user_error} = gettext('You must enter an username');
 			} else {
-				$panel->add_error( gettext('Unable to remove user from group') );
+				my $del_user = Vhffs::User::get_by_username( $vhffs, $username);
+				unless( defined $del_user) {
+					$vars->{add_user_error} = gettext('User not found');
+				} elsif( $del_user->get_uid == $group->get_owner_uid ) {
+					$vars->{add_user_error} = gettext('You cannot remove the owner of the group');
+				} elsif( $group->remove_user($del_user) ) {
+					$vars->{add_user_info} = gettext('This user will be removed from this group as soon as possible');
+				} else {
+					$vars->{add_user_error} = gettext('Unable to remove user from group');
+				}
 			}
 		}
 
@@ -482,7 +480,7 @@
 				my $new_user = Vhffs::User::get_by_username( $vhffs, $username);
 				if(defined $new_user) {
 					# Fine, user exists, let's add it
-					if( $group->add_user( $new_user->get_uid ) ) {
+					if( $group->add_user( $new_user ) ) {
 						$vars->{add_user_info} = gettext('User will be added as soon as possible');
 					} else {
 						$vars->{add_user_error} = gettext('Unable to add user, he might already be in the group (waiting for addition or deletion)');
@@ -501,22 +499,6 @@
 			}
 		}
 
-	} elsif( defined( $cgi->param('add_user_list_submit') ) ) {
-		unless( $user->can_modify( $group ) ) {
-			$panel->add_error( gettext( 'You\'re not allowed to do this (ACL rights)' ) );
-		} else {
-			my $uid = $cgi->param( 'uid' );
-			unless( defined $uid and $uid =~ /^\d+$/ ) {
-				$panel->add_error( gettext('CGI Error !') );
-			} else {
-				if( $group->add_user( $uid ) ) {
-					$vars->{add_user_info} = gettext('User will be added as soon as possible');
-				} else {
-					$vars->{add_user_error} = gettext('Unable to add user, he might already be in the group (waiting for addition or deletion)');
-				}
-			}
-		}
-
 	} elsif( defined( $cgi->param('contact_email_submit') ) ) {
 		unless( $vhffs->get_config->get_service_availability('mailgroup')  &&  $user->can_modify( $group ) ) {
 			$panel->add_error( gettext( 'You\'re not allowed to do this (ACL rights)' ) );

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-10 01:39:56 UTC (rev 2133)
+++ branches/vhffs-4.4/vhffs-api/src/Vhffs/Robots/Group.pm	2012-03-10 16:09:42 UTC (rev 2134)
@@ -75,7 +75,7 @@
 	$group->set_status( Vhffs::Constants::ACTIVATED );
 	$group->commit;
 
-	my $usergroup = Vhffs::UserGroup::get_by_user_group( $vhffs, $group->get_owner, $group );
+	my $usergroup = $group->add_user( $group->get_owner );
 	Vhffs::Robots::UserGroup::create( $usergroup );
 
 	quota($group);
@@ -94,7 +94,7 @@
 
 	# Remove users from group
 	foreach( @{$group->get_users} ) {
-		my $usergroup = Vhffs::UserGroup::get_by_user_group( $vhffs, $_, $group );
+		my $usergroup = Vhffs::UserGroup::get_by_user_group( $_, $group );
 		$usergroup->set_status( Vhffs::Constants::WAITING_FOR_DELETION );
 		unless( Vhffs::Robots::UserGroup::delete( $usergroup ) ) {
 			$group->set_status( Vhffs::Constants::DELETION_ERROR );

Modified: branches/vhffs-4.4/vhffs-api/src/Vhffs/Robots/UserGroup.pm
===================================================================
--- branches/vhffs-4.4/vhffs-api/src/Vhffs/Robots/UserGroup.pm	2012-03-10 01:39:56 UTC (rev 2133)
+++ branches/vhffs-4.4/vhffs-api/src/Vhffs/Robots/UserGroup.pm	2012-03-10 16:09:42 UTC (rev 2134)
@@ -49,7 +49,6 @@
 	my $user = $usergroup->get_user;
 	my $group = $usergroup->get_group;
 	my $vhffs = $usergroup->get_vhffs;
-	return undef unless $group->get_status == Vhffs::Constants::ACTIVATED;
 
 	unless( $vhffs->get_config->use_vhffsfs )  {
 		my $groupdir = $group->get_dir;

Modified: branches/vhffs-4.4/vhffs-api/src/Vhffs/UserGroup.pm
===================================================================
--- branches/vhffs-4.4/vhffs-api/src/Vhffs/UserGroup.pm	2012-03-10 01:39:56 UTC (rev 2133)
+++ branches/vhffs-4.4/vhffs-api/src/Vhffs/UserGroup.pm	2012-03-10 16:09:42 UTC (rev 2134)
@@ -87,6 +87,24 @@
 
 =pod
 
+=head2 create
+
+	my $usergroup = Vhffs::UserGroup::create($vhffs, $group, $user)
+
+Create in DB and return a C<Vhffs::UserGroup>.
+
+=cut
+sub create {
+	my ( $user, $group ) = @_;
+	return undef unless defined $user and defined $group;
+
+	my $sql = 'INSERT INTO vhffs_user_group(uid, gid, state) VALUES(?, ?, ?)';
+	my $res = $group->get_db->do( $sql, {}, $user->get_uid, $group->get_gid, Vhffs::Constants::WAITING_FOR_CREATION ) or return undef;
+	return _new Vhffs::UserGroup( $group->get_vhffs, $user, $group, Vhffs::Constants::WAITING_FOR_CREATION );
+}
+
+=pod
+
 =head2 getall
 
 	my $usergroups = Vhffs::UserGroup::getall( $vhffs, $state ;
@@ -123,21 +141,20 @@
 
 =head2 get_by_user_group
 
-	my $usergroup = Vhffs::Group::get_by_user_group($vhffs, $user, $group;
+	my $usergroup = Vhffs::Group::get_by_user_group( $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 ($user, $group) = @_;
+	return undef unless 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);
+	my @params = $user->get_db->selectrow_array($query, undef, $user->get_uid, $group->get_gid);
 	return undef unless(@params);
-	my $usergroup = _new Vhffs::UserGroup($vhffs, $user, $group, @params);
+	my $usergroup = _new Vhffs::UserGroup( $group->get_vhffs, $user, $group, @params);
 	return $usergroup;
 }
 

Modified: branches/vhffs-4.4/vhffs-panel/templates/group/prefs.tt
===================================================================
--- branches/vhffs-4.4/vhffs-panel/templates/group/prefs.tt	2012-03-10 01:39:56 UTC (rev 2133)
+++ branches/vhffs-4.4/vhffs-panel/templates/group/prefs.tt	2012-03-10 16:09:42 UTC (rev 2134)
@@ -40,7 +40,7 @@
 [% FOREACH u IN group_users %]
 [% IF u.active %]
 <form class="table-like" action="#" method="post" accept-charset="utf-8">
-<input type="hidden" name="uid" value="[% u.uid %]"/>
+<input type="hidden" name="username" value="[% u.username %]"/>
 <input type="hidden" name="group" value="[% group.get_groupname | html %]"/>
 <p><label>[% u.username | html %] ([% u.firstname | html %] [% u.lastname | html %])</label>
     <input type="submit" value="[% 'Remove' | i18n | html %]" name="remove_user_submit"/></p>
@@ -77,10 +77,10 @@
 
 [% FOREACH u IN add_user_list %]
 <form class="table-like" action="#" method="post" accept-charset="utf-8">
-<input type="hidden" name="uid" value="[% u.uid %]"/>
+<input type="hidden" name="username" value="[% u.username %]"/>
 <input type="hidden" name="group" value="[% group.get_groupname | html %]"/>
 <p><label>[% u.username | html %] ([% u.realname | html %])</label>
-<input type="submit" name="add_user_list_submit" value="[% 'Add' | i18n | html %]"/></p>
+<input type="submit" name="add_user_submit" value="[% 'Add' | i18n | html %]"/></p>
 </form>
 [% END %]
 

Modified: trunk/vhffs-api/examples/create_group.pl
===================================================================
--- trunk/vhffs-api/examples/create_group.pl	2012-03-10 01:39:56 UTC (rev 2133)
+++ trunk/vhffs-api/examples/create_group.pl	2012-03-10 16:09:42 UTC (rev 2134)
@@ -28,6 +28,3 @@
 {
 	print "Group $groupname created!\n";
 }
-
-$group->add_user( $user->get_uid );
-

Modified: trunk/vhffs-api/examples/join_group.pl
===================================================================
--- trunk/vhffs-api/examples/join_group.pl	2012-03-10 01:39:56 UTC (rev 2133)
+++ trunk/vhffs-api/examples/join_group.pl	2012-03-10 16:09:42 UTC (rev 2134)
@@ -19,4 +19,4 @@
 my $group = Vhffs::Group::get_by_groupname($vhffs, $groupname);
 die("Group not found\n") unless(defined $group);
 
-die("Unable to add $username to group $groupname\n") unless($group->add_user($user->get_uid) > 0);
+die("Unable to add $username to group $groupname\n") unless($group->add_user($user) > 0);

Modified: trunk/vhffs-api/src/Vhffs/Group.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Group.pm	2012-03-10 01:39:56 UTC (rev 2133)
+++ trunk/vhffs-api/src/Vhffs/Group.pm	2012-03-10 16:09:42 UTC (rev 2134)
@@ -361,35 +361,35 @@
 
 =head2 add_user
 
-	$group->add_user($uid);
+	$group->add_user($user);
 
-Adds an user to a group. Returns false if user doesn't exists or if there was an error.
+Adds a C<Vhffs::User> to a C<Vhffs::Group>.
+Returns a C<Vhffs::UserGroup> on success, otherwise returns false.
 
 =cut
 sub add_user {
-	my( $self , $uid ) = @_;
-
-	my $sql = 'INSERT INTO vhffs_user_group(uid, gid, state) VALUES(?, ?, ?)';
-	my $res = $self->get_db->do( $sql, {}, $uid, $self->{gid}, Vhffs::Constants::WAITING_FOR_CREATION );
-	return ( defined $res and $res > 0 );
+	my( $self, $user ) = @_;
+	use Vhffs::UserGroup;
+	return Vhffs::UserGroup::create( $user, $self );
 }
 
 =pod
 
 =head2 remove_user
 
-	$group->remove_user( $uid );
+	$group->remove_user($user);
 
-Remove an user from a given group.
+Remove a C<Vhffs::User> from a C<Vhffs::Group>.
 Return false if an error occurs or if the user wasn't in the group.
 
 =cut
 sub remove_user {
-	my $self = shift;
-	my $uid = shift;
-
-	my $sql = 'UPDATE vhffs_user_group SET state=? WHERE gid=? AND uid=?';
-	return $self->get_db->do( $sql, {}, Vhffs::Constants::WAITING_FOR_DELETION, $self->{gid}, $uid ) > 0;
+	my( $self, $user ) = @_;
+	use Vhffs::UserGroup;
+	my $usergroup = Vhffs::UserGroup::get_by_user_group( $user, $self );
+	return undef unless $usergroup;
+	$usergroup->set_status( Vhffs::Constants::WAITING_FOR_DELETION );
+	return $usergroup->commit;
 }
 
 =pod

Modified: trunk/vhffs-api/src/Vhffs/Panel/Group.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Panel/Group.pm	2012-03-10 01:39:56 UTC (rev 2133)
+++ trunk/vhffs-api/src/Vhffs/Panel/Group.pm	2012-03-10 16:09:42 UTC (rev 2134)
@@ -194,17 +194,9 @@
 
 =cut
 
-sub create_group
-{
-	my( $groupname , $realname, $user , $vhffs, $description ) = @_;
-
-	my $group = Vhffs::Group::create($vhffs, $groupname, $realname, $user->get_uid, undef, $description);
-	return undef unless defined $group;
-
-	# TODO: rework that, this is ridiculous that the panel add the primary user to the recently created group
-	return undef unless $group->add_user( $user->get_uid );
-
-	return $group;
+sub create_group {
+	my( $groupname , $realname, $user, $vhffs, $description ) = @_;
+	return Vhffs::Group::create($vhffs, $groupname, $realname, $user->get_uid, undef, $description);
 }
 
 sub get_groups_starting_with {
@@ -450,21 +442,27 @@
 		}
 
 	} elsif( defined( $cgi->param( 'remove_user_submit' ) ) ) {
-		# User removal
-		my $uid = $cgi->param( 'uid' );
-		unless( defined $uid and $uid =~ /^\d+$/ ) {
-			$panel->add_error( gettext('CGI Error !') );
+		unless( $user->can_modify( $group ) ) {
+			$panel->add_error( gettext( 'You\'re not allowed to do this (ACL rights)' ) );
+		} elsif( not $user->is_admin ) {
+			$panel->add_error( gettext('Only an administrator can remove someone from a group, please contact the administration team') );
 		} else {
-			unless( $uid == $user->get_uid or $user->can_modify( $group ) )  {
-				$panel->add_error( gettext( 'You\'re not allowed to do this (ACL rights)' ) );
-			} elsif( $uid == $group->get_owner_uid ) {
-				$panel->add_error( gettext('You cannot remove the owner of the group') );
-			} elsif( not $user->is_admin ) {
-				$panel->add_error( gettext('Only an administrator can remove someone from a group, please contact the administration team') );
-			} elsif( $group->remove_user($uid) ) {
-				$panel->add_info( gettext('This user will be removed from this group as soon as possible') );
+			my $username = $cgi->param( 'username' );
+			unless( defined $username ) {
+				$panel->add_error( gettext('CGI Error !') );
+			} elsif( $username =~ /^\s*$/ ) {
+				$vars->{add_user_error} = gettext('You must enter an username');
 			} else {
-				$panel->add_error( gettext('Unable to remove user from group') );
+				my $del_user = Vhffs::User::get_by_username( $vhffs, $username);
+				unless( defined $del_user) {
+					$vars->{add_user_error} = gettext('User not found');
+				} elsif( $del_user->get_uid == $group->get_owner_uid ) {
+					$vars->{add_user_error} = gettext('You cannot remove the owner of the group');
+				} elsif( $group->remove_user($del_user) ) {
+					$vars->{add_user_info} = gettext('This user will be removed from this group as soon as possible');
+				} else {
+					$vars->{add_user_error} = gettext('Unable to remove user from group');
+				}
 			}
 		}
 
@@ -482,7 +480,7 @@
 				my $new_user = Vhffs::User::get_by_username( $vhffs, $username);
 				if(defined $new_user) {
 					# Fine, user exists, let's add it
-					if( $group->add_user( $new_user->get_uid ) ) {
+					if( $group->add_user( $new_user ) ) {
 						$vars->{add_user_info} = gettext('User will be added as soon as possible');
 					} else {
 						$vars->{add_user_error} = gettext('Unable to add user, he might already be in the group (waiting for addition or deletion)');
@@ -501,22 +499,6 @@
 			}
 		}
 
-	} elsif( defined( $cgi->param('add_user_list_submit') ) ) {
-		unless( $user->can_modify( $group ) ) {
-			$panel->add_error( gettext( 'You\'re not allowed to do this (ACL rights)' ) );
-		} else {
-			my $uid = $cgi->param( 'uid' );
-			unless( defined $uid and $uid =~ /^\d+$/ ) {
-				$panel->add_error( gettext('CGI Error !') );
-			} else {
-				if( $group->add_user( $uid ) ) {
-					$vars->{add_user_info} = gettext('User will be added as soon as possible');
-				} else {
-					$vars->{add_user_error} = gettext('Unable to add user, he might already be in the group (waiting for addition or deletion)');
-				}
-			}
-		}
-
 	} elsif( defined( $cgi->param('contact_email_submit') ) ) {
 		unless( $vhffs->get_config->get_service_availability('mailgroup')  &&  $user->can_modify( $group ) ) {
 			$panel->add_error( gettext( 'You\'re not allowed to do this (ACL rights)' ) );

Modified: trunk/vhffs-api/src/Vhffs/Robots/Group.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Robots/Group.pm	2012-03-10 01:39:56 UTC (rev 2133)
+++ trunk/vhffs-api/src/Vhffs/Robots/Group.pm	2012-03-10 16:09:42 UTC (rev 2134)
@@ -75,7 +75,7 @@
 	$group->set_status( Vhffs::Constants::ACTIVATED );
 	$group->commit;
 
-	my $usergroup = Vhffs::UserGroup::get_by_user_group( $vhffs, $group->get_owner, $group );
+	my $usergroup = $group->add_user( $group->get_owner );
 	Vhffs::Robots::UserGroup::create( $usergroup );
 
 	quota($group);
@@ -94,7 +94,7 @@
 
 	# Remove users from group
 	foreach( @{$group->get_users} ) {
-		my $usergroup = Vhffs::UserGroup::get_by_user_group( $vhffs, $_, $group );
+		my $usergroup = Vhffs::UserGroup::get_by_user_group( $_, $group );
 		$usergroup->set_status( Vhffs::Constants::WAITING_FOR_DELETION );
 		unless( Vhffs::Robots::UserGroup::delete( $usergroup ) ) {
 			$group->set_status( Vhffs::Constants::DELETION_ERROR );

Modified: trunk/vhffs-api/src/Vhffs/Robots/UserGroup.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Robots/UserGroup.pm	2012-03-10 01:39:56 UTC (rev 2133)
+++ trunk/vhffs-api/src/Vhffs/Robots/UserGroup.pm	2012-03-10 16:09:42 UTC (rev 2134)
@@ -49,7 +49,6 @@
 	my $user = $usergroup->get_user;
 	my $group = $usergroup->get_group;
 	my $vhffs = $usergroup->get_vhffs;
-	return undef unless $group->get_status == Vhffs::Constants::ACTIVATED;
 
 	unless( $vhffs->get_config->use_vhffsfs )  {
 		my $groupdir = $group->get_dir;

Modified: trunk/vhffs-api/src/Vhffs/UserGroup.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/UserGroup.pm	2012-03-10 01:39:56 UTC (rev 2133)
+++ trunk/vhffs-api/src/Vhffs/UserGroup.pm	2012-03-10 16:09:42 UTC (rev 2134)
@@ -87,6 +87,24 @@
 
 =pod
 
+=head2 create
+
+	my $usergroup = Vhffs::UserGroup::create($vhffs, $group, $user)
+
+Create in DB and return a C<Vhffs::UserGroup>.
+
+=cut
+sub create {
+	my ( $user, $group ) = @_;
+	return undef unless defined $user and defined $group;
+
+	my $sql = 'INSERT INTO vhffs_user_group(uid, gid, state) VALUES(?, ?, ?)';
+	my $res = $group->get_db->do( $sql, {}, $user->get_uid, $group->get_gid, Vhffs::Constants::WAITING_FOR_CREATION ) or return undef;
+	return _new Vhffs::UserGroup( $group->get_vhffs, $user, $group, Vhffs::Constants::WAITING_FOR_CREATION );
+}
+
+=pod
+
 =head2 getall
 
 	my $usergroups = Vhffs::UserGroup::getall( $vhffs, $state ;
@@ -123,21 +141,20 @@
 
 =head2 get_by_user_group
 
-	my $usergroup = Vhffs::Group::get_by_user_group($vhffs, $user, $group;
+	my $usergroup = Vhffs::Group::get_by_user_group( $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 ($user, $group) = @_;
+	return undef unless 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);
+	my @params = $user->get_db->selectrow_array($query, undef, $user->get_uid, $group->get_gid);
 	return undef unless(@params);
-	my $usergroup = _new Vhffs::UserGroup($vhffs, $user, $group, @params);
+	my $usergroup = _new Vhffs::UserGroup( $group->get_vhffs, $user, $group, @params);
 	return $usergroup;
 }
 

Modified: trunk/vhffs-panel/templates/group/prefs.tt
===================================================================
--- trunk/vhffs-panel/templates/group/prefs.tt	2012-03-10 01:39:56 UTC (rev 2133)
+++ trunk/vhffs-panel/templates/group/prefs.tt	2012-03-10 16:09:42 UTC (rev 2134)
@@ -40,7 +40,7 @@
 [% FOREACH u IN group_users %]
 [% IF u.active %]
 <form class="table-like" action="#" method="post" accept-charset="utf-8">
-<input type="hidden" name="uid" value="[% u.uid %]"/>
+<input type="hidden" name="username" value="[% u.username %]"/>
 <input type="hidden" name="group" value="[% group.get_groupname | html %]"/>
 <p><label>[% u.username | html %] ([% u.firstname | html %] [% u.lastname | html %])</label>
     <input type="submit" value="[% 'Remove' | i18n | html %]" name="remove_user_submit"/></p>
@@ -77,10 +77,10 @@
 
 [% FOREACH u IN add_user_list %]
 <form class="table-like" action="#" method="post" accept-charset="utf-8">
-<input type="hidden" name="uid" value="[% u.uid %]"/>
+<input type="hidden" name="username" value="[% u.username %]"/>
 <input type="hidden" name="group" value="[% group.get_groupname | html %]"/>
 <p><label>[% u.username | html %] ([% u.realname | html %])</label>
-<input type="submit" name="add_user_list_submit" value="[% 'Add' | i18n | html %]"/></p>
+<input type="submit" name="add_user_submit" value="[% 'Add' | i18n | html %]"/></p>
 </form>
 [% END %]
 


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