diff options
author | John Molakvoæ <skjnldsv@users.noreply.github.com> | 2019-10-05 18:34:14 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-05 18:34:14 +0200 |
commit | 62399c76e81755e385f4c6858c5ee578d19b7e54 (patch) | |
tree | 450dacec7013d4a65cb9d18b1e0ab1a084e96ae7 /lib | |
parent | 637c50e647d4d47d79248497d80ad63a20c09fd6 (diff) | |
parent | b9f963225ff646eabd9c6cd1bb6799eba99d3c79 (diff) | |
download | nextcloud-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')
-rw-r--r-- | lib/composer/composer/autoload_classmap.php | 2 | ||||
-rw-r--r-- | lib/composer/composer/autoload_static.php | 2 | ||||
-rw-r--r-- | lib/private/Group/Database.php | 60 | ||||
-rw-r--r-- | lib/private/Group/Group.php | 15 | ||||
-rw-r--r-- | lib/public/Group/Backend/IGetDisplayNameBackend.php | 3 | ||||
-rw-r--r-- | lib/public/Group/Backend/ISetDisplayNameBackend.php | 38 | ||||
-rw-r--r-- | lib/public/IGroup.php | 9 |
7 files changed, 125 insertions, 4 deletions
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index ab0543b0068..203b6cfecda 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -290,6 +290,7 @@ return array( 'OCP\\Group\\Backend\\IHideFromCollaborationBackend' => $baseDir . '/lib/public/Group/Backend/IHideFromCollaborationBackend.php', 'OCP\\Group\\Backend\\IIsAdminBackend' => $baseDir . '/lib/public/Group/Backend/IIsAdminBackend.php', 'OCP\\Group\\Backend\\IRemoveFromGroupBackend' => $baseDir . '/lib/public/Group/Backend/IRemoveFromGroupBackend.php', + 'OCP\\Group\\Backend\\ISetDisplayNameBackend' => $baseDir . '/lib/public/Group/Backend/ISetDisplayNameBackend.php', 'OCP\\Group\\ISubAdmin' => $baseDir . '/lib/public/Group/ISubAdmin.php', 'OCP\\Http\\Client\\IClient' => $baseDir . '/lib/public/Http/Client/IClient.php', 'OCP\\Http\\Client\\IClientService' => $baseDir . '/lib/public/Http/Client/IClientService.php', @@ -777,6 +778,7 @@ return array( 'OC\\Core\\Migrations\\Version16000Date20190427105638' => $baseDir . '/core/Migrations/Version16000Date20190427105638.php', 'OC\\Core\\Migrations\\Version16000Date20190428150708' => $baseDir . '/core/Migrations/Version16000Date20190428150708.php', 'OC\\Core\\Migrations\\Version17000Date20190514105811' => $baseDir . '/core/Migrations/Version17000Date20190514105811.php', + 'OC\\Core\\Migrations\\Version18000Date20190920085628' => $baseDir . '/core/Migrations/Version18000Date20190920085628.php', 'OC\\Core\\Notification\\RemoveLinkSharesNotifier' => $baseDir . '/core/Notification/RemoveLinkSharesNotifier.php', 'OC\\Core\\Service\\LoginFlowV2Service' => $baseDir . '/core/Service/LoginFlowV2Service.php', 'OC\\DB\\Adapter' => $baseDir . '/lib/private/DB/Adapter.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index d6c449bff48..7641293473c 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -319,6 +319,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OCP\\Group\\Backend\\IHideFromCollaborationBackend' => __DIR__ . '/../../..' . '/lib/public/Group/Backend/IHideFromCollaborationBackend.php', 'OCP\\Group\\Backend\\IIsAdminBackend' => __DIR__ . '/../../..' . '/lib/public/Group/Backend/IIsAdminBackend.php', 'OCP\\Group\\Backend\\IRemoveFromGroupBackend' => __DIR__ . '/../../..' . '/lib/public/Group/Backend/IRemoveFromGroupBackend.php', + 'OCP\\Group\\Backend\\ISetDisplayNameBackend' => __DIR__ . '/../../..' . '/lib/public/Group/Backend/ISetDisplayNameBackend.php', 'OCP\\Group\\ISubAdmin' => __DIR__ . '/../../..' . '/lib/public/Group/ISubAdmin.php', 'OCP\\Http\\Client\\IClient' => __DIR__ . '/../../..' . '/lib/public/Http/Client/IClient.php', 'OCP\\Http\\Client\\IClientService' => __DIR__ . '/../../..' . '/lib/public/Http/Client/IClientService.php', @@ -806,6 +807,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OC\\Core\\Migrations\\Version16000Date20190427105638' => __DIR__ . '/../../..' . '/core/Migrations/Version16000Date20190427105638.php', 'OC\\Core\\Migrations\\Version16000Date20190428150708' => __DIR__ . '/../../..' . '/core/Migrations/Version16000Date20190428150708.php', 'OC\\Core\\Migrations\\Version17000Date20190514105811' => __DIR__ . '/../../..' . '/core/Migrations/Version17000Date20190514105811.php', + 'OC\\Core\\Migrations\\Version18000Date20190920085628' => __DIR__ . '/../../..' . '/core/Migrations/Version18000Date20190920085628.php', 'OC\\Core\\Notification\\RemoveLinkSharesNotifier' => __DIR__ . '/../../..' . '/core/Notification/RemoveLinkSharesNotifier.php', 'OC\\Core\\Service\\LoginFlowV2Service' => __DIR__ . '/../../..' . '/core/Service/LoginFlowV2Service.php', 'OC\\DB\\Adapter' => __DIR__ . '/../../..' . '/lib/private/DB/Adapter.php', 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 * diff --git a/lib/public/Group/Backend/IGetDisplayNameBackend.php b/lib/public/Group/Backend/IGetDisplayNameBackend.php index 69d1742a1e5..2d750b83855 100644 --- a/lib/public/Group/Backend/IGetDisplayNameBackend.php +++ b/lib/public/Group/Backend/IGetDisplayNameBackend.php @@ -28,7 +28,10 @@ namespace OCP\Group\Backend; * @since 17.0.0 */ interface IGetDisplayNameBackend { + /** + * @param string $gid + * @return string * @since 17.0.0 */ public function getDisplayName(string $gid): string; diff --git a/lib/public/Group/Backend/ISetDisplayNameBackend.php b/lib/public/Group/Backend/ISetDisplayNameBackend.php new file mode 100644 index 00000000000..f75be69438d --- /dev/null +++ b/lib/public/Group/Backend/ISetDisplayNameBackend.php @@ -0,0 +1,38 @@ +<?php +declare(strict_types=1); +/** + * @copyright Copyright (c) 2019 Joas Schilling <coding@schilljs.com> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OCP\Group\Backend; + +/** + * @since 18.0.0 + */ +interface ISetDisplayNameBackend { + + /** + * @param string $gid + * @param string $displayName + * @return bool + * @since 18.0.0 + */ + public function setDisplayName(string $gid, string $displayName): bool; + +} diff --git a/lib/public/IGroup.php b/lib/public/IGroup.php index 48fa84df393..8b0eaf0ec0c 100644 --- a/lib/public/IGroup.php +++ b/lib/public/IGroup.php @@ -48,6 +48,15 @@ interface IGroup { public function getDisplayName(); /** + * Set the group display name + * + * @param string $displayName + * @return bool + * @since 18.0.0 + */ + public function setDisplayName(string $displayName): bool; + + /** * get all users in the group * * @return \OCP\IUser[] |