aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/lib/Service/UserConfig.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files/lib/Service/UserConfig.php')
-rw-r--r--apps/files/lib/Service/UserConfig.php94
1 files changed, 66 insertions, 28 deletions
diff --git a/apps/files/lib/Service/UserConfig.php b/apps/files/lib/Service/UserConfig.php
index e405b02c07a..dcf30b7796d 100644
--- a/apps/files/lib/Service/UserConfig.php
+++ b/apps/files/lib/Service/UserConfig.php
@@ -1,24 +1,8 @@
<?php
+
/**
- * @copyright Copyright (c) 2022 John Molakvoæ <skjnldsv@protonmail.com>
- *
- * @author John Molakvoæ <skjnldsv@protonmail.com>
- *
- * @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/>.
- *
+ * SPDX-FileCopyrightText: 2022 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Files\Service;
@@ -28,7 +12,7 @@ use OCP\IUser;
use OCP\IUserSession;
class UserConfig {
- const ALLOWED_CONFIGS = [
+ public const ALLOWED_CONFIGS = [
[
// Whether to crop the files previews or not in the files list
'key' => 'crop_image_previews',
@@ -36,18 +20,72 @@ class UserConfig {
'allowed' => [true, false],
],
[
+ // The view to start the files app in
+ 'key' => 'default_view',
+ 'default' => 'files',
+ 'allowed' => ['files', 'personal'],
+ ],
+ [
+ // Whether to show the folder tree
+ 'key' => 'folder_tree',
+ 'default' => true,
+ 'allowed' => [true, false],
+ ],
+ [
+ // Whether to show the files list in grid view or not
+ 'key' => 'grid_view',
+ 'default' => false,
+ 'allowed' => [true, false],
+ ],
+ [
+ // Whether to show the "confirm file deletion" warning
+ 'key' => 'show_dialog_deletion',
+ 'default' => false,
+ 'allowed' => [true, false],
+ ],
+ [
+ // Whether to show the "confirm file extension change" warning
+ 'key' => 'show_dialog_file_extension',
+ 'default' => true,
+ 'allowed' => [true, false],
+ ],
+ [
+ // Whether to show the files extensions in the files list or not
+ 'key' => 'show_files_extensions',
+ 'default' => true,
+ 'allowed' => [true, false],
+ ],
+ [
// Whether to show the hidden files or not in the files list
'key' => 'show_hidden',
'default' => false,
'allowed' => [true, false],
],
+ [
+ // Whether to show the mime column or not
+ 'key' => 'show_mime_column',
+ 'default' => false,
+ 'allowed' => [true, false],
+ ],
+ [
+ // Whether to sort favorites first in the list or not
+ 'key' => 'sort_favorites_first',
+ 'default' => true,
+ 'allowed' => [true, false],
+ ],
+ [
+ // Whether to sort folders before files in the list or not
+ 'key' => 'sort_folders_first',
+ 'default' => true,
+ 'allowed' => [true, false],
+ ],
];
-
- protected IConfig $config;
protected ?IUser $user = null;
- public function __construct(IConfig $config, IUserSession $userSession) {
- $this->config = $config;
+ public function __construct(
+ protected IConfig $config,
+ IUserSession $userSession,
+ ) {
$this->user = $userSession->getUser();
}
@@ -56,7 +94,7 @@ class UserConfig {
* @return string[]
*/
public function getAllowedConfigKeys(): array {
- return array_map(function($config) {
+ return array_map(function ($config) {
return $config['key'];
}, self::ALLOWED_CONFIGS);
}
@@ -107,7 +145,7 @@ class UserConfig {
if (!in_array($key, $this->getAllowedConfigKeys())) {
throw new \InvalidArgumentException('Unknown config key');
}
-
+
if (!in_array($value, $this->getAllowedConfigValues($key))) {
throw new \InvalidArgumentException('Invalid config value');
}
@@ -130,10 +168,10 @@ class UserConfig {
}
$userId = $this->user->getUID();
- $userConfigs = array_map(function(string $key) use ($userId) {
+ $userConfigs = array_map(function (string $key) use ($userId) {
$value = $this->config->getUserValue($userId, Application::APP_ID, $key, $this->getDefaultConfigValue($key));
// If the default is expected to be a boolean, we need to cast the value
- if (is_bool($this->getDefaultConfigValue($key))) {
+ if (is_bool($this->getDefaultConfigValue($key)) && is_string($value)) {
return $value === '1';
}
return $value;