ソースを参照

Added a demo mode (config: demo_mode = true). In that mode, logins get read-only (even for admins)

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@2951 a333f486-631f-4898-b8df-5754b55c2be0
romainq 11 年 前
コミット
074792f2d0

+ 8 - 0
core/config.class.inc.php

@@ -659,6 +659,14 @@ class Config
 			'source_of_value' => '',
 			'show_in_conf_sample' => true,
 		),
+		'demo_mode' => array(
+			'type' => 'bool',
+			'description' => 'Set to true to prevent users from changing passwords/languages',
+			'default' => false,
+			'value' => '',
+			'source_of_value' => '',
+			'show_in_conf_sample' => false,
+		),
 	);
 
 	public function IsProperty($sPropCode)

+ 27 - 1
datamodels/2.x/authent-local/model.authent-local.php

@@ -74,7 +74,10 @@ class UserLocal extends UserInternal
 
 	public function CanChangePassword()
 	{
-		// For now everyone can change their password..
+		if (MetaModel::GetConfig()->Get('demo_mode'))
+		{
+			return false;
+		}
 		return true;
 	}
 
@@ -104,5 +107,28 @@ class UserLocal extends UserInternal
 		$oChange->DBInsert();
 		$this->DBUpdateTracked($oChange, true);
 	}
+
+	/**
+	 * Returns the set of flags (OPT_ATT_HIDDEN, OPT_ATT_READONLY, OPT_ATT_MANDATORY...)
+	 * for the given attribute in the current state of the object
+	 * @param $sAttCode string $sAttCode The code of the attribute
+	 * @param $aReasons array To store the reasons why the attribute is read-only (info about the synchro replicas)
+	 * @param $sTargetState string The target state in which to evalutate the flags, if empty the current state will be used
+	 * @return integer Flags: the binary combination of the flags applicable to this attribute
+	 */	 	  	 	
+	public function GetAttributeFlags($sAttCode, &$aReasons = array(), $sTargetState = '')
+	{
+		$iFlags = parent::GetAttributeFlags($sAttCode, $aReasons, $sTargetState);
+		if (MetaModel::GetConfig()->Get('demo_mode'))
+		{
+			if (strpos('contactid,login,language,password,profile_list,allowed_org_list', $sAttCode) !== false)
+			{
+				// contactid and allowed_org_list are disabled to make sure the portal remains accessible 
+				$aReasons[] = 'Sorry, this attribute is read-only in the demonstration mode!';
+				$iFlags |= OPT_ATT_READONLY;
+			}
+		}
+		return $iFlags;
+	}
 }
 

+ 8 - 0
pages/preferences.php

@@ -52,6 +52,14 @@ function DisplayPreferences($oP)
   	$aSortedlang = array();
   	foreach($aLanguages as $sCode => $aLang)
   	{
+		if (MetaModel::GetConfig()->Get('demo_mode'))
+		{
+			if ($sCode != Dict::GetUserLanguage())
+			{
+				// Demo mode: only the current user language is listed in the available choices
+				continue;
+			}
+		}
   		$aSortedlang[$aLang['description']] = $sCode;
   	}
   	ksort($aSortedlang);