Przeglądaj źródła

Demo mode: to not allow deleting neither changing the org of persons attached to a user account (this to make sure that the portal users will still have access to the customer portal)

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@4164 a333f486-631f-4898-b8df-5754b55c2be0
romainq 9 lat temu
rodzic
commit
80073d5493

+ 78 - 1
datamodels/2.x/itop-config-mgmt/datamodel.itop-config-mgmt.xml

@@ -526,7 +526,84 @@
           <count_max>0</count_max>
         </field>
       </fields>
-      <methods/>
+      <methods>
+        <method id="CheckToDelete">
+          <static>false</static>
+          <access>public</access>
+          <type>Overload-DBObject</type>
+          <code><![CDATA[  	public function CheckToDelete(&$oDeletionPlan)
+  	{
+  		if (MetaModel::GetConfig()->Get('demo_mode'))
+		{
+			if ($this->HasUserAccount())
+			{
+				// Do not let users change user accounts in demo mode
+				$oDeletionPlan->AddToDelete($this, null);
+				$oDeletionPlan->SetDeletionIssues($this, array('deletion not allowed in demo mode.'), true);
+				$oDeletionPlan->ComputeResults();
+				return false;
+			}
+		}
+		return parent::CheckToDelete($oDeletionPlan);
+  	}
+]]></code>
+        </method>
+        <method id="DBDeleteSingleObject">
+          <static>false</static>
+          <access>public</access>
+          <type>Overload-DBObject</type>
+          <code><![CDATA[  	public function DBDeleteSingleObject(&$oDeletionPlan)
+	{
+		if (MetaModel::GetConfig()->Get('demo_mode'))
+		{
+			if ($this->HasUserAccount())
+			{
+				// Do not let users change user accounts in demo mode
+				return;
+			}
+		}
+		parent::DBDeleteSingleObject();
+	}
+]]></code>
+        </method>
+        <method id="GetAttributeFlags">
+          <static>false</static>
+          <access>public</access>
+          <type>Overload-DBObject</type>
+          <code><![CDATA[	public function GetAttributeFlags($sAttCode, &$aReasons = array(), $sTargetState = '')
+	{
+		if ( ($sAttCode == 'org_id') && (!$this->IsNew()) )
+		{
+			if (MetaModel::GetConfig()->Get('demo_mode'))
+			{
+				if ($this->HasUserAccount())
+				{
+					// Do not let users change user accounts in demo mode
+					return OPT_ATT_READONLY;
+				}
+			}
+		}
+		return parent::GetAttributeFlags($sAttCode, $aReasons, $sTargetState);
+	}
+]]></code>
+        </method>
+        <method id="HasUserAccount">
+          <static>false</static>
+          <access>public</access>
+          <type>Helper</type>
+          <code><![CDATA[  	public function HasUserAccount()
+  	{
+		static $bHasUserAccount = null;
+		if (is_null($bHasUserAccount))
+		{
+			$oUserSet = new DBObjectSet(DBSearch::FromOQL('SELECT User WHERE contactid = :person', array('person' => $this->GetKey())));
+			$bHasUserAccount = ($oUserSet->Count() > 0);
+		}
+		return $bHasUserAccount;
+  	}
+]]></code>
+        </method>
+      </methods>
       <presentation>
         <details>
           <items>