]> source.dussan.org Git - nextcloud-server.git/commitdiff
Allow to set the group display name in the database backend
authorJoas Schilling <coding@schilljs.com>
Fri, 20 Sep 2019 09:33:02 +0000 (11:33 +0200)
committerJoas Schilling <coding@schilljs.com>
Fri, 27 Sep 2019 12:29:56 +0000 (14:29 +0200)
Signed-off-by: Joas Schilling <coding@schilljs.com>
apps/provisioning_api/appinfo/routes.php
apps/provisioning_api/lib/Controller/GroupsController.php
core/Command/Group/Add.php
lib/private/Group/Database.php
lib/private/Group/Group.php
lib/public/Group/Backend/ISetDisplayNameBackend.php [new file with mode: 0644]
lib/public/IGroup.php

index fb0a6b235ce78baeeee06d46fe168c9f3b996b5d..ef13159af5b958f4a937987c34d15a30972d6cd7 100644 (file)
@@ -40,6 +40,7 @@ return [
                ['root' => '/cloud', 'name' => 'Groups#getSubAdminsOfGroup', 'url' => '/groups/{groupId}/subadmins', 'verb' => 'GET', 'requirements' => ['groupId' => '.+']],
                ['root' => '/cloud', 'name' => 'Groups#addGroup', 'url' => '/groups', 'verb' => 'POST'],
                ['root' => '/cloud', 'name' => 'Groups#getGroup', 'url' => '/groups/{groupId}', 'verb' => 'GET', 'requirements' => ['groupId' => '.+']],
+               ['root' => '/cloud', 'name' => 'Groups#updateGroup', 'url' => '/groups/{groupId}', 'verb' => 'PUT', 'requirements' => ['groupId' => '.+']],
                ['root' => '/cloud', 'name' => 'Groups#deleteGroup', 'url' => '/groups/{groupId}', 'verb' => 'DELETE', 'requirements' => ['groupId' => '.+']],
 
                // Users
index 7c4447ac4ebea7594a69ee1400e7f6118f8cb793..72285f55192b62cca6d118890b1be0af0cd5eabf 100644 (file)
@@ -129,7 +129,7 @@ class GroupsController extends AUserData {
         *
         * @param string $groupId
         * @return DataResponse
-        * @throws OCSException 
+        * @throws OCSException
         *
         * @deprecated 14 Use getGroupUsers
         */
@@ -248,6 +248,28 @@ class GroupsController extends AUserData {
                return new DataResponse();
        }
 
+       /**
+        * @PasswordConfirmationRequired
+        *
+        * @param string $groupId
+        * @param string $key
+        * @param string $value
+        * @return DataResponse
+        * @throws OCSException
+        */
+       public function updateGroup(string $groupId, string $key, string $value): DataResponse {
+               if ($key === 'displayname') {
+                       $group = $this->groupManager->get($groupId);
+                       if ($group->setDisplayName($value)) {
+                               return new DataResponse();
+                       }
+
+                       throw new OCSException('Not supported by backend', 101);
+               } else {
+                       throw new OCSException('', \OCP\API::RESPOND_UNAUTHORISED);
+               }
+       }
+
        /**
         * @PasswordConfirmationRequired
         *
index 61253cf163de86c8e01d4ae98ec373bf7ca321de..eb2ecd0c5339960d41617c7bbe66fc38ecb9baff 100644 (file)
@@ -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'));
+                       }
                }
        }
 }
index 5e39398c60da65381751de12217435964f7237b8..4aab8b8eaecc91802b472792bd5e518c5e408744 100644 (file)
@@ -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;
+       }
+
 }
index a50a5ffde78431178288e3ab7ed40104c90ff367..8d86425c8e57fab0e3328e38f312d26175453db7 100644 (file)
@@ -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 (file)
index 0000000..f75be69
--- /dev/null
@@ -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;
+
+}
index 48fa84df393d6c12b7a80cadd8b0e5b53de7a8c2..8b0eaf0ec0c455fa0eef6231890ba088e7cbe043 100644 (file)
@@ -47,6 +47,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
         *