diff --git a/apps/comments/appinfo/info.xml b/apps/comments/appinfo/info.xml index b67def1fb9..ada4915d14 100644 --- a/apps/comments/appinfo/info.xml +++ b/apps/comments/appinfo/info.xml @@ -28,4 +28,10 @@ OCA\Comments\Activity\Provider + + + + OCA\Comments\Collaboration\Sorter + + diff --git a/apps/comments/lib/Collaboration/CommentersSorter.php b/apps/comments/lib/Collaboration/CommentersSorter.php new file mode 100644 index 0000000000..e89a66f148 --- /dev/null +++ b/apps/comments/lib/Collaboration/CommentersSorter.php @@ -0,0 +1,93 @@ + + * + * @author Arthur Schiwon + * + * @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\Comments\Collaboration; + + +use OCP\Collaboration\AutoComplete\ISorter; +use OCP\Comments\ICommentsManager; + +class CommentersSorter implements ISorter { + + /** @var ICommentsManager */ + private $commentsManager; + + public function __construct(ICommentsManager $commentsManager) { + $this->commentsManager = $commentsManager; + } + + public function getId() { + return 'commenters'; + } + + /** + * Sorts people who commented on the given item atop (descelating) of the + * others + * + * @param array $sortArray + * @param array $context + */ + public function sort(array &$sortArray, array $context) { + $commenters = $this->retrieveCommentsInformation($context['itemType'], $context['itemId']); + if(count($commenters) === 0) { + return; + } + + foreach ($sortArray as $type => &$byType) { + if(!isset($commenters[$type])) { + continue; + } + + usort($byType, function ($a, $b) use ($commenters, $type) { + $r = $this->compare($a, $b, $commenters[$type]); + return $r; + }); + + $s = ''; + } + } + + /** + * @param $type + * @param $id + * @return array + */ + protected function retrieveCommentsInformation($type, $id) { + $comments = $this->commentsManager->getForObject($type, $id, 1); + if(count($comments) === 0) { + return []; + } + + return $this->commentsManager->getActorsInTree($comments[0]->getTopmostParentId()); + } + + protected function compare(array $a, array $b, array $commenters) { + $a = $a['value']['shareWith']; + $b = $b['value']['shareWith']; + + $valueA = isset($commenters[$a]) ? $commenters[$a] : 0; + $valueB = isset($commenters[$b]) ? $commenters[$b] : 0; + + return $valueB - $valueA; + } +} diff --git a/apps/comments/tests/Unit/Collaboration/CommentersSorterTest.php b/apps/comments/tests/Unit/Collaboration/CommentersSorterTest.php new file mode 100644 index 0000000000..495dee1f41 --- /dev/null +++ b/apps/comments/tests/Unit/Collaboration/CommentersSorterTest.php @@ -0,0 +1,147 @@ + + * + * @author Arthur Schiwon + * + * @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\Comments\Tests\Unit\Collaboration; + + +use OCA\Comments\Collaboration\CommentersSorter; +use OCP\Comments\IComment; +use OCP\Comments\ICommentsManager; +use Test\TestCase; + +class CommentersSorterTest extends TestCase { + /** @var ICommentsManager|\PHPUnit_Framework_MockObject_MockObject */ + protected $commentsManager; + /** @var CommentersSorter */ + protected $sorter; + + public function setUp() { + parent::setUp(); + + $this->commentsManager = $this->createMock(ICommentsManager::class); + + $this->sorter = new CommentersSorter($this->commentsManager); + } + + /** + * @dataProvider sortDataProvider + * @param $data + */ + public function testSort($data) { + $this->commentsManager->expects($this->once()) + ->method('getForObject') + ->willReturn([$this->createMock(IComment::class)]); + + $this->commentsManager->expects($this->once()) + ->method('getActorsInTree') + ->willReturn($data['actors']); + + $workArray = $data['input']; + $this->sorter->sort($workArray, ['itemType' => 'files', 'itemId' => '24']); + + $this->assertSame($data['expected'], $workArray); + } + + public function sortDataProvider() { + return [[ + [ + #1 – sort properly and otherwise keep existing order + 'actors' => ['users' => ['celia' => 3, 'darius' => 7, 'faruk' => 5, 'gail' => 5], 'bots' => ['r2-d2' => 8]], + 'input' => [ + 'users' => + [ + ['value' => ['shareWith' => 'alice']], + ['value' => ['shareWith' => 'bob']], + ['value' => ['shareWith' => 'celia']], + ['value' => ['shareWith' => 'darius']], + ['value' => ['shareWith' => 'elena']], + ['value' => ['shareWith' => 'faruk']], + ['value' => ['shareWith' => 'gail']], + ], + 'bots' => [ + ['value' => ['shareWith' => 'c-3po']], + ['value' => ['shareWith' => 'r2-d2']], + ] + ], + 'expected' => [ + 'users' => + [ + ['value' => ['shareWith' => 'darius']], + ['value' => ['shareWith' => 'faruk']], + ['value' => ['shareWith' => 'gail']], + ['value' => ['shareWith' => 'celia']], + ['value' => ['shareWith' => 'alice']], + ['value' => ['shareWith' => 'bob']], + ['value' => ['shareWith' => 'elena']], + ], + 'bots' => [ + ['value' => ['shareWith' => 'r2-d2']], + ['value' => ['shareWith' => 'c-3po']], + ] + ], + ], + [ + #2 – no commentors, input equals output + 'actors' => [], + 'input' => [ + 'users' => + [ + ['value' => ['shareWith' => 'alice']], + ['value' => ['shareWith' => 'bob']], + ['value' => ['shareWith' => 'celia']], + ['value' => ['shareWith' => 'darius']], + ['value' => ['shareWith' => 'elena']], + ['value' => ['shareWith' => 'faruk']], + ['value' => ['shareWith' => 'gail']], + ], + 'bots' => [ + ['value' => ['shareWith' => 'c-3po']], + ['value' => ['shareWith' => 'r2-d2']], + ] + ], + 'expected' => [ + 'users' => + [ + ['value' => ['shareWith' => 'alice']], + ['value' => ['shareWith' => 'bob']], + ['value' => ['shareWith' => 'celia']], + ['value' => ['shareWith' => 'darius']], + ['value' => ['shareWith' => 'elena']], + ['value' => ['shareWith' => 'faruk']], + ['value' => ['shareWith' => 'gail']], + ], + 'bots' => [ + ['value' => ['shareWith' => 'c-3po']], + ['value' => ['shareWith' => 'r2-d2']], + ] + ], + ], + [ + #3 – no nothing + 'actors' => [], + 'input' => [], + 'expected' => [], + ], + ]]; + } +} diff --git a/apps/files_sharing/appinfo/info.xml b/apps/files_sharing/appinfo/info.xml index f4119a5597..e98d29aeb8 100644 --- a/apps/files_sharing/appinfo/info.xml +++ b/apps/files_sharing/appinfo/info.xml @@ -59,4 +59,10 @@ Turning the feature off removes shared files and folders on the server for all s OCA\Files_Sharing\Migration\SetPasswordColumn + + + + OCA\Files_Sharing\Collaboration\ShareRecipientSorter + + diff --git a/apps/files_sharing/lib/Collaboration/ShareRecipientSorter.php b/apps/files_sharing/lib/Collaboration/ShareRecipientSorter.php new file mode 100644 index 0000000000..ba07d9d44d --- /dev/null +++ b/apps/files_sharing/lib/Collaboration/ShareRecipientSorter.php @@ -0,0 +1,85 @@ + + * + * @author Arthur Schiwon + * + * @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\Files_Sharing\Collaboration; + + +use OCP\Collaboration\AutoComplete\ISorter; +use OCP\Files\Folder; +use OCP\Files\Node; +use OCP\Share\IManager; + +class ShareRecipientSorter implements ISorter { + + /** @var IManager */ + private $shareManager; + /** @var Folder */ + private $userFolder; + + public function __construct(IManager $shareManager, Folder $userFolder) { + $this->shareManager = $shareManager; + $this->userFolder = $userFolder; + } + + public function getId() { + return 'share-recipients'; + } + + public function sort(array &$sortArray, array $context) { + // let's be tolerant. Comments uses "files" by default, other usages are often singular + if($context['itemType'] !== 'files' && $context['itemType'] !== 'file') { + return; + } + /** @var Node[] $nodes */ + $nodes = $this->userFolder->getById((int)$context['itemId']); + if(count($nodes) === 0) { + return; + } + $al = $this->shareManager->getAccessList($nodes[0]); + + foreach ($sortArray as $type => &$byType) { + if(!isset($al[$type]) || !is_array($al[$type])) { + continue; + } + usort($byType, function ($a, $b) use ($al, $type) { + return $this->compare($a, $b, $al[$type]); + }); + } + } + + /** + * @param array $a + * @param array $b + * @param array $al + * @return int + */ + protected function compare(array $a, array $b, array $al) { + $a = $a['value']['shareWith']; + $b = $b['value']['shareWith']; + + $valueA = (int)in_array($a, $al, true); + $valueB = (int)in_array($b, $al, true); + + return $valueB - $valueA; + } +} diff --git a/apps/files_sharing/tests/Collaboration/ShareRecipientSorterTest.php b/apps/files_sharing/tests/Collaboration/ShareRecipientSorterTest.php new file mode 100644 index 0000000000..edcc9b9ae3 --- /dev/null +++ b/apps/files_sharing/tests/Collaboration/ShareRecipientSorterTest.php @@ -0,0 +1,220 @@ + + * + * @author Arthur Schiwon + * + * @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\Files_Sharing\Tests\Collaboration; + + +use OCA\Files_Sharing\Collaboration\ShareRecipientSorter; +use OCP\Files\Folder; +use OCP\Files\Node; +use OCP\Share\IManager; +use Test\TestCase; + +class ShareRecipientSorterTest extends TestCase { + /** @var IManager|\PHPUnit_Framework_MockObject_MockObject */ + protected $shareManager; + /** @var Folder|\PHPUnit_Framework_MockObject_MockObject */ + protected $userFolder; + /** @var ShareRecipientSorter */ + protected $sorter; + + public function setUp() { + parent::setUp(); + + $this->shareManager = $this->createMock(IManager::class); + $this->userFolder = $this->createMock(Folder::class); + + $this->sorter = new ShareRecipientSorter($this->shareManager, $this->userFolder); + } + + /** + * @dataProvider sortDataProvider + * @param $data + */ + public function testSort($data) { + $node = $this->createMock(Node::class); + + if ($data['context']['itemType'] === 'files') { + $this->userFolder->expects($this->once()) + ->method('getById') + ->with($data['context']['itemId']) + ->willReturn([$node]); + + $this->shareManager->expects($this->once()) + ->method('getAccessList') + ->with($node) + ->willReturn($data['accessList']); + } else { + $this->userFolder->expects($this->never()) + ->method('getById'); + $this->shareManager->expects($this->never()) + ->method('getAccessList'); + } + + $workArray = $data['input']; + $this->sorter->sort($workArray, $data['context']); + + $this->assertSame($data['expected'], $workArray); + } + + public function testSortNoNodes() { + $this->userFolder->expects($this->once()) + ->method('getById') + ->willReturn([]); + + $this->shareManager->expects($this->never()) + ->method('getAccessList'); + + $originalArray = ['users' => [ + ['value' => ['shareWith' => 'alice']], + ['value' => ['shareWith' => 'bob']], + ]]; + $workArray = $originalArray; + $this->sorter->sort($workArray, ['itemType' => 'files', 'itemId' => 404]); + + $this->assertEquals($originalArray, $workArray); + } + + public function sortDataProvider() { + return [[ + [ + #1 – sort properly and otherwise keep existing order + 'context' => ['itemType' => 'files', 'itemId' => 42], + 'accessList' => ['users' => ['celia', 'darius', 'faruk', 'gail'], 'bots' => ['r2-d2']], + 'input' => [ + 'users' => + [ + ['value' => ['shareWith' => 'alice']], + ['value' => ['shareWith' => 'bob']], + ['value' => ['shareWith' => 'celia']], + ['value' => ['shareWith' => 'darius']], + ['value' => ['shareWith' => 'elena']], + ['value' => ['shareWith' => 'faruk']], + ['value' => ['shareWith' => 'gail']], + ], + 'bots' => [ + ['value' => ['shareWith' => 'c-3po']], + ['value' => ['shareWith' => 'r2-d2']], + ] + ], + 'expected' => [ + 'users' => + [ + ['value' => ['shareWith' => 'celia']], + ['value' => ['shareWith' => 'darius']], + ['value' => ['shareWith' => 'faruk']], + ['value' => ['shareWith' => 'gail']], + ['value' => ['shareWith' => 'alice']], + ['value' => ['shareWith' => 'bob']], + ['value' => ['shareWith' => 'elena']], + ], + 'bots' => [ + ['value' => ['shareWith' => 'r2-d2']], + ['value' => ['shareWith' => 'c-3po']], + ] + ], + ], + [ + # 2 – no recipients + 'context' => ['itemType' => 'files', 'itemId' => 42], + 'accessList' => ['users' => false], + 'input' => [ + 'users' => + [ + ['value' => ['shareWith' => 'alice']], + ['value' => ['shareWith' => 'bob']], + ['value' => ['shareWith' => 'celia']], + ['value' => ['shareWith' => 'darius']], + ['value' => ['shareWith' => 'elena']], + ['value' => ['shareWith' => 'faruk']], + ['value' => ['shareWith' => 'gail']], + ], + 'bots' => [ + ['value' => ['shareWith' => 'c-3po']], + ['value' => ['shareWith' => 'r2-d2']], + ] + ], + 'expected' => [ + 'users' => + [ + ['value' => ['shareWith' => 'alice']], + ['value' => ['shareWith' => 'bob']], + ['value' => ['shareWith' => 'celia']], + ['value' => ['shareWith' => 'darius']], + ['value' => ['shareWith' => 'elena']], + ['value' => ['shareWith' => 'faruk']], + ['value' => ['shareWith' => 'gail']], + ], + 'bots' => [ + ['value' => ['shareWith' => 'c-3po']], + ['value' => ['shareWith' => 'r2-d2']], + ] + ], + ], + [ + #3 – unsupported item type + 'context' => ['itemType' => 'announcements', 'itemId' => 42], + 'accessList' => null, // not needed + 'input' => [ + 'users' => + [ + ['value' => ['shareWith' => 'alice']], + ['value' => ['shareWith' => 'bob']], + ['value' => ['shareWith' => 'celia']], + ['value' => ['shareWith' => 'darius']], + ['value' => ['shareWith' => 'elena']], + ['value' => ['shareWith' => 'faruk']], + ['value' => ['shareWith' => 'gail']], + ], + 'bots' => [ + ['value' => ['shareWith' => 'c-3po']], + ['value' => ['shareWith' => 'r2-d2']], + ] + ], + 'expected' => [ + 'users' => + [ + ['value' => ['shareWith' => 'alice']], + ['value' => ['shareWith' => 'bob']], + ['value' => ['shareWith' => 'celia']], + ['value' => ['shareWith' => 'darius']], + ['value' => ['shareWith' => 'elena']], + ['value' => ['shareWith' => 'faruk']], + ['value' => ['shareWith' => 'gail']], + ], + 'bots' => [ + ['value' => ['shareWith' => 'c-3po']], + ['value' => ['shareWith' => 'r2-d2']], + ] + ], + ], + [ + #4 – no nothing + 'context' => ['itemType' => 'files', 'itemId' => 42], + 'accessList' => [], + 'input' => [], + 'expected' => [], + ], + ]]; + } +} diff --git a/core/Controller/AutoCompleteController.php b/core/Controller/AutoCompleteController.php new file mode 100644 index 0000000000..839ed7fe6c --- /dev/null +++ b/core/Controller/AutoCompleteController.php @@ -0,0 +1,89 @@ + + * + * @author Arthur Schiwon + * + * @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 OC\Core\Controller; + +use OCP\AppFramework\Controller; +use OCP\AppFramework\Http\DataResponse; +use OCP\Collaboration\AutoComplete\IManager; +use OCP\Collaboration\Collaborators\ISearch; +use OCP\IRequest; +use OCP\Share; + +class AutoCompleteController extends Controller { + /** @var ISearch */ + private $collaboratorSearch; + /** @var IManager */ + private $autoCompleteManager; + + public function __construct($appName, IRequest $request, ISearch $collaboratorSearch, IManager $autoCompleteManager) { + parent::__construct($appName, $request); + + $this->collaboratorSearch = $collaboratorSearch; + $this->autoCompleteManager = $autoCompleteManager; + } + + /** + * @NoAdminRequired + * + * @param string $itemType + * @param string $itemId + * @param string|null $sorter can be piped, top prio first, e.g.: "commenters|share-recipients" + * @param array $shareTypes + * @return DataResponse + */ + public function get($itemType, $itemId, $sorter = null, $shareTypes = [Share::SHARE_TYPE_USER]) { + // if enumeration/user listings are disabled, we'll receive an empty + // result from search() – thus nothing else to do here. + list($results,) = $this->collaboratorSearch->search('', $shareTypes, false, 20, 0); + + // there won't be exact matches without a search string + unset($results['exact']); + + $sorters = array_reverse(explode('|', $sorter)); + $this->autoCompleteManager->runSorters($sorters, $results, [ + 'itemType' => $itemType, + 'itemId' => $itemId, + ]); + + // transform to expected format + $results = $this->prepareResultArray($results); + + return new DataResponse($results); + } + + + protected function prepareResultArray(array $results) { + $output = []; + foreach ($results as $type => $subResult) { + foreach ($subResult as $result) { + $output[] = [ + 'id' => $result['value']['shareWith'], + 'label' => $result['label'], + 'source' => $type, + ]; + } + } + return $output; + } +} diff --git a/core/routes.php b/core/routes.php index af445d9da8..75d8fb140a 100644 --- a/core/routes.php +++ b/core/routes.php @@ -62,6 +62,7 @@ $application->registerRoutes($this, [ ['name' => 'Js#getJs', 'url' => '/js/{appName}/{fileName}', 'verb' => 'GET'], ['name' => 'contactsMenu#index', 'url' => '/contactsmenu/contacts', 'verb' => 'POST'], ['name' => 'contactsMenu#findOne', 'url' => '/contactsmenu/findOne', 'verb' => 'POST'], + ['name' => 'AutoComplete#get', 'url' => 'autocomplete/get', 'verb' => 'GET'] ], 'ocs' => [ ['root' => '/cloud', 'name' => 'OCS#getCapabilities', 'url' => '/capabilities', 'verb' => 'GET'], diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 07f815f85c..e522d82edf 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -68,6 +68,8 @@ return array( 'OCP\\BackgroundJob\\IJobList' => $baseDir . '/lib/public/BackgroundJob/IJobList.php', 'OCP\\Capabilities\\ICapability' => $baseDir . '/lib/public/Capabilities/ICapability.php', 'OCP\\Capabilities\\IPublicCapability' => $baseDir . '/lib/public/Capabilities/IPublicCapability.php', + 'OCP\\Collaboration\\AutoComplete\\IManager' => $baseDir . '/lib/public/Collaboration/AutoComplete/IManager.php', + 'OCP\\Collaboration\\AutoComplete\\ISorter' => $baseDir . '/lib/public/Collaboration/AutoComplete/ISorter.php', 'OCP\\Collaboration\\Collaborators\\ISearch' => $baseDir . '/lib/public/Collaboration/Collaborators/ISearch.php', 'OCP\\Collaboration\\Collaborators\\ISearchPlugin' => $baseDir . '/lib/public/Collaboration/Collaborators/ISearchPlugin.php', 'OCP\\Collaboration\\Collaborators\\ISearchResult' => $baseDir . '/lib/public/Collaboration/Collaborators/ISearchResult.php', @@ -389,6 +391,7 @@ return array( 'OC\\Cache\\CappedMemoryCache' => $baseDir . '/lib/private/Cache/CappedMemoryCache.php', 'OC\\Cache\\File' => $baseDir . '/lib/private/Cache/File.php', 'OC\\CapabilitiesManager' => $baseDir . '/lib/private/CapabilitiesManager.php', + 'OC\\Collaboration\\AutoComplete\\Manager' => $baseDir . '/lib/private/Collaboration/AutoComplete/Manager.php', 'OC\\Collaboration\\Collaborators\\GroupPlugin' => $baseDir . '/lib/private/Collaboration/Collaborators/GroupPlugin.php', 'OC\\Collaboration\\Collaborators\\LookupPlugin' => $baseDir . '/lib/private/Collaboration/Collaborators/LookupPlugin.php', 'OC\\Collaboration\\Collaborators\\MailPlugin' => $baseDir . '/lib/private/Collaboration/Collaborators/MailPlugin.php', @@ -494,6 +497,7 @@ return array( 'OC\\Core\\Command\\User\\Report' => $baseDir . '/core/Command/User/Report.php', 'OC\\Core\\Command\\User\\ResetPassword' => $baseDir . '/core/Command/User/ResetPassword.php', 'OC\\Core\\Command\\User\\Setting' => $baseDir . '/core/Command/User/Setting.php', + 'OC\\Core\\Controller\\AutoCompleteController' => $baseDir . '/core/Controller/AutoCompleteController.php', 'OC\\Core\\Controller\\AvatarController' => $baseDir . '/core/Controller/AvatarController.php', 'OC\\Core\\Controller\\ClientFlowLoginController' => $baseDir . '/core/Controller/ClientFlowLoginController.php', 'OC\\Core\\Controller\\ContactsMenuController' => $baseDir . '/core/Controller/ContactsMenuController.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 0d327b7267..4f538e9602 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -98,6 +98,8 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OCP\\BackgroundJob\\IJobList' => __DIR__ . '/../../..' . '/lib/public/BackgroundJob/IJobList.php', 'OCP\\Capabilities\\ICapability' => __DIR__ . '/../../..' . '/lib/public/Capabilities/ICapability.php', 'OCP\\Capabilities\\IPublicCapability' => __DIR__ . '/../../..' . '/lib/public/Capabilities/IPublicCapability.php', + 'OCP\\Collaboration\\AutoComplete\\IManager' => __DIR__ . '/../../..' . '/lib/public/Collaboration/AutoComplete/IManager.php', + 'OCP\\Collaboration\\AutoComplete\\ISorter' => __DIR__ . '/../../..' . '/lib/public/Collaboration/AutoComplete/ISorter.php', 'OCP\\Collaboration\\Collaborators\\ISearch' => __DIR__ . '/../../..' . '/lib/public/Collaboration/Collaborators/ISearch.php', 'OCP\\Collaboration\\Collaborators\\ISearchPlugin' => __DIR__ . '/../../..' . '/lib/public/Collaboration/Collaborators/ISearchPlugin.php', 'OCP\\Collaboration\\Collaborators\\ISearchResult' => __DIR__ . '/../../..' . '/lib/public/Collaboration/Collaborators/ISearchResult.php', @@ -419,6 +421,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OC\\Cache\\CappedMemoryCache' => __DIR__ . '/../../..' . '/lib/private/Cache/CappedMemoryCache.php', 'OC\\Cache\\File' => __DIR__ . '/../../..' . '/lib/private/Cache/File.php', 'OC\\CapabilitiesManager' => __DIR__ . '/../../..' . '/lib/private/CapabilitiesManager.php', + 'OC\\Collaboration\\AutoComplete\\Manager' => __DIR__ . '/../../..' . '/lib/private/Collaboration/AutoComplete/Manager.php', 'OC\\Collaboration\\Collaborators\\GroupPlugin' => __DIR__ . '/../../..' . '/lib/private/Collaboration/Collaborators/GroupPlugin.php', 'OC\\Collaboration\\Collaborators\\LookupPlugin' => __DIR__ . '/../../..' . '/lib/private/Collaboration/Collaborators/LookupPlugin.php', 'OC\\Collaboration\\Collaborators\\MailPlugin' => __DIR__ . '/../../..' . '/lib/private/Collaboration/Collaborators/MailPlugin.php', @@ -524,6 +527,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OC\\Core\\Command\\User\\Report' => __DIR__ . '/../../..' . '/core/Command/User/Report.php', 'OC\\Core\\Command\\User\\ResetPassword' => __DIR__ . '/../../..' . '/core/Command/User/ResetPassword.php', 'OC\\Core\\Command\\User\\Setting' => __DIR__ . '/../../..' . '/core/Command/User/Setting.php', + 'OC\\Core\\Controller\\AutoCompleteController' => __DIR__ . '/../../..' . '/core/Controller/AutoCompleteController.php', 'OC\\Core\\Controller\\AvatarController' => __DIR__ . '/../../..' . '/core/Controller/AvatarController.php', 'OC\\Core\\Controller\\ClientFlowLoginController' => __DIR__ . '/../../..' . '/core/Controller/ClientFlowLoginController.php', 'OC\\Core\\Controller\\ContactsMenuController' => __DIR__ . '/../../..' . '/core/Controller/ContactsMenuController.php', diff --git a/lib/private/Collaboration/AutoComplete/Manager.php b/lib/private/Collaboration/AutoComplete/Manager.php new file mode 100644 index 0000000000..f801ea2333 --- /dev/null +++ b/lib/private/Collaboration/AutoComplete/Manager.php @@ -0,0 +1,81 @@ + + * + * @author Arthur Schiwon + * + * @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 OC\Collaboration\AutoComplete; + +use OCP\Collaboration\AutoComplete\IManager; +use OCP\Collaboration\AutoComplete\ISorter; +use OCP\IServerContainer; + +class Manager implements IManager { + /** @var string[] */ + protected $sorters =[]; + + /** @var ISorter[] */ + protected $sorterInstances = []; + /** @var IServerContainer */ + private $c; + + public function __construct(IServerContainer $container) { + $this->c = $container; + } + + public function runSorters(array $sorters, array &$sortArray, array $context) { + $sorterInstances = $this->getSorters(); + while($sorter = array_shift($sorters)) { + if(isset($sorterInstances[$sorter])) { + $sorterInstances[$sorter]->sort($sortArray, $context); + } else { + $this->c->getLogger()->warning('No sorter for ID "{id}", skipping', [ + 'app' => 'core', 'id' => $sorter + ]); + } + } + } + + public function registerSorter($className) { + $sorters[] = $className; + } + + protected function getSorters() { + if(count($this->sorterInstances) === 0) { + foreach ($this->sorters as $sorter) { + /** @var ISorter $instance */ + $instance = $this->c->resolve($sorter); + if(!$instance instanceof ISorter) { + $this->c->getLogger()->notice('Skipping sorter which is not an instance of ISorter. Class name: {class}', + ['app' => 'core', 'class' => $sorter]); + continue; + } + $sorterId = trim($instance->getId()); + if(trim($sorterId) === '') { + $this->c->getLogger()->notice('Skipping sorter with empty ID. Class name: {class}', + ['app' => 'core', 'class' => $sorter]); + continue; + } + $this->sorterInstances[$sorterId] = $instance; + } + } + return $this->sorterInstances; + } +} diff --git a/lib/private/Comments/Manager.php b/lib/private/Comments/Manager.php index 078e1eef4d..a6b2102da6 100644 --- a/lib/private/Comments/Manager.php +++ b/lib/private/Comments/Manager.php @@ -317,6 +317,71 @@ class Manager implements ICommentsManager { return $tree; } + /** + * Get the actor types and ID that commented in the tree specified by the ID + * + * @param string $id + * @return array + * @since 13.0.0 + * + * The return array looks like this: + * + * [ + * 'user' => [ + * 'alice' => 2, + * 'bob' => 3 + * ], + * 'robot' => [ + * 'r2-d2' => 5, + * 'c-3po' => 17, + * ] + * ] + */ + public function getActorsInTree($id) { + $tree = $this->getTree($id); + $actors = []; + $this->extractActor($tree, $actors); + return $actors; + } + + /** + * @param array $node + * @param array &$actors + * + * build an array that looks like: + * + * [ + * 'user' => [ + * 'alice' => 2, + * 'bob' => 3 + * ], + * 'robot' => [ + * 'r2-d2' => 5, + * 'c-3po' => 17, + * ] + * ] + * + */ + protected function extractActor(array $node, array &$actors) { + if(isset($node['replies'])) { + foreach ($node['replies'] as $subNode) { + $this->extractActor($subNode, $actors); + } + } + if(isset($node['comment']) && $node['comment'] instanceof IComment) { + /** @var IComment $comment */ + $comment = $node['comment']; + if(!isset($actors[$comment->getActorType()])) { + $actors[$comment->getActorType()] = []; + } + if(!isset($actors[$comment->getActorType()][$comment->getActorId()])) { + $actors[$comment->getActorType()][$comment->getActorId()] = 1; + } else { + $actors[$comment->getActorType()][$comment->getActorId()] += 1; + } + } + } + /** * returns comments for a specific object (e.g. a file). * diff --git a/lib/private/Server.php b/lib/private/Server.php index 29aee06d89..c03b7e0460 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -1011,6 +1011,11 @@ class Server extends ServerContainer implements IServerContainer { }); $this->registerAlias('CollaboratorSearch', \OCP\Collaboration\Collaborators\ISearch::class); + $this->registerService(\OCP\Collaboration\AutoComplete\IManager::class, function (Server $c) { + return new Collaboration\AutoComplete\Manager($c); + }); + $this->registerAlias('AutoCompleteManager', \OCP\Collaboration\AutoComplete\IManager::class); + $this->registerService('SettingsManager', function (Server $c) { $manager = new \OC\Settings\Manager( $c->getLogger(), @@ -1801,6 +1806,13 @@ class Server extends ServerContainer implements IServerContainer { return $this->query('CollaboratorSearch'); } + /** + * @return \OCP\Collaboration\AutoComplete\IManager + */ + public function getAutoCompleteManager(){ + return $this->query('AutoCompleteManager'); + } + /** * Returns the LDAP Provider * diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index 42f2170122..9245b9d4f5 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -1322,7 +1322,7 @@ class Manager implements IManager { * * @param \OCP\Files\Node $path * @param bool $recursive Should we check all parent folders as well - * @param bool $currentAccess Should the user have currently access to the file + * @param bool $currentAccess Ensure the recipient has access to the file (e.g. did not unshare it) * @return array */ public function getAccessList(\OCP\Files\Node $path, $recursive = true, $currentAccess = false) { diff --git a/lib/private/legacy/app.php b/lib/private/legacy/app.php index bd261b05e5..efa2afd735 100644 --- a/lib/private/legacy/app.php +++ b/lib/private/legacy/app.php @@ -185,6 +185,8 @@ class OC_App { 'class' => $plugin['@value'], ]; \OC::$server->getCollaboratorSearch()->registerPlugin($pluginInfo); + } else if ($plugin['@attributes']['type'] === 'autocomplete-sort') { + \OC::$server->getAutoCompleteManager()->registerSorter($plugin['@value']); } } } diff --git a/lib/public/Collaboration/AutoComplete/IManager.php b/lib/public/Collaboration/AutoComplete/IManager.php new file mode 100644 index 0000000000..e9f33727cd --- /dev/null +++ b/lib/public/Collaboration/AutoComplete/IManager.php @@ -0,0 +1,46 @@ + + * + * @author Arthur Schiwon + * + * @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\Collaboration\AutoComplete; + +/** + * Interface IManager + * + * @package OCP\Collaboration\AutoComplete + * @since 13.0.0 + */ +interface IManager { + /** + * @param string $className – class name of the ISorter implementation + * @since 13.0.0 + */ + public function registerSorter($className); + + /** + * @param array $sorters list of sorter IDs, seperated by "|" + * @param array $sortArray array representation of OCP\Collaboration\Collaborators\ISearchResult + * @param array $context context info of the search, keys: itemType, itemId + * @since 13.0.0 + */ + public function runSorters(array $sorters, array &$sortArray, array $context); +} diff --git a/lib/public/Collaboration/AutoComplete/ISorter.php b/lib/public/Collaboration/AutoComplete/ISorter.php new file mode 100644 index 0000000000..538ca41003 --- /dev/null +++ b/lib/public/Collaboration/AutoComplete/ISorter.php @@ -0,0 +1,50 @@ + + * + * @author Arthur Schiwon + * + * @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\Collaboration\AutoComplete; + +/** + * Interface ISorter + * + * Sorts the list of .e.g users for auto completion + * + * @package OCP\Collaboration\AutoComplete + * @since 13.0.0 + */ +interface ISorter { + + /** + * @return string The ID of the sorter, e.g. commenters + * @since 13.0.0 + */ + public function getId(); + + /** + * executes the sort action + * + * @param array $sortArray the array to be sorted, provided as reference + * @param array $context carries key 'itemType' and 'itemId' of the source object (e.g. a file) + * @since 13.0.0 + */ + public function sort(array &$sortArray, array $context); +} diff --git a/lib/public/Comments/ICommentsManager.php b/lib/public/Comments/ICommentsManager.php index 61633af95c..e3ea7888ff 100644 --- a/lib/public/Comments/ICommentsManager.php +++ b/lib/public/Comments/ICommentsManager.php @@ -137,6 +137,28 @@ interface ICommentsManager { */ public function getNumberOfUnreadCommentsForFolder($folderId, IUser $user); + /** + * Get the actor types and ID that commented in the tree specified by the ID + * + * @param string $id + * @return array + * @since 13.0.0 + * + * The return array looks like this: + * + * [ + * 'users' => [ + * 'alice', + * 'bob', + * ], + * 'robots' => [ + * 'r2-d2', + * 'c-3po', + * ] + * ] + */ + public function getActorsInTree($id); + /** * creates a new comment and returns it. At this point of time, it is not * saved in the used data storage. Use save() after setting other fields diff --git a/tests/Core/Controller/AutoCompleteControllerTest.php b/tests/Core/Controller/AutoCompleteControllerTest.php new file mode 100644 index 0000000000..59dac58b95 --- /dev/null +++ b/tests/Core/Controller/AutoCompleteControllerTest.php @@ -0,0 +1,84 @@ + + * + * @author Arthur Schiwon + * + * @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 Tests\Core\Controller; + + +use OC\Core\Controller\AutoCompleteController; +use OCP\Collaboration\AutoComplete\IManager; +use OCP\Collaboration\Collaborators\ISearch; +use OCP\IRequest; +use Test\TestCase; + +class AutoCompleteControllerTest extends TestCase { + /** @var ISearch|\PHPUnit_Framework_MockObject_MockObject */ + protected $collaboratorSearch; + /** @var IManager|\PHPUnit_Framework_MockObject_MockObject */ + protected $autoCompleteManager; + /** @var AutoCompleteController */ + protected $controller; + + protected function setUp() { + parent::setUp(); + + /** @var IRequest $request */ + $request = $this->createMock(IRequest::class); + $this->collaboratorSearch = $this->createMock(ISearch::class); + $this->autoCompleteManager = $this->createMock(IManager::class); + + $this->controller = new AutoCompleteController( + 'core', + $request, + $this->collaboratorSearch, + $this->autoCompleteManager + ); + } + + public function testGet() { + $searchResults = [ + 'exact' => [ + 'users' => [], + 'robots' => [], + ], + 'users' => [ + ['label' => 'Alice A.', 'value' => ['shareWith' => 'alice']], + ['label' => 'Bob Y.', 'value' => ['shareWith' => 'bob']], + ], + ]; + + $expected = [ + [ 'id' => 'alice', 'label' => 'Alice A.', 'source' => 'users'], + [ 'id' => 'bob', 'label' => 'Bob Y.', 'source' => 'users'], + ]; + + $this->collaboratorSearch->expects($this->once()) + ->method('search') + ->willReturn([$searchResults, false]); + + $response = $this->controller->get('files', '42', null); + + $list = $response->getData(); + $this->assertEquals($expected, $list); // has better error output… + $this->assertSame($expected, $list); + } +} diff --git a/tests/lib/Comments/FakeManager.php b/tests/lib/Comments/FakeManager.php index 840961fb90..d3dd1dfb58 100644 --- a/tests/lib/Comments/FakeManager.php +++ b/tests/lib/Comments/FakeManager.php @@ -1,12 +1,14 @@ getManager(); } @@ -109,7 +110,7 @@ class ManagerTest extends TestCase { $id = strval($qb->getLastInsertId()); $comment = $manager->get($id); - $this->assertTrue($comment instanceof \OCP\Comments\IComment); + $this->assertTrue($comment instanceof IComment); $this->assertSame($comment->getId(), $id); $this->assertSame($comment->getParentId(), '2'); $this->assertSame($comment->getTopmostParentId(), '1'); @@ -152,14 +153,14 @@ class ManagerTest extends TestCase { // Verifying the root comment $this->assertTrue(isset($tree['comment'])); - $this->assertTrue($tree['comment'] instanceof \OCP\Comments\IComment); + $this->assertTrue($tree['comment'] instanceof IComment); $this->assertSame($tree['comment']->getId(), strval($headId)); $this->assertTrue(isset($tree['replies'])); $this->assertSame(count($tree['replies']), 3); // one level deep foreach ($tree['replies'] as $reply) { - $this->assertTrue($reply['comment'] instanceof \OCP\Comments\IComment); + $this->assertTrue($reply['comment'] instanceof IComment); $this->assertSame($reply['comment']->getId(), strval($id)); $this->assertSame(count($reply['replies']), 0); $id--; @@ -174,7 +175,7 @@ class ManagerTest extends TestCase { // Verifying the root comment $this->assertTrue(isset($tree['comment'])); - $this->assertTrue($tree['comment'] instanceof \OCP\Comments\IComment); + $this->assertTrue($tree['comment'] instanceof IComment); $this->assertSame($tree['comment']->getId(), strval($id)); $this->assertTrue(isset($tree['replies'])); $this->assertSame(count($tree['replies']), 0); @@ -200,14 +201,14 @@ class ManagerTest extends TestCase { // Verifying the root comment $this->assertTrue(isset($tree['comment'])); - $this->assertTrue($tree['comment'] instanceof \OCP\Comments\IComment); + $this->assertTrue($tree['comment'] instanceof IComment); $this->assertSame($tree['comment']->getId(), strval($headId)); $this->assertTrue(isset($tree['replies'])); $this->assertSame(count($tree['replies']), 2); // one level deep foreach ($tree['replies'] as $reply) { - $this->assertTrue($reply['comment'] instanceof \OCP\Comments\IComment); + $this->assertTrue($reply['comment'] instanceof IComment); $this->assertSame($reply['comment']->getId(), strval($idToVerify)); $this->assertSame(count($reply['replies']), 0); $idToVerify--; @@ -223,7 +224,7 @@ class ManagerTest extends TestCase { $this->assertTrue(is_array($comments)); $this->assertSame(count($comments), 1); - $this->assertTrue($comments[0] instanceof \OCP\Comments\IComment); + $this->assertTrue($comments[0] instanceof IComment); $this->assertSame($comments[0]->getMessage(), 'nice one'); } @@ -243,7 +244,7 @@ class ManagerTest extends TestCase { $this->assertTrue(is_array($comments)); foreach ($comments as $comment) { - $this->assertTrue($comment instanceof \OCP\Comments\IComment); + $this->assertTrue($comment instanceof IComment); $this->assertSame($comment->getMessage(), 'nice one'); $this->assertSame($comment->getId(), strval($idToVerify)); $idToVerify--; @@ -252,6 +253,37 @@ class ManagerTest extends TestCase { } while (count($comments) > 0); } + public function testGetActorsInTree() { + $manager = $this->getManager(); + + $headId = $this->addDatabaseEntry(0, 0); + + $id = $this->addDatabaseEntry($headId, $headId, new \DateTime('-3 hours')); + $comment = $manager->get($id)->setActor('users', 'bob'); + $manager->save($comment); + + $this->addDatabaseEntry($headId, $headId, new \DateTime('-2 hours')); + $this->addDatabaseEntry($headId, $headId, new \DateTime('-2 hours')); + + $id = $this->addDatabaseEntry($headId, $headId, new \DateTime('-1 hour')); + $comment = $manager->get($id)->setActor('users', 'bob'); + $manager->save($comment); + + $id = $this->addDatabaseEntry($headId, $headId, new \DateTime('-4 hour')); + $comment = $manager->get($id)->setActor('users', 'cynthia'); + $manager->save($comment); + + $actors = $manager->getActorsInTree($headId); + $this->assertTrue(isset($actors['users'])); + $this->assertCount(3, $actors['users']); + $this->assertTrue(isset($actors['users']['alice'])); + $this->assertTrue(isset($actors['users']['bob'])); + $this->assertTrue(isset($actors['users']['cynthia'])); + $this->assertSame(3, $actors['users']['alice']); + $this->assertSame(2, $actors['users']['bob']); + $this->assertSame(1, $actors['users']['cynthia']); + } + public function testGetForObjectWithDateTimeConstraint() { $this->addDatabaseEntry(0, 0, new \DateTime('-6 hours')); $this->addDatabaseEntry(0, 0, new \DateTime('-5 hours')); @@ -282,7 +314,7 @@ class ManagerTest extends TestCase { $this->assertTrue(is_array($comments)); foreach ($comments as $comment) { - $this->assertTrue($comment instanceof \OCP\Comments\IComment); + $this->assertTrue($comment instanceof IComment); $this->assertSame($comment->getMessage(), 'nice one'); $this->assertSame($comment->getId(), strval($idToVerify)); $this->assertTrue(intval($comment->getId()) >= 4); @@ -334,6 +366,7 @@ class ManagerTest extends TestCase { $this->addDatabaseEntry(0, 0, null, null, $fileIds[$i]); } $this->addDatabaseEntry(0, 0, (new \DateTime())->modify('-2 days'), null, $fileIds[0]); + /** @var IUser|\PHPUnit_Framework_MockObject_MockObject $user */ $user = $this->createMock(IUser::class); $user->expects($this->any()) ->method('getUID') @@ -368,6 +401,10 @@ class ManagerTest extends TestCase { /** * @dataProvider invalidCreateArgsProvider * @expectedException \InvalidArgumentException + * @param string $aType + * @param string $aId + * @param string $oType + * @param string $oId */ public function testCreateCommentInvalidArguments($aType, $aId, $oType, $oId) { $manager = $this->getManager(); @@ -381,7 +418,7 @@ class ManagerTest extends TestCase { $objectId = 'bielefeld'; $comment = $this->getManager()->create($actorType, $actorId, $objectType, $objectId); - $this->assertTrue($comment instanceof \OCP\Comments\IComment); + $this->assertTrue($comment instanceof IComment); $this->assertSame($comment->getActorType(), $actorType); $this->assertSame($comment->getActorId(), $actorId); $this->assertSame($comment->getObjectType(), $objectType); @@ -405,7 +442,7 @@ class ManagerTest extends TestCase { $id = strval($this->addDatabaseEntry(0, 0)); $comment = $manager->get($id); - $this->assertTrue($comment instanceof \OCP\Comments\IComment); + $this->assertTrue($comment instanceof IComment); $done = $manager->delete($id); $this->assertTrue($done); $manager->get($id); @@ -515,6 +552,8 @@ class ManagerTest extends TestCase { /** * @dataProvider invalidActorArgsProvider * @expectedException \InvalidArgumentException + * @param string $type + * @param string $id */ public function testDeleteReferencesOfActorInvalidInput($type, $id) { $manager = $this->getManager(); @@ -551,7 +590,7 @@ class ManagerTest extends TestCase { public function testDeleteReferencesOfActorWithUserManagement() { $user = \OC::$server->getUserManager()->createUser('xenia', '123456'); - $this->assertTrue($user instanceof \OCP\IUser); + $this->assertTrue($user instanceof IUser); $manager = \OC::$server->getCommentsManager(); $comment = $manager->create('users', $user->getUID(), 'files', 'file64'); @@ -565,8 +604,8 @@ class ManagerTest extends TestCase { $user->delete(); $comment = $manager->get($commentID); - $this->assertSame($comment->getActorType(), \OCP\Comments\ICommentsManager::DELETED_USER); - $this->assertSame($comment->getActorId(), \OCP\Comments\ICommentsManager::DELETED_USER); + $this->assertSame($comment->getActorType(), ICommentsManager::DELETED_USER); + $this->assertSame($comment->getActorId(), ICommentsManager::DELETED_USER); } public function invalidObjectArgsProvider() { @@ -581,6 +620,8 @@ class ManagerTest extends TestCase { /** * @dataProvider invalidObjectArgsProvider * @expectedException \InvalidArgumentException + * @param string $type + * @param string $id */ public function testDeleteCommentsAtObjectInvalidInput($type, $id) { $manager = $this->getManager(); @@ -607,7 +648,7 @@ class ManagerTest extends TestCase { foreach ($ids as $id) { try { $manager->get(strval($id)); - } catch (\OCP\Comments\NotFoundException $e) { + } catch (NotFoundException $e) { $verified++; } } @@ -620,6 +661,7 @@ class ManagerTest extends TestCase { } public function testSetMarkRead() { + /** @var IUser|\PHPUnit_Framework_MockObject_MockObject $user */ $user = $this->createMock(IUser::class); $user->expects($this->any()) ->method('getUID') @@ -636,6 +678,7 @@ class ManagerTest extends TestCase { } public function testSetMarkReadUpdate() { + /** @var IUser|\PHPUnit_Framework_MockObject_MockObject $user */ $user = $this->createMock(IUser::class); $user->expects($this->any()) ->method('getUID') @@ -655,6 +698,7 @@ class ManagerTest extends TestCase { } public function testReadMarkDeleteUser() { + /** @var IUser|\PHPUnit_Framework_MockObject_MockObject $user */ $user = $this->createMock(IUser::class); $user->expects($this->any()) ->method('getUID') @@ -672,6 +716,7 @@ class ManagerTest extends TestCase { } public function testReadMarkDeleteObject() { + /** @var IUser|\PHPUnit_Framework_MockObject_MockObject $user */ $user = $this->createMock(IUser::class); $user->expects($this->any()) ->method('getUID')