Quellcode durchsuchen

allow group backends to mark that a group should now be shown in search dialogs

Signed-off-by: Robin Appelman <robin@icewind.nl>
tags/v16.0.0alpha1
Robin Appelman vor 5 Jahren
Ursprung
Commit
db750898ee
Es ist kein Account mit der E-Mail-Adresse des Committers verbunden

+ 4
- 0
lib/private/Collaboration/Collaborators/GroupPlugin.php Datei anzeigen

@@ -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)) {

+ 11
- 0
lib/private/Group/Group.php Datei anzeigen

@@ -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);
}
}

+ 38
- 0
lib/public/Group/Backend/IHideFromCollaborationBackend.php Datei anzeigen

@@ -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;
}

+ 6
- 0
lib/public/IGroup.php Datei anzeigen

@@ -138,4 +138,10 @@ interface IGroup {
* @since 14.0.0
*/
public function canAddUser();

/**
* @return bool
* @since 16.0.0
*/
public function hideFromCollaboration(): bool;
}

+ 18
- 1
tests/lib/Collaboration/Collaborators/GroupPluginTest.php Datei anzeigen

@@ -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,
],
];

}

/**

Laden…
Abbrechen
Speichern