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

Roland Mas lolando at libremir.placard.fr.eu.org
Wed Sep 22 18:28:18 CEST 2010


Author: lolando
Date: 2010-09-22 18:28:18 +0200 (Wed, 22 Sep 2010)
New Revision: 10638

Modified:
   trunk/src/common/include/RBAC.php
   trunk/src/common/include/RBACEngine.class.php
   trunk/src/www/include/role_utils.php
   trunk/src/www/project/admin/roleedit.php
   trunk/src/www/project/admin/users.php
Log:
Improvements in public/shared role handling

Modified: trunk/src/common/include/RBAC.php
===================================================================
--- trunk/src/common/include/RBAC.php	2010-09-22 16:14:49 UTC (rev 10637)
+++ trunk/src/common/include/RBAC.php	2010-09-22 16:28:18 UTC (rev 10638)
@@ -1113,6 +1113,21 @@
 		return true;
 	}
 
+	function getDisplayableName($group = NULL) {
+		if ($this->getHomeProject() == NULL) {
+			return sprintf (_('%s (global role)'),
+					$this->getName ()) ;
+		} elseif ($group == NULL
+			  || $this->getHomeProject()->getID() != $group->getID()) {
+			return sprintf (_('%s (in project %s)'),
+					$this->getName (),
+					$this->getHomeProject()->getPublicName()) ;
+		} else {
+			return $this->getName () ;
+		}
+	}
+
+
 }
 
 // Actual classes

Modified: trunk/src/common/include/RBACEngine.class.php
===================================================================
--- trunk/src/common/include/RBACEngine.class.php	2010-09-22 16:14:49 UTC (rev 10637)
+++ trunk/src/common/include/RBACEngine.class.php	2010-09-22 16:28:18 UTC (rev 10638)
@@ -29,6 +29,7 @@
 	private $_cached_roles = array () ;
 	private $_cached_available_roles = NULL ;
 	private $_cached_global_roles = NULL ;
+	private $_cached_public_roles = NULL ;
 
 	public static function getInstance() {
 		if (!isset(self::$_instance)) {
@@ -87,8 +88,28 @@
 		return $this->_cached_global_roles ;
 	}
 
+	public function getPublicRoles() {
+		if ($this->_cached_public_roles != NULL) {
+			return $this->_cached_public_roles ;
+		}
+
+		$this->_cached_public_roles = array () ;
+
+		if (USE_PFO_RBAC) {
+			$res = db_query_params ('SELECT role_id FROM pfo_role WHERE is_public=$1',
+						array ('true'));
+			while ($arr =& db_fetch_array($res)) {
+				$this->_cached_public_roles[] = $this->getRoleById ($arr['role_id']) ;
+			}
+		}
+		
+		return $this->_cached_public_roles ;
+	}
+
 	public function invalidateRoleCaches () {
 		$this->_cached_available_roles = NULL ;
+		$this->_cached_global_roles = NULL ;
+		$this->_cached_public_roles = NULL ;
 	}
 
 	public function getAvailableRolesForUser($user) {

Modified: trunk/src/www/include/role_utils.php
===================================================================
--- trunk/src/www/include/role_utils.php	2010-09-22 16:14:49 UTC (rev 10637)
+++ trunk/src/www/include/role_utils.php	2010-09-22 16:28:18 UTC (rev 10638)
@@ -40,16 +40,7 @@
 	foreach ($roles as $role) {
 		$ids[] = $role->getID ();
 
-		if ($role->getHomeProject() == NULL) {
-			$names[] = sprintf (_('%s (global role)'),
-					    $role->getName ()) ;
-		} elseif ($role->getHomeProject()->getID() != $group_id) {
-			$names[] = sprintf (_('%s (in project %s)'),
-					    $role->getName (),
-					    $role->getHomeProject()->getPublicName()) ;
-		} else {
-			$names[] = $role->getName () ;
-		}
+		$names[] = $role->getDisplayableName($group) ;
 	}
 
 	if ($selected == 'xzxzxz') {

Modified: trunk/src/www/project/admin/roleedit.php
===================================================================
--- trunk/src/www/project/admin/roleedit.php	2010-09-22 16:14:49 UTC (rev 10637)
+++ trunk/src/www/project/admin/roleedit.php	2010-09-22 16:28:18 UTC (rev 10638)
@@ -159,15 +159,10 @@
 <form action="'.getStringFromServer('PHP_SELF').'?group_id='.$group_id.'&amp;role_id='. $role_id .'" method="post">';
 
 if (USE_PFO_RBAC) {
-	if ($role->getHomeProject() == NULL) {
+	if ($role->getHomeProject() == NULL
+	    || $role->getHomeProject()->getID() != $group_id) {
 		echo '<p><strong>'._('Role Name').'</strong></p>' ;
-		printf (_('%s (global role)'),
-			$role->getName ()) ;
-	} elseif ($role->getHomeProject()->getID() != $group_id) {
-		echo '<p><strong>'._('Role Name').'</strong></p>' ;
-		printf (_('%s (in project %s)'),
-			$role->getName (),
-			$role->getHomeProject()->getPublicName()) ;
+		echo $role->getDisplayableName ($group) ;
 	} else {
 		echo '<p><strong>'._('Role Name').'</strong><br /><input type="text" name="role_name" value="'.$role->getName().'"><br />' ;
 		echo '<input type="checkbox" name="public" value="1"' ;

Modified: trunk/src/www/project/admin/users.php
===================================================================
--- trunk/src/www/project/admin/users.php	2010-09-22 16:14:49 UTC (rev 10637)
+++ trunk/src/www/project/admin/users.php	2010-09-22 16:28:18 UTC (rev 10638)
@@ -238,6 +238,31 @@
 		echo '<input type="text" name="role_name" size="10" value="" />';
 		echo '&nbsp;<input type="submit" name="add" value="'._("Create Role").'" /></p></form>';
 
+
+
+if (USE_PFO_RBAC) {
+	echo $HTML->boxMiddle(_("External Roles"));
+
+		$public_roles = RBACEngine::getInstance()->getPublicRoles() ;
+		$pr2 = array () ;
+		foreach ($public_roles as $r) {
+			$grs = $r->getLinkedProjects () ;
+			$seen = false ;
+			foreach ($grs as $g) {
+				if ($g->getID() == $group_id) {
+					$seen = true ;
+					break ;
+				}
+			}
+			if (!$seen) {
+				$pr2[] = $r ;
+			}
+		}
+		foreach ($pr2 as $r) {
+			echo $r->getDisplayableName($group)."<br />" ;
+		}
+}
+
 		echo $HTML->boxBottom();
 
 		?></td>
@@ -304,4 +329,9 @@
 
 project_admin_footer(array());
 
+// Local Variables:
+// mode: php
+// c-file-style: "bsd"
+// End:
+
 ?>




More information about the Fusionforge-commits mailing list