summaryrefslogtreecommitdiffstats
path: root/lib/private/Group
diff options
context:
space:
mode:
authorJohn Molakvoæ <skjnldsv@users.noreply.github.com>2019-10-05 18:34:14 +0200
committerGitHub <noreply@github.com>2019-10-05 18:34:14 +0200
commit62399c76e81755e385f4c6858c5ee578d19b7e54 (patch)
tree450dacec7013d4a65cb9d18b1e0ab1a084e96ae7 /lib/private/Group
parent637c50e647d4d47d79248497d80ad63a20c09fd6 (diff)
parentb9f963225ff646eabd9c6cd1bb6799eba99d3c79 (diff)
downloadnextcloud-server-62399c76e81755e385f4c6858c5ee578d19b7e54.tar.gz
nextcloud-server-62399c76e81755e385f4c6858c5ee578d19b7e54.zip
Allow group displaynames in the database backend (#17221)
Allow group displaynames in the database backend
Diffstat (limited to 'lib/private/Group')
-rw-r--r--lib/private/Group/Database.php60
-rw-r--r--lib/private/Group/Group.php15
2 files changed, 71 insertions, 4 deletions
diff --git a/lib/private/Group/Database.php b/lib/private/Group/Database.php
index 4df70f143ba..7028b1fa81b 100644
--- a/lib/private/Group/Database.php
+++ b/lib/private/Group/Database.php
@@ -49,7 +49,10 @@ use OCP\Group\Backend\ICountDisabledInGroup;
use OCP\Group\Backend\ICountUsersBackend;
use OCP\Group\Backend\ICreateGroupBackend;
use OCP\Group\Backend\IDeleteGroupBackend;
+use OCP\Group\Backend\IGetDisplayNameBackend;
+use OCP\Group\Backend\IGroupDetailsBackend;
use OCP\Group\Backend\IRemoveFromGroupBackend;
+use OCP\Group\Backend\ISetDisplayNameBackend;
use OCP\IDBConnection;
/**
@@ -61,7 +64,10 @@ class Database extends ABackend
ICountUsersBackend,
ICreateGroupBackend,
IDeleteGroupBackend,
- IRemoveFromGroupBackend {
+ IGetDisplayNameBackend,
+ IGroupDetailsBackend,
+ IRemoveFromGroupBackend,
+ ISetDisplayNameBackend {
/** @var string[] */
private $groupCache = [];
@@ -103,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;
@@ -396,7 +403,7 @@ class Database extends ABackend
*/
public function countDisabledInGroup(string $gid): int {
$this->fixDI();
-
+
$query = $this->dbConn->getQueryBuilder();
$query->select($query->createFunction('COUNT(DISTINCT ' . $query->getColumnName('uid') . ')'))
->from('preferences', 'p')
@@ -405,11 +412,11 @@ class Database extends ABackend
->andWhere($query->expr()->eq('configkey', $query->createNamedParameter('enabled')))
->andWhere($query->expr()->eq('configvalue', $query->createNamedParameter('false'), IQueryBuilder::PARAM_STR))
->andWhere($query->expr()->eq('gid', $query->createNamedParameter($gid), IQueryBuilder::PARAM_STR));
-
+
$result = $query->execute();
$count = $result->fetchColumn();
$result->closeCursor();
-
+
if ($count !== false) {
$count = (int)$count;
} else {
@@ -419,4 +426,49 @@ class Database extends ABackend
return $count;
}
+ public function getDisplayName(string $gid): string {
+ $this->fixDI();
+
+ $query = $this->dbConn->getQueryBuilder();
+ $query->select('displayname')
+ ->from('groups')
+ ->where($query->expr()->eq('gid', $query->createNamedParameter($gid)));
+
+ $result = $query->execute();
+ $displayName = $result->fetchColumn();
+ $result->closeCursor();
+
+ return (string) $displayName;
+ }
+
+ public function getGroupDetails(string $gid): array {
+ $displayName = $this->getDisplayName($gid);
+ if ($displayName !== '') {
+ return ['displayName' => $displayName];
+ }
+
+ return [];
+ }
+
+ public function setDisplayName(string $gid, string $displayName): bool {
+ if (!$this->groupExists($gid)) {
+ return false;
+ }
+
+ $this->fixDI();
+
+ $displayName = trim($displayName);
+ if ($displayName === '') {
+ $displayName = $gid;
+ }
+
+ $query = $this->dbConn->getQueryBuilder();
+ $query->update('groups')
+ ->set('displayname', $query->createNamedParameter($displayName))
+ ->where($query->expr()->eq('gid', $query->createNamedParameter($gid)));
+ $query->execute();
+
+ return true;
+ }
+
}
diff --git a/lib/private/Group/Group.php b/lib/private/Group/Group.php
index a50a5ffde78..8d86425c8e5 100644
--- a/lib/private/Group/Group.php
+++ b/lib/private/Group/Group.php
@@ -33,6 +33,7 @@ namespace OC\Group;
use OCP\Group\Backend\IGetDisplayNameBackend;
use OCP\Group\Backend\IHideFromCollaborationBackend;
use OC\Hooks\PublicEmitter;
+use OCP\Group\Backend\ISetDisplayNameBackend;
use OCP\GroupInterface;
use OCP\IGroup;
use OCP\IUser;
@@ -101,6 +102,20 @@ class Group implements IGroup {
return $this->displayName;
}
+ public function setDisplayName(string $displayName): bool {
+ $displayName = trim($displayName);
+ if ($displayName !== '') {
+ foreach ($this->backends as $backend) {
+ if (($backend instanceof ISetDisplayNameBackend)
+ && $backend->setDisplayName($this->gid, $displayName)) {
+ $this->displayName = $displayName;
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
/**
* get all users in the group
*