From fd085f5fde32c274161b4c4f08af7da3b29532fa Mon Sep 17 00:00:00 2001 From: yuri Date: Tue, 19 Dec 2017 16:43:30 +0200 Subject: [PATCH] fix settings admin items --- application/Espo/Core/Utils/Config.php | 26 ++++++++++++++++++++++++++ application/Espo/Services/App.php | 16 ++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/application/Espo/Core/Utils/Config.php b/application/Espo/Core/Utils/Config.php index dd3b58fb20..50cc7647b4 100644 --- a/application/Espo/Core/Utils/Config.php +++ b/application/Espo/Core/Utils/Config.php @@ -117,6 +117,32 @@ class Config return $lastBranch; } + /** + * Whether parameter is set + * + * @param string $name + * @return bool + */ + public function has($name) + { + $keys = explode('.', $name); + + $lastBranch = $this->loadConfig(); + foreach ($keys as $keyName) { + if (isset($lastBranch[$keyName]) && (is_array($lastBranch) || is_object($lastBranch))) { + if (is_array($lastBranch)) { + $lastBranch = $lastBranch[$keyName]; + } else { + $lastBranch = $lastBranch->$keyName; + } + } else { + return false; + } + } + + return true; + } + /** * Set an option to the config * diff --git a/application/Espo/Services/App.php b/application/Espo/Services/App.php index 4357613a2f..ab58db9109 100644 --- a/application/Espo/Services/App.php +++ b/application/Espo/Services/App.php @@ -43,6 +43,7 @@ class App extends \Espo\Core\Services\Base $this->addDependency('acl'); $this->addDependency('container'); $this->addDependency('entityManager'); + $this->addDependency('metadata'); } protected function getPreferences() @@ -83,6 +84,21 @@ class App extends \Espo\Core\Services\Base $settings->$item = $this->getConfig()->get($item); } + if ($this->getUser()->isAdmin()) { + foreach ($this->getConfig()->get('adminItems') as $item) { + if ($this->getConfig()->has($item)) { + $settings->$item = $this->getConfig()->get($item); + } + } + } + + $settingsFieldDefs = $this->getInjection('metadata')->get('entityDefs.Settings.fields', []); + foreach ($settingsFieldDefs as $field => $d) { + if ($d['type'] === 'password') { + unset($settings->$field); + } + } + unset($userData->authTokenId); unset($userData->password);