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

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


Author: lolando
Date: 2010-09-21 19:20:13 +0200 (Tue, 21 Sep 2010)
New Revision: 10600

Modified:
   trunk/src/common/include/RBACEngine.class.php
   trunk/src/common/include/Role.class.php
   trunk/src/www/admin/index.php
   trunk/src/www/include/role_utils.php
Log:
UI to create global roles and edit their permissions (nothing to add users to them yet)

Modified: trunk/src/common/include/RBACEngine.class.php
===================================================================
--- trunk/src/common/include/RBACEngine.class.php	2010-09-21 16:15:40 UTC (rev 10599)
+++ trunk/src/common/include/RBACEngine.class.php	2010-09-21 17:20:13 UTC (rev 10600)
@@ -28,6 +28,7 @@
 	private static $_instance ;
 	private $_cached_roles = array () ;
 	private $_cached_available_roles = NULL ;
+	private $_cached_global_roles = NULL ;
 
 	public static function getInstance() {
 		if (!isset(self::$_instance)) {
@@ -68,6 +69,24 @@
 		return $this->_cached_available_roles ;
 	}
 
+	public function getGlobalRoles() {
+		if ($this->_cached_global_roles != NULL) {
+			return $this->_cached_global_roles ;
+		}
+
+		$this->_cached_global_roles = array () ;
+
+		if (USE_PFO_RBAC) {
+			$res = db_query_params ('SELECT role_id FROM pfo_role WHERE home_group_id IS NULL',
+						array ());
+			while ($arr =& db_fetch_array($res)) {
+				$this->_cached_global_roles[] = $this->getRoleById ($arr['role_id']) ;
+			}
+		}
+		
+		return $this->_cached_global_roles ;
+	}
+
 	public function invalidateRoleCaches () {
 		$this->_cached_available_roles = NULL ;
 	}

Modified: trunk/src/common/include/Role.class.php
===================================================================
--- trunk/src/common/include/Role.class.php	2010-09-21 16:15:40 UTC (rev 10599)
+++ trunk/src/common/include/Role.class.php	2010-09-21 17:20:13 UTC (rev 10600)
@@ -172,15 +172,16 @@
 	 */
 	function create($role_name,$data) {
 		if (USE_PFO_RBAC) {
-			if ($this->Group == NULL
-			    && !forge_check_global_perm ('forge_admin')) {
-				$this->setPermissionDeniedError();
-				return false;
+			if ($this->Group == NULL) {
+				if (!forge_check_global_perm ('forge_admin')) {
+					$this->setPermissionDeniedError();
+					return false;
+				}
 			} elseif (!forge_check_perm ('project_admin', $this->Group->getID())) {
 				$this->setPermissionDeniedError();
 				return false;
 			}			
-
+			
 			db_begin();
 			if ($this->Group == NULL) {
 				$res = db_query_params('SELECT role_name FROM pfo_role WHERE home_group_id IS NULL AND role_name=$1',
@@ -295,7 +296,7 @@
 		if ($this->Group == NULL) {
 			return $this->create($name,array());
 		}
-
+		
 		if (array_key_exists ($name, $this->defaults)) {
 			$arr =& $this->defaults[$name];
 		} else {
@@ -342,7 +343,7 @@
 
 		return $this->create($name,$data);
 	}
-
+	
 	function normalizeDataForSection (&$new_sa, $section) {
 		if (array_key_exists ($section, $this->setting_array)) {
 			$new_sa[$section][0] = $this->setting_array[$section][0] ;

Modified: trunk/src/www/admin/index.php
===================================================================
--- trunk/src/www/admin/index.php	2010-09-21 16:15:40 UTC (rev 10599)
+++ trunk/src/www/admin/index.php	2010-09-21 17:20:13 UTC (rev 10600)
@@ -30,6 +30,7 @@
 require_once('../env.inc.php');
 require_once $gfcommon.'include/pre.php';
 require_once $gfwww.'admin/admin_utils.php';
+require_once $gfwww.'include/role_utils.php';
 
 $feedback = htmlspecialchars(getStringFromRequest('feedback'));
 
@@ -72,6 +73,25 @@
     ?></a>
     </li>
 </ul>
+<?php if (USE_PFO_RBAC) { ?>
+<h2><?php echo _('Global roles and permissions'); ?></h2>
+	<ul>
+	<li><?php
+
+		echo '<form action="globalroleedit.php" method="post"><p>';
+		echo global_role_box('role_id');
+		echo '&nbsp;<input type="submit" name="edit" value="'._("Edit Role").'" /></p></form>';
+?>
+</li>
+<li>
+<?
+
+		echo '<form action="globalroleedit.php" method="post"><p>';
+		echo '<input type="text" name="role_name" size="10" value="" />';
+		echo '&nbsp;<input type="submit" name="add" value="'._("Add Role").'" /></p></form>';
+	?></li>
+</ul>
+<?php } ?>
 <h2><?php echo _('Project Maintenance'); ?></h2>
 <ul>
 	<li><?php

Modified: trunk/src/www/include/role_utils.php
===================================================================
--- trunk/src/www/include/role_utils.php	2010-09-21 16:15:40 UTC (rev 10599)
+++ trunk/src/www/include/role_utils.php	2010-09-21 17:20:13 UTC (rev 10600)
@@ -59,6 +59,25 @@
 	return html_build_select_box_from_arrays($ids,$names,$name,$selected,false,'',false);
 }
 
+function global_role_box ($name,$selected='xzxzxz') {
+	$roles = RBACEngine::getInstance()->getGlobalRoles () ;
+
+	$ids = array () ;
+	$names = array () ;
+	
+	foreach ($roles as $role) {
+		$ids[] = $role->getID ();
+		
+		$names[] = $role->getName () ;
+	}
+
+	if ($selected == 'xzxzxz') {
+		$selected = $ids[0] ;
+	}
+
+	return html_build_select_box_from_arrays($ids,$names,$name,$selected,false,'',false);
+}
+
 // Local Variables:
 // mode: php
 // c-file-style: "bsd"




More information about the Fusionforge-commits mailing list