diff options
author | Joas Schilling <coding@schilljs.com> | 2019-09-20 11:33:02 +0200 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2019-09-27 14:29:56 +0200 |
commit | 653628c8fb69dc3f9d26751520f91e43a18f17ae (patch) | |
tree | ef2dfb5f01bc19e09386364895ec9c8620ec3257 /lib | |
parent | 45506adc5c2a34a8c812a2a3c9273a8447b450af (diff) | |
download | nextcloud-server-653628c8fb69dc3f9d26751520f91e43a18f17ae.tar.gz nextcloud-server-653628c8fb69dc3f9d26751520f91e43a18f17ae.zip |
Allow to set the group display name in the database backend
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Group/Database.php | 24 | ||||
-rw-r--r-- | lib/private/Group/Group.php | 15 | ||||
-rw-r--r-- | lib/public/Group/Backend/ISetDisplayNameBackend.php | 38 | ||||
-rw-r--r-- | lib/public/IGroup.php | 9 |
4 files changed, 85 insertions, 1 deletions
diff --git a/lib/private/Group/Database.php b/lib/private/Group/Database.php index 5e39398c60d..4aab8b8eaec 100644 --- a/lib/private/Group/Database.php +++ b/lib/private/Group/Database.php @@ -52,6 +52,7 @@ 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; /** @@ -65,7 +66,8 @@ class Database extends ABackend IDeleteGroupBackend, IGetDisplayNameBackend, IGroupDetailsBackend, - IRemoveFromGroupBackend { + IRemoveFromGroupBackend, + ISetDisplayNameBackend { /** @var string[] */ private $groupCache = []; @@ -450,4 +452,24 @@ class Database extends ABackend return []; } + /** + * @param string $gid + * @param string $displayName + * @return bool + * @since 18.0.0 + */ + public function setDisplayName(string $gid, string $displayName): bool { + if (!$this->groupExists($gid)) { + return false; + } + + $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/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[] |