From 6033baca2392884acd28596cf9c02e52b1799ab4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Wed, 26 Apr 2017 14:54:56 +0200 Subject: [PATCH] Remove old search endpoint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- appinfo/routes.php | 3 - lib/Controller/ShareController.php | 85 ---------- tests/unit/controller/ShareControllerTest.php | 151 ------------------ 3 files changed, 239 deletions(-) delete mode 100644 lib/Controller/ShareController.php delete mode 100644 tests/unit/controller/ShareControllerTest.php diff --git a/appinfo/routes.php b/appinfo/routes.php index bbf8772cd..0e9a54899 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -25,9 +25,6 @@ return [ 'routes' => [ ['name' => 'page#index', 'url' => '/', 'verb' => 'GET'], - // share - ['name' => 'share#searchUser', 'url' => '/share/search/{search}', 'verb' => 'GET'], - // boards ['name' => 'board#index', 'url' => '/boards', 'verb' => 'GET'], ['name' => 'board#create', 'url' => '/boards', 'verb' => 'POST'], diff --git a/lib/Controller/ShareController.php b/lib/Controller/ShareController.php deleted file mode 100644 index 1a89976cc..000000000 --- a/lib/Controller/ShareController.php +++ /dev/null @@ -1,85 +0,0 @@ - - * - * @author Julius Härtl - * - * @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 OCA\Deck\Controller; - -use OCA\Deck\Db\Acl; - -use OCA\Deck\Service\BoardService; -use OCP\IGroupManager; -use OCP\IRequest; -use OCP\AppFramework\Controller; -use OCP\IUserManager; - -class ShareController extends Controller { - - private $userManager; - private $groupManager; - private $boardService; - private $userId; - - public function __construct($appName, IRequest $request, IUserManager $userManager, IGroupManager $groupManager, BoardService $boardService, $userId) { - parent::__construct($appName, $request); - $this->userManager = $userManager; - $this->groupManager = $groupManager; - $this->userId = $userId; - $this->boardService = $boardService; - - } - - /** - * @NoAdminRequired - * @param $search - * @return array - */ - public function searchUser($search) { - $limit = 3; - $offset = null; - $result = []; - foreach ($this->groupManager->search($search, $limit, $offset) as $idx => $group) { - $acl = new Acl(); - $acl->setType('group'); - $acl->setParticipant($group->getGID()); - $acl->setPermissionEdit(true); - $acl->setPermissionShare(true); - $acl->setPermissionManage(true); - $result[] = $acl; - } - $limit = 10; - foreach ($this->userManager->searchDisplayName($search, $limit, $offset) as $idx => $user) { - if ($user->getUID() === $this->userId) { - continue; - } - $acl = new Acl(); - $acl->setType('user'); - $acl->setParticipant($user->getUID()); - $acl->setPermissionEdit(true); - $acl->setPermissionShare(true); - $acl->setPermissionManage(true); - $result[] = $acl; - } - return $result; - } - - -} diff --git a/tests/unit/controller/ShareControllerTest.php b/tests/unit/controller/ShareControllerTest.php deleted file mode 100644 index b350d726b..000000000 --- a/tests/unit/controller/ShareControllerTest.php +++ /dev/null @@ -1,151 +0,0 @@ - - * - * @author Julius Härtl - * - * @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 OCA\Deck\Controller; - -use OCA\Deck\Db\Acl; -use OCP\IGroup; -use OCP\IUser; - -class ShareControllerTest extends \PHPUnit_Framework_TestCase { - - private $controller; - private $request; - private $userManager; - private $groupManager; - private $boardService; - private $permissionService; - private $userId = 'user'; - - public function setUp() { - $this->l10n = $this->request = $this->getMockBuilder( - '\OCP\IL10n') - ->disableOriginalConstructor() - ->getMock(); - $this->request = $this->getMockBuilder( - '\OCP\IRequest') - ->disableOriginalConstructor() - ->getMock(); - $this->userManager = $this->getMockBuilder( - '\OCP\IUserManager') - ->disableOriginalConstructor() - ->getMock(); - $this->groupManager = $this->getMockBuilder( - '\OCP\IGroupManager') - ->disableOriginalConstructor() - ->getMock(); - $this->boardService = $this->getMockBuilder( - '\OCA\Deck\Service\BoardService') - ->disableOriginalConstructor() - ->getMock(); - - $this->groupManager->method('getUserGroupIds') - ->willReturn(['admin', 'group1', 'group2']); - $this->userManager->method('get') - ->with($this->userId) - ->willReturn('user'); - - $this->controller = new ShareController( - 'deck', - $this->request, - $this->userManager, - $this->groupManager, - $this->boardService, - $this->userId - ); - } - - - public function testSearchGroup() { - $group = $this->getMockBuilder(IGroup::class) - ->disableOriginalConstructor() - ->getMock(); - $group->expects($this->once()) - ->method('getGID') - ->willReturn('foo'); - $groups = [$group]; - $this->groupManager->expects($this->once()) - ->method('search') - ->with('foo') - ->willReturn($groups); - $this->userManager->expects($this->once()) - ->method('searchDisplayName') - ->willReturn([]); - $actual = $this->controller->searchUser('foo'); - - $acl = new Acl(); - $acl->setType('group'); - $acl->setParticipant('foo'); - $acl->setPermissionEdit(true); - $acl->setPermissionShare(true); - $acl->setPermissionManage(true); - $this->assertEquals([$acl], $actual); - } - public function testSearchUser() { - $user = $this->getMockBuilder(IUser::class) - ->disableOriginalConstructor() - ->getMock(); - $user->expects($this->any()) - ->method('getUID') - ->willReturn('foo'); - $users = [$user]; - $this->groupManager->expects($this->once()) - ->method('search') - ->willReturn([]); - - $this->userManager->expects($this->once()) - ->method('searchDisplayName') - ->with('foo') - ->willReturn($users); - $actual = $this->controller->searchUser('foo'); - - $acl = new Acl(); - $acl->setType('user'); - $acl->setParticipant('foo'); - $acl->setPermissionEdit(true); - $acl->setPermissionShare(true); - $acl->setPermissionManage(true); - $this->assertEquals([$acl], $actual); - } - - public function testSearchUserExcludeOwn() { - $user = $this->getMockBuilder(IUser::class) - ->disableOriginalConstructor() - ->getMock(); - $user->expects($this->any()) - ->method('getUID') - ->willReturn('user'); - $users = [$user]; - $this->groupManager->expects($this->once()) - ->method('search') - ->willReturn([]); - - $this->userManager->expects($this->once()) - ->method('searchDisplayName') - ->with('user') - ->willReturn($users); - $actual = $this->controller->searchUser('user'); - $this->assertEquals([], $actual); - } - -}