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

Roland Mas lolando at libremir.placard.fr.eu.org
Thu Sep 23 11:53:11 CEST 2010


Author: lolando
Date: 2010-09-23 11:53:11 +0200 (Thu, 23 Sep 2010)
New Revision: 10647

Modified:
   trunk/src/www/admin/globalroleedit.php
   trunk/src/www/include/role_utils.php
   trunk/src/www/project/admin/roleedit.php
   trunk/src/www/project/admin/users.php
Log:
RBAC: fixes + UI to link/unlink external roles to a project (ie. global roles, or roles defined in another project)

Modified: trunk/src/www/admin/globalroleedit.php
===================================================================
--- trunk/src/www/admin/globalroleedit.php	2010-09-23 08:44:18 UTC (rev 10646)
+++ trunk/src/www/admin/globalroleedit.php	2010-09-23 09:53:11 UTC (rev 10647)
@@ -68,8 +68,10 @@
 if (getStringFromRequest('submit')) {
 	if ($role instanceof RoleExplicit) {
 		$role_name = trim(getStringFromRequest('role_name'));
+		$public = getIntFromRequest('public') ? true : false ;
 	} else {
 		$role_name = $role->getName() ;
+		$public = $role->isPublic () ;
 	}
 	if (!$role_name) {
 		$warning_msg .= ' Missing Role Name ';
@@ -82,6 +84,9 @@
 				$feedback = _('Successfully Created New Role');
 			}
 		} else {
+			if ($role instanceof RoleExplicit) {
+				$role->setPublic($public) ;
+			}
 			if (!$role->update($role_name,$data)) {
 				$error_msg .= $role->getErrorMessage();
 			} else {
@@ -181,6 +186,11 @@
 		
 if ($role instanceof RoleExplicit) {
 	echo '<p><strong>'._('Role Name').'</strong><br /><input type="text" name="role_name" value="'.$role->getName().'"></p>';
+	echo '<input type="checkbox" name="public" value="1"' ;
+	if ($role->isPublic()) {
+		echo ' checked' ;
+	}
+	echo '> '._('Shared role').'</p>' ;
 } else {
 	echo '<p><strong>'._('Role Name').'</strong><br />'.$role->getName().'</p>';
 }

Modified: trunk/src/www/include/role_utils.php
===================================================================
--- trunk/src/www/include/role_utils.php	2010-09-23 08:44:18 UTC (rev 10646)
+++ trunk/src/www/include/role_utils.php	2010-09-23 09:53:11 UTC (rev 10647)
@@ -50,6 +50,36 @@
 	return html_build_select_box_from_arrays($ids,$names,$name,$selected,false,'',false);
 }
 
+function external_role_box ($group_id,$name) {
+	$group = group_get_object ($group_id) ;
+	$roles = array () ;
+	foreach (RBACEngine::getInstance()->getPublicRoles() as $r) {
+		$grs = $r->getLinkedProjects () ;
+		$seen = false ;
+		foreach ($grs as $g) {
+			if ($g->getID() == $group_id) {
+				$seen = true ;
+				break ;
+			}
+		}
+		if (!$seen) {
+			$roles[] = $r ;
+		}
+	}
+
+	$ids = array () ;
+	$names = array () ;
+	foreach ($roles as $role) {
+		$ids[] = $role->getID ();
+
+		$names[] = $role->getDisplayableName($group) ;
+	}
+
+	$selected = $ids[0] ;
+
+	return html_build_select_box_from_arrays($ids,$names,$name);
+}
+
 function global_role_box ($name,$selected='xzxzxz') {
 	$roles = RBACEngine::getInstance()->getGlobalRoles () ;
 

Modified: trunk/src/www/project/admin/roleedit.php
===================================================================
--- trunk/src/www/project/admin/roleedit.php	2010-09-23 08:44:18 UTC (rev 10646)
+++ trunk/src/www/project/admin/roleedit.php	2010-09-23 09:53:11 UTC (rev 10647)
@@ -118,7 +118,9 @@
 					$feedback = _('Successfully Created New Role');
 				}
 			} else {
-				$role->setPublic($public) ;
+				if ($role instanceof RoleExplicit) {
+					$role->setPublic($public) ;
+				}
 				if (!$role->update($role_name,$data)) {
 					$error_msg .= $role->getErrorMessage();
 				} else {

Modified: trunk/src/www/project/admin/users.php
===================================================================
--- trunk/src/www/project/admin/users.php	2010-09-23 08:44:18 UTC (rev 10646)
+++ trunk/src/www/project/admin/users.php	2010-09-23 09:53:11 UTC (rev 10647)
@@ -56,6 +56,36 @@
 	plugin_hook ("project_admin_users", $hook_params);
 }
 
+function cache_external_roles () {
+	global $used_external_roles, $unused_external_roles, $group, $group_id;
+
+	if (USE_PFO_RBAC) {
+		$unused_external_roles = array () ;
+		foreach (RBACEngine::getInstance()->getPublicRoles() as $r) {
+			$grs = $r->getLinkedProjects () ;
+			$seen = false ;
+			foreach ($grs as $g) {
+				if ($g->getID() == $group_id) {
+					$seen = true ;
+					break ;
+				}
+			}
+			if (!$seen) {
+				$unused_external_roles[] = $r ;
+			}
+		}
+		$used_external_roles = array () ;
+		foreach ($group->getRoles() as $r) {
+			if ($r->getHomeProject() == NULL
+			    || $r->getHomeProject()->getID() != $group_id) {
+				$used_external_roles[] = $r ;
+			}
+		}
+	}
+}
+
+cache_external_roles () ;
+
 if (getStringFromRequest('submit')) {
 	if (getStringFromRequest('adduser')) {
 		/*
@@ -144,6 +174,36 @@
 				$feedback .= 'Rejected';
 			}
 		}
+	} else if (getStringFromRequest('linkrole')) {
+		/* link a role to this project */
+		if (USE_PFO_RBAC) {
+			$role_id = getIntFromRequest('role_id');
+			foreach ($unused_external_roles as $r) {
+				if ($r->getID() == $role_id) {
+					if (!$r->linkProject($group)) {
+						$error_msg = $r->getErrorMessage();
+					} else {
+						$feedback = _("Role linked successfully");
+						cache_external_roles () ;
+					}
+				}
+			}
+		}
+	} else if (getStringFromRequest('unlinkrole')) {
+		/* unlink a role from this project */
+		if (USE_PFO_RBAC) {
+			$role_id = getIntFromRequest('role_id');
+			foreach ($used_external_roles as $r) {
+				if ($r->getID() == $role_id) {
+					if (!$r->unLinkProject($group)) {
+						$error_msg = $r->getErrorMessage();
+					} else {
+						$feedback = _("Role unlinked successfully");
+						cache_external_roles () ;
+					}
+				}
+			}
+		}
 	}
 }
 
@@ -241,33 +301,44 @@
 
 
 if (USE_PFO_RBAC) {
-	echo $HTML->boxMiddle(_("External Roles"));
+	if (count ($used_external_roles)) {
+		echo $HTML->boxMiddle(_("Currently used external roles"));
+		$ids = array () ;
+		$names = array () ;
+		foreach ($used_external_roles as $r) {
+			$ids[] = $r->getID() ;
+			$names[] = $r->getDisplayableName($group) ;
+		}		
+		echo '<form action="'.getStringFromServer('PHP_SELF').'" method="post">' ;
+		echo '<input type="hidden" name="submit" value="y" />' ;
+		echo '<input type="hidden" name="group_id" value="'.$group_id.'" />' ;
+		
+		echo html_build_select_box_from_arrays($ids,$names,'role_id','',false,'',false,'');
+		echo '<input type="submit" name="unlinkrole" value="'._("Unlink external role").'" /></form><br />' ;
+	}
 
-		$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 />" ;
-		}
+	if (count ($unused_external_roles)) {
+		echo $HTML->boxMiddle(_("Available external roles"));
+		$ids = array () ;
+		$names = array () ;
+		foreach ($unused_external_roles as $r) {
+			$ids[] = $r->getID() ;
+			$names[] = $r->getDisplayableName($group) ;
+		}		
+		echo '<form action="'.getStringFromServer('PHP_SELF').'" method="post">' ;
+		echo '<input type="hidden" name="submit" value="y" />' ;
+		echo '<input type="hidden" name="group_id" value="'.$group_id.'" />' ;
+		
+		echo html_build_select_box_from_arrays($ids,$names,'role_id','',false,'',false,'');
+		echo '<input type="submit" name="linkrole" value="'._("Link external role").'" /></form><br />' ;
+	}
 }
 
 		echo $HTML->boxBottom();
-
+	
 		?></td>
 		<td><?php
-
+			 
 		echo $HTML->boxTop(_("Project Members"));
 
 		/*




More information about the Fusionforge-commits mailing list