[Fusionforge-commits] r9792 - trunk/gforge/common/include

Roland Mas lolando at libremir.placard.fr.eu.org
Fri May 21 09:46:07 CEST 2010


Author: lolando
Date: 2010-05-21 09:46:07 +0200 (Fri, 21 May 2010)
New Revision: 9792

Modified:
   trunk/gforge/common/include/RBACEngine.class.php
Log:
Added methods to check for a specific user's permissions (not necessarily the currently logged-in user's)

Modified: trunk/gforge/common/include/RBACEngine.class.php
===================================================================
--- trunk/gforge/common/include/RBACEngine.class.php	2010-05-21 07:45:57 UTC (rev 9791)
+++ trunk/gforge/common/include/RBACEngine.class.php	2010-05-21 07:46:07 UTC (rev 9792)
@@ -54,6 +54,20 @@
 		return $result ;
 	}
 
+	public function getAvailableRolesForUser($user) {
+		$result = array () ;
+
+		$result[] = RoleAnonymous::getInstance() ;
+		$result[] = RoleLoggedIn::getInstance() ;
+		
+		$groups = $user->getGroups() ;
+		foreach ($groups as $g) {
+			$result[] = $user->getRole($g) ;
+		}
+		
+		return $result ;
+	}
+
 	public function isActionAllowed ($section, $reference, $action = NULL) {
 		$rlist = $this->getAvailableRoles () ;
 		foreach ($rlist as $r) {
@@ -67,6 +81,20 @@
 	public function isGlobalActionAllowed ($section, $action = NULL) {
 		return $this->isActionAllowed ($section, -1, $action) ;
 	}
+
+	public function isActionAllowedForUser ($user, $section, $reference, $action = NULL) {
+		$rlist = $this->getAvailableRolesForUser ($user) ;
+		foreach ($rlist as $r) {
+			if ($r->hasPermission ($user, $section, $reference, $action)) {
+				return true ;
+			}
+		}
+		return false ;
+	}
+
+	public function isGlobalActionAllowedForUser ($user, $section, $action = NULL) {
+		return $this->isActionAllowedForUser ($user, $section, -1, $action) ;
+	}
 }
 
 function forge_check_perm ($section, $reference, $action = NULL) {
@@ -80,3 +108,22 @@
 
 	return $engine->isGlobalActionAllowed($section, $action) ;
 }
+
+function forge_check_perm_for_user ($user, $section, $reference, $action = NULL) {
+	$engine = RBACEngine::getInstance() ;
+
+	return $engine->isActionAllowedForUser($user, $section, $reference, $action) ;
+}
+
+function forge_check_global_perm_for_user ($user, $section, $action = NULL) {
+	$engine = RBACEngine::getInstance() ;
+
+	return $engine->isGlobalActionAllowedForUser($user, $section, $action) ;
+}
+
+// Local Variables:
+// mode: php
+// c-file-style: "bsd"
+// End:
+
+?>




More information about the Fusionforge-commits mailing list