[evolvis-commits] r18379: small-fixes pending merges:↵ Thorsten Glaser 2012-04-25 fix SCM access for linked roles↵ Thorsten Glaser 2012-04-25 a user is also a member of a group if he’s in a linked external role↵ Thorsten Glaser 2012-04-25 announce that memberlist.php has users from external roles, too↵ Thorsten Glaser 2012-04-25 display users from external roles, too↵ Thorsten Glaser 2012-04-25 move forge_cache_external_roles() into a common include and genericise

mirabilos at evolvis.org mirabilos at evolvis.org
Wed Apr 25 18:01:12 CEST 2012


Author: mirabilos
Date: 2012-04-25 18:01:12 +0200 (Wed, 25 Apr 2012)
New Revision: 18379

Modified:
   trunk/gforge_base/evolvisforge-5.1/src/common/include/RBAC.php
   trunk/gforge_base/evolvisforge-5.1/src/common/include/RBACEngine.class.php
   trunk/gforge_base/evolvisforge-5.1/src/common/include/User.class.php
   trunk/gforge_base/evolvisforge-5.1/src/common/widget/Widget_ProjectMembers.class.php
   trunk/gforge_base/evolvisforge-5.1/src/www/project/admin/users.php
   trunk/gforge_base/evolvisforge-5.1/src/www/project/memberlist.php
Log:
small-fixes pending merges:
  Thorsten Glaser 2012-04-25 fix SCM access for linked roles
    Thorsten Glaser 2012-04-25 a user is also a member of a group if he’s in a linked external role
    Thorsten Glaser 2012-04-25 announce that memberlist.php has users from external roles, too
    Thorsten Glaser 2012-04-25 display users from external roles, too
    Thorsten Glaser 2012-04-25 move forge_cache_external_roles() into a common include and genericise

Modified: trunk/gforge_base/evolvisforge-5.1/src/common/include/RBAC.php
===================================================================
--- trunk/gforge_base/evolvisforge-5.1/src/common/include/RBAC.php	2012-04-25 12:47:49 UTC (rev 18378)
+++ trunk/gforge_base/evolvisforge-5.1/src/common/include/RBAC.php	2012-04-25 16:01:12 UTC (rev 18379)
@@ -266,6 +266,8 @@
 	}
 
 	function linkProject ($project) { // From the PFO spec
+		global $SYS;
+
 		$hp = $this->getHomeProject () ;
 		if ($hp != NULL && $hp->getID() == $project->getID()) {
 			$this->setError ("Can't link to home project") ;
@@ -287,10 +289,23 @@
 			return false;
 		}
 
+		foreach ($this->getUsers() as $member) {
+			if (!$SYS->sysGroupCheckUser($project->getID(),
+			    $member->getID())) {
+				$this->setError('linkProject(' .
+				    $project->getID() .'):CheckUser(' .
+				    $member->getUnixName() . ') ' .
+				    $SYS->getErrorMessage());
+				return false;
+			}
+		}
+
 		return true ;
 	}
 
 	function unlinkProject ($project) { // From the PFO spec
+		global $SYS;
+
 		$hp = $this->getHomeProject () ;
 		if ($hp != NULL && $hp->getID() == $project->getID()) {
 			$this->setError ("Can't unlink from home project") ;
@@ -307,6 +322,17 @@
 
 		$this->removeObsoleteSettings () ;
 
+		foreach ($this->getUsers() as $member) {
+			if (!$SYS->sysGroupCheckUser($project->getID(),
+			    $member->getID())) {
+				$this->setError('unlinkProject(' .
+				    $project->getID() .'):CheckUser(' .
+				    $member->getUnixName() . ') ' .
+				    $SYS->getErrorMessage());
+				return false;
+			}
+		}
+
 		return true ;
 	}
 
@@ -914,6 +940,7 @@
 	 */
 	function update($role_name,$data,$check_perms=true) {
 		global $SYS;
+
 		if (USE_PFO_RBAC) {
 			if ($check_perms) {
 				if ($this->getHomeProject() == NULL) {
@@ -953,6 +980,7 @@
 				foreach ($refs as $refid => $value) {
 					$this->setSetting ($sect, $refid, $value) ;
 					if ($sect == 'scm') {
+						$this->refetchData();
 						foreach ($this->getUsers() as $u) {
 							if (!$SYS->sysGroupCheckUser($refid,$u->getID())) {
 								$this->setError($SYS->getErrorMessage());

Modified: trunk/gforge_base/evolvisforge-5.1/src/common/include/RBACEngine.class.php
===================================================================
--- trunk/gforge_base/evolvisforge-5.1/src/common/include/RBACEngine.class.php	2012-04-25 12:47:49 UTC (rev 18378)
+++ trunk/gforge_base/evolvisforge-5.1/src/common/include/RBACEngine.class.php	2012-04-25 16:01:12 UTC (rev 18379)
@@ -450,9 +450,42 @@
 	return $engine->isGlobalActionAllowedForUser($user, $section, $action) ;
 }
 
+function forge_cache_external_roles($group) {
+	global $used_external_roles, $unused_external_roles;
+
+	$used_external_roles = array();
+	$unused_external_roles = array();
+	if (!USE_PFO_RBAC) {
+		return;
+	}
+	$group_id = $group->getID();
+
+	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;
+		}
+	}
+
+	foreach ($group->getRoles() as $r) {
+		if ($r->getHomeProject() == NULL ||
+		    $r->getHomeProject()->getID() != $group_id) {
+			$used_external_roles[] = $r;
+		}
+	}
+
+	sortRoleList($used_external_roles, $group, 'composite');
+	sortRoleList($unused_external_roles, $group, 'composite');
+}
+
 // Local Variables:
 // mode: php
 // c-file-style: "bsd"
 // End:
-
-?>

Modified: trunk/gforge_base/evolvisforge-5.1/src/common/include/User.class.php
===================================================================
--- trunk/gforge_base/evolvisforge-5.1/src/common/include/User.class.php	2012-04-25 12:47:49 UTC (rev 18378)
+++ trunk/gforge_base/evolvisforge-5.1/src/common/include/User.class.php	2012-04-25 16:01:12 UTC (rev 18379)
@@ -1515,7 +1515,7 @@
 		switch ($type) {
 		case 0:
 		default:
-			foreach ($this->getGroups() as $p) {
+			foreach ($this->getGroups(false) as $p) {
 				if ($p->getID() == $group_id) {
 					return true ;
 				}

Modified: trunk/gforge_base/evolvisforge-5.1/src/common/widget/Widget_ProjectMembers.class.php
===================================================================
--- trunk/gforge_base/evolvisforge-5.1/src/common/widget/Widget_ProjectMembers.class.php	2012-04-25 12:47:49 UTC (rev 18378)
+++ trunk/gforge_base/evolvisforge-5.1/src/common/widget/Widget_ProjectMembers.class.php	2012-04-25 16:01:12 UTC (rev 18379)
@@ -1,8 +1,10 @@
 <?php
 /**
  * Copyright (c) Xerox Corporation, Codendi Team, 2001-2009. All rights reserved
+ * Copyright (c) 2012
+ *	Thorsten Glaser <t.glaser at tarent.de>
  *
- * This file is a part of Codendi.
+ * This file is a part of FusionForge, originating from Codendi.
  *
  * Codendi is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -118,7 +120,7 @@
 		echo '<p><span rel="sioc:has_usergroup">';
 		echo '<span about="members/" typeof="sioc:UserGroup">';
 		echo '<span rel="http://www.w3.org/2002/07/owl#sameAs">';
-		echo util_make_link ('/project/memberlist.php?group_id='.$group_id,sprintf(_('View the %1$d Member(s)'),count($members)));
+		echo util_make_link ('/project/memberlist.php?group_id='.$group_id,sprintf(_('View the %1$d Member(s), as well as users linked from external roles'),count($members)));
 		echo '</span>';
 		echo '</span>';
 		echo '</span></p>';

Modified: trunk/gforge_base/evolvisforge-5.1/src/www/project/admin/users.php
===================================================================
--- trunk/gforge_base/evolvisforge-5.1/src/www/project/admin/users.php	2012-04-25 12:47:49 UTC (rev 18378)
+++ trunk/gforge_base/evolvisforge-5.1/src/www/project/admin/users.php	2012-04-25 16:01:12 UTC (rev 18379)
@@ -59,40 +59,8 @@
 	plugin_hook ("project_admin_users", $hook_params);
 }
 
-function cache_external_roles () {
-	global $used_external_roles, $unused_external_roles, $group, $group_id;
+forge_cache_external_roles($group);
 
-	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 ;
-			}
-		}
-
-		sortRoleList ($used_external_roles, $group, 'composite') ;
-		sortRoleList ($unused_external_roles, $group, 'composite') ;
-
-	}
-}
-
-cache_external_roles () ;
-
 if (getStringFromRequest('submit')) {
 	if (getStringFromRequest('adduser')) {
 		/*
@@ -199,7 +167,7 @@
 						$error_msg = $r->getErrorMessage();
 					} else {
 						$feedback = _("Role linked successfully");
-						cache_external_roles () ;
+						forge_cache_external_roles($group);
 					}
 				}
 			}
@@ -214,7 +182,7 @@
 						$error_msg = $r->getErrorMessage();
 					} else {
 						$feedback = _("Role unlinked successfully");
-						cache_external_roles () ;
+						forge_cache_external_roles($group);
 					}
 				}
 			}

Modified: trunk/gforge_base/evolvisforge-5.1/src/www/project/memberlist.php
===================================================================
--- trunk/gforge_base/evolvisforge-5.1/src/www/project/memberlist.php	2012-04-25 12:47:49 UTC (rev 18378)
+++ trunk/gforge_base/evolvisforge-5.1/src/www/project/memberlist.php	2012-04-25 16:01:12 UTC (rev 18379)
@@ -4,7 +4,8 @@
  *
  * Copyright 1999-2001 (c) VA Linux Systems
  * Copyright 2002-2004 (c) GForge Team
- * http://fusionforge.org/
+ * Copyright (c) 2012
+ *	Thorsten Glaser <t.glaser at tarent.de>
  *
  * This file is part of FusionForge. FusionForge is free software;
  * you can redistribute it and/or modify it under the terms of the
@@ -45,6 +46,8 @@
 print '<span rev="sioc:has_usergroup" resource="'. $project_stdzd_uri . '"></span>';
 print '</div>';
 
+$group_id = $project->getID();
+
 $title_arr=array();
 $title_arr[]=_('Member');
 $title_arr[]=_('Username');
@@ -55,11 +58,58 @@
 
 echo $GLOBALS['HTML']->listTableTop ($title_arr);
 
-// list members
-$members = $project->getUsers() ;
+$members = array();
+$i = 0;
+foreach ($project->getUsers() as $user) {
+	$uid = $user->getID();
+	if (!isset($members[$uid])) {
+		$members[$uid] = array(
+			'u' => $user,
+			'order' => $i++,
+			'roles' => array(),
+		    );
+	}
+	if (USE_PFO_RBAC) {
+		$roles = RBACEngine::getInstance()->getAvailableRolesForUser($user);
+		sortRoleList($roles);
+		foreach ($roles as $role) {
+			if ($role->getHomeProject() &&
+			    $role->getHomeProject()->getID() == $group_id) {
+				$members[$uid]['roles'][] = $role->getName();
+			}
+		}
+	} else {
+		$members[$uid]['roles'][] = $user->getRole($project)->getName();
+	}
+}
 
+forge_cache_external_roles($project);
+foreach ($used_external_roles as $role) {
+	if (!($role instanceof RoleExplicit)) {
+		continue;
+	}
+	foreach ($role->getUsers() as $user) {
+		$uid = $user->getID();
+		if (!isset($members[$uid])) {
+			$members[$uid] = array(
+				'u' => $user,
+				'order' => $i++,
+				'roles' => array(),
+			    );
+		}
+		$members[$uid]['roles'][] = $role->getDisplayableName($project);
+	}
+}
+
+uasort($members, create_function('$a, $b', '
+	$av = $a["order"];
+	$bv = $b["order"];
+	return ($av == $bv ? 0 : (($av < $bv) ? -1 : 1));
+    '));
+
 $i=0;
-foreach ($members as $user) {
+foreach ($members as $member) {
+	$user =& $member['u'];
 	echo '<tr '.$HTML->boxGetAltRowStyle($i++).'>'."\n";
 	// RDFa
 	$member_uri = util_make_url_u ($user->getUnixName(),$user->getID());
@@ -88,19 +138,7 @@
         print '<span property="fusionforge:has_job" content="'.$role_string.'">';
         echo '</span>';*/
 
-	if (USE_PFO_RBAC) {
-		$roles = RBACEngine::getInstance()->getAvailableRolesForUser ($user) ;
-		sortRoleList ($roles) ;
-		$role_names = array () ;
-		foreach ($roles as $role) {
-			if ($role->getHomeProject() && $role->getHomeProject()->getID() == $project->getID()) {
-				$role_names[] = $role->getName() ;
-			}
-		}
-		$role_string = implode (', ', $role_names) ;
-	} else {
-		$role_string = $user->getRole ($project)->getName() ;
-	}
+	$role_string = $member['roles'] ? implode(", ", $member['roles']) : "(none)";
 
 	echo '<td>';
 	echo util_display_user($user->getUnixName(),$user->getID(),$user->getUnixName(), 's');
@@ -115,5 +153,3 @@
 echo $GLOBALS['HTML']->listTableBottom();
 
 site_project_footer(array());
-
-?>



More information about the evolvis-commits mailing list