[Fusionforge-commits] r9478 - in trunk/gforge: common/include plugins/mediawiki/common

Roland Mas lolando at libremir.placard.fr.eu.org
Wed Apr 14 16:14:31 CEST 2010


Author: lolando
Date: 2010-04-14 16:14:31 +0200 (Wed, 14 Apr 2010)
New Revision: 9478

Modified:
   trunk/gforge/common/include/Plugin.class.php
   trunk/gforge/common/include/Role.class.php
   trunk/gforge/common/include/rbac_texts.php
   trunk/gforge/plugins/mediawiki/common/MediaWikiPlugin.class.php
Log:
Added machinery to delegate permissions to plugins

Modified: trunk/gforge/common/include/Plugin.class.php
===================================================================
--- trunk/gforge/common/include/Plugin.class.php	2010-04-14 14:14:21 UTC (rev 9477)
+++ trunk/gforge/common/include/Plugin.class.php	2010-04-14 14:14:31 UTC (rev 9478)
@@ -107,11 +107,53 @@
 		
 		return $result ;
 	}
+
 	function getThemePath(){
 		return util_make_url('plugins/'.$this->name.'/themes/default');
 	}
+
+	function registerRoleValues(&$params, $values) {
+		$role =& $params['role'] ;
+	}
+		
 }
 
+class PluginSpecificRoleSetting {
+	var $role ;
+	var $name = '' ;
+	var $section = '' ;
+	var $values = array () ;
+	var $default_values = array () ;
+
+	function PluginSpecificRoleSetting (&$role, $name) {
+		$this->role =& $role ;
+		$this->name = $name ;
+	}
+
+	function SetAllowedValues ($values) {
+		$this->role->role_values = array_replace_recursive ($this->role->role_values,
+								    array ($this->name => $values)) ;
+	}
+
+	function SetDefaultValues ($defaults) {
+		foreach ($defaults as $rname => $v) {
+			$this->role->defaults[$rname][$this->name] = $v ;
+		}
+	}
+
+	function setValueDescriptions ($descs) {
+		global $rbac_permission_names ;
+		foreach ($descs as $k => $v) {
+			$rbac_permission_names[$this->name.$k] = $v ;
+		}
+	}
+
+	function setDescription ($desc) {
+		global $rbac_edit_section_names ;
+		$rbac_edit_section_names[$this->name] = $desc ;
+	}
+}
+
 // Local Variables:
 // mode: php
 // c-file-style: "bsd"

Modified: trunk/gforge/common/include/Role.class.php
===================================================================
--- trunk/gforge/common/include/Role.class.php	2010-04-14 14:14:21 UTC (rev 9477)
+++ trunk/gforge/common/include/Role.class.php	2010-04-14 14:14:31 UTC (rev 9478)
@@ -139,7 +139,7 @@
 		$hook_params['role'] =& $this;
 		plugin_hook ("role_get", $hook_params);
 
-		if ($GLOBALS['default_roles']) {
+		if (isset ($GLOBALS['default_roles'])) {
 			$this->defaults = array_merge_recursive ($this->defaults,
 								 $GLOBALS['default_roles']) ;
 			foreach ($this->defaults as $k => $v) {

Modified: trunk/gforge/common/include/rbac_texts.php
===================================================================
--- trunk/gforge/common/include/rbac_texts.php	2010-04-14 14:14:21 UTC (rev 9477)
+++ trunk/gforge/common/include/rbac_texts.php	2010-04-14 14:14:31 UTC (rev 9478)
@@ -26,9 +26,12 @@
  * This file maps symbolic values to localised texts for the role permissions
  */
 
+require_once $gfcommon.'include/PluginManager.class.php';
+
 function setup_rbac_strings () {
 	global $rbac_permission_names, $rbac_edit_section_names ;
-	$rbac_permission_names = array (
+	$rbac_permission_names = array_replace_recursive ($rbac_permission_names, 
+							  array (
 		'frspackage0' => _('Private'),
 		'frspackage1' => _('Public'),
 		'frspackage' => _('File Release System'),
@@ -78,9 +81,11 @@
 		'webcal2' => _('See'),
 		'webcal1' => _('Modify'),
 		'webcal0' => _('No access')
+								  )
 		);
 
-	$rbac_edit_section_names = array (
+	$rbac_edit_section_names = array_replace_recursive ($rbac_edit_section_names,
+							    array (
 		'forum' => _('Forum'),
 		'newforum' => _('Default for new forums'),
 		'forumpublic' => _('Forum'),
@@ -103,7 +108,10 @@
 		'scm' => _('SCM'),
 		'scmpublic' => _('SCM'),
 		'docman' => _('Documentation Manager'),
+								    )
 		) ;
+
+	plugin_hook ("role_translate_strings") ;
   }
 
 setup_rbac_strings () ;

Modified: trunk/gforge/plugins/mediawiki/common/MediaWikiPlugin.class.php
===================================================================
--- trunk/gforge/plugins/mediawiki/common/MediaWikiPlugin.class.php	2010-04-14 14:14:21 UTC (rev 9477)
+++ trunk/gforge/plugins/mediawiki/common/MediaWikiPlugin.class.php	2010-04-14 14:14:31 UTC (rev 9478)
@@ -31,6 +31,7 @@
 		$this->hooks[] = "groupisactivecheckboxpost" ; //
 		$this->hooks[] = "project_public_area";
 		$this->hooks[] = "role_get";
+		$this->hooks[] = "role_translate_strings";
 	}
 
 	function CallHook ($hookname, $params) {
@@ -108,21 +109,25 @@
 			}
 		} elseif ($hookname == "role_get") {
 			$role =& $params['role'] ;
-			$role->role_values['plugin_mediawiki_edit'] = array ('0', '1', '2') ;
 			
-			$defaults = array (
-				'Admin' 	   => array ('plugin_mediawiki_edit' => '2'),
-				'Senior Developer' => array ('plugin_mediawiki_edit' => '2'),
-				'Junior Developer' => array ('plugin_mediawiki_edit' => '1'),
-				'Doc Writer' 	   => array ('plugin_mediawiki_edit' => '2'),
-				'Support Tech' 	   => array ('plugin_mediawiki_edit' => '0')
-				) ;
-
-			$role->defaults = array_merge_recursive ($role->defaults,
-								 $defaults) ;
-		} 
+			$edit = new PluginSpecificRoleSetting ($role,
+							       'plugin_mediawiki_edit') ;
+			$edit->SetAllowedValues (array ('0', '1', '2')) ;
+			$edit->SetDefaultValues (array ('Admin' => '2',
+							'Senior Developer' => '2',
+							'Junior Developer' => '1',
+							'Doc Writer' => '2',
+							'Support Tech' => '0')) ;
+		} elseif ($hookname == "role_translate_strings") {
+			$edit = new PluginSpecificRoleSetting ($role,
+							       'plugin_mediawiki_edit') ;
+			$edit->setDescription (_('Mediawiki write access')) ;
+			$edit->setValueDescriptions (array ('0' => _('No editing'),
+							    '1' => _('Edit existing pages only'), 
+							    '2' => _('Edit and create pages'))) ;
+		}
 	}
-}
+  }
 
 // Local Variables:
 // mode: php




More information about the Fusionforge-commits mailing list