noalyss-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Noalyss-commit] [noalyss] 01/08: Remove inexistant user


From: Dany De Bontridder
Subject: [Noalyss-commit] [noalyss] 01/08: Remove inexistant user
Date: Sat, 13 Feb 2016 01:41:52 +0000

sparkyx pushed a commit to branch master
in repository noalyss.

commit 9536b7901ed2a7cec5db196c3a38dd9b333df3d2
Author: Dany De Bontridder <address@hidden>
Date:   Thu Feb 11 16:34:49 2016 +0100

    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 c18fe03..5b2c49a 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 e6c7ca3..df28c47 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 17a8dd8..8619827 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 '<span class="error">'._('Ne pas recharger la page, sinon votre 
base de données sera restaurée une fois de plus').'</span>';
        Dossier::synchro_admin($id);
+        User::remove_inexistant_user($id);
         echo $retour;
 
         echo '</div>';
diff --git a/include/upgrade.inc.php b/include/upgrade.inc.php
index e214c1a..17afab2 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 df95410..c81e043 100644
--- a/unit-test/include/class/class_userTest.php
+++ b/unit-test/include/class/class_userTest.php
@@ -1,12 +1,14 @@
 <?php
-define ('USE_ID',999999);
-define ('USE_FIRST_NAME','Unit test');
-define ('USE_NAME','UNIT');
-define ('USE_LOGIN','unit-test');
-define ('USE_ACTIVE',1);
-define ('USE_PASS','passord');
-define ('USE_ADMIN',0);
-define ('USE_EMAIL','address@hidden');
+
+define('USE_ID', 999999);
+define('USE_FIRST_NAME', 'Unit test');
+define('USE_NAME', 'UNIT');
+define('USE_LOGIN', 'unit-test');
+define('USE_ACTIVE', 1);
+define('USE_PASS', 'passord');
+define('USE_ADMIN', 0);
+define('USE_EMAIL', 'address@hidden');
+
 /**
  * Generated by PHPUnit_SkeletonGenerator on 2016-02-10 at 22:48:23.
  */
@@ -27,12 +29,15 @@ class UserTest extends PHPUnit_Framework_TestCase
         // create database connx : 
         $this->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);
+    }
 }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]