[Fusionforge-commits] r10732 - trunk/src/common/include

Roland Mas lolando at libremir.placard.fr.eu.org
Mon Sep 27 16:48:10 CEST 2010


Author: lolando
Date: 2010-09-27 16:48:10 +0200 (Mon, 27 Sep 2010)
New Revision: 10732

Modified:
   trunk/src/common/include/RBAC.php
   trunk/src/common/include/Role.class.php
Log:
Fixed role normalization

Modified: trunk/src/common/include/RBAC.php
===================================================================
--- trunk/src/common/include/RBAC.php	2010-09-27 14:13:49 UTC (rev 10731)
+++ trunk/src/common/include/RBAC.php	2010-09-27 14:48:10 UTC (rev 10732)
@@ -237,9 +237,6 @@
 	public function setSettings($data) {
 		throw new Exception ("Not implemented") ;
 	}
-	public function normalizeData () {
-		throw new Exception ("Not implemented") ;
-	}
 	public function delete () {
 		throw new Exception ("Not implemented") ;
 	}
@@ -1162,6 +1159,153 @@
 		db_commit () ;
 		return true ;
 	}
+
+	function normalizeDataForSection (&$new_sa, $section) {
+		if (array_key_exists ($section, $this->setting_array)) {
+			$new_sa[$section][0] = $this->setting_array[$section][0] ;
+		} elseif (array_key_exists ($this->data_array['role_name'], $this->defaults)
+			  && array_key_exists ($section, $this->defaults[$this->data_array['role_name']])) {
+			$new_sa[$section][0] = $this->defaults[$this->data_array['role_name']][$section] ;
+		} else {
+			$new_sa[$section][0] = 0 ;
+		}
+		return $new_sa ;
+	}
+
+	function normalizePermsForSection (&$new_pa, $section, $refid) {
+		if (array_key_exists ($section, $this->perms_array)
+		    && array_key_exists ($refid, $this->perms_array[$section])) {
+			$new_pa[$section][$refid] = $this->perms_array[$section][$refid] ;
+		} elseif (array_key_exists ($this->data_array['role_name'], $this->defaults)
+			  && array_key_exists ($section, $this->defaults[$this->data_array['role_name']])) {
+			$new_pa[$section][$refid] = $this->defaults[$this->data_array['role_name']][$section] ;
+		} else {
+			$new_pa[$section][$refid] = 0 ;
+		}
+		return $new_pa ;
+	}
+
+	function normalizeData () { // From the PFO spec
+		$this->removeObsoleteSettings () ;
+
+		$this->fetchData ($this->getID()) ;
+
+		$projects = $this->getLinkedProjects() ;		
+		$new_sa = array () ;
+		$new_pa = array () ;
+		
+		// Add missing settings
+		// ...project-wide settings
+		if (USE_PFO_RBAC) {
+			$arr = array ('project_read', 'project_admin', 'frs', 'scm', 'docman', 'tracker_admin', 'new_tracker', 'forum_admin', 'new_forum', 'pm_admin', 'new_pm', 'webcal') ;
+			foreach ($projects as $p) {
+				foreach ($arr as $section) {
+					$this->normalizePermsForSection ($new_pa, $section, $p->getID()) ;
+				}
+			}
+			$this->normalizePermsForSection ($new_pa, 'forge_admin', -1) ;
+			$this->normalizePermsForSection ($new_pa, 'approve_projects', -1) ;
+			$this->normalizePermsForSection ($new_pa, 'approve_news', -1) ;
+			$this->normalizePermsForSection ($new_pa, 'forge_stats', -1) ;
+		} else {
+			$arr = array ('projectadmin', 'frs', 'scm', 'docman', 'forumadmin', 'trackeradmin', 'newtracker', 'pmadmin', 'newpm', 'webcal') ;
+			foreach ($arr as $section) {
+				$this->normalizeDataForSection ($new_sa, $section) ;
+			}
+		}
+
+		$hook_params = array ();
+		$hook_params['role'] =& $this;
+		$hook_params['new_sa'] =& $new_sa ; 
+		$hook_params['new_pa'] =& $new_pa ; 
+		plugin_hook ("role_normalize", $hook_params);
+
+		// ...tracker-related settings
+		$new_sa['tracker'] = array () ;
+		$new_pa['tracker'] = array () ;
+		foreach ($projects as $p) {
+			$atf = new ArtifactTypeFactory ($p) ;
+			$trackers = $atf->getArtifactTypes () ;
+			foreach ($trackers as $t) {
+				if (USE_PFO_RBAC) {
+					if (array_key_exists ('tracker', $this->perms_array)
+					    && array_key_exists ($t->getID(), $this->perms_array['tracker']) ) {
+						$new_pa['tracker'][$t->getID()] = $this->perms_array['tracker'][$t->getID()] ;
+					} elseif (array_key_exists ('new_tracker', $this->perms_array)
+					    && array_key_exists ($p->getID(), $this->perms_array['new_tracker']) ) {
+						$new_pa['tracker'][$t->getID()] = $new_pa['new_tracker'][$p->getID()] ;
+					}
+				} else {
+					if (array_key_exists ('tracker', $this->setting_array)
+					    && array_key_exists ($t->getID(), $this->setting_array['tracker']) ) {
+						$new_sa['tracker'][$t->getID()] = $this->setting_array['tracker'][$t->getID()] ;
+					} else {
+						$new_sa['tracker'][$t->getID()] = $new_sa['newtracker'][0] ;
+					}
+				}
+			}
+		}
+		
+		// ...forum-related settings
+		$new_sa['forum'] = array () ;
+		$new_pa['forum'] = array () ;
+		foreach ($projects as $p) {
+			$ff = new ForumFactory ($p) ;
+			$forums = $ff->getForums () ;
+			foreach ($forums as $f) {
+				if (USE_PFO_RBAC) {
+					if (array_key_exists ('forum', $this->perms_array)
+					    && array_key_exists ($f->getID(), $this->perms_array['forum']) ) {
+						$new_pa['forum'][$f->getID()] = $this->perms_array['forum'][$f->getID()] ;
+					} elseif (array_key_exists ('new_forum', $this->perms_array)
+					    && array_key_exists ($p->getID(), $this->perms_array['new_forum']) ) {
+						$new_pa['forum'][$f->getID()] = $new_pa['new_forum'][$p->getID()] ;
+					}
+				} else {
+					if (array_key_exists ('forum', $this->setting_array)
+					    && array_key_exists ($f->getID(), $this->setting_array['forum']) ) {
+						$new_sa['forum'][$f->getID()] = $this->setting_array['forum'][$f->getID()] ;
+					} else {
+						$new_sa['forum'][$f->getID()] = $new_sa['newforum'][0] ;
+					}
+				}
+			}
+		}
+		
+		// ...pm-related settings
+		$new_sa['pm'] = array () ;
+		$new_pa['pm'] = array () ;
+		foreach ($projects as $p) {
+			$pgf = new ProjectGroupFactory ($p) ;
+			$pgs = $pgf->getProjectGroups () ;
+			foreach ($pgs as $g) {
+				if (USE_PFO_RBAC) {
+					if (array_key_exists ('pm', $this->perms_array)
+					    && array_key_exists ($g->getID(), $this->perms_array['pm']) ) {
+						$new_pa['pm'][$g->getID()] = $this->perms_array['pm'][$g->getID()] ;
+					} elseif (array_key_exists ('new_pm', $this->perms_array)
+					    && array_key_exists ($p->getID(), $this->perms_array['new_pm']) ) {
+						$new_pa['pm'][$g->getID()] = $new_pa['new_pm'][$p->getID()] ;
+					}
+				} else {
+					if (array_key_exists ('pm', $this->setting_array)
+					    && array_key_exists ($g->getID(), $this->setting_array['pm']) ) {
+						$new_sa['pm'][$g->getID()] = $this->setting_array['pm'][$g->getID()] ;
+					} else {
+						$new_sa['pm'][$g->getID()] = $new_sa['newpm'][0] ;
+					}
+				}
+			}
+		}
+		
+		// Save
+		if (USE_PFO_RBAC) {
+			$this->update ($this->getName(), $new_pa) ;
+		} else {
+			$this->update ($this->getName(), $new_sa) ;
+		}
+		return true;
+	}
 }
 
 // Actual classes

Modified: trunk/src/common/include/Role.class.php
===================================================================
--- trunk/src/common/include/Role.class.php	2010-09-27 14:13:49 UTC (rev 10731)
+++ trunk/src/common/include/Role.class.php	2010-09-27 14:48:10 UTC (rev 10732)
@@ -344,153 +344,6 @@
 		return $this->create($name,$data);
 	}
 	
-	function normalizeDataForSection (&$new_sa, $section) {
-		if (array_key_exists ($section, $this->setting_array)) {
-			$new_sa[$section][0] = $this->setting_array[$section][0] ;
-		} elseif (array_key_exists ($this->data_array['role_name'], $this->defaults)
-			  && array_key_exists ($section, $this->defaults[$this->data_array['role_name']])) {
-			$new_sa[$section][0] = $this->defaults[$this->data_array['role_name']][$section] ;
-		} else {
-			$new_sa[$section][0] = 0 ;
-		}
-		return $new_sa ;
-	}
-
-	function normalizePermsForSection (&$new_pa, $section, $refid) {
-		if (array_key_exists ($section, $this->perms_array)
-		    && array_key_exists ($refid, $this->perms_array[$section])) {
-			$new_pa[$section][$refid] = $this->perms_array[$section][$refid] ;
-		} elseif (array_key_exists ($this->data_array['role_name'], $this->defaults)
-			  && array_key_exists ($section, $this->defaults[$this->data_array['role_name']])) {
-			$new_pa[$section][$refid] = $this->defaults[$this->data_array['role_name']][$section] ;
-		} else {
-			$new_pa[$section][$refid] = 0 ;
-		}
-		return $new_pa ;
-	}
-
-	function normalizeData () { // From the PFO spec
-		$this->removeObsoleteSettings () ;
-
-		$this->fetchData ($this->getID()) ;
-
-		$projects = $this->getLinkedProjects() ;		
-		$new_sa = array () ;
-		$new_pa = array () ;
-		
-		// Add missing settings
-		// ...project-wide settings
-		if (USE_PFO_RBAC) {
-			$arr = array ('project_read', 'project_admin', 'frs', 'scm', 'docman', 'tracker_admin', 'new_tracker', 'forum_admin', 'new_forum', 'pm_admin', 'new_pm', 'webcal') ;
-			foreach ($projects as $p) {
-				foreach ($arr as $section) {
-					$this->normalizePermsForSection ($new_pa, $section, $p->getID()) ;
-				}
-			}
-			$this->normalizePermsForSection ($new_pa, 'forge_admin', -1) ;
-			$this->normalizePermsForSection ($new_pa, 'approve_projects', -1) ;
-			$this->normalizePermsForSection ($new_pa, 'approve_news', -1) ;
-			$this->normalizePermsForSection ($new_pa, 'forge_stats', -1) ;
-		} else {
-			$arr = array ('projectadmin', 'frs', 'scm', 'docman', 'forumadmin', 'trackeradmin', 'newtracker', 'pmadmin', 'newpm', 'webcal') ;
-			foreach ($arr as $section) {
-				$this->normalizeDataForSection ($new_sa, $section) ;
-			}
-		}
-
-		$hook_params = array ();
-		$hook_params['role'] =& $this;
-		$hook_params['new_sa'] =& $new_sa ; 
-		$hook_params['new_pa'] =& $new_pa ; 
-		plugin_hook ("role_normalize", $hook_params);
-
-		// ...tracker-related settings
-		$new_sa['tracker'] = array () ;
-		$new_pa['tracker'] = array () ;
-		foreach ($projects as $p) {
-			$atf = new ArtifactTypeFactory ($p) ;
-			$trackers = $atf->getArtifactTypes () ;
-			foreach ($trackers as $t) {
-				if (USE_PFO_RBAC) {
-					if (array_key_exists ('tracker', $this->perms_array)
-					    && array_key_exists ($t->getID(), $this->perms_array['tracker']) ) {
-						$new_pa['tracker'][$t->getID()] = $this->perms_array['tracker'][$t->getID()] ;
-					} elseif (array_key_exists ('new_tracker', $this->perms_array)
-					    && array_key_exists ($p->getID(), $this->perms_array['new_tracker']) ) {
-						$new_pa['tracker'][$t->getID()] = $new_pa['new_tracker'][$p->getID()] ;
-					}
-				} else {
-					if (array_key_exists ('tracker', $this->setting_array)
-					    && array_key_exists ($t->getID(), $this->setting_array['tracker']) ) {
-						$new_sa['tracker'][$t->getID()] = $this->setting_array['tracker'][$t->getID()] ;
-					} else {
-						$new_sa['tracker'][$t->getID()] = $new_sa['newtracker'][0] ;
-					}
-				}
-			}
-		}
-		
-		// ...forum-related settings
-		$new_sa['forum'] = array () ;
-		$new_pa['forum'] = array () ;
-		foreach ($projects as $p) {
-			$ff = new ForumFactory ($p) ;
-			$forums = $ff->getForums () ;
-			foreach ($forums as $f) {
-				if (USE_PFO_RBAC) {
-					if (array_key_exists ('forum', $this->perms_array)
-					    && array_key_exists ($f->getID(), $this->perms_array['forum']) ) {
-						$new_pa['forum'][$f->getID()] = $this->perms_array['forum'][$f->getID()] ;
-					} elseif (array_key_exists ('new_forum', $this->perms_array)
-					    && array_key_exists ($p->getID(), $this->perms_array['new_forum']) ) {
-						$new_pa['forum'][$f->getID()] = $new_pa['new_forum'][$p->getID()] ;
-					}
-				} else {
-					if (array_key_exists ('forum', $this->setting_array)
-					    && array_key_exists ($f->getID(), $this->setting_array['forum']) ) {
-						$new_sa['forum'][$f->getID()] = $this->setting_array['forum'][$f->getID()] ;
-					} else {
-						$new_sa['forum'][$f->getID()] = $new_sa['newforum'][0] ;
-					}
-				}
-			}
-		}
-		
-		// ...pm-related settings
-		$new_sa['pm'] = array () ;
-		$new_pa['pm'] = array () ;
-		foreach ($projects as $p) {
-			$pgf = new ProjectGroupFactory ($p) ;
-			$pgs = $pgf->getProjectGroups () ;
-			foreach ($pgs as $g) {
-				if (USE_PFO_RBAC) {
-					if (array_key_exists ('pm', $this->perms_array)
-					    && array_key_exists ($g->getID(), $this->perms_array['pm']) ) {
-						$new_pa['pm'][$g->getID()] = $this->perms_array['pm'][$g->getID()] ;
-					} elseif (array_key_exists ('new_pm', $this->perms_array)
-					    && array_key_exists ($p->getID(), $this->perms_array['new_pm']) ) {
-						$new_pa['pm'][$g->getID()] = $new_pa['new_pm'][$p->getID()] ;
-					}
-				} else {
-					if (array_key_exists ('pm', $this->setting_array)
-					    && array_key_exists ($g->getID(), $this->setting_array['pm']) ) {
-						$new_sa['pm'][$g->getID()] = $this->setting_array['pm'][$g->getID()] ;
-					} else {
-						$new_sa['pm'][$g->getID()] = $new_sa['newpm'][0] ;
-					}
-				}
-			}
-		}
-		
-		// Save
-		if (USE_PFO_RBAC) {
-			$this->update ($this->data_array['role_name'], $new_pa) ;
-		} else {
-			$this->update ($this->data_array['role_name'], $new_sa) ;
-		}
-		return true;
-	}
-
 	/**
 	 *	delete - delete a role in the database.
 	 *




More information about the Fusionforge-commits mailing list