aboutsummaryrefslogtreecommitdiffstats
path: root/core/Command/User
diff options
context:
space:
mode:
authorJohannes Leuker <j.leuker@hosting.de>2019-07-15 14:52:05 +0200
committerJohannes Leuker <j.leuker@hosting.de>2020-12-02 10:27:57 +0100
commit7daef37813e24f9dccca18cf9193b95a0d251b4e (patch)
tree2c86a1a6bf8bfd04e35067a7efbe3377a28ea54f /core/Command/User
parent6156a49f6ed258da2e4949f16d331959af537adb (diff)
downloadnextcloud-server-7daef37813e24f9dccca18cf9193b95a0d251b4e.tar.gz
nextcloud-server-7daef37813e24f9dccca18cf9193b95a0d251b4e.zip
Wrap display_name similarly to email to allow changes via occ
Signed-off-by: Johannes Leuker <j.leuker@hosting.de>
Diffstat (limited to 'core/Command/User')
-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;