]> source.dussan.org Git - nextcloud-server.git/commitdiff
allow group backends to mark that a group should now be shown in search dialogs
authorRobin Appelman <robin@icewind.nl>
Fri, 22 Feb 2019 15:36:25 +0000 (16:36 +0100)
committerRobin Appelman <robin@icewind.nl>
Mon, 25 Feb 2019 15:06:09 +0000 (16:06 +0100)
Signed-off-by: Robin Appelman <robin@icewind.nl>
lib/private/Collaboration/Collaborators/GroupPlugin.php
lib/private/Group/Group.php
lib/public/Group/Backend/IHideFromCollaborationBackend.php [new file with mode: 0644]
lib/public/IGroup.php
tests/lib/Collaboration/Collaborators/GroupPluginTest.php

index 7eee042076eb09bbe9017c7599d7c7309830b214..b1e331132befd2c6297ca18825fcde6718490175 100644 (file)
@@ -73,6 +73,10 @@ class GroupPlugin implements ISearchPlugin {
 
                $lowerSearch = strtolower($search);
                foreach ($groups as $group) {
+                       if ($group->hideFromCollaboration()) {
+                               continue;
+                       }
+
                        // FIXME: use a more efficient approach
                        $gid = $group->getGID();
                        if (!in_array($gid, $groupIds)) {
index 0d54cf8e35a9dd13f75b711d57ef56c4b6f18259..df8de7af5d5d05cfce3d9faa7791a70af584394c 100644 (file)
@@ -30,6 +30,7 @@
 
 namespace OC\Group;
 
+use OCP\Group\Backend\IHideFromCollaborationBackend;
 use OCP\GroupInterface;
 use OCP\IGroup;
 use OCP\IUser;
@@ -350,4 +351,14 @@ class Group implements IGroup {
                }
                return false;
        }
+
+       /**
+        * @return bool
+        * @since 16.0.0
+        */
+       public function hideFromCollaboration(): bool {
+               return array_reduce($this->backends, function(bool $hide, GroupInterface $backend) {
+                       return $hide | ($backend instanceof IHideFromCollaborationBackend && $backend->hideGroup($this->gid));
+               }, false);
+       }
 }
diff --git a/lib/public/Group/Backend/IHideFromCollaborationBackend.php b/lib/public/Group/Backend/IHideFromCollaborationBackend.php
new file mode 100644 (file)
index 0000000..81afbc3
--- /dev/null
@@ -0,0 +1,38 @@
+<?php declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2019 Robin Appelman <robin@icewind.nl>
+ *
+ * @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 16.0.0
+ *
+ * Allow the backend to mark groups to be excluded from being shown in search dialogs
+ */
+interface IHideFromCollaborationBackend {
+       /**
+        * Check if a group should be hidden from search dialogs
+        *
+        * @param string $groupId
+        * @return bool
+        * @since 16.0.0
+        */
+       public function hideGroup(string $groupId): bool;
+}
index 8fa87e35ce3b867168ed314e2bfb04bc2b6e5421..48fa84df393d6c12b7a80cadd8b0e5b53de7a8c2 100644 (file)
@@ -138,4 +138,10 @@ interface IGroup {
         * @since 14.0.0
         */
        public function canAddUser();
+
+       /**
+        * @return bool
+        * @since 16.0.0
+        */
+       public function hideFromCollaboration(): bool;
 }
index 9849bdb874a2a21c7de2686173c8573d01554f0c..36d98ee302fbe0ad3832a81bfea8e597bf85574d 100644 (file)
@@ -101,9 +101,10 @@ class GroupPluginTest extends TestCase {
        /**
         * @param string $gid
         * @param null $displayName
+        * @param bool $hide
         * @return IGroup|\PHPUnit_Framework_MockObject_MockObject
         */
-       protected function getGroupMock($gid, $displayName = null) {
+       protected function getGroupMock($gid, $displayName = null, $hide = false) {
                $group = $this->createMock(IGroup::class);
 
                $group->expects($this->any())
@@ -119,6 +120,9 @@ class GroupPluginTest extends TestCase {
                        ->method('getDisplayName')
                        ->willReturn($displayName);
 
+               $group->method('hideFromCollaboration')
+                       ->willReturn($hide);
+
                return $group;
        }
 
@@ -413,7 +417,20 @@ class GroupPluginTest extends TestCase {
                                true,
                                $this->getGroupMock('test'),
                        ],
+                       [
+                               'test', false, false,
+                               [
+                                       $this->getGroupMock('test', null, true),
+                                       $this->getGroupMock('test1'),
+                               ],
+                               [],
+                               [],
+                               [],
+                               true,
+                               false,
+                       ],
                ];
+
        }
 
        /**