From 1f2ad9ecdb6b6bc99e6547913d063ce51e301506 Mon Sep 17 00:00:00 2001 From: Denis Flaven Date: Thu, 4 Dec 2014 10:02:14 +0000 Subject: [PATCH] Demo mode: prevent the deletion of Users... SVN:trunk[3452] --- .../userrightsprofile.class.inc.php | 13 +++++++++++ core/dbobject.class.php | 2 +- core/userrights.class.inc.php | 23 +++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/addons/userrights/userrightsprofile.class.inc.php b/addons/userrights/userrightsprofile.class.inc.php index ae84eb261..326f4ef0a 100644 --- a/addons/userrights/userrightsprofile.class.inc.php +++ b/addons/userrights/userrightsprofile.class.inc.php @@ -271,6 +271,19 @@ class URP_UserProfile extends UserRightsBaseClassGUI { return Dict::Format('UI:UserManagement:LinkBetween_User_And_Profile', $this->Get('userlogin'), $this->Get('profile')); } + + public function CheckToDelete(&$oDeletionPlan) + { + if (MetaModel::GetConfig()->Get('demo_mode')) + { + // Users deletion is NOT allowed 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); + } } class URP_UserOrg extends UserRightsBaseClassGUI diff --git a/core/dbobject.class.php b/core/dbobject.class.php index 535c0cf62..257ee262b 100644 --- a/core/dbobject.class.php +++ b/core/dbobject.class.php @@ -1226,7 +1226,7 @@ abstract class DBObject implements iDisplay } } - final public function CheckToDelete(&$oDeletionPlan) + public function CheckToDelete(&$oDeletionPlan) { $this->MakeDeletionPlan($oDeletionPlan); $oDeletionPlan->ComputeResults(); diff --git a/core/userrights.class.inc.php b/core/userrights.class.inc.php index 5a42ccbdc..bb488b438 100644 --- a/core/userrights.class.inc.php +++ b/core/userrights.class.inc.php @@ -347,6 +347,29 @@ abstract class User extends cmdbAbstractObject } } } + + public function CheckToDelete(&$oDeletionPlan) + { + if (MetaModel::GetConfig()->Get('demo_mode')) + { + // Users deletion is NOT allowed 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); + } + + protected function DBDeleteSingleObject() + { + if (MetaModel::GetConfig()->Get('demo_mode')) + { + // Users deletion is NOT allowed in demo mode + return; + } + parent::DBDeleteSingleObject(); + } } /**