[Fusionforge-commits] r7391 - trunk/gforge/common/include

Alain Peyrat aljeux at libremir.placard.fr.eu.org
Thu Apr 9 22:06:51 CEST 2009


Author: aljeux
Date: 2009-04-09 22:06:51 +0200 (Thu, 09 Apr 2009)
New Revision: 7391

Modified:
   trunk/gforge/common/include/Role.class.php
Log:
Roles: Adding control on role_name, adding setVal & delVal method and small fixes

Modified: trunk/gforge/common/include/Role.class.php
===================================================================
--- trunk/gforge/common/include/Role.class.php	2009-04-09 12:12:45 UTC (rev 7390)
+++ trunk/gforge/common/include/Role.class.php	2009-04-09 20:06:51 UTC (rev 7391)
@@ -120,6 +120,14 @@
 			return false;
 		}
 
+		// 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;
+		}
+
 		db_begin();
 		$res = db_query_params ('INSERT INTO role (group_id, role_name) VALUES ($1, $2)',
 					array ($this->Group->getID(),
@@ -162,6 +170,10 @@
 				}
 			}
 		}
+		if (!$this->fetchData($role_id)) {
+			db_rollback();
+			return false;
+		}
 		db_commit();
 		return $role_id;
 	}
@@ -288,7 +300,33 @@
 		return $this->setting_array[$section][$ref_id];
 	}
 
+	function setVal($section, $ref_id, $value) {
+		$this->setting_array[$section][$ref_id] = $value;
+		return $this->update( $this->getName(), $this->setting_array);
+	}
+
 	/**
+	 *	delVal - delete a value out of the array of settings for this role.
+	 *
+	 *	@param	string	The name of the role.
+	 *	@param	integer	The ref_id (ex: group_artifact_id, group_forum_id) for this item.
+	 */
+	function delVal($section, $ref_id) {
+		unset($this->setting_array[$section][$ref_id]);
+
+		$sql = 'DELETE FROM role_setting
+				WHERE role_id=$1
+				AND section_name=$2
+				AND ref_id=$3';
+		$res=db_query_params($sql, array($this->getID(), $section, $ref_id));
+		if (!$res || db_affected_rows($res) < 1) {
+			$this->setError('delVal($section, $ref_id)'.db_error());
+			return false;
+		}
+		return true;
+	}
+
+	/**
 	 *	update - update a new in the database.
 	 *
 	 *	@param	string	The name of the role.
@@ -313,6 +351,15 @@
 		db_begin();
 
 		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)');
+				db_rollback();
+				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(),
@@ -386,13 +433,13 @@
 							// I have doubt the following is usefull
 							// This is probably buggy if used
 							if ($cvs_flags>1) {
-								if (!$SYS->sysUserSetAttribute($user_id,"debGforgeCvsShell","/bin/bash")) {
+								if (!$SYS->sysUserSetAttribute(db_result($res,$z,'user_id'),"debGforgeCvsShell","/bin/bash")) {
 									$this->setError($SYS->getErrorMessage());
 									db_rollback();
 									return false;
 								}
 							} else {
-								if (!$SYS->sysUserSetAttribute($user_id,"debGforgeCvsShell","/bin/cvssh")) {
+								if (!$SYS->sysUserSetAttribute(db_result($res,$z,'user_id'),"debGforgeCvsShell","/bin/cvssh")) {
 									$this->setError($SYS->getErrorMessage());
 									db_rollback();
 									return false;




More information about the Fusionforge-commits mailing list