diff options
author | Lukas Reschke <lukas@statuscode.ch> | 2016-10-20 18:32:51 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-20 18:32:51 +0200 |
commit | 0864f53675e00c6606f614c34bb0ccfc5e5409a4 (patch) | |
tree | 10d5f3138c84a0be982226e7582700f84779e4f6 /apps/files | |
parent | ed4ed7911a9329462fef02c2d50709b3f092538e (diff) | |
parent | 361f008c705009eee8d7435f46095760ac706456 (diff) | |
download | nextcloud-server-0864f53675e00c6606f614c34bb0ccfc5e5409a4.tar.gz nextcloud-server-0864f53675e00c6606f614c34bb0ccfc5e5409a4.zip |
Merge pull request #1796 from nextcloud/oc_fav-report
Make it possible to filter by tags with REPORT method
Diffstat (limited to 'apps/files')
-rw-r--r-- | apps/files/appinfo/routes.php | 6 | ||||
-rw-r--r-- | apps/files/js/favoritesfilelist.js | 27 | ||||
-rw-r--r-- | apps/files/lib/Controller/ApiController.php | 17 | ||||
-rw-r--r-- | apps/files/lib/Service/TagService.php | 21 | ||||
-rw-r--r-- | apps/files/tests/Controller/ApiControllerTest.php | 176 | ||||
-rw-r--r-- | apps/files/tests/js/favoritesfilelistspec.js | 53 |
6 files changed, 36 insertions, 264 deletions
diff --git a/apps/files/appinfo/routes.php b/apps/files/appinfo/routes.php index 6237e8413ed..49dbe553435 100644 --- a/apps/files/appinfo/routes.php +++ b/apps/files/appinfo/routes.php @@ -45,12 +45,6 @@ $application->registerRoutes( 'requirements' => array('path' => '.+'), ), array( - 'name' => 'API#getFilesByTag', - 'url' => '/api/v1/tags/{tagName}/files', - 'verb' => 'GET', - 'requirements' => array('tagName' => '.+'), - ), - array( 'name' => 'API#getRecentFiles', 'url' => '/api/v1/recent/', 'verb' => 'GET' diff --git a/apps/files/js/favoritesfilelist.js b/apps/files/js/favoritesfilelist.js index e6532ab188c..380689be10b 100644 --- a/apps/files/js/favoritesfilelist.js +++ b/apps/files/js/favoritesfilelist.js @@ -75,24 +75,25 @@ $(document).ready(function() { // there is only root this._setCurrentDir('/', false); - this._reloadCall = $.ajax({ - url: OC.generateUrl('/apps/files/api/v1/tags/{tagName}/files', {tagName: tagName}), - type: 'GET', - dataType: 'json' - }); + this._reloadCall = this.filesClient.getFilteredFiles( + { + favorite: true + }, + { + properties: this._getWebdavProperties() + } + ); var callBack = this.reloadCallback.bind(this); return this._reloadCall.then(callBack, callBack); }, - reloadCallback: function(result) { - delete this._reloadCall; - this.hideMask(); - - if (result.files) { - this.setFiles(result.files.sort(this._sortComparator)); - return true; + reloadCallback: function(status, result) { + if (result) { + // prepend empty dir info because original handler + result.unshift({}); } - return false; + + return OCA.Files.FileList.prototype.reloadCallback.call(this, status, result); } }); diff --git a/apps/files/lib/Controller/ApiController.php b/apps/files/lib/Controller/ApiController.php index 7ce83bfca15..d6f88581b96 100644 --- a/apps/files/lib/Controller/ApiController.php +++ b/apps/files/lib/Controller/ApiController.php @@ -174,23 +174,6 @@ class ApiController extends Controller { } /** - * Returns a list of all files tagged with the given tag. - * - * @NoAdminRequired - * - * @param string $tagName tag name to filter by - * @return DataResponse - */ - public function getFilesByTag($tagName) { - $nodes = $this->tagService->getFilesByTag($tagName); - $files = $this->formatNodes($nodes); - foreach ($files as &$file) { - $file['tags'] = [$tagName]; - } - return new DataResponse(['files' => $files]); - } - - /** * Returns a list of recently modifed files. * * @NoAdminRequired diff --git a/apps/files/lib/Service/TagService.php b/apps/files/lib/Service/TagService.php index 04e962b5e17..4482fb45371 100644 --- a/apps/files/lib/Service/TagService.php +++ b/apps/files/lib/Service/TagService.php @@ -90,26 +90,5 @@ class TagService { // list is up to date, in case of concurrent changes ? return $tags; } - - /** - * Get all files for the given tag - * - * @param string $tagName tag name to filter by - * @return Node[] list of matching files - * @throws \Exception if the tag does not exist - */ - public function getFilesByTag($tagName) { - try { - $fileIds = $this->tagger->getIdsForTag($tagName); - } catch (\Exception $e) { - return []; - } - - $allNodes = []; - foreach ($fileIds as $fileId) { - $allNodes = array_merge($allNodes, $this->homeFolder->getById((int) $fileId)); - } - return $allNodes; - } } diff --git a/apps/files/tests/Controller/ApiControllerTest.php b/apps/files/tests/Controller/ApiControllerTest.php index 9bfc6d6f5e8..4b7bec065a0 100644 --- a/apps/files/tests/Controller/ApiControllerTest.php +++ b/apps/files/tests/Controller/ApiControllerTest.php @@ -103,182 +103,6 @@ class ApiControllerTest extends TestCase { ); } - public function testGetFilesByTagEmpty() { - $tagName = 'MyTagName'; - $this->tagService->expects($this->once()) - ->method('getFilesByTag') - ->with($this->equalTo([$tagName])) - ->will($this->returnValue([])); - - $expected = new DataResponse(['files' => []]); - $this->assertEquals($expected, $this->apiController->getFilesByTag([$tagName])); - } - - public function testGetFilesByTagSingle() { - $tagName = 'MyTagName'; - $fileInfo = new FileInfo( - '/root.txt', - $this->getMockBuilder('\OC\Files\Storage\Storage') - ->disableOriginalConstructor() - ->getMock(), - '/var/www/root.txt', - [ - 'mtime' => 55, - 'mimetype' => 'application/pdf', - 'permissions' => 31, - 'size' => 1234, - 'etag' => 'MyEtag', - ], - $this->getMockBuilder('\OCP\Files\Mount\IMountPoint') - ->disableOriginalConstructor() - ->getMock() - ); - $node = $this->getMockBuilder('\OC\Files\Node\File') - ->disableOriginalConstructor() - ->getMock(); - $node->expects($this->once()) - ->method('getFileInfo') - ->will($this->returnValue($fileInfo)); - $this->tagService->expects($this->once()) - ->method('getFilesByTag') - ->with($this->equalTo([$tagName])) - ->will($this->returnValue([$node])); - - $this->shareManager->expects($this->any()) - ->method('getSharesBy') - ->with( - $this->equalTo('user1'), - $this->anything(), - $node, - $this->equalTo(false), - $this->equalTo(1) - ) - ->will($this->returnCallback(function($userId, $shareType) { - if ($shareType === \OCP\Share::SHARE_TYPE_USER || $shareType === \OCP\Share::SHARE_TYPE_LINK) { - return ['dummy_share']; - } - return []; - })); - - $expected = new DataResponse([ - 'files' => [ - [ - 'id' => null, - 'parentId' => null, - 'mtime' => 55000, - 'name' => 'root.txt', - 'permissions' => 31, - 'mimetype' => 'application/pdf', - 'size' => 1234, - 'type' => 'file', - 'etag' => 'MyEtag', - 'path' => '/', - 'tags' => [ - [ - 'MyTagName' - ] - ], - 'shareTypes' => [\OCP\Share::SHARE_TYPE_USER, \OCP\Share::SHARE_TYPE_LINK] - ], - ], - ]); - $this->assertEquals($expected, $this->apiController->getFilesByTag([$tagName])); - } - - public function testGetFilesByTagMultiple() { - $tagName = 'MyTagName'; - $fileInfo1 = new FileInfo( - '/root.txt', - $this->getMockBuilder('\OC\Files\Storage\Storage') - ->disableOriginalConstructor() - ->getMock(), - '/var/www/root.txt', - [ - 'mtime' => 55, - 'mimetype' => 'application/pdf', - 'permissions' => 31, - 'size' => 1234, - 'etag' => 'MyEtag', - ], - $this->getMockBuilder('\OCP\Files\Mount\IMountPoint') - ->disableOriginalConstructor() - ->getMock() - ); - $fileInfo2 = new FileInfo( - '/root.txt', - $this->getMockBuilder('\OC\Files\Storage\Storage') - ->disableOriginalConstructor() - ->getMock(), - '/var/www/some/sub.txt', - [ - 'mtime' => 999, - 'mimetype' => 'application/binary', - 'permissions' => 31, - 'size' => 9876, - 'etag' => 'SubEtag', - ], - $this->getMockBuilder('\OCP\Files\Mount\IMountPoint') - ->disableOriginalConstructor() - ->getMock() - ); - $node1 = $this->getMockBuilder('\OC\Files\Node\File') - ->disableOriginalConstructor() - ->getMock(); - $node1->expects($this->once()) - ->method('getFileInfo') - ->will($this->returnValue($fileInfo1)); - $node2 = $this->getMockBuilder('\OC\Files\Node\File') - ->disableOriginalConstructor() - ->getMock(); - $node2->expects($this->once()) - ->method('getFileInfo') - ->will($this->returnValue($fileInfo2)); - $this->tagService->expects($this->once()) - ->method('getFilesByTag') - ->with($this->equalTo([$tagName])) - ->will($this->returnValue([$node1, $node2])); - - $expected = new DataResponse([ - 'files' => [ - [ - 'id' => null, - 'parentId' => null, - 'mtime' => 55000, - 'name' => 'root.txt', - 'permissions' => 31, - 'mimetype' => 'application/pdf', - 'size' => 1234, - 'type' => 'file', - 'etag' => 'MyEtag', - 'path' => '/', - 'tags' => [ - [ - 'MyTagName' - ] - ], - ], - [ - 'id' => null, - 'parentId' => null, - 'mtime' => 999000, - 'name' => 'root.txt', - 'permissions' => 31, - 'mimetype' => 'application/binary', - 'size' => 9876, - 'type' => 'file', - 'etag' => 'SubEtag', - 'path' => '/', - 'tags' => [ - [ - 'MyTagName' - ] - ], - ] - ], - ]); - $this->assertEquals($expected, $this->apiController->getFilesByTag([$tagName])); - } - public function testUpdateFileTagsEmpty() { $expected = new DataResponse([]); $this->assertEquals($expected, $this->apiController->updateFileTags('/path.txt')); diff --git a/apps/files/tests/js/favoritesfilelistspec.js b/apps/files/tests/js/favoritesfilelistspec.js index 1c833d334e2..db890927ed4 100644 --- a/apps/files/tests/js/favoritesfilelistspec.js +++ b/apps/files/tests/js/favoritesfilelistspec.js @@ -41,13 +41,9 @@ describe('OCA.Files.FavoritesFileList tests', function() { '</div>' ); }); - afterEach(function() { - fileList.destroy(); - fileList = undefined; - }); describe('loading file list', function() { - var response; + var fetchStub; beforeEach(function() { fileList = new OCA.Files.FavoritesFileList( @@ -55,36 +51,31 @@ describe('OCA.Files.FavoritesFileList tests', function() { ); OCA.Files.FavoritesPlugin.attach(fileList); - fileList.reload(); - - /* jshint camelcase: false */ - response = { - files: [{ - id: 7, - name: 'test.txt', - path: '/somedir', - size: 123, - mtime: 11111000, - tags: [OC.TAG_FAVORITE], - permissions: OC.PERMISSION_ALL, - mimetype: 'text/plain' - }] - }; + fetchStub = sinon.stub(fileList.filesClient, 'getFilteredFiles'); + }); + afterEach(function() { + fetchStub.restore(); + fileList.destroy(); + fileList = undefined; }); it('render files', function() { - var request; + var deferred = $.Deferred(); + fetchStub.returns(deferred.promise()); - expect(fakeServer.requests.length).toEqual(1); - request = fakeServer.requests[0]; - expect(request.url).toEqual( - OC.generateUrl('apps/files/api/v1/tags/{tagName}/files', {tagName: OC.TAG_FAVORITE}) - ); + fileList.reload(); - fakeServer.requests[0].respond( - 200, - { 'Content-Type': 'application/json' }, - JSON.stringify(response) - ); + expect(fetchStub.calledOnce).toEqual(true); + + deferred.resolve(207, [{ + id: 7, + name: 'test.txt', + path: '/somedir', + size: 123, + mtime: 11111000, + tags: [OC.TAG_FAVORITE], + permissions: OC.PERMISSION_ALL, + mimetype: 'text/plain' + }]); var $rows = fileList.$el.find('tbody tr'); var $tr = $rows.eq(0); |