summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2020-12-02 15:05:20 +0100
committerGitHub <noreply@github.com>2020-12-02 15:05:20 +0100
commite25a62c69dc83ba5655577181f4ea41a47c742b5 (patch)
tree16a7cd45a17b025d6912d5f9b897583fa5e2f4c5 /core
parent0da8221327dbce2bb6e2c9cf69bc21090299f37f (diff)
parent7daef37813e24f9dccca18cf9193b95a0d251b4e (diff)
downloadnextcloud-server-e25a62c69dc83ba5655577181f4ea41a47c742b5.tar.gz
nextcloud-server-e25a62c69dc83ba5655577181f4ea41a47c742b5.zip
Merge pull request #24348 from hosting-de/feature/console-user-display-name
Wrap display_name similarly to email to allow changes via occ
Diffstat (limited to 'core')
-rw-r--r--core/Command/User/Setting.php47
1 files changed, 37 insertions, 10 deletions
diff --git a/core/Command/User/Setting.php b/core/Command/User/Setting.php
index 2ce09fba646..60aecca5a0c 100644
--- a/core/Command/User/Setting.php
+++ b/core/Command/User/Setting.php
@@ -178,10 +178,24 @@ class Setting extends Base {
return 1;
}
- if ($app === 'settings' && $key === 'email') {
+ if ($app === 'settings' && in_array($key , ['email', 'display_name'])) {
$user = $this->userManager->get($uid);
if ($user instanceof IUser) {
- $user->setEMailAddress($input->getArgument('value'));
+ if ($key === 'email') {
+ $user->setEMailAddress($input->getArgument('value'));
+ } elseif ($key === 'display_name') {
+ if (!$user->setDisplayName($input->getArgument('value'))) {
+ if ($user->getDisplayName() === $input->getArgument('value')) {
+ $output->writeln('<error>New and old display name are the same</error>');
+ } elseif ($input->getArgument('value') === '') {
+ $output->writeln('<error>New display name can\'t be empty</error>');
+ } else {
+ $output->writeln('<error>Could not set display name</error>');
+ }
+ return 1;
+ }
+ }
+ // setEmailAddress and setDisplayName both internally set the value
return 0;
}
}
@@ -194,11 +208,17 @@ class Setting extends Base {
return 1;
}
- if ($app === 'settings' && $key === 'email') {
+ if ($app === 'settings' && in_array($key , ['email', 'display_name'])) {
$user = $this->userManager->get($uid);
if ($user instanceof IUser) {
- $user->setEMailAddress('');
- return 0;
+ if ($key === 'email') {
+ $user->setEMailAddress('');
+ // setEmailAddress already deletes the value
+ return 0;
+ } elseif ($key === 'display_name') {
+ $output->writeln('<error>Display name can\'t be deleted.</error>');
+ return 1;
+ }
}
}
@@ -207,14 +227,17 @@ class Setting extends Base {
} elseif ($value !== null) {
$output->writeln($value);
return 0;
+ } elseif ($input->hasParameterOption('--default-value')) {
+ $output->writeln($input->getOption('default-value'));
+ return 0;
} else {
- if ($input->hasParameterOption('--default-value')) {
- $output->writeln($input->getOption('default-value'));
+ if ($app === 'settings' && $key === 'display_name') {
+ $user = $this->userManager->get($uid);
+ $output->writeln($user->getDisplayName());
return 0;
- } else {
- $output->writeln('<error>The setting does not exist for user "' . $uid . '".</error>');
- return 1;
}
+ $output->writeln('<error>The setting does not exist for user "' . $uid . '".</error>');
+ return 1;
}
} else {
$settings = $this->getUserSettings($uid, $app);
@@ -238,6 +261,10 @@ class Setting extends Base {
while ($row = $result->fetch()) {
$settings[$row['appid']][$row['configkey']] = $row['configvalue'];
}
+
+ $user = $this->userManager->get($uid);
+ $settings['settings']['display_name'] = $user->getDisplayName();
+
$result->closeCursor();
return $settings;