[Fusionforge-commits] r10579 - in trunk/src: common/include www/project/admin

Roland Mas lolando at libremir.placard.fr.eu.org
Mon Sep 20 23:06:30 CEST 2010


Author: lolando
Date: 2010-09-20 23:06:29 +0200 (Mon, 20 Sep 2010)
New Revision: 10579

Modified:
   trunk/src/common/include/Role.class.php
   trunk/src/www/project/admin/roleedit.php
Log:
Fixed role renaming

Modified: trunk/src/common/include/Role.class.php
===================================================================
--- trunk/src/common/include/Role.class.php	2010-09-20 21:02:26 UTC (rev 10578)
+++ trunk/src/common/include/Role.class.php	2010-09-20 21:06:29 UTC (rev 10579)
@@ -77,22 +77,41 @@
 	 */
 	function setName ($role_name) { // From the PFO spec
 		if ($this->getName() != stripslashes($role_name)) {
-			// Check if role_name is not already used.
-			$res = db_query_params('SELECT role_name FROM role WHERE group_id=$1 AND role_name=$2',
-				array ($this->Group->getID(), htmlspecialchars($role_name)));
-			if (db_numrows($res)) {
-				$this->setError('Cannot create a role with this name (already used)');
-				return false;
+			if (USE_PFO_RBAC) {
+				db_begin();
+				$res = db_query_params('SELECT role_name FROM pfo_role WHERE home_group_id=$1 AND role_name=$2',
+						       array ($this->Group->getID(), htmlspecialchars($role_name)));
+				if (db_numrows($res)) {
+					$this->setError('Cannot create a role with this name (already used)');
+					db_rollback () ;
+					return false;
+				}
+				$res = db_query_params ('UPDATE pfo_role SET role_name=$1 WHERE role_id=$2',
+							array (htmlspecialchars($role_name),
+							       $this->getID())) ;
+				if (!$res || db_affected_rows($res) < 1) {
+					$this->setError('update::name::'.db_error());
+					return false;
+				}
+				db_commit();
+			} else {
+				// Check if role_name is not already used.
+				$res = db_query_params('SELECT role_name FROM role WHERE group_id=$1 AND role_name=$2',
+						       array ($this->Group->getID(), htmlspecialchars($role_name)));
+				if (db_numrows($res)) {
+					$this->setError('Cannot create a role with this name (already used)');
+					return false;
+				}
+				
+				$res = db_query_params ('UPDATE role SET role_name=$1 WHERE group_id=$2 AND role_id=$3',
+							array (htmlspecialchars($role_name),
+							       $this->Group->getID(),
+							       $this->getID())) ;
+				if (!$res || db_affected_rows($res) < 1) {
+					$this->setError('update::name::'.db_error());
+					return false;
+				}
 			}
-
-			$res = db_query_params ('UPDATE role SET role_name=$1 WHERE group_id=$2 AND role_id=$3',
-						array (htmlspecialchars($role_name),
-						       $this->Group->getID(),
-						       $this->getID())) ;
-			if (!$res || db_affected_rows($res) < 1) {
-				$this->setError('update::name::'.db_error());
-				return false;
-			}
 		}
 		return true ;
 	}

Modified: trunk/src/www/project/admin/roleedit.php
===================================================================
--- trunk/src/www/project/admin/roleedit.php	2010-09-20 21:02:26 UTC (rev 10578)
+++ trunk/src/www/project/admin/roleedit.php	2010-09-20 21:06:29 UTC (rev 10579)
@@ -93,7 +93,7 @@
 
 	if (getStringFromRequest('submit')) {
 		if (($role->getHomeProject() != NULL)
-		    && ($role->getHomeProject()->getID() != $group_id)) {
+		    && ($role->getHomeProject()->getID() == $group_id)) {
 			$role_name = trim(getStringFromRequest('role_name'));
 		} else {
 			$role_name = $role->getName() ;




More information about the Fusionforge-commits mailing list