aboutsummaryrefslogtreecommitdiffstats
path: root/core/Command/User/Setting.php
diff options
context:
space:
mode:
Diffstat (limited to 'core/Command/User/Setting.php')
-rw-r--r--core/Command/User/Setting.php121
1 files changed, 56 insertions, 65 deletions
diff --git a/core/Command/User/Setting.php b/core/Command/User/Setting.php
index de621aea182..7fc5aab1dc7 100644
--- a/core/Command/User/Setting.php
+++ b/core/Command/User/Setting.php
@@ -1,61 +1,28 @@
<?php
+
/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Johannes Leuker <j.leuker@hosting.de>
- * @author Kim Brose <kim.brose@rwth-aachen.de>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * 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, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
-
namespace OC\Core\Command\User;
use OC\Core\Command\Base;
use OCP\IConfig;
-use OCP\IDBConnection;
use OCP\IUser;
use OCP\IUserManager;
+use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class Setting extends Base {
- /** @var IUserManager */
- protected $userManager;
-
- /** @var IConfig */
- protected $config;
-
- /** @var IDBConnection */
- protected $connection;
-
- /**
- * @param IUserManager $userManager
- * @param IConfig $config
- * @param IDBConnection $connection
- */
- public function __construct(IUserManager $userManager, IConfig $config, IDBConnection $connection) {
+ public function __construct(
+ protected IUserManager $userManager,
+ protected IConfig $config,
+ ) {
parent::__construct();
- $this->userManager = $userManager;
- $this->config = $config;
- $this->connection = $connection;
}
protected function configure() {
@@ -66,7 +33,7 @@ class Setting extends Base {
->addArgument(
'uid',
InputArgument::REQUIRED,
- 'User ID used to login'
+ 'Account ID used to login'
)
->addArgument(
'app',
@@ -126,9 +93,14 @@ class Setting extends Base {
}
protected function checkInput(InputInterface $input) {
- $uid = $input->getArgument('uid');
- if (!$input->getOption('ignore-missing-user') && !$this->userManager->userExists($uid)) {
- throw new \InvalidArgumentException('The user "' . $uid . '" does not exist.');
+ if (!$input->getOption('ignore-missing-user')) {
+ $uid = $input->getArgument('uid');
+ $user = $this->userManager->get($uid);
+ if (!$user) {
+ throw new \InvalidArgumentException('The user "' . $uid . '" does not exist.');
+ }
+ // normalize uid
+ $input->setArgument('uid', $user->getUID());
}
if ($input->getArgument('key') === '' && $input->hasParameterOption('--default-value')) {
@@ -179,11 +151,12 @@ class Setting extends Base {
return 1;
}
- if ($app === 'settings' && in_array($key , ['email', 'display_name'])) {
+ if ($app === 'settings' && in_array($key, ['email', 'display_name'])) {
$user = $this->userManager->get($uid);
if ($user instanceof IUser) {
if ($key === 'email') {
- $user->setEMailAddress($input->getArgument('value'));
+ $email = $input->getArgument('value');
+ $user->setSystemEMailAddress(mb_strtolower(trim($email)));
} elseif ($key === 'display_name') {
if (!$user->setDisplayName($input->getArgument('value'))) {
if ($user->getDisplayName() === $input->getArgument('value')) {
@@ -209,7 +182,7 @@ class Setting extends Base {
return 1;
}
- if ($app === 'settings' && in_array($key , ['email', 'display_name'])) {
+ if ($app === 'settings' && in_array($key, ['email', 'display_name'])) {
$user = $this->userManager->get($uid);
if ($user instanceof IUser) {
if ($key === 'email') {
@@ -247,27 +220,45 @@ class Setting extends Base {
}
}
- protected function getUserSettings($uid, $app) {
- $query = $this->connection->getQueryBuilder();
- $query->select('*')
- ->from('preferences')
- ->where($query->expr()->eq('userid', $query->createNamedParameter($uid)));
-
+ protected function getUserSettings(string $uid, string $app): array {
+ $settings = $this->config->getAllUserValues($uid);
if ($app !== '') {
- $query->andWhere($query->expr()->eq('appid', $query->createNamedParameter($app)));
- }
-
- $result = $query->execute();
- $settings = [];
- while ($row = $result->fetch()) {
- $settings[$row['appid']][$row['configkey']] = $row['configvalue'];
+ if (isset($settings[$app])) {
+ $settings = [$app => $settings[$app]];
+ } else {
+ $settings = [];
+ }
}
$user = $this->userManager->get($uid);
- $settings['settings']['display_name'] = $user->getDisplayName();
-
- $result->closeCursor();
+ if ($user !== null) {
+ // Only add the display name if the user exists
+ $settings['settings']['display_name'] = $user->getDisplayName();
+ }
return $settings;
}
+
+ /**
+ * @param string $argumentName
+ * @param CompletionContext $context
+ * @return string[]
+ */
+ public function completeArgumentValues($argumentName, CompletionContext $context) {
+ if ($argumentName === 'uid') {
+ return array_map(static fn (IUser $user) => $user->getUID(), $this->userManager->search($context->getCurrentWord()));
+ }
+ if ($argumentName === 'app') {
+ $userId = $context->getWordAtIndex($context->getWordIndex() - 1);
+ $settings = $this->getUserSettings($userId, '');
+ return array_keys($settings);
+ }
+ if ($argumentName === 'key') {
+ $userId = $context->getWordAtIndex($context->getWordIndex() - 2);
+ $app = $context->getWordAtIndex($context->getWordIndex() - 1);
+ $settings = $this->getUserSettings($userId, $app);
+ return array_keys($settings[$app]);
+ }
+ return [];
+ }
}