From 653628c8fb69dc3f9d26751520f91e43a18f17ae Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 20 Sep 2019 11:33:02 +0200 Subject: Allow to set the group display name in the database backend Signed-off-by: Joas Schilling --- core/Command/Group/Add.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'core/Command') diff --git a/core/Command/Group/Add.php b/core/Command/Group/Add.php index 61253cf163d..eb2ecd0c533 100644 --- a/core/Command/Group/Add.php +++ b/core/Command/Group/Add.php @@ -28,6 +28,7 @@ use OC\Core\Command\Base; use OCP\IGroupManager; 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 Add extends Base { @@ -49,7 +50,13 @@ class Add extends Base { ->addArgument( 'groupid', InputArgument::REQUIRED, - 'Group name' + 'Group id' + ) + ->addOption( + 'display-name', + null, + InputOption::VALUE_REQUIRED, + 'Group name used in the web UI (can contain any characters)' ); } @@ -62,6 +69,10 @@ class Add extends Base { } else { $group = $this->groupManager->createGroup($gid); $output->writeln('Created group "' . $group->getGID() . '"'); + + if ($input->hasOption('display-name')) { + $group->setDisplayName($input->getOption('display-name')); + } } } } -- cgit v1.2.3 From b9f963225ff646eabd9c6cd1bb6799eba99d3c79 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 27 Sep 2019 14:28:54 +0200 Subject: Do not allow to have an empty display name Signed-off-by: Joas Schilling --- core/Command/Group/Add.php | 5 +++-- lib/private/Group/Database.php | 6 ++++++ 2 files changed, 9 insertions(+), 2 deletions(-) (limited to 'core/Command') diff --git a/core/Command/Group/Add.php b/core/Command/Group/Add.php index eb2ecd0c533..f2ee6195a44 100644 --- a/core/Command/Group/Add.php +++ b/core/Command/Group/Add.php @@ -70,8 +70,9 @@ class Add extends Base { $group = $this->groupManager->createGroup($gid); $output->writeln('Created group "' . $group->getGID() . '"'); - if ($input->hasOption('display-name')) { - $group->setDisplayName($input->getOption('display-name')); + $displayName = trim((string) $input->getOption('display-name')); + if ($displayName !== '') { + $group->setDisplayName($displayName); } } } diff --git a/lib/private/Group/Database.php b/lib/private/Group/Database.php index 21febce8e66..a616146db6d 100644 --- a/lib/private/Group/Database.php +++ b/lib/private/Group/Database.php @@ -109,6 +109,7 @@ class Database extends ABackend $builder = $this->dbConn->getQueryBuilder(); $result = $builder->insert('groups') ->setValue('gid', $builder->createNamedParameter($gid)) + ->setValue('displayname', $builder->createNamedParameter($gid)) ->execute(); } catch(UniqueConstraintViolationException $e) { $result = 0; @@ -451,6 +452,11 @@ class Database extends ABackend $this->fixDI(); + $displayName = trim($displayName); + if ($displayName === '') { + $displayName = $gid; + } + $query = $this->dbConn->getQueryBuilder(); $query->update('groups') ->set('displayname', $query->createNamedParameter($displayName)) -- cgit v1.2.3