[Fusionforge-commits] r9768 - in trunk/gforge: common/include db

Roland Mas lolando at libremir.placard.fr.eu.org
Fri May 21 09:41:41 CEST 2010


Author: lolando
Date: 2010-05-21 09:41:41 +0200 (Fri, 21 May 2010)
New Revision: 9768

Modified:
   trunk/gforge/common/include/Role.class.php
   trunk/gforge/db/20100415-pfo-rbac-publicrole.sql
Log:
Added machinery to link a role to several projects beside its home project

Modified: trunk/gforge/common/include/Role.class.php
===================================================================
--- trunk/gforge/common/include/Role.class.php	2010-05-21 07:41:31 UTC (rev 9767)
+++ trunk/gforge/common/include/Role.class.php	2010-05-21 07:41:41 UTC (rev 9768)
@@ -121,7 +121,6 @@
 					    'webcal'=>'2')
 		);
 
-
 	/**
 	 *  Role($group,$id) - CONSTRUCTOR.
 	 *
@@ -231,6 +230,63 @@
 		return true;
 	}
 
+	function getHomeProject () {
+		return $this->Group ;
+	}
+
+	function getLinkedProjects () {
+		$res = db_query_params('SELECT group_id FROM role_project_refs WHERE role_id=$1',
+				       array ($this->getID()));
+		
+		$result = array (return $this->Group) ;
+		
+		while ($arr =& db_fetch_array($res)) {
+			$result[] = group_get_object ($arr['group_id']) ;
+		}
+		return $result ;
+	}
+
+	function linkProject ($project) {
+		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) {
+		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.
 	 *

Modified: trunk/gforge/db/20100415-pfo-rbac-publicrole.sql
===================================================================
--- trunk/gforge/db/20100415-pfo-rbac-publicrole.sql	2010-05-21 07:41:31 UTC (rev 9767)
+++ trunk/gforge/db/20100415-pfo-rbac-publicrole.sql	2010-05-21 07:41:41 UTC (rev 9768)
@@ -3,5 +3,6 @@
 
 CREATE TABLE role_project_refs (
        role_id integer DEFAULT 0 NOT NULL REFERENCES role,
-       group_id integer DEFAULT 0 NOT NULL REFERENCES groups
+       group_id integer DEFAULT 0 NOT NULL REFERENCES groups,
+       CONSTRAINT role_project_refs_unique UNIQUE (role_id, group_id)
 ) ;




More information about the Fusionforge-commits mailing list