Explorar o código

Fix for Trac #315: default organization not handled properly when there is just one organization allowed for the user.

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@937 a333f486-631f-4898-b8df-5754b55c2be0
dflaven %!s(int64=14) %!d(string=hai) anos
pai
achega
cf65e0a2a8
Modificáronse 2 ficheiros con 19 adicións e 1 borrados
  1. 18 0
      application/applicationcontext.class.inc.php
  2. 1 1
      pages/UI.php

+ 18 - 0
application/applicationcontext.class.inc.php

@@ -66,6 +66,24 @@ class ApplicationContext
 				{
 					self::$aDefaultValues[$sName] = $sValue;
 				}
+				// Hmm, there must be a better (more generic) way to handle the case below:
+				// When there is only one possible (allowed) organization, the context must be
+				// fixed to this org
+				if ($sName == 'org_id')
+				{
+					if (MetaModel::IsValidClass('Organization'))
+					{
+						$oSearchFilter = new DBObjectSearch('Organization');
+						$oSet = new CMDBObjectSet($oSearchFilter);
+						$iCount = $oSet->Count();
+						if ($iCount == 1)
+						{
+							// Only one possible value for org_id, set it in the context
+							$oOrg = $oSet->Fetch();
+							self::$aDefaultValues[$sName] = $oOrg->GetKey();
+						}
+					}					
+				}
 			}
 		}
 		$this->aValues = self::$aDefaultValues;

+ 1 - 1
pages/UI.php

@@ -500,13 +500,13 @@ try
 	require_once('../application/wizardhelper.class.inc.php');
 
 	require_once('../application/startup.inc.php');
-	$oAppContext = new ApplicationContext();
 	$operation = utils::ReadParam('operation', '');
 
 	$oKPI = new ExecutionKPI();
 
 	require_once('../application/loginwebpage.class.inc.php');
 	LoginWebPage::DoLogin(); // Check user rights and prompt if needed
+	$oAppContext = new ApplicationContext();
 
 	$oKPI->ComputeAndReport('User login');