From db750898ee3cb165218f4428265ab9dc258c93c2 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 22 Feb 2019 16:36:25 +0100 Subject: [PATCH 1/2] allow group backends to mark that a group should now be shown in search dialogs Signed-off-by: Robin Appelman --- .../Collaborators/GroupPlugin.php | 4 ++ lib/private/Group/Group.php | 11 ++++++ .../Backend/IHideFromCollaborationBackend.php | 38 +++++++++++++++++++ lib/public/IGroup.php | 6 +++ .../Collaborators/GroupPluginTest.php | 19 +++++++++- 5 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 lib/public/Group/Backend/IHideFromCollaborationBackend.php diff --git a/lib/private/Collaboration/Collaborators/GroupPlugin.php b/lib/private/Collaboration/Collaborators/GroupPlugin.php index 7eee042076..b1e331132b 100644 --- a/lib/private/Collaboration/Collaborators/GroupPlugin.php +++ b/lib/private/Collaboration/Collaborators/GroupPlugin.php @@ -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)) { diff --git a/lib/private/Group/Group.php b/lib/private/Group/Group.php index 0d54cf8e35..df8de7af5d 100644 --- a/lib/private/Group/Group.php +++ b/lib/private/Group/Group.php @@ -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 index 0000000000..81afbc3d56 --- /dev/null +++ b/lib/public/Group/Backend/IHideFromCollaborationBackend.php @@ -0,0 +1,38 @@ + + * + * @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 . + * + */ + +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; +} diff --git a/lib/public/IGroup.php b/lib/public/IGroup.php index 8fa87e35ce..48fa84df39 100644 --- a/lib/public/IGroup.php +++ b/lib/public/IGroup.php @@ -138,4 +138,10 @@ interface IGroup { * @since 14.0.0 */ public function canAddUser(); + + /** + * @return bool + * @since 16.0.0 + */ + public function hideFromCollaboration(): bool; } diff --git a/tests/lib/Collaboration/Collaborators/GroupPluginTest.php b/tests/lib/Collaboration/Collaborators/GroupPluginTest.php index 9849bdb874..36d98ee302 100644 --- a/tests/lib/Collaboration/Collaborators/GroupPluginTest.php +++ b/tests/lib/Collaboration/Collaborators/GroupPluginTest.php @@ -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, + ], ]; + } /** From dd95f430e0d2b11f2a99649e25c2d477c3abcc51 Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Mon, 25 Feb 2019 20:08:46 +0100 Subject: [PATCH 2/2] Update autoloader files Signed-off-by: Morris Jobke --- lib/composer/composer/autoload_classmap.php | 1 + lib/composer/composer/autoload_static.php | 1 + 2 files changed, 2 insertions(+) diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index bb1ea11f2e..9ac6d83744 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -266,6 +266,7 @@ return array( 'OCP\\Group\\Backend\\ICreateGroupBackend' => $baseDir . '/lib/public/Group/Backend/ICreateGroupBackend.php', 'OCP\\Group\\Backend\\IDeleteGroupBackend' => $baseDir . '/lib/public/Group/Backend/IDeleteGroupBackend.php', 'OCP\\Group\\Backend\\IGroupDetailsBackend' => $baseDir . '/lib/public/Group/Backend/IGroupDetailsBackend.php', + '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\\ISubAdmin' => $baseDir . '/lib/public/Group/ISubAdmin.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 9108350456..ca5e47bb9f 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -296,6 +296,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OCP\\Group\\Backend\\ICreateGroupBackend' => __DIR__ . '/../../..' . '/lib/public/Group/Backend/ICreateGroupBackend.php', 'OCP\\Group\\Backend\\IDeleteGroupBackend' => __DIR__ . '/../../..' . '/lib/public/Group/Backend/IDeleteGroupBackend.php', 'OCP\\Group\\Backend\\IGroupDetailsBackend' => __DIR__ . '/../../..' . '/lib/public/Group/Backend/IGroupDetailsBackend.php', + '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\\ISubAdmin' => __DIR__ . '/../../..' . '/lib/public/Group/ISubAdmin.php',