[Fusionforge-commits] r10597 - trunk/src/common/include

Roland Mas lolando at libremir.placard.fr.eu.org
Tue Sep 21 16:19:32 CEST 2010


Author: lolando
Date: 2010-09-21 16:19:32 +0200 (Tue, 21 Sep 2010)
New Revision: 10597

Modified:
   trunk/src/common/include/RBAC.php
   trunk/src/common/include/Role.class.php
Log:
Move some RBAC-related methods to the upper class

Modified: trunk/src/common/include/RBAC.php
===================================================================
--- trunk/src/common/include/RBAC.php	2010-09-21 14:17:58 UTC (rev 10596)
+++ trunk/src/common/include/RBAC.php	2010-09-21 14:19:32 UTC (rev 10597)
@@ -237,12 +237,6 @@
 	public function setSettings($data) {
 		throw new Exception ("Not implemented") ;
 	}
-	public function linkProject ($project) {
-		throw new Exception ("Not implemented") ;
-	}
-	public function unlinkProject ($project) {
-		throw new Exception ("Not implemented") ;
-	}
 	public function normalizeData () {
 		throw new Exception ("Not implemented") ;
 	}
@@ -273,6 +267,49 @@
 		return group_get_objects (array_unique ($ids)) ;
 	}
 
+	function linkProject ($project) { // From the PFO spec
+		$hp = $this->getHomeProject () ;
+		if ($hp != NULL && $hp->getID() == $project->getID()) {
+			$this->setError ("Can't link to home project") ;
+			return false ;
+		}
+
+		$res = db_query_params('SELECT group_id FROM role_project_refs WHERE role_id=$1 AND group_id=$2',
+				       array ($this->getID(),
+					      $project->getID()));
+
+		if (db_numrows($res)) {
+			return true ;
+		}
+		$res = db_query_params('INSERT INTO role_project_refs (role_id, group_id) VALUES ($1, $2)',
+				       array ($this->getID(),
+					      $project->getID()));
+		if (!$res || db_affected_rows($res) < 1) {
+			$this->setError('linkProject('.$project->getID().') '.db_error());
+			return false;
+		}
+
+		return true ;
+	}
+
+	function unlinkProject ($project) { // From the PFO spec
+		$hp = $this->getHomeProject () ;
+		if ($hp != NULL && $hp->getID() == $project->getID()) {
+			$this->setError ("Can't unlink from home project") ;
+			return false ;
+		}
+
+		$res = db_query_params('DELETE FROM role_project_refs WHERE role_id=$1 AND group_id=$2',
+				       array ($this->getID(),
+					      $project->getID()));
+		if (!$res) {
+			$this->setError('unlinkProject('.$project->getID().') '.db_error());
+			return false;
+		}
+
+		return true ;
+	}
+
 	/**
 	 *  fetchData - May need to refresh database fields.
 	 *

Modified: trunk/src/common/include/Role.class.php
===================================================================
--- trunk/src/common/include/Role.class.php	2010-09-21 14:17:58 UTC (rev 10596)
+++ trunk/src/common/include/Role.class.php	2010-09-21 14:19:32 UTC (rev 10597)
@@ -133,7 +133,7 @@
 	 *      @return boolean True if updated OK
 	 */
 	function setPublic ($flag) { // From the PFO spec
-		$res = db_query_params ('UPDATE role SET is_public=$1 WHERE role_id=$1',
+		$res = db_query_params ('UPDATE pfo_role SET is_public=$1 WHERE role_id=$1',
 					array ($flag,
 					       $this->getID())) ;
 		if (!$res || db_affected_rows($res) < 1) {
@@ -147,62 +147,6 @@
 		return $this->Group ;
 	}
 
-	function getLinkedProjects () { // From the PFO spec
-		$result = array () ;
-
-		$result[] = $this->Group ;
-
-		$res = db_query_params('SELECT group_id FROM role_project_refs WHERE role_id=$1',
-				       array ($this->getID()));
-		
-	
-		while ($arr = db_fetch_array($res)) {
-			$result[] = group_get_object ($arr['group_id']) ;
-		}
-		return $result ;
-	}
-
-	function linkProject ($project) { // From the PFO spec
-		if ($project->getID() == $this->getHomeProject()->getID()) {
-			$this->setError ("Can't link to home project") ;
-			return false ;
-		}
-
-		$res = db_query_params('SELECT group_id FROM role_project_refs WHERE role_id=$1 AND group_id=$2',
-				       array ($this->getID(),
-					      $project->getID()));
-
-		if (db_numrows($res)) {
-			return true ;
-		}
-		$res = db_query_params('INSERT INTO role_project_refs (role_id, group_id) VALUES ($1, $2)',
-				       array ($this->getID(),
-					      $project->getID()));
-		if (!$res || db_affected_rows($res) < 1) {
-			$this->setError('linkProject('.$project->getID().') '.db_error());
-			return false;
-		}
-
-		return true ;
-	}
-
-	function unlinkProject ($project) { // From the PFO spec
-		if ($project->getID() == $this->getHomeProject()->getID()) {
-			$this->setError ("Can't unlink from home project") ;
-			return false ;
-		}
-
-		$res = db_query_params('DELETE FROM role_project_refs WHERE role_id=$1 AND group_id=$2',
-				       array ($this->getID(),
-					      $project->getID()));
-		if (!$res) {
-			$this->setError('unlinkProject('.$project->getID().') '.db_error());
-			return false;
-		}
-
-		return true ;
-	}
-
 	/**
 	 *	create - create a new role in the database.
 	 *




More information about the Fusionforge-commits mailing list