diff options
author | Michael Weimann <mail@michael-weimann.eu> | 2018-12-19 23:13:35 +0100 |
---|---|---|
committer | Michael Weimann <mail@michael-weimann.eu> | 2019-01-14 00:08:24 +0100 |
commit | 813ff430f159fdc8aade236048f4a8ff18ac3b2e (patch) | |
tree | bb8fe0773a03ed43dba3c9cdecbb3343251fdb1a /lib | |
parent | 6993faaf67b6e822f7b03bd972fe42c9b4dd1d5d (diff) | |
download | nextcloud-server-813ff430f159fdc8aade236048f4a8ff18ac3b2e.tar.gz nextcloud-server-813ff430f159fdc8aade236048f4a8ff18ac3b2e.zip |
Implement storing and loading the server info
Signed-off-by: Michael Weimann <mail@michael-weimann.eu>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Settings/Admin/ServerInfo.php | 86 | ||||
-rw-r--r-- | lib/private/Settings/Personal/PersonalInfo.php | 14 |
2 files changed, 91 insertions, 9 deletions
diff --git a/lib/private/Settings/Admin/ServerInfo.php b/lib/private/Settings/Admin/ServerInfo.php index e4c7a83ed87..8ac4f890504 100644 --- a/lib/private/Settings/Admin/ServerInfo.php +++ b/lib/private/Settings/Admin/ServerInfo.php @@ -1,26 +1,104 @@ <?php +/** + * @copyright Copyright (c) 2018 Michael Weimann <mail@michael-weimann.eu> + * + * @author Michael Weimann <mail@michael-weimann.eu> + * + * @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 OC\Settings\Admin; use OCP\AppFramework\Http\TemplateResponse; +use OCP\IConfig; +use OCP\IGroupManager; +use OCP\IUser; use OCP\Settings\ISettings; /** - * Class ServerInfo - * - * @package OC\Settings\Admin + * This class describes the server info settings. */ class ServerInfo implements ISettings { + const SETTING_LOCATION = 'serverinfo.location'; + const SETTING_PROVIDER = 'serverinfo.provider'; + const SETTING_PROVIDER_WEBSITE = 'serverinfo.provider.website'; + const SETTING_PROVIDER_PRIVACY_LINK = 'serverinfo.provider.privacylink'; + const SETTING_PROVIDER_ADMIN_CONTACT = 'serverinfo.admincontact'; + + /** + * @var IConfig + */ + private $config; + + /** + * @var IGroupManager + */ + private $groupManager; + + /** + * ServerInfo constructor. + * + * @param IConfig $config + * @param IGroupManager $groupManager + */ + public function __construct(IConfig $config, IGroupManager $groupManager) { + $this->config = $config; + $this->groupManager = $groupManager; + } + /** * @return TemplateResponse */ public function getForm() { - $parameters = []; + $parameters = [ + 'location' => $this->config->getSystemValue(self::SETTING_LOCATION), + 'provider' => $this->config->getSystemValue(self::SETTING_PROVIDER), + 'providerWebsite' => $this->config->getSystemValue(self::SETTING_PROVIDER_WEBSITE), + 'providerPrivacyLink' => $this->config->getSystemValue(self::SETTING_PROVIDER_PRIVACY_LINK), + 'adminUsers' => $this->getAdminListValues(), + 'adminContact' => $this->config->getSystemValue(self::SETTING_PROVIDER_ADMIN_CONTACT), + ]; return new TemplateResponse('settings', 'settings/admin/server-info', $parameters, ''); } /** + * Returns the admin list values. + * + * @return array[] An array or arrays with the keys 'id' and 'displayName' + */ + private function getAdminListValues() { + $adminGroup = $this->groupManager->get('admin'); + $users = $adminGroup->getUsers(); + + $users = array_map(function(IUser $user) { + return [ + 'id' => $user->getUID(), + 'displayName' => $user->getDisplayName() + ]; + }, $users); + + usort($your_data, function(array $a, array $b) { + return strcmp($a['displayName'], $b['displayName']); + }); + + return $users; + } + + /** * Returns the server info section id. * * @return string diff --git a/lib/private/Settings/Personal/PersonalInfo.php b/lib/private/Settings/Personal/PersonalInfo.php index 42a89a5f309..444600f967a 100644 --- a/lib/private/Settings/Personal/PersonalInfo.php +++ b/lib/private/Settings/Personal/PersonalInfo.php @@ -26,6 +26,7 @@ namespace OC\Settings\Personal; use OC\Accounts\AccountManager; +use OC\Settings\Admin\ServerInfo; use OCA\FederatedFileSharing\AppInfo\Application; use OCP\App\IAppManager; use OCP\AppFramework\Http\TemplateResponse; @@ -115,6 +116,9 @@ class PersonalInfo implements ISettings { $localeParameters = $this->getLocales($user); $messageParameters = $this->getMessageParameters($userData); + $adminContactConfigId = $this->config->getSystemValue(ServerInfo::SETTING_PROVIDER_ADMIN_CONTACT); + $adminContact = $this->userManager->get($adminContactConfigId); + $parameters = [ 'total_space' => $totalSpace, 'usage' => \OC_Helper::humanFileSize($storageInfo['used']), @@ -141,12 +145,12 @@ class PersonalInfo implements ISettings { 'twitterVerification' => $userData[AccountManager::PROPERTY_TWITTER]['verified'], 'groups' => $this->getGroups($user), 'dataLocation' => 'Germany', - 'provider' => 'Mustermann GmbH', - 'providerLink' => 'https://www.hetzner.de/', - 'providerPrivacyLink' => 'https://www.hetzner.de/rechtliches/datenschutz', + 'provider' => $this->config->getSystemValue(ServerInfo::SETTING_PROVIDER), + 'providerLink' => $this->config->getSystemValue(ServerInfo::SETTING_PROVIDER_WEBSITE), + 'providerPrivacyLink' => $this->config->getSystemValue(ServerInfo::SETTING_PROVIDER_PRIVACY_LINK), 'encryptionEnabled' => true || $this->encryptionManager->isEnabled(), - 'adminName' => 'Michael Weimann', - 'adminMail' => 'mail@michael-weimann.eu' + 'adminName' => $adminContact !== null ? $adminContact->getDisplayName() : '', + 'adminMail' => $adminContact !== null ? $adminContact->getEMailAddress() : '', ] + $messageParameters + $languageParameters + $localeParameters; return new TemplateResponse('settings', 'settings/personal/personal.info', $parameters, ''); |