diff options
author | brantje <brantje@gmail.com> | 2016-12-30 14:51:32 +0300 |
---|---|---|
committer | brantje <brantje@gmail.com> | 2016-12-30 15:37:40 +0300 |
commit | 7bb18391848e9611a80d7832ca10068f229a4e17 (patch) | |
tree | b8ea4cd476303736415330be6314c04c5d4dd353 /lib | |
parent | 9b83946f0b47253ebac68918c18a62d24134d43e (diff) |
Refactor settings, create SettingsService
Fix settings not working in ownCloud
Signed-off-by: brantje <brantje@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/AppInfo/Application.php | 4 | ||||
-rw-r--r-- | lib/Service/SettingsService.php | 114 | ||||
-rw-r--r-- | lib/Settings/Admin.php | 70 |
3 files changed, 117 insertions, 71 deletions
diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index ca9cdc3a..711365ba 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -36,6 +36,7 @@ use OCA\Passman\Service\FileService; use OCA\Passman\Service\VaultService; use OCA\Passman\Utility\Utils; use OCA\Passman\Service\NotificationService; +Use OCA\Passman\Service\SettingsService; use OCP\IConfig; use OCP\IDBConnection; @@ -72,7 +73,7 @@ class Application extends App { $c->query('CredentialService'), $c->query('NotificationService'), $c->query('FileService'), - $c->query('IConfig') + $c->query('SettingsService') ); }); @@ -112,6 +113,7 @@ class Application extends App { $container->registerAlias('Utils', Utils::class); $container->registerAlias('IDBConnection', IDBConnection::class); $container->registerAlias('IConfig', IConfig::class); + $container->registerAlias('SettingsService', SettingsService::class); } /** diff --git a/lib/Service/SettingsService.php b/lib/Service/SettingsService.php new file mode 100644 index 00000000..c61af779 --- /dev/null +++ b/lib/Service/SettingsService.php @@ -0,0 +1,114 @@ +<?php +/** + * Nextcloud - passman + * + * @copyright Copyright (c) 2016, Sander Brand (brantje@gmail.com) + * @copyright Copyright (c) 2016, Marcos Zuriaga Miguel (wolfi@wolfi.es) + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OCA\Passman\Service; + +use OCP\IConfig; + + +class SettingsService { + + private $userId; + private $config; + private $appName; + public $settings; + + private $numeric_settings = array( + 'link_sharing_enabled', + 'user_sharing_enabled', + 'vault_key_strength', + 'check_version', + 'https_check', + 'disable_contextmenu' + ); + + public function __construct($UserId, IConfig $config, $AppName) { + $this->userId = $UserId; + $this->config = $config; + $this->appName = $AppName; + } + + /** + * Get all app settings + * + * @return array + */ + public function getAppSettings() { + $this->settings = array( + 'link_sharing_enabled' => intval($this->config->getAppValue('passman', 'link_sharing_enabled', 1)), + 'user_sharing_enabled' => intval($this->config->getAppValue('passman', 'user_sharing_enabled', 1)), + 'vault_key_strength' => intval($this->config->getAppValue('passman', 'vault_key_strength', 3)), + 'check_version' => intval($this->config->getAppValue('passman', 'check_version', 1)), + 'https_check' => intval($this->config->getAppValue('passman', 'https_check', 1)), + 'disable_contextmenu' => intval($this->config->getAppValue('passman', 'disable_contextmenu', 1)), + ); + return $this->settings; + } + + /** + * Get a app setting + * + * @param $key string + * @param null $default_value The default value if key does not exist + * @return mixed + */ + public function getAppSetting($key, $default_value = null) { + $value = $this->config->getAppValue('passman', $key, $default_value); + if (in_array($key, $this->numeric_settings)) { + $value = intval($value); + } + return $value; + } + + /** + * Set a app setting + * + * @param $key string Setting name + * @param $value mixed Value of the setting + */ + public function setAppSetting($key, $value) { + $this->config->setAppValue('passman', $key, $value); + } + + /** + * Set a user setting + * + * @param $key string Setting name + * @param $value mixed Value of the setting + */ + + public function setUserSetting($key, $value){ + return $this->config->setUserValue($this->userId, $this->appName, $key, $value); + } + + /** + * Check if an setting is enabled (value of 1) + * + * @param $setting + * @return bool + */ + public function isEnabled($setting){ + $value = intval($this->config->getAppValue('passman', $setting, false)); + return ($value === 1); + } +}
\ No newline at end of file diff --git a/lib/Settings/Admin.php b/lib/Settings/Admin.php deleted file mode 100644 index 90f27ab4..00000000 --- a/lib/Settings/Admin.php +++ /dev/null @@ -1,70 +0,0 @@ -<?php -/** - * Nextcloud - passman - * - * @copyright Copyright (c) 2016, Sander Brand (brantje@gmail.com) - * @copyright Copyright (c) 2016, Marcos Zuriaga Miguel (wolfi@wolfi.es) - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - */ - -namespace OCA\Passman\Settings; - - -use OCP\AppFramework\Http\TemplateResponse; -use OCP\IConfig; -use OCP\IL10N; -use OCP\Settings\ISettings; - -class Admin implements ISettings { - - private $config; - private $l; - - public function __construct( - IConfig $config, - IL10N $l) { - $this->config = $config; - $this->l = $l; - } - - /** - * @return TemplateResponse - */ - public function getForm() { - - return new TemplateResponse('passman', 'settings-admin'); - } - - /** - * @return string the section ID, e.g. 'sharing' - */ - public function getSection() { - return 'additional'; - } - - /** - * @return int whether the form should be rather on the top or bottom of - * the admin section. The forms are arranged in ascending order of the - * priority values. It is required to return a value between 0 and 100. - * - * E.g.: 70 - */ - public function getPriority() { - return 0; - } - -} |