Browse Source

Do not allow to have an empty display name

Signed-off-by: Joas Schilling <coding@schilljs.com>
Joas Schilling 5 years ago
parent
commit
b9f963225f
2 changed files with 9 additions and 2 deletions
  1. 3 2
      core/Command/Group/Add.php
  2. 6 0
      lib/private/Group/Database.php

+ 3 - 2
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);
 			}
 		}
 	}

+ 6 - 0
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))