[vhffs-dev] [2217] Improved the way we managed users created by robots.

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


Revision: 2217
Author:   gradator
Date:     2012-10-18 22:06:32 +0200 (Thu, 18 Oct 2012)
Log Message:
-----------
Improved the way we managed users created by robots. User who success having a validated group or being adding added to an active group are switched to a validated state which prevent them to be automatically removed.

Modified Paths:
--------------
    trunk/vhffs-api/src/Vhffs/Object.pm
    trunk/vhffs-api/src/Vhffs/User.pm
    trunk/vhffs-api/src/Vhffs/UserGroup.pm
    trunk/vhffs-backend/src/pgsql/initdb.sql.in
    trunk/vhffs-compat/from-4.4-to-4.5.sql

Modified: trunk/vhffs-api/src/Vhffs/Object.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/Object.pm	2012-10-16 19:01:02 UTC (rev 2216)
+++ trunk/vhffs-api/src/Vhffs/Object.pm	2012-10-18 20:06:32 UTC (rev 2217)
@@ -665,6 +665,7 @@
 	setlocale( LC_ALL , $prevlocale );
 
 	$user->set_note( $user->get_note +1 );
+	$user->set_validated( 1 );
 	$user->commit;
 
 	return $self->commit;

Modified: trunk/vhffs-api/src/Vhffs/User.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/User.pm	2012-10-16 19:01:02 UTC (rev 2216)
+++ trunk/vhffs-api/src/Vhffs/User.pm	2012-10-18 20:06:32 UTC (rev 2217)
@@ -102,7 +102,7 @@
 
 =cut
 sub _new {
-	my ($class, $vhffs, $uid, $gid, $oid, $username, $passwd, $homedir, $shell, $admin, $firstname, $lastname, $address, $zipcode, $city, $country, $mail, $gpg_key, $note, $language, $theme, $lastloginpanel, $ircnick, $date_creation, $description, $state) = @_;
+	my ($class, $vhffs, $uid, $gid, $oid, $username, $passwd, $homedir, $shell, $admin, $firstname, $lastname, $address, $zipcode, $city, $country, $mail, $gpg_key, $note, $language, $theme, $lastloginpanel, $ircnick, $validated, $date_creation, $description, $state) = @_;
 	my $self = $class->SUPER::_new($vhffs, $oid, $uid, $gid, $date_creation, $description, '', $state, Vhffs::Constants::TYPE_USER);
 	return undef unless(defined $self);
 	$self->{uid} = $uid;
@@ -125,6 +125,7 @@
 	$self->{theme} = $theme;
 	$self->{lastloginpanel} = $lastloginpanel;
 	$self->{ircnick} = $ircnick;
+	$self->{validated} = $validated;
 	return $self;
 }
 
@@ -284,7 +285,7 @@
 
 	my $ts = time() - $age;
 
-	my $query = 'SELECT u.uid FROM vhffs_users u INNER JOIN vhffs_object o ON o.object_id=u.object_id WHERE u.admin=? AND o.state=? AND o.date_creation<? AND ( u.lastloginpanel IS NULL OR u.lastloginpanel<? ) AND u.uid NOT IN (SELECT u.uid FROM vhffs_users u INNER JOIN vhffs_user_group ug ON u.uid=ug.uid)';
+	my $query = 'SELECT u.uid FROM vhffs_users u INNER JOIN vhffs_object o ON o.object_id=u.object_id WHERE u.admin=? AND u.validated=false AND o.state=? AND o.date_creation<? AND ( u.lastloginpanel IS NULL OR u.lastloginpanel<? ) AND u.uid NOT IN (SELECT u.uid FROM vhffs_users u INNER JOIN vhffs_user_group ug ON u.uid=ug.uid)';
 
 	my $request = $vhffs->get_db->prepare( $query );
 	$request->execute( Vhffs::Constants::USER_NORMAL , Vhffs::Constants::ACTIVATED , $ts , $ts );
@@ -308,7 +309,7 @@
 =cut
 sub get_by_uid {
 	my ($vhffs, $uid) = @_;
-	my $query = 'SELECT u.uid, u.gid, u.object_id, u.username, u.passwd, u.homedir, u.shell, u.admin, u.firstname, u.lastname, u.address, u.zipcode, u.city, u.country, u.mail, u.gpg_key, u.note, u.language, u.theme, u.lastloginpanel, u.ircnick, o.date_creation, o.description, o.state FROM vhffs_users u INNER JOIN vhffs_object o ON o.object_id = u.object_id WHERE u.uid = ?';
+	my $query = 'SELECT u.uid, u.gid, u.object_id, u.username, u.passwd, u.homedir, u.shell, u.admin, u.firstname, u.lastname, u.address, u.zipcode, u.city, u.country, u.mail, u.gpg_key, u.note, u.language, u.theme, u.lastloginpanel, u.ircnick, u.validated, o.date_creation, o.description, o.state FROM vhffs_users u INNER JOIN vhffs_object o ON o.object_id = u.object_id WHERE u.uid = ?';
 	my $dbh = $vhffs->get_db;
 	my @params = $dbh->selectrow_array($query, undef, $uid);
 	return undef unless(@params);
@@ -327,7 +328,7 @@
 =cut
 sub get_by_username {
 	my ($vhffs, $username) = @_;
-	my $query = 'SELECT u.uid, u.gid, u.object_id, u.username, u.passwd, u.homedir, u.shell, u.admin, u.firstname, u.lastname, u.address, u.zipcode, u.city, u.country, u.mail, u.gpg_key, u.note, u.language, u.theme, u.lastloginpanel, u.ircnick, o.date_creation, o.description, o.state FROM vhffs_users u INNER JOIN vhffs_object o ON o.object_id = u.object_id WHERE u.username = ?';
+	my $query = 'SELECT u.uid, u.gid, u.object_id, u.username, u.passwd, u.homedir, u.shell, u.admin, u.firstname, u.lastname, u.address, u.zipcode, u.city, u.country, u.mail, u.gpg_key, u.note, u.language, u.theme, u.lastloginpanel, u.ircnick, u.validated, o.date_creation, o.description, o.state FROM vhffs_users u INNER JOIN vhffs_object o ON o.object_id = u.object_id WHERE u.username = ?';
 	my $dbh = $vhffs->get_db;
 	my @params = $dbh->selectrow_array($query, undef, $username);
 	return undef unless(@params);
@@ -344,7 +345,7 @@
 =cut
 sub get_by_ircnick {
 	my ($vhffs, $ircnick) = @_;
-	my $query = 'SELECT u.uid, u.gid, u.object_id, u.username, u.passwd, u.homedir, u.shell, u.admin, u.firstname, u.lastname, u.address, u.zipcode, u.city, u.country, u.mail, u.gpg_key, u.note, u.language, u.theme, u.lastloginpanel, u.ircnick, o.date_creation, o.description, o.state FROM vhffs_users u INNER JOIN vhffs_object o ON o.object_id = u.object_id WHERE u.ircnick = ?';
+	my $query = 'SELECT u.uid, u.gid, u.object_id, u.username, u.passwd, u.homedir, u.shell, u.admin, u.firstname, u.lastname, u.address, u.zipcode, u.city, u.country, u.mail, u.gpg_key, u.note, u.language, u.theme, u.lastloginpanel, u.ircnick, u.validated, o.date_creation, o.description, o.state FROM vhffs_users u INNER JOIN vhffs_object o ON o.object_id = u.object_id WHERE u.ircnick = ?';
 	my $dbh = $vhffs->get_db;
 	my @params = $dbh->selectrow_array($query, undef, $ircnick);
 	return undef unless(@params);
@@ -373,13 +374,13 @@
 	return -1 unless defined $self->{'passwd'} and $self->{'passwd'} ne '';
 	return -2 if $self->SUPER::commit < 0;
 
-	my $sql = 'UPDATE vhffs_users SET shell = ?, passwd = ?, admin = ?, firstname = ?, lastname = ?, address = ?, zipcode = ?, country = ?, mail = ?, city = ?, gpg_key = ?, note = ?, language = ?, theme = ?, lastloginpanel = ?, ircnick = ? WHERE uid = ?';
+	my $sql = 'UPDATE vhffs_users SET shell = ?, passwd = ?, admin = ?, firstname = ?, lastname = ?, address = ?, zipcode = ?, country = ?, mail = ?, city = ?, gpg_key = ?, note = ?, language = ?, theme = ?, lastloginpanel = ?, ircnick = ?, validated = ? WHERE uid = ?';
 	my $sth = $self->get_db->prepare($sql) or return -1;
 	$sth->execute($self->{'shell'}, $self->{'passwd'}, $self->{'admin'},
 		$self->{'firstname'}, $self->{'lastname'}, $self->{'address'}, $self->{'zipcode'},
 		$self->{'country'}, $self->{'mail'}, $self->{'city'}, $self->{'gpg_key'}, $self->{'note'},
 		$self->{'language'}, $self->{'theme'}, $self->{'lastloginpanel'},
-		$self->{'ircnick'}, $self->{'uid'}) or return -3;
+		$self->{'ircnick'}, $self->{'validated'}, $self->{'uid'}) or return -3;
 
 	return 1;
 }
@@ -773,6 +774,20 @@
 
 =pod
 
+=head2 get_validated
+
+	$user->get_validated;
+
+Returns user validated state. A user get validated when its group got accepted or when it joined a group.
+
+=cut
+sub get_validated {
+	my $self = shift;
+	return( $self->{'validated'} );
+}
+
+=pod
+
 =head2 set_shell
 
 	$user->set_shell( $shell );
@@ -1003,6 +1018,21 @@
 
 =pod
 
+=head2 set_validated
+
+	$user->set_validated( $valid );
+
+Set user validated state.
+
+=cut
+sub set_validated {
+	my $self = shift;
+	my $value = shift;
+	$self->{'validated'} = $value;
+}
+
+=pod
+
 =head2 set_admin
 
 	$user->set_admin( $level );

Modified: trunk/vhffs-api/src/Vhffs/UserGroup.pm
===================================================================
--- trunk/vhffs-api/src/Vhffs/UserGroup.pm	2012-10-16 19:01:02 UTC (rev 2216)
+++ trunk/vhffs-api/src/Vhffs/UserGroup.pm	2012-10-18 20:06:32 UTC (rev 2217)
@@ -100,7 +100,12 @@
 
 	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 );
+	my $self = _new Vhffs::UserGroup( $group->get_vhffs, $user, $group, Vhffs::Constants::WAITING_FOR_CREATION );
+	if( defined $self ) {
+		$user->set_validated( 1 );
+		$user->commit;
+	}
+	return $self;
 }
 
 =pod

Modified: trunk/vhffs-backend/src/pgsql/initdb.sql.in
===================================================================
--- trunk/vhffs-backend/src/pgsql/initdb.sql.in	2012-10-16 19:01:02 UTC (rev 2216)
+++ trunk/vhffs-backend/src/pgsql/initdb.sql.in	2012-10-18 20:06:32 UTC (rev 2217)
@@ -122,6 +122,8 @@
 	lastloginpanel int8,
 -- IRC nick
 	ircnick varchar(16),
+-- Validated account (got a validated group or joined a group)
+	validated boolean NOT NULL DEFAULT false,
 	CONSTRAINT vhffs_users_pkey PRIMARY KEY (uid)
 ) WITH (OIDS);
 

Modified: trunk/vhffs-compat/from-4.4-to-4.5.sql
===================================================================
--- trunk/vhffs-compat/from-4.4-to-4.5.sql	2012-10-16 19:01:02 UTC (rev 2216)
+++ trunk/vhffs-compat/from-4.4-to-4.5.sql	2012-10-18 20:06:32 UTC (rev 2217)
@@ -214,3 +214,7 @@
 	UPDATE vhffs_mx_box SET state=15 WHERE state=8;
 	UPDATE vhffs_mx_box SET state=14 WHERE state=7;
 COMMIT;
+
+-- add validated bool field to vhffs_users, so that we don't automatically delete users who used to be in a group/projet
+ALTER TABLE vhffs_users ADD COLUMN validated BOOLEAN NOT NULL DEFAULT false;
+UPDATE vhffs_users SET validated=true WHERE uid IN (SELECT ug.uid FROM vhffs_user_group ug);


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