diff --git a/addons/userrights/userrightsmatrix.class.inc.php b/addons/userrights/userrightsmatrix.class.inc.php index acc9fe33e..1d5cc1ffa 100644 --- a/addons/userrights/userrightsmatrix.class.inc.php +++ b/addons/userrights/userrightsmatrix.class.inc.php @@ -1,9 +1,10 @@ "addon/userrights", "key_type" => "autoincrement", "name_attcode" => "", "state_attcode" => "", - "reconc_keys" => array(), + "reconc_keys" => [], "db_table" => "priv_ur_matrixclasses", "db_key_field" => "id", "db_finalclass_field" => "", - ); + ]; MetaModel::Init_Params($aParams); //MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeExternalKey("userid", array("targetclass"=>"User", "jointype"=> "", "allowed_values"=>null, "sql"=>"userid", "is_null_allowed"=>false, "on_target_delete"=>DEL_MANUAL, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeExternalField("login", array("allowed_values"=>null, "extkey_attcode"=> 'userid', "target_attcode"=>"login"))); - MetaModel::Init_AddAttribute(new AttributeString("class", array("allowed_values"=>null, "sql"=>"class", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array()))); + MetaModel::Init_AddAttribute(new AttributeExternalKey("userid", ["targetclass" => "User", "jointype" => "", "allowed_values" => null, "sql" => "userid", "is_null_allowed" => false, "on_target_delete" => DEL_MANUAL, "depends_on" => []])); + MetaModel::Init_AddAttribute(new AttributeExternalField("login", ["allowed_values" => null, "extkey_attcode" => 'userid', "target_attcode" => "login"])); + MetaModel::Init_AddAttribute(new AttributeString("class", ["allowed_values" => null, "sql" => "class", "default_value" => null, "is_null_allowed" => false, "depends_on" => []])); - MetaModel::Init_AddAttribute(new AttributeString("action", array("allowed_values"=>null, "sql"=>"action", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeEnum("permission", array("allowed_values"=>new ValueSetEnum('yes,no'), "sql"=>"permission", "default_value"=>"yes", "is_null_allowed"=>false, "depends_on"=>array()))); + MetaModel::Init_AddAttribute(new AttributeString("action", ["allowed_values" => null, "sql" => "action", "default_value" => "", "is_null_allowed" => false, "depends_on" => []])); + MetaModel::Init_AddAttribute(new AttributeEnum("permission", ["allowed_values" => new ValueSetEnum('yes,no'), "sql" => "permission", "default_value" => "yes", "is_null_allowed" => false, "depends_on" => []])); } } @@ -54,25 +54,25 @@ class UserRightsMatrixClassStimulusGrant extends DBObject { public static function Init() { - $aParams = array - ( + $aParams = + [ "category" => "addon/userrights", "key_type" => "autoincrement", "name_attcode" => "", "state_attcode" => "", - "reconc_keys" => array(), + "reconc_keys" => [], "db_table" => "priv_ur_matrixclassesstimulus", "db_key_field" => "id", "db_finalclass_field" => "", - ); + ]; MetaModel::Init_Params($aParams); //MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeExternalKey("userid", array("targetclass"=>"User", "jointype"=> "", "allowed_values"=>null, "sql"=>"userid", "is_null_allowed"=>false, "on_target_delete"=>DEL_MANUAL, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeExternalField("login", array("allowed_values"=>null, "extkey_attcode"=> 'userid', "target_attcode"=>"login"))); - MetaModel::Init_AddAttribute(new AttributeString("class", array("allowed_values"=>null, "sql"=>"class", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array()))); + MetaModel::Init_AddAttribute(new AttributeExternalKey("userid", ["targetclass" => "User", "jointype" => "", "allowed_values" => null, "sql" => "userid", "is_null_allowed" => false, "on_target_delete" => DEL_MANUAL, "depends_on" => []])); + MetaModel::Init_AddAttribute(new AttributeExternalField("login", ["allowed_values" => null, "extkey_attcode" => 'userid', "target_attcode" => "login"])); + MetaModel::Init_AddAttribute(new AttributeString("class", ["allowed_values" => null, "sql" => "class", "default_value" => null, "is_null_allowed" => false, "depends_on" => []])); - MetaModel::Init_AddAttribute(new AttributeString("stimulus", array("allowed_values"=>null, "sql"=>"action", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeEnum("permission", array("allowed_values"=>new ValueSetEnum('yes,no'), "sql"=>"permission", "default_value"=>"yes", "is_null_allowed"=>false, "depends_on"=>array()))); + MetaModel::Init_AddAttribute(new AttributeString("stimulus", ["allowed_values" => null, "sql" => "action", "default_value" => "", "is_null_allowed" => false, "depends_on" => []])); + MetaModel::Init_AddAttribute(new AttributeEnum("permission", ["allowed_values" => new ValueSetEnum('yes,no'), "sql" => "permission", "default_value" => "yes", "is_null_allowed" => false, "depends_on" => []])); } } @@ -80,42 +80,39 @@ class UserRightsMatrixAttributeGrant extends DBObject { public static function Init() { - $aParams = array - ( + $aParams = + [ "category" => "addon/userrights", "key_type" => "autoincrement", "name_attcode" => "", "state_attcode" => "", - "reconc_keys" => array(), + "reconc_keys" => [], "db_table" => "priv_ur_matrixattributes", "db_key_field" => "id", "db_finalclass_field" => "", - ); + ]; MetaModel::Init_Params($aParams); //MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeExternalKey("userid", array("targetclass"=>"User", "jointype"=> "", "allowed_values"=>null, "sql"=>"userid", "is_null_allowed"=>false, "on_target_delete"=>DEL_MANUAL, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeExternalField("login", array("allowed_values"=>null, "extkey_attcode"=> 'userid', "target_attcode"=>"login"))); - MetaModel::Init_AddAttribute(new AttributeString("class", array("allowed_values"=>null, "sql"=>"class", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeString("attcode", array("allowed_values"=>null, "sql"=>"attcode", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array()))); + MetaModel::Init_AddAttribute(new AttributeExternalKey("userid", ["targetclass" => "User", "jointype" => "", "allowed_values" => null, "sql" => "userid", "is_null_allowed" => false, "on_target_delete" => DEL_MANUAL, "depends_on" => []])); + MetaModel::Init_AddAttribute(new AttributeExternalField("login", ["allowed_values" => null, "extkey_attcode" => 'userid', "target_attcode" => "login"])); + MetaModel::Init_AddAttribute(new AttributeString("class", ["allowed_values" => null, "sql" => "class", "default_value" => null, "is_null_allowed" => false, "depends_on" => []])); + MetaModel::Init_AddAttribute(new AttributeString("attcode", ["allowed_values" => null, "sql" => "attcode", "default_value" => null, "is_null_allowed" => false, "depends_on" => []])); - MetaModel::Init_AddAttribute(new AttributeString("action", array("allowed_values"=>null, "sql"=>"action", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeEnum("permission", array("allowed_values"=>new ValueSetEnum('yes,no'), "sql"=>"permission", "default_value"=>"yes", "is_null_allowed"=>false, "depends_on"=>array()))); + MetaModel::Init_AddAttribute(new AttributeString("action", ["allowed_values" => null, "sql" => "action", "default_value" => "", "is_null_allowed" => false, "depends_on" => []])); + MetaModel::Init_AddAttribute(new AttributeEnum("permission", ["allowed_values" => new ValueSetEnum('yes,no'), "sql" => "permission", "default_value" => "yes", "is_null_allowed" => false, "depends_on" => []])); } } - - - class UserRightsMatrix extends UserRightsAddOnAPI { - static public $m_aActionCodes = array( + public static $m_aActionCodes = [ UR_ACTION_READ => 'read', UR_ACTION_MODIFY => 'modify', UR_ACTION_DELETE => 'delete', UR_ACTION_BULK_READ => 'bulk read', UR_ACTION_BULK_MODIFY => 'bulk modify', UR_ACTION_BULK_DELETE => 'bulk delete', - ); + ]; // Installation: create the very first user public function CreateAdministrator($sAdminUser, $sAdminPwd, $sLanguage = 'EN US') @@ -149,8 +146,7 @@ class UserRightsMatrix extends UserRightsAddOnAPI // Users must be added manually // This procedure will then update the matrix when a new user is found or a new class/attribute appears $oUserSet = new DBObjectSet(DBObjectSearch::FromOQL("SELECT User")); - while ($oUser = $oUserSet->Fetch()) - { + while ($oUser = $oUserSet->Fetch()) { $this->SetupUser($oUser->GetKey()); } return true; @@ -158,23 +154,16 @@ class UserRightsMatrix extends UserRightsAddOnAPI protected function SetupUser($iUserId, $bNewUser = false) { - foreach(array('bizmodel', 'application', 'gui', 'core/cmdb') as $sCategory) - { - foreach (MetaModel::GetClasses($sCategory) as $sClass) - { - foreach (self::$m_aActionCodes as $iActionCode => $sAction) - { - if ($bNewUser) - { + foreach (['bizmodel', 'application', 'gui', 'core/cmdb'] as $sCategory) { + foreach (MetaModel::GetClasses($sCategory) as $sClass) { + foreach (self::$m_aActionCodes as $iActionCode => $sAction) { + if ($bNewUser) { $bAddCell = true; - } - else - { + } else { $oSet = new DBObjectSet(DBObjectSearch::FromOQL("SELECT UserRightsMatrixClassGrant WHERE class = '$sClass' AND action = '$sAction' AND userid = $iUserId")); $bAddCell = ($oSet->Count() < 1); } - if ($bAddCell) - { + if ($bAddCell) { // Create a new entry $oMyClassGrant = MetaModel::NewObject("UserRightsMatrixClassGrant"); $oMyClassGrant->Set("userid", $iUserId); @@ -184,19 +173,14 @@ class UserRightsMatrix extends UserRightsAddOnAPI $iId = $oMyClassGrant->DBInsertNoReload(); } } - foreach (MetaModel::EnumStimuli($sClass) as $sStimulusCode => $oStimulus) - { - if ($bNewUser) - { + foreach (MetaModel::EnumStimuli($sClass) as $sStimulusCode => $oStimulus) { + if ($bNewUser) { $bAddCell = true; - } - else - { + } else { $oSet = new DBObjectSet(DBObjectSearch::FromOQL("SELECT UserRightsMatrixClassStimulusGrant WHERE class = '$sClass' AND stimulus = '$sStimulusCode' AND userid = $iUserId")); $bAddCell = ($oSet->Count() < 1); } - if ($bAddCell) - { + if ($bAddCell) { // Create a new entry $oMyClassGrant = MetaModel::NewObject("UserRightsMatrixClassStimulusGrant"); $oMyClassGrant->Set("userid", $iUserId); @@ -206,21 +190,15 @@ class UserRightsMatrix extends UserRightsAddOnAPI $iId = $oMyClassGrant->DBInsertNoReload(); } } - foreach (MetaModel::GetAttributesList($sClass) as $sAttCode) - { - if ($bNewUser) - { + foreach (MetaModel::GetAttributesList($sClass) as $sAttCode) { + if ($bNewUser) { $bAddCell = true; - } - else - { + } else { $oSet = new DBObjectSet(DBObjectSearch::FromOQL("SELECT UserRightsMatrixAttributeGrant WHERE class = '$sClass' AND attcode = '$sAttCode' AND userid = $iUserId")); $bAddCell = ($oSet->Count() < 1); } - if ($bAddCell) - { - foreach (array('read', 'modify') as $sAction) - { + if ($bAddCell) { + foreach (['read', 'modify'] as $sAction) { // Create a new entry $oMyAttGrant = MetaModel::NewObject("UserRightsMatrixAttributeGrant"); $oMyAttGrant->Set("userid", $iUserId); @@ -261,14 +239,13 @@ class UserRightsMatrix extends UserRightsAddOnAPI */ } - public function Init() { // Could be loaded in a shared memory (?) return true; } - public function GetSelectFilter($oUser, $sClass, $aSettings = array()) + public function GetSelectFilter($oUser, $sClass, $aSettings = []) { $oNullFilter = new DBObjectSearch($sClass); return $oNullFilter; @@ -276,21 +253,18 @@ class UserRightsMatrix extends UserRightsAddOnAPI public function IsActionAllowed($oUser, $sClass, $iActionCode, $oInstanceSet = null) { - if (!array_key_exists($iActionCode, self::$m_aActionCodes)) - { + if (!array_key_exists($iActionCode, self::$m_aActionCodes)) { return UR_ALLOWED_NO; } $sAction = self::$m_aActionCodes[$iActionCode]; $oSet = new DBObjectSet(DBObjectSearch::FromOQL("SELECT UserRightsMatrixClassGrant WHERE class = '$sClass' AND action = '$sAction' AND userid = '{$oUser->GetKey()}'")); - if ($oSet->Count() < 1) - { + if ($oSet->Count() < 1) { return UR_ALLOWED_NO; } $oGrantRecord = $oSet->Fetch(); - switch ($oGrantRecord->Get('permission')) - { + switch ($oGrantRecord->Get('permission')) { case 'yes': $iRetCode = UR_ALLOWED_YES; break; @@ -304,21 +278,18 @@ class UserRightsMatrix extends UserRightsAddOnAPI public function IsActionAllowedOnAttribute($oUser, $sClass, $sAttCode, $iActionCode, $oInstanceSet = null) { - if (!array_key_exists($iActionCode, self::$m_aActionCodes)) - { + if (!array_key_exists($iActionCode, self::$m_aActionCodes)) { return UR_ALLOWED_NO; } $sAction = self::$m_aActionCodes[$iActionCode]; $oSet = new DBObjectSet(DBObjectSearch::FromOQL("SELECT UserRightsMatrixAttributeGrant WHERE class = '$sClass' AND attcode = '$sAttCode' AND action = '$sAction' AND userid = '{$oUser->GetKey()}'")); - if ($oSet->Count() < 1) - { + if ($oSet->Count() < 1) { return UR_ALLOWED_NO; } $oGrantRecord = $oSet->Fetch(); - switch ($oGrantRecord->Get('permission')) - { + switch ($oGrantRecord->Get('permission')) { case 'yes': $iRetCode = UR_ALLOWED_YES; break; @@ -333,14 +304,12 @@ class UserRightsMatrix extends UserRightsAddOnAPI public function IsStimulusAllowed($oUser, $sClass, $sStimulusCode, $oInstanceSet = null) { $oSet = new DBObjectSet(DBObjectSearch::FromOQL("SELECT UserRightsMatrixClassStimulusGrant WHERE class = '$sClass' AND stimulus = '$sStimulusCode' AND userid = '{$oUser->GetKey()}'")); - if ($oSet->Count() < 1) - { + if ($oSet->Count() < 1) { return UR_ALLOWED_NO; } $oGrantRecord = $oSet->Fetch(); - switch ($oGrantRecord->Get('permission')) - { + switch ($oGrantRecord->Get('permission')) { case 'yes': $iRetCode = UR_ALLOWED_YES; break; @@ -358,5 +327,3 @@ class UserRightsMatrix extends UserRightsAddOnAPI } UserRights::SelectModule('UserRightsMatrix'); - -?> diff --git a/addons/userrights/userrightsnull.class.inc.php b/addons/userrights/userrightsnull.class.inc.php index 5cfcee2ab..5186baf35 100644 --- a/addons/userrights/userrightsnull.class.inc.php +++ b/addons/userrights/userrightsnull.class.inc.php @@ -1,9 +1,10 @@ diff --git a/addons/userrights/userrightsprofile.class.inc.php b/addons/userrights/userrightsprofile.class.inc.php index 366630510..04cebe587 100644 --- a/addons/userrights/userrightsprofile.class.inc.php +++ b/addons/userrights/userrightsprofile.class.inc.php @@ -1,4 +1,5 @@ "addon/userrights,grant_by_profile,filter", "key_type" => "autoincrement", "name_attcode" => "name", - "complementary_name_attcode" => array('description'), + "complementary_name_attcode" => ['description'], "state_attcode" => "", - "reconc_keys" => array(), + "reconc_keys" => [], "db_table" => "priv_urp_profiles", "db_key_field" => "id", "db_finalclass_field" => "", - ); + ]; MetaModel::Init_Params($aParams); //MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeString("name", array("allowed_values"=>null, "sql"=>"name", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeString("description", array("allowed_values"=>null, "sql"=>"description", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array()))); + MetaModel::Init_AddAttribute(new AttributeString("name", ["allowed_values" => null, "sql" => "name", "default_value" => null, "is_null_allowed" => false, "depends_on" => []])); + MetaModel::Init_AddAttribute(new AttributeString("description", ["allowed_values" => null, "sql" => "description", "default_value" => null, "is_null_allowed" => false, "depends_on" => []])); - MetaModel::Init_AddAttribute(new AttributeLinkedSetIndirect("user_list", array("linked_class"=>"URP_UserProfile", "ext_key_to_me"=>"profileid", "ext_key_to_remote"=>"userid", "allowed_values"=>null, "count_min"=>1, "count_max"=>0, "depends_on"=>array()))); + MetaModel::Init_AddAttribute(new AttributeLinkedSetIndirect("user_list", ["linked_class" => "URP_UserProfile", "ext_key_to_me" => "profileid", "ext_key_to_remote" => "userid", "allowed_values" => null, "count_min" => 1, "count_max" => 0, "depends_on" => []])); // Display lists - MetaModel::Init_SetZListItems('details', array('name', 'description', 'user_list')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('description')); // Attributes to be displayed for a list + MetaModel::Init_SetZListItems('details', ['name', 'description', 'user_list']); // Attributes to be displayed for the complete details + MetaModel::Init_SetZListItems('list', ['description']); // Attributes to be displayed for a list // Search criteria - MetaModel::Init_SetZListItems('standard_search', array('name','description')); // Criteria of the std search form - MetaModel::Init_SetZListItems('default_search', array ('name','description')); + MetaModel::Init_SetZListItems('standard_search', ['name','description']); // Criteria of the std search form + MetaModel::Init_SetZListItems('default_search', ['name','description']); } protected static $m_aCacheProfiles = null; public static function DoCreateProfile($sName, $sDescription) { - if (is_null(self::$m_aCacheProfiles)) - { - self::$m_aCacheProfiles = array(); + if (is_null(self::$m_aCacheProfiles)) { + self::$m_aCacheProfiles = []; $oFilterAll = new DBObjectSearch('URP_Profiles'); $oSet = new DBObjectSet($oFilterAll); - while ($oProfile = $oSet->Fetch()) - { + while ($oProfile = $oSet->Fetch()) { self::$m_aCacheProfiles[$oProfile->Get('name')] = $oProfile->GetKey(); } } $sCacheKey = $sName; - if (isset(self::$m_aCacheProfiles[$sCacheKey])) - { + if (isset(self::$m_aCacheProfiles[$sCacheKey])) { return self::$m_aCacheProfiles[$sCacheKey]; } $oNewObj = MetaModel::NewObject("URP_Profiles"); @@ -89,27 +86,21 @@ class URP_Profiles extends UserRightsBaseClassGUI return $iId; } - function GetGrantAsHtml($oUserRights, $sClass, $sAction) + public function GetGrantAsHtml($oUserRights, $sClass, $sAction) { $bGrant = $oUserRights->GetProfileActionGrant($this->GetKey(), $sClass, $sAction); - if (is_null($bGrant)) - { + if (is_null($bGrant)) { return ''.Dict::S('UI:UserManagement:ActionAllowed:No').''; - } - elseif ($bGrant) - { + } elseif ($bGrant) { return ''.Dict::S('UI:UserManagement:ActionAllowed:Yes').''; - } - else - { + } else { return ''.Dict::S('UI:UserManagement:ActionAllowed:No').''; } } - function DoShowGrantSumary($oPage) + public function DoShowGrantSumary($oPage) { - if ($this->GetRawName() == "Administrator") - { + if ($this->GetRawName() == "Administrator") { // Looks dirty, but ok that's THE ONE $oPage->p(Dict::S('UI:UserManagement:AdminProfile+')); return; @@ -118,21 +109,18 @@ class URP_Profiles extends UserRightsBaseClassGUI // Note: for sure, we assume that the instance is derived from UserRightsProfile $oUserRights = UserRights::GetModuleInstance(); - $aDisplayData = array(); - foreach (MetaModel::GetClasses('bizmodel,grant_by_profile') as $sClass) - { - $aStimuli = array(); - foreach (MetaModel::EnumStimuli($sClass) as $sStimulusCode => $oStimulus) - { + $aDisplayData = []; + foreach (MetaModel::GetClasses('bizmodel,grant_by_profile') as $sClass) { + $aStimuli = []; + foreach (MetaModel::EnumStimuli($sClass) as $sStimulusCode => $oStimulus) { $bGrant = $oUserRights->GetClassStimulusGrant($this->GetKey(), $sClass, $sStimulusCode); - if ($bGrant === true) - { + if ($bGrant === true) { $aStimuli[] = ''.utils::EscapeHtml($oStimulus->GetLabel()).''; } } $sStimuli = implode(', ', $aStimuli); - $aDisplayData[] = array( + $aDisplayData[] = [ 'class' => MetaModel::GetName($sClass), 'read' => $this->GetGrantAsHtml($oUserRights, $sClass, 'r'), 'bulkread' => $this->GetGrantAsHtml($oUserRights, $sClass, 'br'), @@ -141,22 +129,22 @@ class URP_Profiles extends UserRightsBaseClassGUI 'delete' => $this->GetGrantAsHtml($oUserRights, $sClass, 'd'), 'bulkdelete' => $this->GetGrantAsHtml($oUserRights, $sClass, 'bd'), 'stimuli' => $sStimuli, - ); + ]; } - $aDisplayConfig = array(); - $aDisplayConfig['class'] = array('label' => Dict::S('UI:UserManagement:Class'), 'description' => Dict::S('UI:UserManagement:Class+')); - $aDisplayConfig['read'] = array('label' => Dict::S('UI:UserManagement:Action:Read'), 'description' => Dict::S('UI:UserManagement:Action:Read+')); - $aDisplayConfig['bulkread'] = array('label' => Dict::S('UI:UserManagement:Action:BulkRead'), 'description' => Dict::S('UI:UserManagement:Action:BulkRead+')); - $aDisplayConfig['write'] = array('label' => Dict::S('UI:UserManagement:Action:Modify'), 'description' => Dict::S('UI:UserManagement:Action:Modify+')); - $aDisplayConfig['bulkwrite'] = array('label' => Dict::S('UI:UserManagement:Action:BulkModify'), 'description' => Dict::S('UI:UserManagement:Action:BulkModify+')); - $aDisplayConfig['delete'] = array('label' => Dict::S('UI:UserManagement:Action:Delete'), 'description' => Dict::S('UI:UserManagement:Action:Delete+')); - $aDisplayConfig['bulkdelete'] = array('label' => Dict::S('UI:UserManagement:Action:BulkDelete'), 'description' => Dict::S('UI:UserManagement:Action:BulkDelete+')); - $aDisplayConfig['stimuli'] = array('label' => Dict::S('UI:UserManagement:Action:Stimuli'), 'description' => Dict::S('UI:UserManagement:Action:Stimuli+')); + $aDisplayConfig = []; + $aDisplayConfig['class'] = ['label' => Dict::S('UI:UserManagement:Class'), 'description' => Dict::S('UI:UserManagement:Class+')]; + $aDisplayConfig['read'] = ['label' => Dict::S('UI:UserManagement:Action:Read'), 'description' => Dict::S('UI:UserManagement:Action:Read+')]; + $aDisplayConfig['bulkread'] = ['label' => Dict::S('UI:UserManagement:Action:BulkRead'), 'description' => Dict::S('UI:UserManagement:Action:BulkRead+')]; + $aDisplayConfig['write'] = ['label' => Dict::S('UI:UserManagement:Action:Modify'), 'description' => Dict::S('UI:UserManagement:Action:Modify+')]; + $aDisplayConfig['bulkwrite'] = ['label' => Dict::S('UI:UserManagement:Action:BulkModify'), 'description' => Dict::S('UI:UserManagement:Action:BulkModify+')]; + $aDisplayConfig['delete'] = ['label' => Dict::S('UI:UserManagement:Action:Delete'), 'description' => Dict::S('UI:UserManagement:Action:Delete+')]; + $aDisplayConfig['bulkdelete'] = ['label' => Dict::S('UI:UserManagement:Action:BulkDelete'), 'description' => Dict::S('UI:UserManagement:Action:BulkDelete+')]; + $aDisplayConfig['stimuli'] = ['label' => Dict::S('UI:UserManagement:Action:Stimuli'), 'description' => Dict::S('UI:UserManagement:Action:Stimuli+')]; $oPage->table($aDisplayConfig, $aDisplayData); } - function DisplayBareRelations(WebPage $oPage, $bEditMode = false) + public function DisplayBareRelations(WebPage $oPage, $bEditMode = false) { parent::DisplayBareRelations($oPage, $bEditMode); @@ -166,10 +154,9 @@ class URP_Profiles extends UserRightsBaseClassGUI public static function GetReadOnlyAttributes() { - return array('name', 'description'); + return ['name', 'description']; } - // returns an array of id => array of column => php value(so-called "real value") public static function GetPredefinedObjects() { @@ -181,15 +168,13 @@ class URP_Profiles extends UserRightsBaseClassGUI protected function OnDelete() { // Don't remove admin profile - if ($this->Get('name') === ADMIN_PROFILE_NAME) - { + if ($this->Get('name') === ADMIN_PROFILE_NAME) { throw new SecurityException(Dict::Format('UI:Login:Error:AccessAdmin')); } // Note: this may break the rule that says: "a user must have at least ONE profile" ! $oLnkSet = $this->Get('user_list'); - while($oLnk = $oLnkSet->Fetch()) - { + while ($oLnk = $oLnkSet->Fetch()) { $oLnk->DBDelete(); } } @@ -202,11 +187,10 @@ class URP_Profiles extends UserRightsBaseClassGUI * @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 = '') + public function GetAttributeFlags($sAttCode, &$aReasons = [], $sTargetState = '') { $iFlags = parent::GetAttributeFlags($sAttCode, $aReasons, $sTargetState); - if (MetaModel::GetConfig()->Get('demo_mode')) - { + if (MetaModel::GetConfig()->Get('demo_mode')) { $aReasons[] = 'Sorry, profiles are read-only in the demonstration mode!'; $iFlags |= OPT_ATT_READONLY; } @@ -214,52 +198,52 @@ class URP_Profiles extends UserRightsBaseClassGUI } } - - class URP_UserProfile extends UserRightsBaseClassGUI { public static function Init() { - $aParams = array - ( + $aParams = + [ "category" => "addon/userrights,grant_by_profile,filter", "key_type" => "autoincrement", - "name_attcode" => array("userlogin", "profile"), + "name_attcode" => ["userlogin", "profile"], "state_attcode" => "", - "reconc_keys" => array(), + "reconc_keys" => [], "db_table" => "priv_urp_userprofile", "db_key_field" => "id", "db_finalclass_field" => "", "is_link" => true, /** @since 3.1.0 N°6482 */ - 'uniqueness_rules' => array( - 'no_duplicate' => array( - 'attributes' => array( + 'uniqueness_rules' => [ + 'no_duplicate' => [ + 'attributes' => [ 0 => 'userid', 1 => 'profileid', - ), + ], 'filter' => '', 'disabled' => false, 'is_blocking' => true, - ), - ), - ); + ], + ], + ]; MetaModel::Init_Params($aParams); //MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeExternalKey("userid", array("targetclass" => "User", "jointype" => "", "allowed_values" => null, "sql" => "userid", "is_null_allowed" => false, "on_target_delete" => DEL_AUTO, "depends_on" => array()))); - MetaModel::Init_AddAttribute(new AttributeExternalField("userlogin", array("allowed_values" => null, "extkey_attcode" => 'userid', "target_attcode" => "login"))); + MetaModel::Init_AddAttribute(new AttributeExternalKey("userid", ["targetclass" => "User", "jointype" => "", "allowed_values" => null, "sql" => "userid", "is_null_allowed" => false, "on_target_delete" => DEL_AUTO, "depends_on" => []])); + MetaModel::Init_AddAttribute(new AttributeExternalField("userlogin", ["allowed_values" => null, "extkey_attcode" => 'userid', "target_attcode" => "login"])); - MetaModel::Init_AddAttribute(new AttributeExternalKey("profileid", - array("targetclass" => "URP_Profiles", "jointype" => "", "allowed_values" => null, "sql" => "profileid", "is_null_allowed" => false, "on_target_delete" => DEL_AUTO, "depends_on" => array(), "allow_target_creation" => false))); - MetaModel::Init_AddAttribute(new AttributeExternalField("profile", array("allowed_values" => null, "extkey_attcode" => 'profileid', "target_attcode" => "name"))); + MetaModel::Init_AddAttribute(new AttributeExternalKey( + "profileid", + ["targetclass" => "URP_Profiles", "jointype" => "", "allowed_values" => null, "sql" => "profileid", "is_null_allowed" => false, "on_target_delete" => DEL_AUTO, "depends_on" => [], "allow_target_creation" => false] + )); + MetaModel::Init_AddAttribute(new AttributeExternalField("profile", ["allowed_values" => null, "extkey_attcode" => 'profileid', "target_attcode" => "name"])); - MetaModel::Init_AddAttribute(new AttributeString("reason", array("allowed_values" => null, "sql" => "description", "default_value" => null, "is_null_allowed" => true, "depends_on" => array()))); + MetaModel::Init_AddAttribute(new AttributeString("reason", ["allowed_values" => null, "sql" => "description", "default_value" => null, "is_null_allowed" => true, "depends_on" => []])); // Display lists - MetaModel::Init_SetZListItems('details', array('userid', 'profileid', 'reason')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('userid', 'profileid', 'reason')); // Attributes to be displayed for a list + MetaModel::Init_SetZListItems('details', ['userid', 'profileid', 'reason']); // Attributes to be displayed for the complete details + MetaModel::Init_SetZListItems('list', ['userid', 'profileid', 'reason']); // Attributes to be displayed for a list // Search criteria - MetaModel::Init_SetZListItems('standard_search', array('userid', 'profileid')); // Criteria of the std search form - MetaModel::Init_SetZListItems('advanced_search', array('userid', 'profileid')); // Criteria of the advanced search form + MetaModel::Init_SetZListItems('standard_search', ['userid', 'profileid']); // Criteria of the std search form + MetaModel::Init_SetZListItems('advanced_search', ['userid', 'profileid']); // Criteria of the advanced search form } public function CheckToDelete(&$oDeletionPlan) @@ -267,15 +251,14 @@ class URP_UserProfile extends UserRightsBaseClassGUI 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->SetDeletionIssues($this, ['deletion not allowed in demo mode.'], true); $oDeletionPlan->ComputeResults(); return false; } try { $this->CheckIfProfileIsAllowed(UR_ACTION_DELETE); - } - catch (SecurityException $e) { + } catch (SecurityException $e) { // Users deletion is NOT allowed $oDeletionPlan->AddToDelete($this, null); $oDeletionPlan->SetDeletionIssues($this, [$e->getMessage()], true); @@ -292,15 +275,14 @@ class URP_UserProfile extends UserRightsBaseClassGUI 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->SetDeletionIssues($this, ['deletion not allowed in demo mode.'], true); $oDeletionPlan->ComputeResults(); return false; } try { $this->CheckIfProfileIsAllowed(UR_ACTION_DELETE); - } - catch (SecurityException $e) { + } catch (SecurityException $e) { // Users deletion is NOT allowed $oDeletionPlan->AddToDelete($this, null); $oDeletionPlan->SetDeletionIssues($this, [$e->getMessage()], true); @@ -336,29 +318,26 @@ class URP_UserProfile extends UserRightsBaseClassGUI protected function CheckIfProfileIsAllowed($iActionCode) { // When initializing or admin, we need to let everything pass trough - if (!UserRights::IsLoggedIn() || UserRights::IsAdministrator()) { return; } + if (!UserRights::IsLoggedIn() || UserRights::IsAdministrator()) { + return; + } // Only administrators can manage administrators $iOrigUserId = $this->GetOriginal('userid'); - if (!empty($iOrigUserId)) - { + if (!empty($iOrigUserId)) { $oUser = MetaModel::GetObject('User', $iOrigUserId, true, true); - if (UserRights::IsAdministrator($oUser) && !UserRights::IsAdministrator()) - { + if (UserRights::IsAdministrator($oUser) && !UserRights::IsAdministrator()) { throw new SecurityException(Dict::Format('UI:Login:Error:AccessRestricted')); } } $oUser = MetaModel::GetObject('User', $this->Get('userid'), true, true); - if (UserRights::IsAdministrator($oUser) && !UserRights::IsAdministrator()) - { + if (UserRights::IsAdministrator($oUser) && !UserRights::IsAdministrator()) { throw new SecurityException(Dict::Format('UI:Login:Error:AccessRestricted')); } - if (!UserRights::IsActionAllowed(get_class($this), $iActionCode, DBObjectSet::FromObject($this))) - { + if (!UserRights::IsActionAllowed(get_class($this), $iActionCode, DBObjectSet::FromObject($this))) { throw new SecurityException(Dict::Format('UI:Error:ObjectCannotBeUpdated')); } - if (!UserRights::IsAdministrator() && ($this->Get('profile') === ADMIN_PROFILE_NAME)) - { + if (!UserRights::IsAdministrator() && ($this->Get('profile') === ADMIN_PROFILE_NAME)) { throw new SecurityException(Dict::Format('UI:Login:Error:AccessAdmin')); } } @@ -369,33 +348,33 @@ class URP_UserOrg extends UserRightsBaseClassGUI { public static function Init() { - $aParams = array - ( + $aParams = + [ "category" => "addon/userrights,grant_by_profile", "key_type" => "autoincrement", - "name_attcode" => array("userlogin", "allowed_org_name"), + "name_attcode" => ["userlogin", "allowed_org_name"], "state_attcode" => "", - "reconc_keys" => array(), + "reconc_keys" => [], "db_table" => "priv_urp_userorg", "db_key_field" => "id", "db_finalclass_field" => "", - ); + ]; MetaModel::Init_Params($aParams); //MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeExternalKey("userid", array("targetclass"=>"User", "jointype"=> "", "allowed_values"=>null, "sql"=>"userid", "is_null_allowed"=>false, "on_target_delete"=>DEL_AUTO, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeExternalField("userlogin", array("allowed_values"=>null, "extkey_attcode"=> 'userid', "target_attcode"=>"login"))); + MetaModel::Init_AddAttribute(new AttributeExternalKey("userid", ["targetclass" => "User", "jointype" => "", "allowed_values" => null, "sql" => "userid", "is_null_allowed" => false, "on_target_delete" => DEL_AUTO, "depends_on" => []])); + MetaModel::Init_AddAttribute(new AttributeExternalField("userlogin", ["allowed_values" => null, "extkey_attcode" => 'userid', "target_attcode" => "login"])); - MetaModel::Init_AddAttribute(new AttributeExternalKey("allowed_org_id", array("targetclass"=>"Organization", "jointype"=> "", "allowed_values"=>null, "sql"=>"allowed_org_id", "is_null_allowed"=>false, "on_target_delete"=>DEL_AUTO, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeExternalField("allowed_org_name", array("allowed_values"=>null, "extkey_attcode"=> 'allowed_org_id', "target_attcode"=>"name"))); + MetaModel::Init_AddAttribute(new AttributeExternalKey("allowed_org_id", ["targetclass" => "Organization", "jointype" => "", "allowed_values" => null, "sql" => "allowed_org_id", "is_null_allowed" => false, "on_target_delete" => DEL_AUTO, "depends_on" => []])); + MetaModel::Init_AddAttribute(new AttributeExternalField("allowed_org_name", ["allowed_values" => null, "extkey_attcode" => 'allowed_org_id', "target_attcode" => "name"])); - MetaModel::Init_AddAttribute(new AttributeString("reason", array("allowed_values"=>null, "sql"=>"reason", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); + MetaModel::Init_AddAttribute(new AttributeString("reason", ["allowed_values" => null, "sql" => "reason", "default_value" => null, "is_null_allowed" => true, "depends_on" => []])); // Display lists - MetaModel::Init_SetZListItems('details', array('userid', 'allowed_org_id', 'reason')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('allowed_org_id', 'reason')); // Attributes to be displayed for a list + MetaModel::Init_SetZListItems('details', ['userid', 'allowed_org_id', 'reason']); // Attributes to be displayed for the complete details + MetaModel::Init_SetZListItems('list', ['allowed_org_id', 'reason']); // Attributes to be displayed for a list // Search criteria - MetaModel::Init_SetZListItems('standard_search', array('userid', 'allowed_org_id')); // Criteria of the std search form - MetaModel::Init_SetZListItems('advanced_search', array('userid', 'allowed_org_id')); // Criteria of the advanced search form + MetaModel::Init_SetZListItems('standard_search', ['userid', 'allowed_org_id']); // Criteria of the std search form + MetaModel::Init_SetZListItems('advanced_search', ['userid', 'allowed_org_id']); // Criteria of the advanced search form } protected function OnInsert() @@ -418,40 +397,37 @@ class URP_UserOrg extends UserRightsBaseClassGUI */ protected function CheckIfOrgIsAllowed() { - if (!UserRights::IsLoggedIn() || UserRights::IsAdministrator()) { return; } + if (!UserRights::IsLoggedIn() || UserRights::IsAdministrator()) { + return; + } $oUser = UserRights::GetUserObject(); $oAddon = UserRights::GetModuleInstance(); $aOrgs = $oAddon->GetUserOrgs($oUser, ''); - if (count($aOrgs) > 0) - { + if (count($aOrgs) > 0) { $iOrigOrgId = $this->GetOriginal('allowed_org_id'); - if ((!empty($iOrigOrgId) && !in_array($iOrigOrgId, $aOrgs)) || !in_array($this->Get('allowed_org_id'), $aOrgs)) - { + if ((!empty($iOrigOrgId) && !in_array($iOrigOrgId, $aOrgs)) || !in_array($this->Get('allowed_org_id'), $aOrgs)) { throw new SecurityException(Dict::Format('Class:User/Error:OrganizationNotAllowed')); } } } } - - - class UserRightsProfile extends UserRightsAddOnAPI { - static public $m_aActionCodes = array( + public static $m_aActionCodes = [ UR_ACTION_READ => 'r', UR_ACTION_MODIFY => 'w', UR_ACTION_DELETE => 'd', UR_ACTION_BULK_READ => 'br', UR_ACTION_BULK_MODIFY => 'bw', UR_ACTION_BULK_DELETE => 'bd', - ); + ]; - /** - * @var array $aUsersProfilesList Cache of users' profiles. Hash array of user ID => [profile ID => profile friendlyname, profile ID => profile friendlyname, ...] - * @since 2.7.10 3.0.4 3.1.1 3.2.0 N°6887 - */ + /** + * @var array $aUsersProfilesList Cache of users' profiles. Hash array of user ID => [profile ID => profile friendlyname, profile ID => profile friendlyname, ...] + * @since 2.7.10 3.0.4 3.1.1 3.2.0 N°6887 + */ private $aUsersProfilesList = []; // Installation: create the very first user @@ -472,8 +448,7 @@ class UserRightsProfile extends UserRightsAddOnAPI $oContact = MetaModel::NewObject('Person'); $oContact->Set('name', 'My last name'); $oContact->Set('first_name', 'My first name'); - if (MetaModel::IsValidAttCode('Person', 'org_id')) - { + if (MetaModel::IsValidAttCode('Person', 'org_id')) { $oContact->Set('org_id', $iOrgId); } $oContact->Set('email', 'my.email@foo.org'); @@ -481,20 +456,17 @@ class UserRightsProfile extends UserRightsAddOnAPI } } - $oUser = new UserLocal(); $oUser->Set('login', $sAdminUser); $oUser->Set('password', $sAdminPwd); - if (MetaModel::IsValidAttCode('UserLocal', 'contactid') && ($iContactId != 0)) - { + if (MetaModel::IsValidAttCode('UserLocal', 'contactid') && ($iContactId != 0)) { $oUser->Set('contactid', $iContactId); } $oUser->Set('language', $sLanguage); // Language was chosen during the installation // Add this user to the very specific 'admin' profile - $oAdminProfile = MetaModel::GetObjectFromOQL("SELECT URP_Profiles WHERE name = :name", array('name' => ADMIN_PROFILE_NAME), true /*all data*/); - if (is_object($oAdminProfile)) - { + $oAdminProfile = MetaModel::GetObjectFromOQL("SELECT URP_Profiles WHERE name = :name", ['name' => ADMIN_PROFILE_NAME], true /*all data*/); + if (is_object($oAdminProfile)) { $oUserProfile = new URP_UserProfile(); $oUserProfile->Set('profileid', $oAdminProfile->GetKey()); $oUserProfile->Set('reason', 'By definition, the administrator must have the administrator profile'); @@ -509,11 +481,11 @@ class UserRightsProfile extends UserRightsAddOnAPI { } - protected $m_aUserOrgs = array(); // userid -> array of orgid + protected $m_aUserOrgs = []; // userid -> array of orgid protected $m_aAdministrators = null; // [user id] // Built on demand, could be optimized if necessary (doing a query for each attribute that needs to be read) - protected $m_aObjectActionGrants = array(); + protected $m_aObjectActionGrants = []; /** * Read and cache organizations allowed to the given user @@ -528,31 +500,25 @@ class UserRightsProfile extends UserRightsAddOnAPI public function GetUserOrgs($oUser, $sClass) { $iUser = $oUser->GetKey(); - if (!array_key_exists($iUser, $this->m_aUserOrgs)) - { - $this->m_aUserOrgs[$iUser] = array(); + if (!array_key_exists($iUser, $this->m_aUserOrgs)) { + $this->m_aUserOrgs[$iUser] = []; $sHierarchicalKeyCode = MetaModel::IsHierarchicalClass('Organization'); - if ($sHierarchicalKeyCode !== false) - { + if ($sHierarchicalKeyCode !== false) { $sUserOrgQuery = 'SELECT UserOrg, Org FROM Organization AS Org JOIN Organization AS Root ON Org.'.$sHierarchicalKeyCode.' BELOW Root.id JOIN URP_UserOrg AS UserOrg ON UserOrg.allowed_org_id = Root.id WHERE UserOrg.userid = :userid'; - $oUserOrgSet = new DBObjectSet(DBObjectSearch::FromOQL_AllData($sUserOrgQuery), array(), array('userid' => $iUser)); - while ($aRow = $oUserOrgSet->FetchAssoc()) - { + $oUserOrgSet = new DBObjectSet(DBObjectSearch::FromOQL_AllData($sUserOrgQuery), [], ['userid' => $iUser]); + while ($aRow = $oUserOrgSet->FetchAssoc()) { $oOrg = $aRow['Org']; $this->m_aUserOrgs[$iUser][] = $oOrg->GetKey(); } - } - else - { + } else { $oSearch = new DBObjectSearch('URP_UserOrg'); $oSearch->AllowAllData(); $oCondition = new BinaryExpression(new FieldExpression('userid'), '=', new VariableExpression('userid')); $oSearch->AddConditionExpression($oCondition); - $oUserOrgSet = new DBObjectSet($oSearch, array(), array('userid' => $iUser)); - while ($oUserOrg = $oUserOrgSet->Fetch()) - { + $oUserOrgSet = new DBObjectSet($oSearch, [], ['userid' => $iUser]); + while ($oUserOrg = $oUserOrgSet->Fetch()) { $this->m_aUserOrgs[$iUser][] = $oUserOrg->Get('allowed_org_id'); } } @@ -563,21 +529,19 @@ class UserRightsProfile extends UserRightsAddOnAPI public function ResetCache() { // Loaded by Load cache - $this->m_aUserOrgs = array(); + $this->m_aUserOrgs = []; // Cache - $this->m_aObjectActionGrants = array(); + $this->m_aObjectActionGrants = []; $this->m_aAdministrators = null; } public function LoadCache() { static $bSharedObjectInitialized = false; - if (!$bSharedObjectInitialized) - { + if (!$bSharedObjectInitialized) { $bSharedObjectInitialized = true; - if (self::HasSharing()) - { + if (self::HasSharing()) { SharedObject::InitSharedClassProperties(); } } @@ -615,45 +579,40 @@ class UserRightsProfile extends UserRightsAddOnAPI */ public function ListProfiles($oUser) { - $aRet = array(); + $aRet = []; $oSearch = new DBObjectSearch('URP_UserProfile'); $oSearch->AllowAllData(); $oSearch->NoContextParameters(); $oSearch->Addcondition('userid', $oUser->GetKey(), '='); $oProfiles = new DBObjectSet($oSearch); - while ($oUserProfile = $oProfiles->Fetch()) - { + while ($oUserProfile = $oProfiles->Fetch()) { $aRet[$oUserProfile->Get('profileid')] = $oUserProfile->Get('profileid_friendlyname'); } return $aRet; } - public function GetSelectFilter($oUser, $sClass, $aSettings = array()) + public function GetSelectFilter($oUser, $sClass, $aSettings = []) { $this->LoadCache(); // Let us pass an administrator for bypassing the grant matrix check in order to test this method without the need to set up a complex profile // In the nominal case Administrators never end up here (since they completely bypass GetSelectFilter) - if (!static::IsAdministrator($oUser) && (MetaModel::HasCategory($sClass, 'silo') || MetaModel::HasCategory($sClass, 'bizmodel'))) - { + if (!static::IsAdministrator($oUser) && (MetaModel::HasCategory($sClass, 'silo') || MetaModel::HasCategory($sClass, 'bizmodel'))) { // N°4354 - Categories 'silo' and 'bizmodel' do check the grant matrix. Whereas 'filter' always allows to read (but the result can be filtered) $aObjectPermissions = $this->GetUserActionGrant($oUser, $sClass, UR_ACTION_READ); - if ($aObjectPermissions['permission'] == UR_ALLOWED_NO) - { + if ($aObjectPermissions['permission'] == UR_ALLOWED_NO) { return false; } } $oFilter = true; - $aConditions = array(); + $aConditions = []; // Determine if this class is part of a silo and build the filter for it $sAttCode = self::GetOwnerOrganizationAttCode($sClass); - if (!is_null($sAttCode)) - { + if (!is_null($sAttCode)) { $aUserOrgs = $this->GetUserOrgs($oUser, $sClass); - if (count($aUserOrgs) > 0) - { + if (count($aUserOrgs) > 0) { $oFilter = $this->MakeSelectFilter($sClass, $aUserOrgs, $aSettings, $sAttCode); } // else: No org means 'any org' @@ -662,20 +621,15 @@ class UserRightsProfile extends UserRightsAddOnAPI // Specific conditions to hide, for non-administrators, the Administrator Users, the Administrator Profile and related links // Note: when logged as an administrator, GetSelectFilter is completely bypassed. - if ($this->AdministratorsAreHidden()) - { - if ($sClass == 'URP_Profiles') - { + if ($this->AdministratorsAreHidden()) { + if ($sClass == 'URP_Profiles') { $oExpression = new FieldExpression('id', $sClass); $oScalarExpr = new ScalarExpression(1); $aConditions[] = new BinaryExpression($oExpression, '!=', $oScalarExpr); - } - else if (($sClass == 'URP_UserProfile') || ($sClass == 'User') || (is_subclass_of($sClass, 'User'))) - { + } elseif (($sClass == 'URP_UserProfile') || ($sClass == 'User') || (is_subclass_of($sClass, 'User'))) { $aAdministrators = $this->GetAdministrators(); - if (count($aAdministrators) > 0) - { + if (count($aAdministrators) > 0) { $sAttCode = ($sClass == 'URP_UserProfile') ? 'userid' : 'id'; $oExpression = new FieldExpression($sAttCode, $sClass); $oListExpr = ListExpression::FromScalars($aAdministrators); @@ -685,17 +639,14 @@ class UserRightsProfile extends UserRightsAddOnAPI } // Handling of the added conditions - if (count($aConditions) > 0) - { - if($oFilter === true) - { + if (count($aConditions) > 0) { + if ($oFilter === true) { // No 'silo' filter, let's build a clean one $oFilter = new DBObjectSearch($sClass); } // Add the conditions to the filter - foreach($aConditions as $oCondition) - { + foreach ($aConditions as $oCondition) { $oFilter->AddConditionExpression($oCondition); } } @@ -710,10 +661,9 @@ class UserRightsProfile extends UserRightsAddOnAPI */ private function GetAdministrators() { - if ($this->m_aAdministrators === null) - { + if ($this->m_aAdministrators === null) { // Find all administrators - $this->m_aAdministrators = array(); + $this->m_aAdministrators = []; $oAdministratorsFilter = new DBObjectSearch('User'); $oLnkFilter = new DBObjectSearch('URP_UserProfile'); $oExpression = new FieldExpression('profileid', 'URP_UserProfile'); @@ -723,9 +673,8 @@ class UserRightsProfile extends UserRightsAddOnAPI $oAdministratorsFilter->AddCondition_ReferencedBy($oLnkFilter, 'userid'); $oAdministratorsFilter->AllowAllData(true); // Mandatory to prevent infinite recursion !! $oSet = new DBObjectSet($oAdministratorsFilter); - $oSet->OptimizeColumnLoad(array('User' => array('login'))); - while($oUser = $oSet->Fetch()) - { + $oSet->OptimizeColumnLoad(['User' => ['login']]); + while ($oUser = $oSet->Fetch()) { $this->m_aAdministrators[] = $oUser->GetKey(); } } @@ -741,7 +690,6 @@ class UserRightsProfile extends UserRightsAddOnAPI return ((bool)MetaModel::GetConfig()->Get('security.hide_administrators')); } - // This verb has been made public to allow the development of an accurate feedback for the current configuration public function GetProfileActionGrant($iProfile, $sClass, $sAction) { @@ -758,33 +706,29 @@ class UserRightsProfile extends UserRightsAddOnAPI // load and cache permissions for the current user on the given class // $iUser = $oUser->GetKey(); - if (isset($this->m_aObjectActionGrants[$iUser][$sClass][$iActionCode])){ + if (isset($this->m_aObjectActionGrants[$iUser][$sClass][$iActionCode])) { $aTest = $this->m_aObjectActionGrants[$iUser][$sClass][$iActionCode]; - if (is_array($aTest)) return $aTest; + if (is_array($aTest)) { + return $aTest; + } } $sAction = self::$m_aActionCodes[$iActionCode]; $bStatus = null; - // Cache user's profiles - if(false === array_key_exists($iUser, $this->aUsersProfilesList)){ - $this->aUsersProfilesList[$iUser] = UserRights::ListProfiles($oUser); + // Cache user's profiles + if (false === array_key_exists($iUser, $this->aUsersProfilesList)) { + $this->aUsersProfilesList[$iUser] = UserRights::ListProfiles($oUser); } // Call the API of UserRights because it caches the list for us - foreach($this->aUsersProfilesList[$iUser] as $iProfile => $oProfile) - { + foreach ($this->aUsersProfilesList[$iUser] as $iProfile => $oProfile) { $bGrant = $this->GetProfileActionGrant($iProfile, $sClass, $sAction); - if (!is_null($bGrant)) - { - if ($bGrant) - { - if (is_null($bStatus)) - { + if (!is_null($bGrant)) { + if ($bGrant) { + if (is_null($bStatus)) { $bStatus = true; } - } - else - { + } else { $bStatus = false; } } @@ -792,9 +736,9 @@ class UserRightsProfile extends UserRightsAddOnAPI $iPermission = $bStatus ? UR_ALLOWED_YES : UR_ALLOWED_NO; - $aRes = array( + $aRes = [ 'permission' => $iPermission, - ); + ]; $this->m_aObjectActionGrants[$iUser][$sClass][$iActionCode] = $aRes; return $aRes; } @@ -809,20 +753,13 @@ class UserRightsProfile extends UserRightsAddOnAPI // Note: In most cases the object set is ignored because it was interesting to optimize for huge data sets // and acceptable to consider only the root class of the object set - if ($iPermission != UR_ALLOWED_YES) - { + if ($iPermission != UR_ALLOWED_YES) { // It is already NO for everyone... that's the final word! - } - elseif ($iActionCode == UR_ACTION_READ) - { + } elseif ($iActionCode == UR_ACTION_READ) { // We are protected by GetSelectFilter: the object set contains objects allowed or shared for reading - } - elseif ($iActionCode == UR_ACTION_BULK_READ) - { + } elseif ($iActionCode == UR_ACTION_BULK_READ) { // We are protected by GetSelectFilter: the object set contains objects allowed or shared for reading - } - elseif ($oInstanceSet) - { + } elseif ($oInstanceSet) { // We are protected by GetSelectFilter: the object set contains objects allowed or shared for reading // We have to answer NO for objects shared for reading purposes if (self::HasSharing() && SharedObject::GetSharedClassProperties($sClass)) { @@ -886,8 +823,8 @@ class UserRightsProfile extends UserRightsAddOnAPI // Note: this code is VERY close to the code of IsActionAllowed() $iUser = $oUser->GetKey(); - // Cache user's profiles - if(false === array_key_exists($iUser, $this->aUsersProfilesList)){ + // Cache user's profiles + if (false === array_key_exists($iUser, $this->aUsersProfilesList)) { $this->aUsersProfilesList[$iUser] = UserRights::ListProfiles($oUser); } @@ -895,20 +832,14 @@ class UserRightsProfile extends UserRightsAddOnAPI // and acceptable to consider only the root class of the object set $bStatus = null; // Call the API of UserRights because it caches the list for us - foreach($this->aUsersProfilesList[$iUser] as $iProfile => $oProfile) - { + foreach ($this->aUsersProfilesList[$iUser] as $iProfile => $oProfile) { $bGrant = $this->GetClassStimulusGrant($iProfile, $sClass, $sStimulusCode); - if (!is_null($bGrant)) - { - if ($bGrant) - { - if (is_null($bStatus)) - { + if (!is_null($bGrant)) { + if ($bGrant) { + if (is_null($bStatus)) { $bStatus = true; } - } - else - { + } else { $bStatus = false; } } @@ -932,22 +863,16 @@ class UserRightsProfile extends UserRightsAddOnAPI { $sAttCode = null; - $aCallSpec = array($sClass, 'MapContextParam'); - if (($sClass == 'Organization') || is_subclass_of($sClass, 'Organization')) - { + $aCallSpec = [$sClass, 'MapContextParam']; + if (($sClass == 'Organization') || is_subclass_of($sClass, 'Organization')) { $sAttCode = 'id'; - } - elseif (is_callable($aCallSpec)) - { + } elseif (is_callable($aCallSpec)) { $sAttCode = call_user_func($aCallSpec, 'org_id'); // Returns null when there is no mapping for this parameter - if (!MetaModel::IsValidAttCode($sClass, $sAttCode)) - { + if (!MetaModel::IsValidAttCode($sClass, $sAttCode)) { // Skip silently. The data model checker will tell you something about this... $sAttCode = null; } - } - elseif(MetaModel::IsValidAttCode($sClass, 'org_id')) - { + } elseif (MetaModel::IsValidAttCode($sClass, 'org_id')) { $sAttCode = 'org_id'; } @@ -960,14 +885,11 @@ class UserRightsProfile extends UserRightsAddOnAPI protected static function HasSharing() { static $bHasSharing; - if (!isset($bHasSharing)) - { + if (!isset($bHasSharing)) { $bHasSharing = class_exists('SharedObject'); } return $bHasSharing; } } - UserRights::SelectModule('UserRightsProfile'); - diff --git a/addons/userrights/userrightsprofile.db.class.inc.php b/addons/userrights/userrightsprofile.db.class.inc.php index cba755342..f34f9135d 100644 --- a/addons/userrights/userrightsprofile.db.class.inc.php +++ b/addons/userrights/userrightsprofile.db.class.inc.php @@ -1,4 +1,5 @@ "addon/userrights", "key_type" => "autoincrement", "name_attcode" => "name", - "complementary_name_attcode" => array('description'), + "complementary_name_attcode" => ['description'], "state_attcode" => "", - "reconc_keys" => array(), + "reconc_keys" => [], "db_table" => "priv_urp_profiles", "db_key_field" => "id", "db_finalclass_field" => "", - ); + ]; MetaModel::Init_Params($aParams); //MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeString("name", array("allowed_values"=>null, "sql"=>"name", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeString("description", array("allowed_values"=>null, "sql"=>"description", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array()))); + MetaModel::Init_AddAttribute(new AttributeString("name", ["allowed_values" => null, "sql" => "name", "default_value" => null, "is_null_allowed" => false, "depends_on" => []])); + MetaModel::Init_AddAttribute(new AttributeString("description", ["allowed_values" => null, "sql" => "description", "default_value" => null, "is_null_allowed" => false, "depends_on" => []])); - MetaModel::Init_AddAttribute(new AttributeLinkedSetIndirect("user_list", array("linked_class"=>"URP_UserProfile", "ext_key_to_me"=>"profileid", "ext_key_to_remote"=>"userid", "allowed_values"=>null, "count_min"=>1, "count_max"=>0, "depends_on"=>array()))); + MetaModel::Init_AddAttribute(new AttributeLinkedSetIndirect("user_list", ["linked_class" => "URP_UserProfile", "ext_key_to_me" => "profileid", "ext_key_to_remote" => "userid", "allowed_values" => null, "count_min" => 1, "count_max" => 0, "depends_on" => []])); // Display lists - MetaModel::Init_SetZListItems('details', array('name', 'description', 'user_list')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('description')); // Attributes to be displayed for a list + MetaModel::Init_SetZListItems('details', ['name', 'description', 'user_list']); // Attributes to be displayed for the complete details + MetaModel::Init_SetZListItems('list', ['description']); // Attributes to be displayed for a list // Search criteria - MetaModel::Init_SetZListItems('standard_search', array('name', 'description')); // Criteria of the std search form - MetaModel::Init_SetZListItems('default_search', array ('name', 'description')); + MetaModel::Init_SetZListItems('standard_search', ['name', 'description']); // Criteria of the std search form + MetaModel::Init_SetZListItems('default_search', ['name', 'description']); } protected $m_bCheckReservedNames = true; @@ -102,68 +100,60 @@ class URP_Profiles extends UserRightsBaseClassGUI $this->m_bCheckReservedNames = false; } - - protected static $m_aActions = array( + protected static $m_aActions = [ UR_ACTION_READ => 'Read', UR_ACTION_MODIFY => 'Modify', UR_ACTION_DELETE => 'Delete', UR_ACTION_BULK_READ => 'Bulk Read', UR_ACTION_BULK_MODIFY => 'Bulk Modify', UR_ACTION_BULK_DELETE => 'Bulk Delete', - ); + ]; protected static $m_aCacheActionGrants = null; protected static $m_aCacheStimulusGrants = null; protected static $m_aCacheProfiles = null; - + public static function DoCreateProfile($sName, $sDescription, $bReservedName = false) { - if (is_null(self::$m_aCacheProfiles)) - { - self::$m_aCacheProfiles = array(); + if (is_null(self::$m_aCacheProfiles)) { + self::$m_aCacheProfiles = []; $oFilterAll = new DBObjectSearch('URP_Profiles'); $oSet = new DBObjectSet($oFilterAll); - while ($oProfile = $oSet->Fetch()) - { + while ($oProfile = $oSet->Fetch()) { self::$m_aCacheProfiles[$oProfile->Get('name')] = $oProfile->GetKey(); } - } + } $sCacheKey = $sName; - if (isset(self::$m_aCacheProfiles[$sCacheKey])) - { + if (isset(self::$m_aCacheProfiles[$sCacheKey])) { return self::$m_aCacheProfiles[$sCacheKey]; } $oNewObj = MetaModel::NewObject("URP_Profiles"); $oNewObj->Set('name', $sName); $oNewObj->Set('description', $sDescription); - if ($bReservedName) - { - $oNewObj->DisableCheckOnReservedNames(); + if ($bReservedName) { + $oNewObj->DisableCheckOnReservedNames(); } $iId = $oNewObj->DBInsertNoReload(); - self::$m_aCacheProfiles[$sCacheKey] = $iId; + self::$m_aCacheProfiles[$sCacheKey] = $iId; return $iId; } - + public static function DoCreateActionGrant($iProfile, $iAction, $sClass, $bPermission = true) { $sAction = self::$m_aActions[$iAction]; - - if (is_null(self::$m_aCacheActionGrants)) - { - self::$m_aCacheActionGrants = array(); + + if (is_null(self::$m_aCacheActionGrants)) { + self::$m_aCacheActionGrants = []; $oFilterAll = new DBObjectSearch('URP_ActionGrant'); $oSet = new DBObjectSet($oFilterAll); - while ($oGrant = $oSet->Fetch()) - { + while ($oGrant = $oSet->Fetch()) { self::$m_aCacheActionGrants[$oGrant->Get('profileid').'-'.$oGrant->Get('action').'-'.$oGrant->Get('class')] = $oGrant->GetKey(); } - } + } $sCacheKey = "$iProfile-$sAction-$sClass"; - if (isset(self::$m_aCacheActionGrants[$sCacheKey])) - { + if (isset(self::$m_aCacheActionGrants[$sCacheKey])) { return self::$m_aCacheActionGrants[$sCacheKey]; } @@ -173,26 +163,23 @@ class URP_Profiles extends UserRightsBaseClassGUI $oNewObj->Set('class', $sClass); $oNewObj->Set('action', $sAction); $iId = $oNewObj->DBInsertNoReload(); - self::$m_aCacheActionGrants[$sCacheKey] = $iId; + self::$m_aCacheActionGrants[$sCacheKey] = $iId; return $iId; } - + public static function DoCreateStimulusGrant($iProfile, $sStimulusCode, $sClass) { - if (is_null(self::$m_aCacheStimulusGrants)) - { - self::$m_aCacheStimulusGrants = array(); + if (is_null(self::$m_aCacheStimulusGrants)) { + self::$m_aCacheStimulusGrants = []; $oFilterAll = new DBObjectSearch('URP_StimulusGrant'); $oSet = new DBObjectSet($oFilterAll); - while ($oGrant = $oSet->Fetch()) - { + while ($oGrant = $oSet->Fetch()) { self::$m_aCacheStimulusGrants[$oGrant->Get('profileid').'-'.$oGrant->Get('stimulus').'-'.$oGrant->Get('class')] = $oGrant->GetKey(); } - } + } $sCacheKey = "$iProfile-$sStimulusCode-$sClass"; - if (isset(self::$m_aCacheStimulusGrants[$sCacheKey])) - { + if (isset(self::$m_aCacheStimulusGrants[$sCacheKey])) { return self::$m_aCacheStimulusGrants[$sCacheKey]; } $oNewObj = MetaModel::NewObject("URP_StimulusGrant"); @@ -201,13 +188,13 @@ class URP_Profiles extends UserRightsBaseClassGUI $oNewObj->Set('class', $sClass); $oNewObj->Set('stimulus', $sStimulusCode); $iId = $oNewObj->DBInsertNoReload(); - self::$m_aCacheStimulusGrants[$sCacheKey] = $iId; + self::$m_aCacheStimulusGrants[$sCacheKey] = $iId; return $iId; } - + /* * Create the built-in Administrator profile with its reserved name - */ + */ public static function DoCreateAdminProfile() { self::DoCreateProfile(ADMIN_PROFILE_NAME, 'Has the rights on everything (bypassing any control)', true /* reserved name */); @@ -215,53 +202,40 @@ class URP_Profiles extends UserRightsBaseClassGUI /* * Overload the standard behavior to preserve reserved names - */ + */ public function DoCheckToWrite() { parent::DoCheckToWrite(); - if ($this->m_bCheckReservedNames) - { + if ($this->m_bCheckReservedNames) { $aChanges = $this->ListChanges(); - if (array_key_exists('name', $aChanges)) - { - if ($this->GetOriginal('name') == ADMIN_PROFILE_NAME) - { + if (array_key_exists('name', $aChanges)) { + if ($this->GetOriginal('name') == ADMIN_PROFILE_NAME) { $this->m_aCheckIssues[] = "The name of the Administrator profile must not be changed"; - } - elseif ($this->Get('name') == ADMIN_PROFILE_NAME) - { + } elseif ($this->Get('name') == ADMIN_PROFILE_NAME) { $this->m_aCheckIssues[] = ADMIN_PROFILE_NAME." is a reserved to the built-in Administrator profile"; - } - elseif ($this->GetOriginal('name') == PORTAL_PROFILE_NAME) - { + } elseif ($this->GetOriginal('name') == PORTAL_PROFILE_NAME) { $this->m_aCheckIssues[] = "The name of the User Portal profile must not be changed"; - } - elseif ($this->Get('name') == PORTAL_PROFILE_NAME) - { + } elseif ($this->Get('name') == PORTAL_PROFILE_NAME) { $this->m_aCheckIssues[] = PORTAL_PROFILE_NAME." is a reserved to the built-in User Portal profile"; } } } } - function GetGrantAsHtml($oUserRights, $sClass, $sAction) + public function GetGrantAsHtml($oUserRights, $sClass, $sAction) { $iGrant = $oUserRights->GetProfileActionGrant($this->GetKey(), $sClass, $sAction); - if (!is_null($iGrant)) - { + if (!is_null($iGrant)) { return ''.Dict::S('UI:UserManagement:ActionAllowed:Yes').''; - } - else - { + } else { return ''.Dict::S('UI:UserManagement:ActionAllowed:No').''; } } - - function DoShowGrantSumary($oPage) + + public function DoShowGrantSumary($oPage) { - if ($this->GetRawName() == "Administrator") - { + if ($this->GetRawName() == "Administrator") { // Looks dirty, but ok that's THE ONE $oPage->p(Dict::S('UI:UserManagement:AdminProfile+')); return; @@ -269,25 +243,24 @@ class URP_Profiles extends UserRightsBaseClassGUI // Note: for sure, we assume that the instance is derived from UserRightsProfile $oUserRights = UserRights::GetModuleInstance(); - - $aDisplayData = array(); - foreach (MetaModel::GetClasses('bizmodel') as $sClass) - { - // Skip non instantiable classes - if (MetaModel::IsAbstract($sClass)) continue; - $aStimuli = array(); - foreach (MetaModel::EnumStimuli($sClass) as $sStimulusCode => $oStimulus) - { + $aDisplayData = []; + foreach (MetaModel::GetClasses('bizmodel') as $sClass) { + // Skip non instantiable classes + if (MetaModel::IsAbstract($sClass)) { + continue; + } + + $aStimuli = []; + foreach (MetaModel::EnumStimuli($sClass) as $sStimulusCode => $oStimulus) { $oGrant = $oUserRights->GetClassStimulusGrant($this->GetKey(), $sClass, $sStimulusCode); - if (is_object($oGrant) && ($oGrant->Get('permission') == 'yes')) - { + if (is_object($oGrant) && ($oGrant->Get('permission') == 'yes')) { $aStimuli[] = ''.utils::EscapeHtml($oStimulus->GetLabel()).''; } } $sStimuli = implode(', ', $aStimuli); - - $aDisplayData[] = array( + + $aDisplayData[] = [ 'class' => MetaModel::GetName($sClass), 'read' => $this->GetGrantAsHtml($oUserRights, $sClass, 'Read'), 'bulkread' => $this->GetGrantAsHtml($oUserRights, $sClass, 'Bulk Read'), @@ -296,22 +269,22 @@ class URP_Profiles extends UserRightsBaseClassGUI 'delete' => $this->GetGrantAsHtml($oUserRights, $sClass, 'Delete'), 'bulkdelete' => $this->GetGrantAsHtml($oUserRights, $sClass, 'Bulk Delete'), 'stimuli' => $sStimuli, - ); + ]; } - - $aDisplayConfig = array(); - $aDisplayConfig['class'] = array('label' => Dict::S('UI:UserManagement:Class'), 'description' => Dict::S('UI:UserManagement:Class+')); - $aDisplayConfig['read'] = array('label' => Dict::S('UI:UserManagement:Action:Read'), 'description' => Dict::S('UI:UserManagement:Action:Read+')); - $aDisplayConfig['bulkread'] = array('label' => Dict::S('UI:UserManagement:Action:BulkRead'), 'description' => Dict::S('UI:UserManagement:Action:BulkRead+')); - $aDisplayConfig['write'] = array('label' => Dict::S('UI:UserManagement:Action:Modify'), 'description' => Dict::S('UI:UserManagement:Action:Modify+')); - $aDisplayConfig['bulkwrite'] = array('label' => Dict::S('UI:UserManagement:Action:BulkModify'), 'description' => Dict::S('UI:UserManagement:Action:BulkModify+')); - $aDisplayConfig['delete'] = array('label' => Dict::S('UI:UserManagement:Action:Delete'), 'description' => Dict::S('UI:UserManagement:Action:Delete+')); - $aDisplayConfig['bulkdelete'] = array('label' => Dict::S('UI:UserManagement:Action:BulkDelete'), 'description' => Dict::S('UI:UserManagement:Action:BulkDelete+')); - $aDisplayConfig['stimuli'] = array('label' => Dict::S('UI:UserManagement:Action:Stimuli'), 'description' => Dict::S('UI:UserManagement:Action:Stimuli+')); + + $aDisplayConfig = []; + $aDisplayConfig['class'] = ['label' => Dict::S('UI:UserManagement:Class'), 'description' => Dict::S('UI:UserManagement:Class+')]; + $aDisplayConfig['read'] = ['label' => Dict::S('UI:UserManagement:Action:Read'), 'description' => Dict::S('UI:UserManagement:Action:Read+')]; + $aDisplayConfig['bulkread'] = ['label' => Dict::S('UI:UserManagement:Action:BulkRead'), 'description' => Dict::S('UI:UserManagement:Action:BulkRead+')]; + $aDisplayConfig['write'] = ['label' => Dict::S('UI:UserManagement:Action:Modify'), 'description' => Dict::S('UI:UserManagement:Action:Modify+')]; + $aDisplayConfig['bulkwrite'] = ['label' => Dict::S('UI:UserManagement:Action:BulkModify'), 'description' => Dict::S('UI:UserManagement:Action:BulkModify+')]; + $aDisplayConfig['delete'] = ['label' => Dict::S('UI:UserManagement:Action:Delete'), 'description' => Dict::S('UI:UserManagement:Action:Delete+')]; + $aDisplayConfig['bulkdelete'] = ['label' => Dict::S('UI:UserManagement:Action:BulkDelete'), 'description' => Dict::S('UI:UserManagement:Action:BulkDelete+')]; + $aDisplayConfig['stimuli'] = ['label' => Dict::S('UI:UserManagement:Action:Stimuli'), 'description' => Dict::S('UI:UserManagement:Action:Stimuli+')]; $oPage->table($aDisplayConfig, $aDisplayData); } - function DisplayBareRelations(WebPage $oPage, $bEditMode = false) + public function DisplayBareRelations(WebPage $oPage, $bEditMode = false) { parent::DisplayBareRelations($oPage, $bEditMode); @@ -320,41 +293,41 @@ class URP_Profiles extends UserRightsBaseClassGUI } } - - class URP_UserProfile extends UserRightsBaseClassGUI { public static function Init() { - $aParams = array - ( + $aParams = + [ "category" => "addon/userrights", "key_type" => "autoincrement", - "name_attcode" => array("userlogin", "profile"), + "name_attcode" => ["userlogin", "profile"], "state_attcode" => "", - "reconc_keys" => array(), + "reconc_keys" => [], "db_table" => "priv_urp_userprofile", "db_key_field" => "id", "db_finalclass_field" => "", "is_link" => true, /** @since 3.1.0 N°6482 */ - ); + ]; MetaModel::Init_Params($aParams); //MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeExternalKey("userid", array("targetclass" => "User", "jointype" => "", "allowed_values" => null, "sql" => "userid", "is_null_allowed" => false, "on_target_delete" => DEL_AUTO, "depends_on" => array()))); - MetaModel::Init_AddAttribute(new AttributeExternalField("userlogin", array("allowed_values" => null, "extkey_attcode" => 'userid', "target_attcode" => "login"))); + MetaModel::Init_AddAttribute(new AttributeExternalKey("userid", ["targetclass" => "User", "jointype" => "", "allowed_values" => null, "sql" => "userid", "is_null_allowed" => false, "on_target_delete" => DEL_AUTO, "depends_on" => []])); + MetaModel::Init_AddAttribute(new AttributeExternalField("userlogin", ["allowed_values" => null, "extkey_attcode" => 'userid', "target_attcode" => "login"])); - MetaModel::Init_AddAttribute(new AttributeExternalKey("profileid", - array("targetclass" => "URP_Profiles", "jointype" => "", "allowed_values" => null, "sql" => "profileid", "is_null_allowed" => false, "on_target_delete" => DEL_AUTO, "depends_on" => array(), "allow_target_creation" => false))); - MetaModel::Init_AddAttribute(new AttributeExternalField("profile", array("allowed_values" => null, "extkey_attcode" => 'profileid', "target_attcode" => "name"))); + MetaModel::Init_AddAttribute(new AttributeExternalKey( + "profileid", + ["targetclass" => "URP_Profiles", "jointype" => "", "allowed_values" => null, "sql" => "profileid", "is_null_allowed" => false, "on_target_delete" => DEL_AUTO, "depends_on" => [], "allow_target_creation" => false] + )); + MetaModel::Init_AddAttribute(new AttributeExternalField("profile", ["allowed_values" => null, "extkey_attcode" => 'profileid', "target_attcode" => "name"])); - MetaModel::Init_AddAttribute(new AttributeString("reason", array("allowed_values" => null, "sql" => "description", "default_value" => null, "is_null_allowed" => true, "depends_on" => array()))); + MetaModel::Init_AddAttribute(new AttributeString("reason", ["allowed_values" => null, "sql" => "description", "default_value" => null, "is_null_allowed" => true, "depends_on" => []])); // Display lists - MetaModel::Init_SetZListItems('details', array('userid', 'profileid', 'reason')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('userid', 'profileid', 'reason')); // Attributes to be displayed for a list + MetaModel::Init_SetZListItems('details', ['userid', 'profileid', 'reason']); // Attributes to be displayed for the complete details + MetaModel::Init_SetZListItems('list', ['userid', 'profileid', 'reason']); // Attributes to be displayed for a list // Search criteria - MetaModel::Init_SetZListItems('standard_search', array('userid', 'profileid')); // Criteria of the std search form - MetaModel::Init_SetZListItems('advanced_search', array('userid', 'profileid')); // Criteria of the advanced search form + MetaModel::Init_SetZListItems('standard_search', ['userid', 'profileid']); // Criteria of the std search form + MetaModel::Init_SetZListItems('advanced_search', ['userid', 'profileid']); // Criteria of the advanced search form } } @@ -362,152 +335,146 @@ class URP_UserOrg extends UserRightsBaseClassGUI { public static function Init() { - $aParams = array - ( + $aParams = + [ "category" => "addon/userrights", "key_type" => "autoincrement", - "name_attcode" => array("userlogin", "allowed_org_name"), + "name_attcode" => ["userlogin", "allowed_org_name"], "state_attcode" => "", - "reconc_keys" => array(), + "reconc_keys" => [], "db_table" => "priv_urp_userorg", "db_key_field" => "id", "db_finalclass_field" => "", - ); + ]; MetaModel::Init_Params($aParams); //MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeExternalKey("userid", array("targetclass"=>"User", "jointype"=> "", "allowed_values"=>null, "sql"=>"userid", "is_null_allowed"=>false, "on_target_delete"=>DEL_AUTO, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeExternalField("userlogin", array("allowed_values"=>null, "extkey_attcode"=> 'userid', "target_attcode"=>"login"))); + MetaModel::Init_AddAttribute(new AttributeExternalKey("userid", ["targetclass" => "User", "jointype" => "", "allowed_values" => null, "sql" => "userid", "is_null_allowed" => false, "on_target_delete" => DEL_AUTO, "depends_on" => []])); + MetaModel::Init_AddAttribute(new AttributeExternalField("userlogin", ["allowed_values" => null, "extkey_attcode" => 'userid', "target_attcode" => "login"])); - MetaModel::Init_AddAttribute(new AttributeExternalKey("allowed_org_id", array("targetclass"=>"Organization", "jointype"=> "", "allowed_values"=>null, "sql"=>"allowed_org_id", "is_null_allowed"=>false, "on_target_delete"=>DEL_AUTO, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeExternalField("allowed_org_name", array("allowed_values"=>null, "extkey_attcode"=> 'allowed_org_id', "target_attcode"=>"name"))); + MetaModel::Init_AddAttribute(new AttributeExternalKey("allowed_org_id", ["targetclass" => "Organization", "jointype" => "", "allowed_values" => null, "sql" => "allowed_org_id", "is_null_allowed" => false, "on_target_delete" => DEL_AUTO, "depends_on" => []])); + MetaModel::Init_AddAttribute(new AttributeExternalField("allowed_org_name", ["allowed_values" => null, "extkey_attcode" => 'allowed_org_id', "target_attcode" => "name"])); - MetaModel::Init_AddAttribute(new AttributeString("reason", array("allowed_values"=>null, "sql"=>"reason", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array()))); + MetaModel::Init_AddAttribute(new AttributeString("reason", ["allowed_values" => null, "sql" => "reason", "default_value" => null, "is_null_allowed" => true, "depends_on" => []])); // Display lists - MetaModel::Init_SetZListItems('details', array('userid', 'allowed_org_id', 'reason')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('allowed_org_id', 'reason')); // Attributes to be displayed for a list + MetaModel::Init_SetZListItems('details', ['userid', 'allowed_org_id', 'reason']); // Attributes to be displayed for the complete details + MetaModel::Init_SetZListItems('list', ['allowed_org_id', 'reason']); // Attributes to be displayed for a list // Search criteria - MetaModel::Init_SetZListItems('standard_search', array('userid', 'allowed_org_id')); // Criteria of the std search form - MetaModel::Init_SetZListItems('advanced_search', array('userid', 'allowed_org_id')); // Criteria of the advanced search form + MetaModel::Init_SetZListItems('standard_search', ['userid', 'allowed_org_id']); // Criteria of the std search form + MetaModel::Init_SetZListItems('advanced_search', ['userid', 'allowed_org_id']); // Criteria of the advanced search form } } - class URP_ActionGrant extends UserRightsBaseClass { public static function Init() { - $aParams = array - ( + $aParams = + [ "category" => "addon/userrights", "key_type" => "autoincrement", "name_attcode" => "profileid", "state_attcode" => "", - "reconc_keys" => array(), + "reconc_keys" => [], "db_table" => "priv_urp_grant_actions", "db_key_field" => "id", "db_finalclass_field" => "", - ); + ]; MetaModel::Init_Params($aParams); //MetaModel::Init_InheritAttributes(); // Common to all grant classes (could be factorized by class inheritence, but this has to be benchmarked) - MetaModel::Init_AddAttribute(new AttributeExternalKey("profileid", array("targetclass"=>"URP_Profiles", "jointype"=> "", "allowed_values"=>null, "sql"=>"profileid", "is_null_allowed"=>false, "on_target_delete"=>DEL_SILENT, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeExternalField("profile", array("allowed_values"=>null, "extkey_attcode"=> 'profileid', "target_attcode"=>"name"))); - MetaModel::Init_AddAttribute(new AttributeClass("class", array("class_category"=>"", "more_values"=>"", "sql"=>"class", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeEnum("permission", array("allowed_values"=>new ValueSetEnum('yes,no'), "sql"=>"permission", "default_value"=>"yes", "is_null_allowed"=>false, "depends_on"=>array()))); + MetaModel::Init_AddAttribute(new AttributeExternalKey("profileid", ["targetclass" => "URP_Profiles", "jointype" => "", "allowed_values" => null, "sql" => "profileid", "is_null_allowed" => false, "on_target_delete" => DEL_SILENT, "depends_on" => []])); + MetaModel::Init_AddAttribute(new AttributeExternalField("profile", ["allowed_values" => null, "extkey_attcode" => 'profileid', "target_attcode" => "name"])); + MetaModel::Init_AddAttribute(new AttributeClass("class", ["class_category" => "", "more_values" => "", "sql" => "class", "default_value" => null, "is_null_allowed" => false, "depends_on" => []])); + MetaModel::Init_AddAttribute(new AttributeEnum("permission", ["allowed_values" => new ValueSetEnum('yes,no'), "sql" => "permission", "default_value" => "yes", "is_null_allowed" => false, "depends_on" => []])); - MetaModel::Init_AddAttribute(new AttributeString("action", array("allowed_values"=>null, "sql"=>"action", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); + MetaModel::Init_AddAttribute(new AttributeString("action", ["allowed_values" => null, "sql" => "action", "default_value" => "", "is_null_allowed" => false, "depends_on" => []])); // Display lists - MetaModel::Init_SetZListItems('details', array('profileid', 'class', 'permission', 'action')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('class', 'permission', 'action')); // Attributes to be displayed for a list + MetaModel::Init_SetZListItems('details', ['profileid', 'class', 'permission', 'action']); // Attributes to be displayed for the complete details + MetaModel::Init_SetZListItems('list', ['class', 'permission', 'action']); // Attributes to be displayed for a list // Search criteria - MetaModel::Init_SetZListItems('standard_search', array('profileid', 'class', 'permission', 'action')); // Criteria of the std search form - MetaModel::Init_SetZListItems('advanced_search', array('profileid', 'class', 'permission', 'action')); // Criteria of the advanced search form + MetaModel::Init_SetZListItems('standard_search', ['profileid', 'class', 'permission', 'action']); // Criteria of the std search form + MetaModel::Init_SetZListItems('advanced_search', ['profileid', 'class', 'permission', 'action']); // Criteria of the advanced search form } } - class URP_StimulusGrant extends UserRightsBaseClass { public static function Init() { - $aParams = array - ( + $aParams = + [ "category" => "addon/userrights", "key_type" => "autoincrement", "name_attcode" => "profileid", "state_attcode" => "", - "reconc_keys" => array(), + "reconc_keys" => [], "db_table" => "priv_urp_grant_stimulus", "db_key_field" => "id", "db_finalclass_field" => "", - ); + ]; MetaModel::Init_Params($aParams); //MetaModel::Init_InheritAttributes(); // Common to all grant classes (could be factorized by class inheritence, but this has to be benchmarked) - MetaModel::Init_AddAttribute(new AttributeExternalKey("profileid", array("targetclass"=>"URP_Profiles", "jointype"=> "", "allowed_values"=>null, "sql"=>"profileid", "is_null_allowed"=>false, "on_target_delete"=>DEL_SILENT, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeExternalField("profile", array("allowed_values"=>null, "extkey_attcode"=> 'profileid', "target_attcode"=>"name"))); - MetaModel::Init_AddAttribute(new AttributeClass("class", array("class_category"=>"", "more_values"=>"", "sql"=>"class", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeEnum("permission", array("allowed_values"=>new ValueSetEnum('yes,no'), "sql"=>"permission", "default_value"=>"yes", "is_null_allowed"=>false, "depends_on"=>array()))); + MetaModel::Init_AddAttribute(new AttributeExternalKey("profileid", ["targetclass" => "URP_Profiles", "jointype" => "", "allowed_values" => null, "sql" => "profileid", "is_null_allowed" => false, "on_target_delete" => DEL_SILENT, "depends_on" => []])); + MetaModel::Init_AddAttribute(new AttributeExternalField("profile", ["allowed_values" => null, "extkey_attcode" => 'profileid', "target_attcode" => "name"])); + MetaModel::Init_AddAttribute(new AttributeClass("class", ["class_category" => "", "more_values" => "", "sql" => "class", "default_value" => null, "is_null_allowed" => false, "depends_on" => []])); + MetaModel::Init_AddAttribute(new AttributeEnum("permission", ["allowed_values" => new ValueSetEnum('yes,no'), "sql" => "permission", "default_value" => "yes", "is_null_allowed" => false, "depends_on" => []])); - MetaModel::Init_AddAttribute(new AttributeString("stimulus", array("allowed_values"=>null, "sql"=>"action", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array()))); + MetaModel::Init_AddAttribute(new AttributeString("stimulus", ["allowed_values" => null, "sql" => "action", "default_value" => "", "is_null_allowed" => false, "depends_on" => []])); // Display lists - MetaModel::Init_SetZListItems('details', array('profileid', 'class', 'permission', 'stimulus')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('class', 'permission', 'stimulus')); // Attributes to be displayed for a list + MetaModel::Init_SetZListItems('details', ['profileid', 'class', 'permission', 'stimulus']); // Attributes to be displayed for the complete details + MetaModel::Init_SetZListItems('list', ['class', 'permission', 'stimulus']); // Attributes to be displayed for a list // Search criteria - MetaModel::Init_SetZListItems('standard_search', array('profileid', 'class', 'permission', 'stimulus')); // Criteria of the std search form - MetaModel::Init_SetZListItems('advanced_search', array('profileid', 'class', 'permission', 'stimulus')); // Criteria of the advanced search form + MetaModel::Init_SetZListItems('standard_search', ['profileid', 'class', 'permission', 'stimulus']); // Criteria of the std search form + MetaModel::Init_SetZListItems('advanced_search', ['profileid', 'class', 'permission', 'stimulus']); // Criteria of the advanced search form } } - class URP_AttributeGrant extends UserRightsBaseClass { public static function Init() { - $aParams = array - ( + $aParams = + [ "category" => "addon/userrights", "key_type" => "autoincrement", "name_attcode" => "actiongrantid", "state_attcode" => "", - "reconc_keys" => array(), + "reconc_keys" => [], "db_table" => "priv_urp_grant_attributes", "db_key_field" => "id", "db_finalclass_field" => "", - ); + ]; MetaModel::Init_Params($aParams); //MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeExternalKey("actiongrantid", array("targetclass"=>"URP_ActionGrant", "jointype"=> "", "allowed_values"=>null, "sql"=>"actiongrantid", "is_null_allowed"=>false, "on_target_delete"=>DEL_SILENT, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeString("attcode", array("allowed_values"=>null, "sql"=>"attcode", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array()))); + MetaModel::Init_AddAttribute(new AttributeExternalKey("actiongrantid", ["targetclass" => "URP_ActionGrant", "jointype" => "", "allowed_values" => null, "sql" => "actiongrantid", "is_null_allowed" => false, "on_target_delete" => DEL_SILENT, "depends_on" => []])); + MetaModel::Init_AddAttribute(new AttributeString("attcode", ["allowed_values" => null, "sql" => "attcode", "default_value" => null, "is_null_allowed" => false, "depends_on" => []])); // Display lists - MetaModel::Init_SetZListItems('details', array('actiongrantid', 'attcode')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('attcode')); // Attributes to be displayed for a list + MetaModel::Init_SetZListItems('details', ['actiongrantid', 'attcode']); // Attributes to be displayed for the complete details + MetaModel::Init_SetZListItems('list', ['attcode']); // Attributes to be displayed for a list // Search criteria - MetaModel::Init_SetZListItems('standard_search', array('actiongrantid', 'attcode')); // Criteria of the std search form - MetaModel::Init_SetZListItems('advanced_search', array('actiongrantid', 'attcode')); // Criteria of the advanced search form + MetaModel::Init_SetZListItems('standard_search', ['actiongrantid', 'attcode']); // Criteria of the std search form + MetaModel::Init_SetZListItems('advanced_search', ['actiongrantid', 'attcode']); // Criteria of the advanced search form } } - - - class UserRightsProfile extends UserRightsAddOnAPI { - static public $m_aActionCodes = array( + public static $m_aActionCodes = [ UR_ACTION_READ => 'read', UR_ACTION_MODIFY => 'modify', UR_ACTION_DELETE => 'delete', UR_ACTION_BULK_READ => 'bulk read', UR_ACTION_BULK_MODIFY => 'bulk modify', UR_ACTION_BULK_DELETE => 'bulk delete', - ); + ]; // Installation: create the very first user public function CreateAdministrator($sAdminUser, $sAdminPwd, $sLanguage = 'EN US') @@ -528,8 +495,7 @@ class UserRightsProfile extends UserRightsAddOnAPI $oContact = MetaModel::NewObject('Person'); $oContact->Set('name', 'My last name'); $oContact->Set('first_name', 'My first name'); - if (MetaModel::IsValidAttCode('Person', 'org_id')) - { + if (MetaModel::IsValidAttCode('Person', 'org_id')) { $oContact->Set('org_id', $iOrgId); } $oContact->Set('email', 'my.email@foo.org'); @@ -537,7 +503,6 @@ class UserRightsProfile extends UserRightsAddOnAPI } } - $oUser = new UserLocal(); $oUser->Set('login', $sAdminUser); $oUser->Set('password', $sAdminPwd); @@ -547,7 +512,7 @@ class UserRightsProfile extends UserRightsAddOnAPI $oUser->Set('language', $sLanguage); // Language was chosen during the installation // Add this user to the very specific 'admin' profile - $oAdminProfile = MetaModel::GetObjectFromOQL("SELECT URP_Profiles WHERE name = :name", array('name' => ADMIN_PROFILE_NAME), true /*all data*/); + $oAdminProfile = MetaModel::GetObjectFromOQL("SELECT URP_Profiles WHERE name = :name", ['name' => ADMIN_PROFILE_NAME], true /*all data*/); if (is_object($oAdminProfile)) { $oUserProfile = new URP_UserProfile(); $oUserProfile->Set('profileid', $oAdminProfile->GetKey()); @@ -564,20 +529,19 @@ class UserRightsProfile extends UserRightsAddOnAPI { } - - protected $m_aAdmins = array(); // id -> bool, true if the user has the well-known admin profile - protected $m_aPortalUsers = array(); // id -> bool, true if the user has the well-known portal user profile + protected $m_aAdmins = []; // id -> bool, true if the user has the well-known admin profile + protected $m_aPortalUsers = []; // id -> bool, true if the user has the well-known portal user profile protected $m_aProfiles; // id -> object - protected $m_aUserProfiles = array(); // userid,profileid -> object - protected $m_aUserOrgs = array(); // userid -> array of orgid + protected $m_aUserProfiles = []; // userid,profileid -> object + protected $m_aUserOrgs = []; // userid -> array of orgid // Those arrays could be completed on demand (inheriting parent permissions) protected $m_aClassActionGrants = null; // profile, class, action -> actiongrantid (or false if NO, or null/missing if undefined) - protected $m_aClassStimulusGrants = array(); // profile, class, stimulus -> permission + protected $m_aClassStimulusGrants = []; // profile, class, stimulus -> permission // Built on demand, could be optimized if necessary (doing a query for each attribute that needs to be read) - protected $m_aObjectActionGrants = array(); + protected $m_aObjectActionGrants = []; /** * Read and cache organizations allowed to the given user @@ -592,31 +556,25 @@ class UserRightsProfile extends UserRightsAddOnAPI public function GetUserOrgs($oUser, $sClass) { $iUser = $oUser->GetKey(); - if (!array_key_exists($iUser, $this->m_aUserOrgs)) - { - $this->m_aUserOrgs[$iUser] = array(); + if (!array_key_exists($iUser, $this->m_aUserOrgs)) { + $this->m_aUserOrgs[$iUser] = []; $sHierarchicalKeyCode = MetaModel::IsHierarchicalClass('Organization'); - if ($sHierarchicalKeyCode !== false) - { + if ($sHierarchicalKeyCode !== false) { $sUserOrgQuery = 'SELECT UserOrg, Org FROM Organization AS Org JOIN Organization AS Root ON Org.'.$sHierarchicalKeyCode.' BELOW Root.id JOIN URP_UserOrg AS UserOrg ON UserOrg.allowed_org_id = Root.id WHERE UserOrg.userid = :userid'; - $oUserOrgSet = new DBObjectSet(DBObjectSearch::FromOQL_AllData($sUserOrgQuery), array(), array('userid' => $iUser)); - while ($aRow = $oUserOrgSet->FetchAssoc()) - { + $oUserOrgSet = new DBObjectSet(DBObjectSearch::FromOQL_AllData($sUserOrgQuery), [], ['userid' => $iUser]); + while ($aRow = $oUserOrgSet->FetchAssoc()) { $oOrg = $aRow['Org']; $this->m_aUserOrgs[$iUser][] = $oOrg->GetKey(); } - } - else - { + } else { $oSearch = new DBObjectSearch('URP_UserOrg'); $oSearch->AllowAllData(); $oCondition = new BinaryExpression(new FieldExpression('userid'), '=', new VariableExpression('userid')); $oSearch->AddConditionExpression($oCondition); - - $oUserOrgSet = new DBObjectSet($oSearch, array(), array('userid' => $iUser)); - while ($oUserOrg = $oUserOrgSet->Fetch()) - { + + $oUserOrgSet = new DBObjectSet($oSearch, [], ['userid' => $iUser]); + while ($oUserOrg = $oUserOrgSet->Fetch()) { $this->m_aUserOrgs[$iUser][] = $oUserOrg->Get('allowed_org_id'); } } @@ -629,17 +587,15 @@ class UserRightsProfile extends UserRightsAddOnAPI */ protected function GetUserProfiles($iUser) { - if (!array_key_exists($iUser, $this->m_aUserProfiles)) - { + if (!array_key_exists($iUser, $this->m_aUserProfiles)) { $oSearch = new DBObjectSearch('URP_UserProfile'); $oSearch->AllowAllData(); $oCondition = new BinaryExpression(new FieldExpression('userid'), '=', new VariableExpression('userid')); $oSearch->AddConditionExpression($oCondition); - - $this->m_aUserProfiles[$iUser] = array(); - $oUserProfileSet = new DBObjectSet($oSearch, array(), array('userid' => $iUser)); - while ($oUserProfile = $oUserProfileSet->Fetch()) - { + + $this->m_aUserProfiles[$iUser] = []; + $oUserProfileSet = new DBObjectSet($oSearch, [], ['userid' => $iUser]); + while ($oUserProfile = $oUserProfileSet->Fetch()) { $this->m_aUserProfiles[$iUser][$oUserProfile->Get('profileid')] = $oUserProfile; } } @@ -650,18 +606,18 @@ class UserRightsProfile extends UserRightsAddOnAPI public function ResetCache() { // Loaded by Load cache - $this->m_aProfiles = null; - $this->m_aUserProfiles = array(); - $this->m_aUserOrgs = array(); + $this->m_aProfiles = null; + $this->m_aUserProfiles = []; + $this->m_aUserOrgs = []; - $this->m_aAdmins = array(); - $this->m_aPortalUsers = array(); + $this->m_aAdmins = []; + $this->m_aPortalUsers = []; // Loaded on demand (time consuming as compared to the others) $this->m_aClassActionGrants = null; $this->m_aClassStimulusGrants = null; - - $this->m_aObjectActionGrants = array(); + + $this->m_aObjectActionGrants = []; } // Separate load: this cache is much more time consuming while loading @@ -669,14 +625,15 @@ class UserRightsProfile extends UserRightsAddOnAPI // Could be improved by specifying the profile id public function LoadActionGrantCache() { - if (!is_null($this->m_aClassActionGrants)) return; + if (!is_null($this->m_aClassActionGrants)) { + return; + } $oKPI = new ExecutionKPI(); $oFilter = DBObjectSearch::FromOQL_AllData("SELECT URP_ActionGrant AS p WHERE p.permission = 'yes'"); $aGrants = $oFilter->ToDataArray(); - foreach($aGrants as $aGrant) - { + foreach ($aGrants as $aGrant) { $this->m_aClassActionGrants[$aGrant['profileid']][$aGrant['class']][strtolower($aGrant['action'])] = $aGrant['id']; } @@ -685,43 +642,42 @@ class UserRightsProfile extends UserRightsAddOnAPI public function LoadCache() { - if (!is_null($this->m_aProfiles)) return false; + if (!is_null($this->m_aProfiles)) { + return false; + } // Could be loaded in a shared memory (?) $oKPI = new ExecutionKPI(); - if (self::HasSharing()) - { + if (self::HasSharing()) { SharedObject::InitSharedClassProperties(); } $oProfileSet = new DBObjectSet(DBObjectSearch::FromOQL_AllData("SELECT URP_Profiles")); - $this->m_aProfiles = array(); - while ($oProfile = $oProfileSet->Fetch()) - { - $this->m_aProfiles[$oProfile->GetKey()] = $oProfile; + $this->m_aProfiles = []; + while ($oProfile = $oProfileSet->Fetch()) { + $this->m_aProfiles[$oProfile->GetKey()] = $oProfile; } - $this->m_aClassStimulusGrants = array(); + $this->m_aClassStimulusGrants = []; $oStimGrantSet = new DBObjectSet(DBObjectSearch::FromOQL_AllData("SELECT URP_StimulusGrant")); - $this->m_aStimGrants = array(); - while ($oStimGrant = $oStimGrantSet->Fetch()) - { + $this->m_aStimGrants = []; + while ($oStimGrant = $oStimGrantSet->Fetch()) { $this->m_aClassStimulusGrants[$oStimGrant->Get('profileid')][$oStimGrant->Get('class')][$oStimGrant->Get('stimulus')] = $oStimGrant; } $oKPI->ComputeAndReport('Load of user management cache (excepted Action Grants)'); -/* - echo "
\n"; - print_r($this->m_aProfiles); - print_r($this->m_aUserProfiles); - print_r($this->m_aUserOrgs); - print_r($this->m_aClassActionGrants); - print_r($this->m_aClassStimulusGrants); - echo "\n"; -exit; -*/ + /* + echo "
\n"; + print_r($this->m_aProfiles); + print_r($this->m_aUserProfiles); + print_r($this->m_aUserOrgs); + print_r($this->m_aClassActionGrants); + print_r($this->m_aClassStimulusGrants); + echo "\n"; + exit; + */ return true; } @@ -730,17 +686,14 @@ exit; { //$this->LoadCache(); $iUser = $oUser->GetKey(); - if (!array_key_exists($iUser, $this->m_aAdmins)) - { + if (!array_key_exists($iUser, $this->m_aAdmins)) { $bIsAdmin = false; - foreach($this->GetUserProfiles($iUser) as $oUserProfile) - { - if ($oUserProfile->Get('profile') == ADMIN_PROFILE_NAME) - { + foreach ($this->GetUserProfiles($iUser) as $oUserProfile) { + if ($oUserProfile->Get('profile') == ADMIN_PROFILE_NAME) { $bIsAdmin = true; break; - } - } + } + } $this->m_aAdmins[$iUser] = $bIsAdmin; } return $this->m_aAdmins[$iUser]; @@ -750,45 +703,39 @@ exit; { //$this->LoadCache(); $iUser = $oUser->GetKey(); - if (!array_key_exists($iUser, $this->m_aPortalUsers)) - { + if (!array_key_exists($iUser, $this->m_aPortalUsers)) { $bIsPortalUser = false; - foreach($this->GetUserProfiles($iUser) as $oUserProfile) - { - if ($oUserProfile->Get('profile') == PORTAL_PROFILE_NAME) - { + foreach ($this->GetUserProfiles($iUser) as $oUserProfile) { + if ($oUserProfile->Get('profile') == PORTAL_PROFILE_NAME) { $bIsPortalUser = true; break; - } - } + } + } $this->m_aPortalUsers[$iUser] = $bIsPortalUser; } return $this->m_aPortalUsers[$iUser]; } - public function GetSelectFilter($oUser, $sClass, $aSettings = array()) + public function GetSelectFilter($oUser, $sClass, $aSettings = []) { $this->LoadCache(); $aObjectPermissions = $this->GetUserActionGrant($oUser, $sClass, UR_ACTION_READ); - if ($aObjectPermissions['permission'] == UR_ALLOWED_NO) - { + if ($aObjectPermissions['permission'] == UR_ALLOWED_NO) { return false; } // Determine how to position the objects of this class // $sAttCode = self::GetOwnerOrganizationAttCode($sClass); - if (is_null($sAttCode)) - { + if (is_null($sAttCode)) { // No filtering for this object return true; } // Position the user // $aUserOrgs = $this->GetUserOrgs($oUser, $sClass); - if (count($aUserOrgs) == 0) - { + if (count($aUserOrgs) == 0) { // No org means 'any org' return true; } @@ -803,19 +750,15 @@ exit; // Note: action is forced lowercase to be more flexible (historical bug) $sAction = strtolower($sAction); - if (isset($this->m_aClassActionGrants[$iProfile][$sClass][$sAction])) - { + if (isset($this->m_aClassActionGrants[$iProfile][$sClass][$sAction])) { return $this->m_aClassActionGrants[$iProfile][$sClass][$sAction]; } // Recursively look for the grant record in the class hierarchy $sParentClass = MetaModel::GetParentPersistentClass($sClass); - if (empty($sParentClass)) - { + if (empty($sParentClass)) { $iGrant = null; - } - else - { + } else { // Recursively look for the grant record in the class hierarchy $iGrant = $this->GetProfileActionGrant($iProfile, $sParentClass, $sAction); } @@ -832,48 +775,43 @@ exit; // $iUser = $oUser->GetKey(); $aTest = @$this->m_aObjectActionGrants[$iUser][$sClass][$iActionCode]; - if (is_array($aTest)) return $aTest; + if (is_array($aTest)) { + return $aTest; + } $sAction = self::$m_aActionCodes[$iActionCode]; $iPermission = UR_ALLOWED_NO; - $aAttributes = array(); - foreach($this->GetUserProfiles($iUser) as $iProfile => $oProfile) - { - $iGrant = $this->GetProfileActionGrant($iProfile, $sClass, $sAction); - if (is_null($iGrant) || !$iGrant) - { - continue; // loop to the next profile - } - else - { - $iPermission = UR_ALLOWED_YES; + $aAttributes = []; + foreach ($this->GetUserProfiles($iUser) as $iProfile => $oProfile) { + $iGrant = $this->GetProfileActionGrant($iProfile, $sClass, $sAction); + if (is_null($iGrant) || !$iGrant) { + continue; // loop to the next profile + } else { + $iPermission = UR_ALLOWED_YES; - // update the list of attributes with those allowed for this profile - // - $oSearch = DBObjectSearch::FromOQL_AllData("SELECT URP_AttributeGrant WHERE actiongrantid = :actiongrantid"); - $oSet = new DBObjectSet($oSearch, array(), array('actiongrantid' => $iGrant)); - $aProfileAttributes = $oSet->GetColumnAsArray('attcode', false); - if (count($aProfileAttributes) == 0) - { - $aAllAttributes = array_keys(MetaModel::ListAttributeDefs($sClass)); - $aAttributes = array_merge($aAttributes, $aAllAttributes); - } - else - { - $aAttributes = array_merge($aAttributes, $aProfileAttributes); - } + // update the list of attributes with those allowed for this profile + // + $oSearch = DBObjectSearch::FromOQL_AllData("SELECT URP_AttributeGrant WHERE actiongrantid = :actiongrantid"); + $oSet = new DBObjectSet($oSearch, [], ['actiongrantid' => $iGrant]); + $aProfileAttributes = $oSet->GetColumnAsArray('attcode', false); + if (count($aProfileAttributes) == 0) { + $aAllAttributes = array_keys(MetaModel::ListAttributeDefs($sClass)); + $aAttributes = array_merge($aAttributes, $aAllAttributes); + } else { + $aAttributes = array_merge($aAttributes, $aProfileAttributes); } } + } - $aRes = array( + $aRes = [ 'permission' => $iPermission, 'attributes' => $aAttributes, - ); + ]; $this->m_aObjectActionGrants[$iUser][$sClass][$iActionCode] = $aRes; return $aRes; } - + public function IsActionAllowed($oUser, $sClass, $iActionCode, $oInstanceSet = null) { $this->LoadCache(); @@ -884,62 +822,42 @@ exit; // Note: In most cases the object set is ignored because it was interesting to optimize for huge data sets // and acceptable to consider only the root class of the object set - if ($iPermission != UR_ALLOWED_YES) - { + if ($iPermission != UR_ALLOWED_YES) { // It is already NO for everyone... that's the final word! - } - elseif ($iActionCode == UR_ACTION_READ) - { + } elseif ($iActionCode == UR_ACTION_READ) { // We are protected by GetSelectFilter: the object set contains objects allowed or shared for reading - } - elseif ($iActionCode == UR_ACTION_BULK_READ) - { + } elseif ($iActionCode == UR_ACTION_BULK_READ) { // We are protected by GetSelectFilter: the object set contains objects allowed or shared for reading - } - elseif ($oInstanceSet) - { + } elseif ($oInstanceSet) { // We are protected by GetSelectFilter: the object set contains objects allowed or shared for reading // We have to answer NO for objects shared for reading purposes - if (self::HasSharing()) - { + if (self::HasSharing()) { $aClassProps = SharedObject::GetSharedClassProperties($sClass); - if ($aClassProps) - { + if ($aClassProps) { // This class is shared, GetSelectFilter may allow some objects for read only // But currently we are checking wether the objects might be written... // Let's exclude the objects based on the relevant criteria $sOrgAttCode = self::GetOwnerOrganizationAttCode($sClass); - if (!is_null($sOrgAttCode)) - { + if (!is_null($sOrgAttCode)) { $aUserOrgs = $this->GetUserOrgs($oUser, $sClass); - if (!is_null($aUserOrgs) && count($aUserOrgs) > 0) - { + if (!is_null($aUserOrgs) && count($aUserOrgs) > 0) { $iCountNO = 0; $iCountYES = 0; $oInstanceSet->Rewind(); - while($oObject = $oInstanceSet->Fetch()) - { + while ($oObject = $oInstanceSet->Fetch()) { $iOrg = $oObject->Get($sOrgAttCode); - if (in_array($iOrg, $aUserOrgs)) - { + if (in_array($iOrg, $aUserOrgs)) { $iCountYES++; - } - else - { + } else { $iCountNO++; } } - if ($iCountNO == 0) - { + if ($iCountNO == 0) { $iPermission = UR_ALLOWED_YES; - } - elseif ($iCountYES == 0) - { + } elseif ($iCountYES == 0) { $iPermission = UR_ALLOWED_NO; - } - else - { + } else { $iPermission = UR_ALLOWED_DEPENDS; } } @@ -958,12 +876,9 @@ exit; // and acceptable to consider only the root class of the object set $aObjectPermissions = $this->GetUserActionGrant($oUser, $sClass, $iActionCode); $aAttributes = $aObjectPermissions['attributes']; - if (in_array($sAttCode, $aAttributes)) - { + if (in_array($sAttCode, $aAttributes)) { return $aObjectPermissions['permission']; - } - else - { + } else { return UR_ALLOWED_NO; } } @@ -973,12 +888,9 @@ exit; { $this->LoadCache(); - if (isset($this->m_aClassStimulusGrants[$iProfile][$sClass][$sStimulusCode])) - { + if (isset($this->m_aClassStimulusGrants[$iProfile][$sClass][$sStimulusCode])) { return $this->m_aClassStimulusGrants[$iProfile][$sClass][$sStimulusCode]; - } - else - { + } else { return null; } } @@ -992,15 +904,13 @@ exit; // Note: The object set is ignored because it was interesting to optimize for huge data sets // and acceptable to consider only the root class of the object set $iPermission = UR_ALLOWED_NO; - foreach($this->GetUserProfiles($iUser) as $iProfile => $oProfile) - { - $oGrantRecord = $this->GetClassStimulusGrant($iProfile, $sClass, $sStimulusCode); - if (!is_null($oGrantRecord)) - { - // no need to fetch the record, we've requested the records having permission = 'yes' - $iPermission = UR_ALLOWED_YES; - } + foreach ($this->GetUserProfiles($iUser) as $iProfile => $oProfile) { + $oGrantRecord = $this->GetClassStimulusGrant($iProfile, $sClass, $sStimulusCode); + if (!is_null($oGrantRecord)) { + // no need to fetch the record, we've requested the records having permission = 'yes' + $iPermission = UR_ALLOWED_YES; } + } return $iPermission; } @@ -1011,28 +921,22 @@ exit; /** * Find out which attribute is corresponding the the dimension 'owner org' - * returns null if no such attribute has been found (no filtering should occur) - */ + * returns null if no such attribute has been found (no filtering should occur) + */ public static function GetOwnerOrganizationAttCode($sClass) { $sAttCode = null; - $aCallSpec = array($sClass, 'MapContextParam'); - if (($sClass == 'Organization') || is_subclass_of($sClass, 'Organization')) - { + $aCallSpec = [$sClass, 'MapContextParam']; + if (($sClass == 'Organization') || is_subclass_of($sClass, 'Organization')) { $sAttCode = 'id'; - } - elseif (is_callable($aCallSpec)) - { + } elseif (is_callable($aCallSpec)) { $sAttCode = call_user_func($aCallSpec, 'org_id'); // Returns null when there is no mapping for this parameter - if (!MetaModel::IsValidAttCode($sClass, $sAttCode)) - { + if (!MetaModel::IsValidAttCode($sClass, $sAttCode)) { // Skip silently. The data model checker will tell you something about this... $sAttCode = null; } - } - elseif(MetaModel::IsValidAttCode($sClass, 'org_id')) - { + } elseif (MetaModel::IsValidAttCode($sClass, 'org_id')) { $sAttCode = 'org_id'; } @@ -1045,15 +949,11 @@ exit; protected static function HasSharing() { static $bHasSharing; - if (!isset($bHasSharing)) - { + if (!isset($bHasSharing)) { $bHasSharing = class_exists('SharedObject'); } return $bHasSharing; } } - UserRights::SelectModule('UserRightsProfile'); - -?> diff --git a/addons/userrights/userrightsprojection.class.inc.php b/addons/userrights/userrightsprojection.class.inc.php index 3f41725ef..4aa8fe564 100644 --- a/addons/userrights/userrightsprojection.class.inc.php +++ b/addons/userrights/userrightsprojection.class.inc.php @@ -1,4 +1,5 @@ "addon/userrights", "key_type" => "autoincrement", "name_attcode" => "name", - "complementary_name_attcode" => array('description'), + "complementary_name_attcode" => ['description'], "state_attcode" => "", - "reconc_keys" => array(), + "reconc_keys" => [], "db_table" => "priv_urp_profiles", "db_key_field" => "id", "db_finalclass_field" => "", - ); + ]; MetaModel::Init_Params($aParams); //MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeString("name", array("allowed_values"=>null, "sql"=>"name", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeString("description", array("allowed_values"=>null, "sql"=>"description", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array()))); + MetaModel::Init_AddAttribute(new AttributeString("name", ["allowed_values" => null, "sql" => "name", "default_value" => null, "is_null_allowed" => false, "depends_on" => []])); + MetaModel::Init_AddAttribute(new AttributeString("description", ["allowed_values" => null, "sql" => "description", "default_value" => null, "is_null_allowed" => false, "depends_on" => []])); - MetaModel::Init_AddAttribute(new AttributeLinkedSetIndirect("user_list", array("linked_class"=>"URP_UserProfile", "ext_key_to_me"=>"profileid", "ext_key_to_remote"=>"userid", "allowed_values"=>null, "count_min"=>1, "count_max"=>0, "depends_on"=>array()))); + MetaModel::Init_AddAttribute(new AttributeLinkedSetIndirect("user_list", ["linked_class" => "URP_UserProfile", "ext_key_to_me" => "profileid", "ext_key_to_remote" => "userid", "allowed_values" => null, "count_min" => 1, "count_max" => 0, "depends_on" => []])); // Display lists - MetaModel::Init_SetZListItems('details', array('name', 'description', 'user_list')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('description')); // Attributes to be displayed for a list + MetaModel::Init_SetZListItems('details', ['name', 'description', 'user_list']); // Attributes to be displayed for the complete details + MetaModel::Init_SetZListItems('list', ['description']); // Attributes to be displayed for a list // Search criteria - MetaModel::Init_SetZListItems('standard_search', array('name', 'description')); // Criteria of the std search form - MetaModel::Init_SetZListItems('default_search', array ('name', 'description')); + MetaModel::Init_SetZListItems('standard_search', ['name', 'description']); // Criteria of the std search form + MetaModel::Init_SetZListItems('default_search', ['name', 'description']); } - function GetGrantAsHtml($oUserRights, $sClass, $sAction) + public function GetGrantAsHtml($oUserRights, $sClass, $sAction) { $oGrant = $oUserRights->GetClassActionGrant($this->GetKey(), $sClass, $sAction); - if (is_object($oGrant) && ($oGrant->Get('permission') == 'yes')) - { + if (is_object($oGrant) && ($oGrant->Get('permission') == 'yes')) { return ''.Dict::S('UI:UserManagement:ActionAllowed:Yes').''; - } - else - { + } else { return ''.Dict::S('UI:UserManagement:ActionAllowed:No').''; } } - - function DoShowGrantSumary($oPage) + + public function DoShowGrantSumary($oPage) { - if ($this->GetRawName() == "Administrator") - { + if ($this->GetRawName() == "Administrator") { // Looks dirty, but ok that's THE ONE $oPage->p(Dict::S('UI:UserManagement:AdminProfile+')); return; @@ -101,25 +95,24 @@ class URP_Profiles extends UserRightsBaseClass // Note: for sure, we assume that the instance is derived from UserRightsProjection $oUserRights = UserRights::GetModuleInstance(); - - $aDisplayData = array(); - foreach (MetaModel::GetClasses('bizmodel') as $sClass) - { - // Skip non instantiable classes - if (MetaModel::IsAbstract($sClass)) continue; - $aStimuli = array(); - foreach (MetaModel::EnumStimuli($sClass) as $sStimulusCode => $oStimulus) - { + $aDisplayData = []; + foreach (MetaModel::GetClasses('bizmodel') as $sClass) { + // Skip non instantiable classes + if (MetaModel::IsAbstract($sClass)) { + continue; + } + + $aStimuli = []; + foreach (MetaModel::EnumStimuli($sClass) as $sStimulusCode => $oStimulus) { $oGrant = $oUserRights->GetClassStimulusGrant($this->GetKey(), $sClass, $sStimulusCode); - if (is_object($oGrant) && ($oGrant->Get('permission') == 'yes')) - { + if (is_object($oGrant) && ($oGrant->Get('permission') == 'yes')) { $aStimuli[] = ''.utils::EscapeHtml($oStimulus->GetLabel()).''; } } $sStimuli = implode(', ', $aStimuli); - - $aDisplayData[] = array( + + $aDisplayData[] = [ 'class' => MetaModel::GetName($sClass), 'read' => $this->GetGrantAsHtml($oUserRights, $sClass, 'Read'), 'bulkread' => $this->GetGrantAsHtml($oUserRights, $sClass, 'Bulk Read'), @@ -128,22 +121,22 @@ class URP_Profiles extends UserRightsBaseClass 'delete' => $this->GetGrantAsHtml($oUserRights, $sClass, 'Delete'), 'bulkdelete' => $this->GetGrantAsHtml($oUserRights, $sClass, 'Bulk Delete'), 'stimuli' => $sStimuli, - ); + ]; } - - $aDisplayConfig = array(); - $aDisplayConfig['class'] = array('label' => Dict::S('UI:UserManagement:Class'), 'description' => Dict::S('UI:UserManagement:Class+')); - $aDisplayConfig['read'] = array('label' => Dict::S('UI:UserManagement:Action:Read'), 'description' => Dict::S('UI:UserManagement:Action:Read+')); - $aDisplayConfig['bulkread'] = array('label' => Dict::S('UI:UserManagement:Action:BulkRead'), 'description' => Dict::S('UI:UserManagement:Action:BulkRead+')); - $aDisplayConfig['write'] = array('label' => Dict::S('UI:UserManagement:Action:Modify'), 'description' => Dict::S('UI:UserManagement:Action:Modify+')); - $aDisplayConfig['bulkwrite'] = array('label' => Dict::S('UI:UserManagement:Action:BulkModify'), 'description' => Dict::S('UI:UserManagement:Action:BulkModify+')); - $aDisplayConfig['delete'] = array('label' => Dict::S('UI:UserManagement:Action:Delete'), 'description' => Dict::S('UI:UserManagement:Action:Delete+')); - $aDisplayConfig['bulkdelete'] = array('label' => Dict::S('UI:UserManagement:Action:BulkDelete'), 'description' => Dict::S('UI:UserManagement:Action:BulkDelete+')); - $aDisplayConfig['stimuli'] = array('label' => Dict::S('UI:UserManagement:Action:Stimuli'), 'description' => Dict::S('UI:UserManagement:Action:Stimuli+')); + + $aDisplayConfig = []; + $aDisplayConfig['class'] = ['label' => Dict::S('UI:UserManagement:Class'), 'description' => Dict::S('UI:UserManagement:Class+')]; + $aDisplayConfig['read'] = ['label' => Dict::S('UI:UserManagement:Action:Read'), 'description' => Dict::S('UI:UserManagement:Action:Read+')]; + $aDisplayConfig['bulkread'] = ['label' => Dict::S('UI:UserManagement:Action:BulkRead'), 'description' => Dict::S('UI:UserManagement:Action:BulkRead+')]; + $aDisplayConfig['write'] = ['label' => Dict::S('UI:UserManagement:Action:Modify'), 'description' => Dict::S('UI:UserManagement:Action:Modify+')]; + $aDisplayConfig['bulkwrite'] = ['label' => Dict::S('UI:UserManagement:Action:BulkModify'), 'description' => Dict::S('UI:UserManagement:Action:BulkModify+')]; + $aDisplayConfig['delete'] = ['label' => Dict::S('UI:UserManagement:Action:Delete'), 'description' => Dict::S('UI:UserManagement:Action:Delete+')]; + $aDisplayConfig['bulkdelete'] = ['label' => Dict::S('UI:UserManagement:Action:BulkDelete'), 'description' => Dict::S('UI:UserManagement:Action:BulkDelete+')]; + $aDisplayConfig['stimuli'] = ['label' => Dict::S('UI:UserManagement:Action:Stimuli'), 'description' => Dict::S('UI:UserManagement:Action:Stimuli+')]; $oPage->table($aDisplayConfig, $aDisplayData); } - function DisplayBareRelations(WebPage $oPage, $bEditMode = false) + public function DisplayBareRelations(WebPage $oPage, $bEditMode = false) { parent::DisplayBareRelations($oPage, $bEditMode); @@ -152,34 +145,33 @@ class URP_Profiles extends UserRightsBaseClass } } - class URP_Dimensions extends UserRightsBaseClass { public static function Init() { - $aParams = array - ( + $aParams = + [ "category" => "addon/userrights", "key_type" => "autoincrement", "name_attcode" => "name", "state_attcode" => "", - "reconc_keys" => array(), + "reconc_keys" => [], "db_table" => "priv_urp_dimensions", "db_key_field" => "id", "db_finalclass_field" => "", - ); + ]; MetaModel::Init_Params($aParams); //MetaModel::Init_InheritAttributes(); - MetaModel::Init_AddAttribute(new AttributeString("name", array("allowed_values"=>null, "sql"=>"name", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeString("description", array("allowed_values"=>null, "sql"=>"description", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array()))); - MetaModel::Init_AddAttribute(new AttributeClass("type", array("class_category"=>"bizmodel", "more_values"=>"String,Integer", "sql"=>"type", "default_value"=>'String', "is_null_allowed"=>false, "depends_on"=>array()))); + MetaModel::Init_AddAttribute(new AttributeString("name", ["allowed_values" => null, "sql" => "name", "default_value" => null, "is_null_allowed" => false, "depends_on" => []])); + MetaModel::Init_AddAttribute(new AttributeString("description", ["allowed_values" => null, "sql" => "description", "default_value" => null, "is_null_allowed" => false, "depends_on" => []])); + MetaModel::Init_AddAttribute(new AttributeClass("type", ["class_category" => "bizmodel", "more_values" => "String,Integer", "sql" => "type", "default_value" => 'String', "is_null_allowed" => false, "depends_on" => []])); // Display lists - MetaModel::Init_SetZListItems('details', array('name', 'description', 'type')); // Attributes to be displayed for the complete details - MetaModel::Init_SetZListItems('list', array('description')); // Attributes to be displayed for a list + MetaModel::Init_SetZListItems('details', ['name', 'description', 'type']); // Attributes to be displayed for the complete details + MetaModel::Init_SetZListItems('list', ['description']); // Attributes to be displayed for a list // Search criteria - MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form - MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form + MetaModel::Init_SetZListItems('standard_search', ['name']); // Criteria of the std search form + MetaModel::Init_SetZListItems('advanced_search', ['name']); // Criteria of the advanced search form } public function CheckProjectionSpec($oProjectionSpec, $sProjectedClass) @@ -188,191 +180,162 @@ class URP_Dimensions extends UserRightsBaseClass $sAttribute = $oProjectionSpec->Get('attribute'); // Shortcut: "any value" or "no value" means no projection - if (empty($sExpression)) return; - if ($sExpression == '
\n"; - print_r($this->m_aDimensions); - print_r($this->m_aClassProjs); - print_r($this->m_aProfiles); - print_r($this->m_aUserProfiles); - print_r($this->m_aProPros); - echo "\n"; -exit; -*/ + /* + echo "
\n"; + print_r($this->m_aDimensions); + print_r($this->m_aClassProjs); + print_r($this->m_aProfiles); + print_r($this->m_aUserProfiles); + print_r($this->m_aProPros); + echo "\n"; + exit; + */ return true; } - public function GetSelectFilter($oUser, $sClass, $aSettings = array()) + public function GetSelectFilter($oUser, $sClass, $aSettings = []) { - $aConditions = array(); - foreach ($this->m_aDimensions as $iDimension => $oDimension) - { + $aConditions = []; + foreach ($this->m_aDimensions as $iDimension => $oDimension) { $oClassProj = @$this->m_aClassProjs[$sClass][$iDimension]; - if (is_null($oClassProj)) - { + if (is_null($oClassProj)) { // Authorize any for this dimension, then no additional criteria is required continue; } - + // 1 - Get class projection info // $oExpression = null; $sExpr = $oClassProj->Get('value'); - if ($sExpr == '
| ".implode(" | ", $aHeader)." | \n"; $sHtml .= "'; - } - else - { + } else { $oFinalAttDef = $oAttDef->GetFinalAttDef(); - if (get_class($oFinalAttDef) == 'AttributeDateTime') - { + if (get_class($oFinalAttDef) == 'AttributeDateTime') { $sDate = $oObj->Get($sAttCodeEx); - if ($sDate === null) - { + if ($sDate === null) { $aRow[] = ' | '; $aRow[] = ' | '; - } - else - { + } else { $iDate = AttributeDateTime::GetAsUnixSeconds($sDate); - $aRow[] = ' | '.date('Y-m-d', - $iDate).' | '; // Format kept as-is for 100% backward compatibility of the exports - $aRow[] = ''.date('H:i:s', - $iDate).' | '; // Format kept as-is for 100% backward compatibility of the exports + $aRow[] = ''.date( + 'Y-m-d', + $iDate + ).' | '; // Format kept as-is for 100% backward compatibility of the exports + $aRow[] = ''.date( + 'H:i:s', + $iDate + ).' | '; // Format kept as-is for 100% backward compatibility of the exports } - } - else - { - if ($oAttDef instanceof AttributeCaseLog) - { + } else { + if ($oAttDef instanceof AttributeCaseLog) { $rawValue = $oObj->Get($sAttCodeEx); - $outputValue = str_replace("\n", "'.$outputValue.' | '; - } - else - { + } else { $rawValue = $oObj->Get($sAttCodeEx); // Due to custom formatting rules, empty friendlynames may be rendered as non-empty strings // let's fix this and make sure we render an empty string if the key == 0 - if ($oAttDef instanceof AttributeExternalField && $oAttDef->IsFriendlyName()) - { + if ($oAttDef instanceof AttributeExternalField && $oAttDef->IsFriendlyName()) { $sKeyAttCode = $oAttDef->GetKeyAttCode(); - if ($oObj->Get($sKeyAttCode) == 0) - { + if ($oObj->Get($sKeyAttCode) == 0) { $rawValue = ''; } } if ($bLocalize) { $outputValue = utils::EscapeHtml($oFinalAttDef->GetEditValue($rawValue)); - } - else { + } else { $outputValue = utils::EscapeHtml($rawValue); } $aRow[] = ''.$outputValue.' | '; @@ -1917,57 +1850,42 @@ HTML * @throws \MySQLException * @throws \MySQLHasGoneAwayException */ - public static function DisplaySetAsXML(WebPage $oPage, CMDBObjectSet $oSet, $aParams = array()) + public static function DisplaySetAsXML(WebPage $oPage, CMDBObjectSet $oSet, $aParams = []) { $bLocalize = true; - if (isset($aParams['localize_values'])) - { + if (isset($aParams['localize_values'])) { $bLocalize = (bool)$aParams['localize_values']; } $aClasses = $oSet->GetFilter()->GetSelectedClasses(); - $aAuthorizedClasses = array(); - foreach($aClasses as $sAlias => $sClassName) - { - if (UserRights::IsActionAllowed($sClassName, UR_ACTION_READ, $oSet) != UR_ALLOWED_NO) - { + $aAuthorizedClasses = []; + foreach ($aClasses as $sAlias => $sClassName) { + if (UserRights::IsActionAllowed($sClassName, UR_ACTION_READ, $oSet) != UR_ALLOWED_NO) { $aAuthorizedClasses[$sAlias] = $sClassName; } } - $aList = array(); + $aList = []; $aList[$sAlias] = MetaModel::GetZListItems($sClassName, 'details'); $oPage->add("