[Fusionforge-commits] r10659 - in trunk/src: common/include common/widget www/include www/my www/project www/project/admin

Roland Mas lolando at libremir.placard.fr.eu.org
Fri Sep 24 12:59:24 CEST 2010


Author: lolando
Date: 2010-09-24 12:59:24 +0200 (Fri, 24 Sep 2010)
New Revision: 10659

Modified:
   trunk/src/common/include/RBAC.php
   trunk/src/common/widget/Widget_MyProjects.class.php
   trunk/src/www/include/user_home.php
   trunk/src/www/my/index.php
   trunk/src/www/project/admin/users.php
   trunk/src/www/project/memberlist.php
Log:
Basic UI to allow users to have several roles inside one project, and fixes for places where the old assumption stops working

Modified: trunk/src/common/include/RBAC.php
===================================================================
--- trunk/src/common/include/RBAC.php	2010-09-23 18:52:37 UTC (rev 10658)
+++ trunk/src/common/include/RBAC.php	2010-09-24 10:59:24 UTC (rev 10659)
@@ -1193,6 +1193,7 @@
 		$already_there = array () ;
 		$res = db_query_params ('DELETE FROM pfo_user_role WHERE user_id=ANY($1) AND role_id=$2',
 					array (db_int_array_to_any_clause($ids), $this->getID())) ;
+		return true ;
 	}
 
 	public function removeUser ($user) {

Modified: trunk/src/common/widget/Widget_MyProjects.class.php
===================================================================
--- trunk/src/common/widget/Widget_MyProjects.class.php	2010-09-23 18:52:37 UTC (rev 10658)
+++ trunk/src/common/widget/Widget_MyProjects.class.php	2010-09-24 10:59:24 UTC (rev 10659)
@@ -40,6 +40,7 @@
 	$groups = $user->getGroups() ;
 	sortProjectList ($groups) ;
 	$roles = RBACEngine::getInstance()->getAvailableRolesForUser ($user) ;
+	sortRoleList ($roles) ;
 
 	if (count ($groups) < 1) {
 		$html_my_projects .= _("You're not a member of any project");
@@ -60,22 +61,22 @@
 				'<A href="/projects/'. $g->getUnixName() .'/">'.
 				$g->getPublicName().'</A>';
 			
-			$bestrole = NULL ;
 			$isadmin = false ;
+			$role_names = array () ;
 			foreach ($roles as $r) {
 				if ($r instanceof RoleExplicit
 				    && $r->getHomeProject() != NULL
 				    && $r->getHomeProject()->getID() == $g->getID()) {
-					$bestrole = $r ;
+					$role_names[] = $r->getName() ;
 					if ($r->hasPermission ('project_admin', $g->getID())) {
 						$isadmin = true ;
-						break ;
 					}
 				}
 			}
 			if ($isadmin) {
 				$html_my_projects .= ' <small><A HREF="/project/admin/?group_id='.$g->getID().'">['._("Admin").']</A></small>';
 			}
+			$html_my_projects .= ' <small>('.htmlspecialchars (implode (', ', $role_names)).')</small>';
 			if (!$g->isPublic()) {
 				$html_my_projects .= ' (*)';
 				$private_shown = true;

Modified: trunk/src/www/include/user_home.php
===================================================================
--- trunk/src/www/include/user_home.php	2010-09-23 18:52:37 UTC (rev 10658)
+++ trunk/src/www/include/user_home.php	2010-09-24 10:59:24 UTC (rev 10659)
@@ -185,32 +185,23 @@
 
     echo $HTML->boxMiddle(_('Project Info'), _('Project Info'));
 
-	// now get listing of groups for that user
-	$res_cat = db_query_params ('SELECT groups.group_name, 
-	 groups.unix_group_name, 
-	 groups.group_id, 
-	 user_group.admin_flags,
-         role.role_name
-	 FROM 
-	 groups,user_group,role WHERE user_group.user_id=$1 AND  user_group.role_id=role.role_id AND
-	 groups.group_id=user_group.group_id AND groups.is_public=$2 AND groups.status=$3',
-			array($user_id,
-				'1',
-				'A'));
+$projects = $user->getGroups () ;
+sortProjectList ($projects) ;
+$roles = RBACEngine::getInstance()->getAvailableRolesForUser ($user) ;
+sortRoleList ($roles) ;
 
 // see if there were any groups
 echo '<div xmlns:sioc="http://rdfs.org/sioc/ns#" xmlns:doap="http://usefulinc.com/ns/doap#">'."\n";
-if (db_numrows($res_cat) < 1) {
+if (count ($projects) < 1) {
 	?>
 	<p><?php echo _('This developer is not a member of any projects.') ?></p>
 	<?php
 } else { // endif no groups
 	print "<p>"._('This developer is a member of the following projects:')."<br />&nbsp;";
 	
-	while ($row_cat = db_fetch_array($res_cat)) {
-
-		$project_link = util_make_link_g ($row_cat['unix_group_name'],$row_cat['group_id'],$row_cat['group_name']);
-		$project_uri = util_make_url_g ($row_cat['unix_group_name'],$row_cat['group_id']);
+	foreach ($projects as $p) {
+		$project_link = util_make_link_g ($p->getUnixName(),$p->getID(),$p->getPublicName());
+		$project_uri = util_make_url_g ($p->getUnixName(),$p->getID());
 		// sioc:UserGroups for all members of a project are named after /projects/A_PROJECT/members/ 
 		$usergroup_uri = $project_uri .'members/';
 		
@@ -219,12 +210,20 @@
 			.'<div about="'. $usergroup_uri .'" typeof="sioc:UserGroup">'."\n"
 			.'<span rel="sioc:usergroup_of">'."\n"
 			.'<div about="'. $project_uri .'" typeof="sioc:Space">';
-		//print '<div property="sioc:has_function" content= "'.$row_cat['role_name'].'" xmlns:sioc="http://rdfs.org/sioc/ns#">';
+		$role_names = array () ;
+		foreach ($roles as $r) {
+			if ($r instanceof RoleExplicit
+			    && $r->getHomeProject() != NULL
+			    && $r->getHomeProject()->getID() == $p->getID()) {
+				$role_names[] = $r->getName() ;
+				print '<div property="sioc:has_function" content= "'.$r->getName().'" xmlns:sioc="http://rdfs.org/sioc/ns#">';
+			}
+		}
 		
-		print ('<br />' . $project_link .' ('.$row_cat['role_name'].')');
+		print ('<br />' . $project_link .' ('.htmlspecialchars (implode (', ', $role_names)).')');
 		print "\n";
 		
-		if (trim($row_cat['admin_flags']) == 'A') {
+		if (forge_check_perm_for_user ($user, 'project_admin', $p->getID())) {
 			print '<span rev="doap:maintainer" resource="#me"></span>';
 		}
 		else {

Modified: trunk/src/www/my/index.php
===================================================================
--- trunk/src/www/my/index.php	2010-09-23 18:52:37 UTC (rev 10658)
+++ trunk/src/www/my/index.php	2010-09-24 10:59:24 UTC (rev 10659)
@@ -405,17 +405,17 @@
 		echo '<tr><td colspan="3"><strong>'._('You\'re not a member of any active projects').'</strong></td></tr>';
 	} else {
 		$roles = RBACEngine::getInstance()->getAvailableRolesForUser ($user) ;
+		sortRoleList ($roles) ;
 		foreach ($groups as $g) {
-			$bestrole = NULL ;
 			$img="trash.png";
+			$role_names = array () ;
 			foreach ($roles as $r) {
 				if ($r instanceof RoleExplicit
 				    && $r->getHomeProject() != NULL
 				    && $r->getHomeProject()->getID() == $g->getID()) {
-					$bestrole = $r ;
+					$role_names[] = $r->getName() ;
 					if ($r->hasPermission ('project_admin', $g->getID())) {
 						$img="trash-x.png";
-						break ;
 					}
 				}
 			}
@@ -426,7 +426,7 @@
 
 			echo '</td>
 			<td>'.util_make_link_g ($g->getUnixName(),$g->getID(),$g->getPublicName()).'</td>
-			<td>'. htmlspecialchars($r->getName()) .'</td></tr>';
+			<td>'. htmlspecialchars (implode (', ', $role_names)) .'</td></tr>';
 
 
 		}

Modified: trunk/src/www/project/admin/users.php
===================================================================
--- trunk/src/www/project/admin/users.php	2010-09-23 18:52:37 UTC (rev 10658)
+++ trunk/src/www/project/admin/users.php	2010-09-24 10:59:24 UTC (rev 10659)
@@ -122,9 +122,16 @@
 	} else if (getStringFromRequest('rmuser')) {
 		/* remove a member from this project */
 		$user_id = getIntFromRequest('user_id');
-		if (!$group->removeUser($user_id)) {
-			$error_msg = $group->getErrorMessage();
+		$role_id = getIntFromRequest('role_id');
+		$role = RBACEngine::getInstance()->getRoleById($role_id) ;
+		if ($role->getHomeProject() == NULL) {
+			session_require_global_perm ('forge_admin') ;
 		} else {
+			session_require_perm ('project_admin', $role->getHomeProject()->getID()) ;
+		}
+		if (!$role->removeUser (user_get_object ($user_id))) {
+			$error_msg = $role->getErrorMessage() ;
+		} else {
 			$feedback = _("Member Removed Successfully");
 		}
 	} else if (getStringFromRequest('updateuser')) {
@@ -356,42 +363,47 @@
 echo '<table width="100%"><thead><tr>';
 echo '<th>'._('User name').'</th>';
 echo '<th>'._('Role').'</th>';
-echo '<th>'._('Update').'</th>';
 echo '<th>'._('Remove').'</th>';
 echo '</tr></thead><tbody>';
 
 foreach ($members as $user) {
-	echo '
+	$roles = array () ;
+	foreach (RBACEngine::getInstance()->getAvailableRolesForUser ($user) as $role) {
+		if ($role->getHomeProject() && $role->getHomeProject()->getID() == $group->getID()) {
+			$roles[] = $role ;
+		}
+	}
+
+	sortRoleList ($roles) ;
+
+	$seen = false ;
+	foreach ($roles as $role) {
+		echo '<tr>' ;
+		if (!$seen) {
+			echo '<td style="white-space: nowrap;" rowspan="'.count($roles).'"><a href="/users/'.$user->getUnixName().'">';
+			$display = $user->getRealName();
+			if (!empty($display)) {
+				echo $user->getRealName();
+			} else {
+				echo $user->getUnixName();
+			}
+			echo '</a></td>';
+			$seen = true ;
+		} 
+			
+		echo '
 		<form action="'.getStringFromServer('PHP_SELF').'" method="post">
-                        <tr>
-                        <td style="white-space: nowrap;">
 			  <input type="hidden" name="submit" value="y" />
 			  <input type="hidden" name="user_id" value="'.$user->getID().'" />
-			  <input type="hidden" name="group_id" value="'. $group_id .'" />
-			  <a href="/users/'.$user->getUnixName().'">';
-	$display = $user->getRealName();
-	if (!empty($display)) {
-		echo $user->getRealName();
-	} else {
-		echo $user->getUnixName();
+			  <input type="hidden" name="group_id" value="'. $group_id .'" />' ;
+			
+		echo '<td style="white-space: nowrap;">';
+		echo $role->getName() ;
+		echo '<input type="hidden" name="role_id" value="'.$role->getID().'" />' ;
+		echo '</td><td><input type="submit" name="rmuser" value="'._("Remove").'" />
+                        </td>
+                </form></tr>';
 	}
-	echo '</a>
-			</td>
-			<td style="white-space: nowrap; text-align: right;">';
-
-	$roles = RBACEngine::getInstance()->getAvailableRolesForUser ($user) ;
-	foreach ($roles as $role) {
-		if ($role->getHomeProject() && $role->getHomeProject()->getID() == $group->getID()) {
-			$role_id = $role->getID() ;
-			break ;
-		}
-	}
-	echo role_box($group_id,'role_id',$role_id);
-	echo '</td><td><input type="submit" name="updateuser" value="'._("Update").'" />';
-	echo '</td><td><input type="submit" name="rmuser" value="'._("Remove").'" />
-                        </td>
-			</tr>
-                </form>';
 }
 echo '</tbody></table>';
 echo $HTML->boxBottom(); 

Modified: trunk/src/www/project/memberlist.php
===================================================================
--- trunk/src/www/project/memberlist.php	2010-09-23 18:52:37 UTC (rev 10658)
+++ trunk/src/www/project/memberlist.php	2010-09-24 10:59:24 UTC (rev 10659)
@@ -50,7 +50,7 @@
 $title_arr=array();
 $title_arr[]=_('Member');
 $title_arr[]=_('Username');
-$title_arr[]=_('Role/Position');
+$title_arr[]=_('Role(s)/Position(s)');
 if(forge_get_config('use_people')) {
 	$title_arr[]=_('Skills');
 }
@@ -88,6 +88,7 @@
 
 	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()) {




More information about the Fusionforge-commits mailing list