From 9536b7901ed2a7cec5db196c3a38dd9b333df3d2 Mon Sep 17 00:00:00 2001 From: Dany De Bontridder Date: Thu, 11 Feb 2016 16:34:49 +0100 Subject: [PATCH] Remove inexistant user --- include/class/class_user.php | 18 +++++ include/dossier.inc.php | 1 + include/restore.inc.php | 1 + include/upgrade.inc.php | 1 + unit-test/include/class/class_userTest.php | 90 ++++++++++++++-------- 5 files changed, 78 insertions(+), 33 deletions(-) diff --git a/include/class/class_user.php b/include/class/class_user.php index c18fe03bb..5b2c49a0f 100644 --- a/include/class/class_user.php +++ b/include/class/class_user.php @@ -1315,6 +1315,24 @@ class User } + static function remove_inexistant_user($p_dossier) + { + $cnx_repo=new Database(); + $cnx_dossier=new Database($p_dossier); + + $a_user=$cnx_dossier->get_array('select user_name from profile_user'); + if ( ! $a_user ) return; + $nb=count($a_user); + for ($i=0;$i < $nb;$i++) { + if ( $cnx_repo->get_value('select count(*) from ac_users where use_login=$1', + array($a_user[$i]['user_name'])) == 0) { + $cnx_dossier->exec_sql("delete from user_sec_jrn where uj_login=$1",array($a_user[$i]['user_name'])); + $cnx_dossier->exec_sql("delete from profile_user where user_name=$1",array($a_user[$i]['user_name'])); + $cnx_dossier->exec_sql("delete from user_sec_act where ua_login=$1",array($a_user[$i]['user_name'])); + $cnx_dossier->exec_sql("delete from user_sec_jrn where uj_login=$1",array($a_user[$i]['user_name'])); + } + } + } } ?> diff --git a/include/dossier.inc.php b/include/dossier.inc.php index e6c7ca35f..df28c4735 100644 --- a/include/dossier.inc.php +++ b/include/dossier.inc.php @@ -172,6 +172,7 @@ if ( isset ($_POST["DATABASE"]) ) $Res=$cn->exec_sql($sql); Dossier::synchro_admin($l_id); + User::remove_inexistant_user($l_id); } diff --git a/include/restore.inc.php b/include/restore.inc.php index 17a8dd8be..8619827b9 100644 --- a/include/restore.inc.php +++ b/include/restore.inc.php @@ -134,6 +134,7 @@ if ( isset ($_REQUEST['sa'] )) $new_cn->apply_patch($name,0); echo ''._('Ne pas recharger la page, sinon votre base de données sera restaurée une fois de plus').''; Dossier::synchro_admin($id); + User::remove_inexistant_user($id); echo $retour; echo ''; diff --git a/include/upgrade.inc.php b/include/upgrade.inc.php index e214c1a6f..17afab216 100644 --- a/include/upgrade.inc.php +++ b/include/upgrade.inc.php @@ -71,6 +71,7 @@ if ($sb === "upg_all" && (!defined('MULTI')||(defined('MULTI')&&MULTI==1))) $db=new Database($db_row['dos_id'], 'dos'); $db->apply_patch($db_row['dos_name']); Dossier::synchro_admin($db_row['dos_id']); + User::remove_inexistant_user($db_row['dos_id']); } else { diff --git a/unit-test/include/class/class_userTest.php b/unit-test/include/class/class_userTest.php index df954109a..c81e04358 100644 --- a/unit-test/include/class/class_userTest.php +++ b/unit-test/include/class/class_userTest.php @@ -1,12 +1,14 @@ cn=new Database(); // create a user - $this->cn->exec_sql('delete from jnt_use_dos where use_id=$1',array(USE_ID)); - $this->cn->exec_sql('delete from ac_users where use_id=$1',array(USE_ID)); + $this->cn->exec_sql('delete from jnt_use_dos where use_id=$1', + array(USE_ID)); + $this->cn->exec_sql('delete from ac_users where use_id=$1', + array(USE_ID)); $this->cn->exec_sql('insert into ac_users (use_id,use_first_name,use_name,use_login,use_active,use_pass,use_admin,use_email) values ($1,$2,$3,$4,$5,$6,$7,$8)', - array(USE_ID,USE_FIRST_NAME,USE_NAME,USE_LOGIN,USE_ACTIVE,USE_PASS,USE_ADMIN,USE_EMAIL)); - - $this->object=new User($cn,USE_ID); + array(USE_ID, USE_FIRST_NAME, USE_NAME, USE_LOGIN, USE_ACTIVE, USE_PASS, + USE_ADMIN, USE_EMAIL)); + + $this->object=new User($cn, USE_ID); } /** @@ -42,8 +47,10 @@ class UserTest extends PHPUnit_Framework_TestCase protected function tearDown() { //drop user - $this->cn->exec_sql('delete from jnt_use_dos where use_id=$1',array(USE_ID)); - $this->cn->exec_sql('delete from ac_users where use_id = $1',array(USE_ID)); + $this->cn->exec_sql('delete from jnt_use_dos where use_id=$1', + array(USE_ID)); + $this->cn->exec_sql('delete from ac_users where use_id = $1', + array(USE_ID)); } /** @@ -52,18 +59,16 @@ class UserTest extends PHPUnit_Framework_TestCase */ public function testLoad() { - + $this->object->load(); - $this->assertEquals($this->object->id , USE_ID) ; - $this->assertEquals($this->object->name , USE_NAME) ; - $this->assertEquals($this->object->first_name , USE_FIRST_NAME ); - $this->assertEquals($this->object->login , USE_LOGIN) ; - $this->assertEquals($this->object->active , USE_ACTIVE) ; - $this->assertEquals($this->object->password, USE_PASS) ; - $this->assertEquals($this->object->admin , USE_ADMIN) ; - $this->assertEquals($this->object->email , USE_EMAIL) ; - - + $this->assertEquals($this->object->id, USE_ID); + $this->assertEquals($this->object->name, USE_NAME); + $this->assertEquals($this->object->first_name, USE_FIRST_NAME); + $this->assertEquals($this->object->login, USE_LOGIN); + $this->assertEquals($this->object->active, USE_ACTIVE); + $this->assertEquals($this->object->password, USE_PASS); + $this->assertEquals($this->object->admin, USE_ADMIN); + $this->assertEquals($this->object->email, USE_EMAIL); } /** @@ -601,8 +606,9 @@ class UserTest extends PHPUnit_Framework_TestCase public function testRevoke_access() { $cn_dossier=new Database(DOSSIER); - User::revoke_access(USE_LOGIN, DOSSIER); - $this->assertEquals($cn_dossier->get_value('select count(*) from profile_user where user_name =$1 ',array(USE_LOGIN)),0); + User::revoke_access(USE_LOGIN, DOSSIER); + $this->assertEquals($cn_dossier->get_value('select count(*) from profile_user where user_name =$1 ', + array(USE_LOGIN)), 0); } /** @@ -611,10 +617,28 @@ class UserTest extends PHPUnit_Framework_TestCase */ public function testGrant_admin_access() { - $cn_dossier=new Database(TARGET); - User::grant_admin_access(USE_LOGIN, DOSSIER); - - $this->assertEquals($cn_dossier->get_value('select count(*) from profile_user where user_name =$1 ',array(USE_LOGIN)),1); - } + $cn_dossier=new Database(DOSSIER); + User::grant_admin_access(USE_LOGIN, DOSSIER); + $this->assertEquals($cn_dossier->get_value('select count(*) from profile_user where user_name =$1 ', + array(USE_LOGIN)), 1); + } + /** + * @covers User::remove_inexistant_user + */ + public function testRemove_inexistant_user() { + // insert inexisting user + $cn=new Database (DOSSIER); + $cn->exec_sql('insert into profile_user (user_name,p_id) values ($1,$2)', + array('unknown/user',1)); + + //verify presence of it in DOSSIER + $this->assertEquals($cn->get_value('select count(*) from profile_user where user_name=$1',array('unknown/user')),1); + + //remove him + User::remove_inexistant_user(DOSSIER); + + // check his removal + $this->assertEquals($cn->get_value('select count(*) from profile_user where user_name=$1',array('unknown/user')),0); + } }