From a63f5534cf31b3df9c5f95a25e442b90b264c7be Mon Sep 17 00:00:00 2001
From: gloas <gloas@afi-loas.afi-sa.net>
Date: Thu, 20 Feb 2014 12:03:50 +0100
Subject: [PATCH] rel #9979 you can edit role level of a SIGB subscriber ->
 issue: duplicat user in db

---
 library/ZendAfi/Acl/AdminControllerRoles.php  | 61 ++++++++++---------
 .../admin/controllers/UsersControllerTest.php | 45 +++++++++++++-
 2 files changed, 74 insertions(+), 32 deletions(-)

diff --git a/library/ZendAfi/Acl/AdminControllerRoles.php b/library/ZendAfi/Acl/AdminControllerRoles.php
index a0c8b05e79f..8a9862ff9ca 100644
--- a/library/ZendAfi/Acl/AdminControllerRoles.php
+++ b/library/ZendAfi/Acl/AdminControllerRoles.php
@@ -36,18 +36,18 @@ class ZendAfi_Acl_AdminControllerRoles extends Zend_Acl {
 	
 	protected static $listeRole = [
 		'0' => ['abrege' => 'invite','libelle' => 'invité'],   													// 0 - Invité - Par default axx contenu.
-	//	'1' => array('abrege' => 'abonne','libelle' => 'abonné'),															// 1 - Abonne (registered) - Utilisateur du site (fonctionnalité non pergame reservation par mail, etc...)
-	'2' => ['abrege' => 'abonne_sigb','libelle' => 'abonné identifié SIGB'], 		// 2 - Abonne identifié dans 1 sigb - Utilisateur de site bib.( axx fonctionalité pergame)
-	'3' => ['abrege' => 'modo_bib','libelle' => 'rédacteur bibliothèque'],				// 3 - Modo bib - Modo all MAIS que sur sa bib
-	'4' => ['abrege' => 'admin_bib','libelle' => 'administrateur bibliothèque'],	// 4 - Admin de bib - Axx all MAIS que sur sa bib
-	'5' => ['abrege' => 'modo_portail','libelle' => 'rédacteur portail'],				// 5 - Modo portail - Axx moderation tag / avis / fiche bib / cms / etc
-	'6' => ['abrege' => 'admin_portail','libelle' => 'administrateur portail'],		// 6 - Admin portail - Axx all sauf traitement AFI
-	'7' => ['abrege' => 'super_admin','libelle' => 'super administrateur'],					// 7 - SuperAdmin - Axx all
-	];
+		//	'1' => array('abrege' => 'abonne','libelle' => 'abonné'),															// 1 - Abonne (registered) - Utilisateur du site (fonctionnalité non pergame reservation par mail, etc...)
+		'2' => ['abrege' => 'abonne_sigb','libelle' => 'abonné identifié SIGB'], 		// 2 - Abonne identifié dans 1 sigb - Utilisateur de site bib.( axx fonctionalité pergame)
+		'3' => ['abrege' => 'modo_bib','libelle' => 'rédacteur bibliothèque'],				// 3 - Modo bib - Modo all MAIS que sur sa bib
+		'4' => ['abrege' => 'admin_bib','libelle' => 'administrateur bibliothèque'],	// 4 - Admin de bib - Axx all MAIS que sur sa bib
+		'5' => ['abrege' => 'modo_portail','libelle' => 'rédacteur portail'],				// 5 - Modo portail - Axx moderation tag / avis / fiche bib / cms / etc
+		'6' => ['abrege' => 'admin_portail','libelle' => 'administrateur portail'],		// 6 - Admin portail - Axx all sauf traitement AFI
+		'7' => ['abrege' => 'super_admin','libelle' => 'super administrateur'],					// 7 - SuperAdmin - Axx all
+		];
 
- //----------------------------------------------------------------------------------
- // Contrusteur : init des autorisations basiques
- //----------------------------------------------------------------------------------
+	//----------------------------------------------------------------------------------
+	// Contrusteur : init des autorisations basiques
+	//----------------------------------------------------------------------------------
 	public function __construct()
 	{
 		//All Admin Controllers OPAC 2
@@ -134,9 +134,9 @@ class ZendAfi_Acl_AdminControllerRoles extends Zend_Acl {
 		return $roles;
 	}
 
- //----------------------------------------------------------------------------------
- // Rend le libelle d'un role
- //----------------------------------------------------------------------------------
+	//----------------------------------------------------------------------------------
+	// Rend le libelle d'un role
+	//----------------------------------------------------------------------------------
 	public static function getLibelleRole($role_level)
  	{
  		return self::$listeRole[$role_level]["libelle"];
@@ -147,23 +147,26 @@ class ZendAfi_Acl_AdminControllerRoles extends Zend_Acl {
  		return self::$listeRole[$role_level]["abrege"];
 	}
   
- //----------------------------------------------------------------------------------
- // Rend la combo des roles
- //----------------------------------------------------------------------------------
+	//----------------------------------------------------------------------------------
+	// Rend la combo des roles
+	//----------------------------------------------------------------------------------
 	public static function rendCombo($selected,$user_role_level,$tous=false)
 	{
-	$html[]='<select name="role">';
-	if($tous==true)
-	{
-		$sel = ($selected=="") ? ' selected="selected"' : '';
-		$html[]='<option value=""'.$sel.'>&nbsp;</option>';
-	}
-	foreach(self::$listeRole as $level => $role)	{
-		if ($role["abrege"] == $selected or ($selected > "" and $level==(int)$selected )) $ligne='selected="selected"'; else $ligne="";
-		if ($level <= $user_role_level and $level!=static::SUPER_ADMIN) $html[]= '<option value="'.$level.'" '.$ligne.'>'. $role["libelle"] . '</option>';
-	}
-	$html[]='</select>';
-	return (implode($html));
+		if($selected=='abonne_sigb')
+			return self::getLibelleRole(2);
+		
+		$html[]='<select name="role">';
+		if($tous==true)
+			{
+				$sel = ($selected=="") ? ' selected="selected"' : '';
+				$html[]='<option value=""'.$sel.'>&nbsp;</option>';
+			}
+		foreach(self::$listeRole as $level => $role)	{
+			if ($role["abrege"] == $selected or ($selected > "" and $level==(int)$selected )) $ligne='selected="selected"'; else $ligne="";
+			if ($level <= $user_role_level and $level!=static::SUPER_ADMIN) $html[]= '<option value="'.$level.'" '.$ligne.'>'. $role["libelle"] . '</option>';
+		}
+		$html[]='</select>';
+		return (implode($html));
 	}
 
 	public static function rendNomRole($level_role)
diff --git a/tests/application/modules/admin/controllers/UsersControllerTest.php b/tests/application/modules/admin/controllers/UsersControllerTest.php
index 6438148a2a6..3cd9cb364e8 100644
--- a/tests/application/modules/admin/controllers/UsersControllerTest.php
+++ b/tests/application/modules/admin/controllers/UsersControllerTest.php
@@ -102,85 +102,124 @@ class UsersControllerEditMarcusTest extends UsersControllerWithMarcusTestCase {
 		$this->dispatch('/admin/users/edit/id/10', true);
 	}
 
+  
+  /** @test **/
+	public function roleLevelShouldBeSIGBSubscriber() {
+		$this->assertXpathContentContains('//tr/td','abonné identifié SIGB');
+	}
+
 
+	/** @test **/
 	public function testIdentifiantIsMMiller() {
 		$this->assertXPath("//input[@name='username'][@value='mmiller']");
 	}
 
 	
+	/** @test **/
 	public function testPasswordIsMysecret() {
 		$this->assertXPath("//input[@name='password'][@value='mysecret']");
 	}
 
+
+	/** @test **/
 	public function testNomIsMiller() {
 		$this->assertXPath("//input[@name='nom'][@value='Miller']");
 	}
 
+
+	/** @test **/
 	public function testPrenomIsMarcus() {
 		$this->assertXPath("//input[@name='prenom'][@value='Marcus']");
 	}
 
-
+	
+	/** @test **/
 	public function testGroupesAreMultimediaAndReferent() {
 		$this->assertXPath("//input[@name='id_items'][@value='20-22']",$this->_response->getBody());
 	}
 
 
+  /** @test **/
 	public function testUserGroupCategoriesNotSelectable() {
 		$this->assertXPathContentContains('//script', 'categoriesNotSelectable');
 	}
 
+
+	/** @test **/
 	public function testSelectedRoleIsAbonneSIGB() {
-		$this->assertXPathContentContains("//select[@name='role']/option[@value='2'][@selected='selected']",
-																			'abonné identifié SIGB');
+		$this->assertNotXPath("//select[@name='role']");
 	}
 
+	
+	/** @test **/
 	public function testSelectedBibIsIdOne() {
 		$this->assertXPath("//input[@name='bib'][@value='1']", $this->_response->getBody());
 	}
 
+
+	/** @test **/
 	public function testMailIsMarcusAtGmailDotCom() {
 		$this->assertXPath("//input[@name='mail'][@value='marcus@gmail.com']");
 	}
 
+
+	/** @test **/
 	public function testTelephoneIs0123456789() {
 		$this->assertXPath("//input[@name='telephone'][@value='01 23 45 67 89']");
 	}
 
+
+	/** @test **/
 	public function testMobileIs0623456789() {
 		$this->assertXPath("//input[@name='mobile'][@value='06 23 45 67 89']");
 	}
 
+
+	/** @test **/
 	public function testComboCiviliteShouldHaveMonsieurSelected() {
 		$this->assertXPathContentContains("//select[@name='civilite']//option[@value='0']", 'Indéfinie');
 		$this->assertXPathContentContains("//select[@name='civilite']//option[@value='1']", 'Madame');
 		$this->assertXPathContentContains("//select[@name='civilite']//option[@value='2'][@selected='selected']", 'Monsieur');
 	}
 
+
+	/** @test **/
 	public function testAdresseIs34avenueFunk() {
 		$this->assertXPathContentContains("//textarea[@name='adresse']", '34 avenue Funk');
 	}
 
+
+	/** @test **/
 	public function testCodePostalIs99000() {
 		$this->assertXPath("//input[@name='code_postal'][@value='99000']");
 	}
 
+
+	/** @test **/
 	public function testVilleIsJazzCity() {
 		$this->assertXPath("//input[@name='ville'][@value='Jazz City']");
 	}
 
+
+	/** @test **/
 	public function testNumeroCarteIs00123() {
 		$this->assertXPath("//input[@name='id_abon'][@value='00123']");
 	}
 
+
+	/** @test **/
 	public function testOrdreIsOne() {
 		$this->assertXPath("//input[@name='ordre'][@value='1']");
 	}
 
+
+	/** @test **/
 	public function testDateDebut() {
 		$this->assertQueryContentContains("td", '19-07-2009');
 	}
 
+
+	/** @test **/
 	public function testDateFin() {
 		$this->assertQueryContentContains("td", '19-07-2010');
 	}
-- 
GitLab