]> source.dussan.org Git - nextcloud-server.git/commitdiff
share api expanded by tags (#26583) 3876/head
authorMichael Jobst <mjobst+github@tecratech.de>
Thu, 10 Nov 2016 08:13:25 +0000 (09:13 +0100)
committerMorris Jobke <hey@morrisjobke.de>
Tue, 11 Apr 2017 16:54:13 +0000 (11:54 -0500)
* share api expanded by tags

* Modified files_sharing JS Unit tests

* modified tests. renamed request parameter. refactoring

* Update Share20OCS.php

Added missing function description

* Update Helper.php

Added missing function description

* Update Helper.php

implicit boolean conversion to !empty()

* Update Share20OCSTest.php

Signed-off-by: Morris Jobke <hey@morrisjobke.de>
apps/files/ajax/list.php
apps/files/js/tagsplugin.js
apps/files/lib/Helper.php
apps/files_sharing/js/sharedfilelist.js
apps/files_sharing/lib/Controller/ShareAPIController.php
apps/files_sharing/tests/js/sharedfilelistSpec.js

index 2cd097654351f30e9d9d8685b5018f40b290aa7a..d91db8744c41e0de9ab5267815957ed608dddfe1 100644 (file)
@@ -71,7 +71,6 @@ try {
                $files = \OCA\Files\Helper::getFiles($dir, $sortAttribute, $sortDirection);
        }
 
-       $files = \OCA\Files\Helper::populateTags($files);
        $data['directory'] = $dir;
        $data['files'] = \OCA\Files\Helper::formatFileInfos($files);
        $data['permissions'] = $permissions;
index 67bd9c667c84154fa20413c554e553b47255f9d2..9bd20be4bf88fc4d6ef58d3493d79c6ad632dd88 100644 (file)
 
                allowedLists: [
                        'files',
-                       'favorites'
+                       'favorites',
+                       'systemtags',
+                       'shares.self',
+                       'shares.others',
+                       'shares.link'
                ],
 
                _extendFileActions: function(fileActions) {
 })(OCA);
 
 OC.Plugins.register('OCA.Files.FileList', OCA.Files.TagsPlugin);
-
index b6b209dea70d11fccbcc300b7de8b4d94e4c6931..c3d809579139d01981a2970548edffd99e01cb18 100644 (file)
@@ -208,19 +208,40 @@ class Helper {
         * Populate the result set with file tags
         *
         * @param array $fileList
+        * @param string $fileIdentifier identifier attribute name for values in $fileList
         * @return array file list populated with tags
         */
-       public static function populateTags(array $fileList) {
-               $filesById = array();
+       public static function populateTags(array $fileList, $fileIdentifier = 'fileid') {
+               $filesById = [];
                foreach ($fileList as $fileData) {
-                       $filesById[$fileData['fileid']] = $fileData;
+                       $filesById[$fileData[$fileIdentifier]] = $fileData;
                }
                $tagger = \OC::$server->getTagManager()->load('files');
                $tags = $tagger->getTagsForObjects(array_keys($filesById));
-               if ($tags) {
+
+               if (!is_array($tags)) {
+                       throw new \UnexpectedValueException('$tags must be an array');
+               }
+
+               if (!empty($tags)) {
                        foreach ($tags as $fileId => $fileTags) {
                                $filesById[$fileId]['tags'] = $fileTags;
                        }
+
+                       foreach ($filesById as $key => $fileWithTags) {
+                               foreach($fileList as $key2 => $file){
+                                       if( $file[$fileIdentifier] == $key){
+                                               $fileList[$key2] = $fileWithTags;
+                                       }
+                               }
+                       }
+
+                       foreach ($fileList as $key => $file) {
+                               if (!array_key_exists('tags', $file)) {
+                                       $fileList[$key]['tags'] = [];
+                               }
+                       }
+
                }
                return $fileList;
        }
index 326bd1b5bf86e978b3273580c940b6043d6e65b2..b11b302c6c296287379473c7fe599dd6020604da 100644 (file)
@@ -56,7 +56,6 @@
                        if (options && options.linksOnly) {
                                this._linksOnly = true;
                        }
-                       OC.Plugins.attach('OCA.Sharing.FileList', this);
                },
 
                _renderRow: function() {
@@ -83,7 +82,7 @@
                        // add row with expiration date for link only shares - influenced by _createRow of filelist
                        if (this._linksOnly) {
                                var expirationTimestamp = 0;
-                               if(fileData.shares[0].expiration !== null) {
+                               if(fileData.shares && fileData.shares[0].expiration !== null) {
                                        expirationTimestamp = moment(fileData.shares[0].expiration).valueOf();
                                }
                                $tr.attr('data-expiration', expirationTimestamp);
                                /* jshint camelcase: false */
                                data: {
                                        format: 'json',
-                                       shared_with_me: !!this._sharedWithUser
+                                       shared_with_me: !!this._sharedWithUser,
+                                       include_tags: true
                                },
                                type: 'GET',
                                beforeSend: function(xhr) {
                                        url: OC.linkToOCS('apps/files_sharing/api/v1') + 'remote_shares',
                                        /* jshint camelcase: false */
                                        data: {
-                                               format: 'json'
+                                               format: 'json',
+                                               include_tags: true
                                        },
                                        type: 'GET',
                                        beforeSend: function(xhr) {
                                                type: share.type,
                                                id: share.file_id,
                                                path: OC.dirname(share.mountpoint),
-                                               permissions: share.permissions
+                                               permissions: share.permissions,
+                                               tags: share.tags || []
                                        };
 
                                        file.shares = [{
                                        var file = {
                                                id: share.file_source,
                                                icon: OC.MimeType.getIconUrl(share.mimetype),
-                                               mimetype: share.mimetype
+                                               mimetype: share.mimetype,
+                                               tags: share.tags || []
                                        };
                                        if (share.item_type === 'folder') {
                                                file.type = 'dir';
index bc525b6ef8218ced2139c38f01763fd049f530db..bd57d80dab0f93d045411eca7b79c58a99c881bd 100644 (file)
@@ -23,6 +23,7 @@
  */
 namespace OCA\Files_Sharing\Controller;
 
+use OCA\Files\Helper;
 use OCP\AppFramework\Http\DataResponse;
 use OCP\AppFramework\OCS\OCSBadRequestException;
 use OCP\AppFramework\OCS\OCSException;
@@ -484,9 +485,10 @@ class ShareAPIController extends OCSController {
 
        /**
         * @param \OCP\Files\File|\OCP\Files\Folder $node
+        * @param boolean $includeTags
         * @return DataResponse
         */
-       private function getSharedWithMe($node = null) {
+       private function getSharedWithMe($node = null, $includeTags) {
 
                $userShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_USER, $node, -1, 0);
                $groupShares = $this->shareManager->getSharedWith($this->currentUser, \OCP\Share::SHARE_TYPE_GROUP, $node, -1, 0);
@@ -509,6 +511,10 @@ class ShareAPIController extends OCSController {
                        }
                }
 
+               if ($includeTags) {
+                       $formatted = Helper::populateTags($formatted, 'file_source');
+               }
+
                return new DataResponse($formatted);
        }
 
@@ -572,7 +578,8 @@ class ShareAPIController extends OCSController {
                $shared_with_me = 'false',
                $reshares = 'false',
                $subfiles = 'false',
-               $path = null
+               $path = null,
+               $include_tags = 'false'
        ) {
 
                if ($path !== null) {
@@ -588,7 +595,7 @@ class ShareAPIController extends OCSController {
                }
 
                if ($shared_with_me === 'true') {
-                       $result = $this->getSharedWithMe($path);
+                       $result = $this->getSharedWithMe($path, $include_tags);
                        return $result;
                }
 
@@ -634,6 +641,10 @@ class ShareAPIController extends OCSController {
                        }
                }
 
+               if ($include_tags) {
+                       $formatted = Helper::populateTags($formatted, 'file_source');
+               }
+
                return new DataResponse($formatted);
        }
 
index f177b61c78a0466ae7e832639fc527b7705facc6..3efbb8fcea3f4c18b38143cf1b8ad05997a73ae0 100644 (file)
@@ -48,6 +48,8 @@ describe('OCA.Sharing.FileList tests', function() {
                        '<div id="emptycontent">Empty content message</div>' +
                        '</div>'
                );
+
+               OC.Plugins.register('OCA.Files.FileList', OCA.Files.TagsPlugin);
        });
        afterEach(function() {
                testFiles = undefined;
@@ -93,6 +95,7 @@ describe('OCA.Sharing.FileList tests', function() {
                                                share_type: OC.Share.SHARE_TYPE_USER,
                                                share_with: 'user1',
                                                share_with_displayname: 'User One',
+                                               tags: [OC.TAG_FAVORITE],
                                                mimetype: 'text/plain',
                                                uid_owner: 'user2',
                                                displayname_owner: 'User Two'
@@ -133,12 +136,12 @@ describe('OCA.Sharing.FileList tests', function() {
                        expect(fakeServer.requests.length).toEqual(2);
                        expect(fakeServer.requests[0].url).toEqual(
                                OC.linkToOCS('apps/files_sharing/api/v1') +
-                               'shares?format=json&shared_with_me=true'
+                               'shares?format=json&shared_with_me=true&include_tags=true'
                        );
 
                        expect(fakeServer.requests[1].url).toEqual(
                                OC.linkToOCS('apps/files_sharing/api/v1') +
-                               'remote_shares?format=json'
+                               'remote_shares?format=json&include_tags=true'
                        );
 
                        fakeServer.requests[0].respond(
@@ -150,7 +153,7 @@ describe('OCA.Sharing.FileList tests', function() {
                        fakeServer.requests[1].respond(
                                200,
                                { 'Content-Type': 'application/json' },
-                               JSON.stringify(ocsResponseRemote)                       
+                               JSON.stringify(ocsResponseRemote)
                        );
 
                        var $rows = fileList.$el.find('tbody tr');
@@ -167,6 +170,8 @@ describe('OCA.Sharing.FileList tests', function() {
                        expect($tr.attr('data-mtime')).toEqual('11111000');
                        expect($tr.attr('data-share-owner')).toEqual('User Two');
                        expect($tr.attr('data-share-id')).toEqual('7');
+                       expect($tr.attr('data-favorite')).toEqual('true');
+                       expect($tr.attr('data-tags')).toEqual(OC.TAG_FAVORITE);
                        expect($tr.find('a.name').attr('href')).toEqual(
                                OC.webroot +
                                '/remote.php/webdav/local%20path/local%20name.txt'
@@ -185,6 +190,8 @@ describe('OCA.Sharing.FileList tests', function() {
                        expect($tr.attr('data-mtime')).toEqual('22222000');
                        expect($tr.attr('data-share-owner')).toEqual('user3@foo.bar/');
                        expect($tr.attr('data-share-id')).toEqual('8');
+                       expect($tr.attr('data-favorite')).not.toBeDefined();
+                       expect($tr.attr('data-tags')).toEqual('');
                        expect($tr.find('a.name').attr('href')).toEqual(
                                OC.webroot +
                                '/remote.php/webdav/b.txt'
@@ -209,11 +216,11 @@ describe('OCA.Sharing.FileList tests', function() {
                        expect(fakeServer.requests.length).toEqual(2);
                        expect(fakeServer.requests[0].url).toEqual(
                                OC.linkToOCS('apps/files_sharing/api/v1') +
-                               'shares?format=json&shared_with_me=true'
+                               'shares?format=json&shared_with_me=true&include_tags=true'
                        );
                        expect(fakeServer.requests[1].url).toEqual(
                                OC.linkToOCS('apps/files_sharing/api/v1') +
-                               'remote_shares?format=json'
+                               'remote_shares?format=json&include_tags=true'
                        );
 
                        fakeServer.requests[0].respond(
@@ -241,6 +248,8 @@ describe('OCA.Sharing.FileList tests', function() {
                        expect($tr.attr('data-mtime')).toEqual('11111000');
                        expect($tr.attr('data-share-owner')).toEqual('User Two');
                        expect($tr.attr('data-share-id')).toEqual('7');
+                       expect($tr.attr('data-favorite')).toEqual('true');
+                       expect($tr.attr('data-tags')).toEqual(OC.TAG_FAVORITE);
                        expect($tr.find('a.name').attr('href')).toEqual(
                                OC.webroot +
                                '/index.php/apps/files' +
@@ -260,6 +269,8 @@ describe('OCA.Sharing.FileList tests', function() {
                        expect($tr.attr('data-mtime')).toEqual('22222000');
                        expect($tr.attr('data-share-owner')).toEqual('user3@foo.bar/');
                        expect($tr.attr('data-share-id')).toEqual('8');
+                       expect($tr.attr('data-favorite')).not.toBeDefined();
+                       expect($tr.attr('data-tags')).toEqual('');
                        expect($tr.find('a.name').attr('href')).toEqual(
                                OC.webroot +
                                '/index.php/apps/files' +
@@ -301,6 +312,7 @@ describe('OCA.Sharing.FileList tests', function() {
                                                share_type: OC.Share.SHARE_TYPE_USER,
                                                share_with: 'user2',
                                                share_with_displayname: 'User Two',
+                                               tags: [OC.TAG_FAVORITE],
                                                mimetype: 'text/plain',
                                                uid_owner: 'user1',
                                                displayname_owner: 'User One'
@@ -315,7 +327,7 @@ describe('OCA.Sharing.FileList tests', function() {
                        request = fakeServer.requests[0];
                        expect(request.url).toEqual(
                                OC.linkToOCS('apps/files_sharing/api/v1') +
-                               'shares?format=json&shared_with_me=false'
+                               'shares?format=json&shared_with_me=false&include_tags=true'
                        );
 
                        fakeServer.requests[0].respond(
@@ -337,6 +349,8 @@ describe('OCA.Sharing.FileList tests', function() {
                        expect($tr.attr('data-mtime')).toEqual('11111000');
                        expect($tr.attr('data-share-owner')).not.toBeDefined();
                        expect($tr.attr('data-share-id')).toEqual('7');
+                       expect($tr.attr('data-favorite')).toEqual('true');
+                       expect($tr.attr('data-tags')).toEqual(OC.TAG_FAVORITE);
                        expect($tr.find('a.name').attr('href')).toEqual(
                                OC.webroot +
                                '/remote.php/webdav/local%20path/local%20name.txt'
@@ -355,7 +369,7 @@ describe('OCA.Sharing.FileList tests', function() {
                        request = fakeServer.requests[0];
                        expect(request.url).toEqual(
                                OC.linkToOCS('apps/files_sharing/api/v1') +
-                               'shares?format=json&shared_with_me=false'
+                               'shares?format=json&shared_with_me=false&include_tags=true'
                        );
 
                        fakeServer.requests[0].respond(
@@ -377,6 +391,8 @@ describe('OCA.Sharing.FileList tests', function() {
                        expect($tr.attr('data-mtime')).toEqual('11111000');
                        expect($tr.attr('data-share-owner')).not.toBeDefined();
                        expect($tr.attr('data-share-id')).toEqual('7');
+                       expect($tr.attr('data-favorite')).toEqual('true');
+                       expect($tr.attr('data-tags')).toEqual(OC.TAG_FAVORITE);
                        expect($tr.find('a.name').attr('href')).toEqual(
                                OC.webroot +
                                '/index.php/apps/files' +
@@ -400,13 +416,14 @@ describe('OCA.Sharing.FileList tests', function() {
                                token: 'abc',
                                mimetype: 'text/plain',
                                uid_owner: 'user1',
-                               displayname_owner: 'User One'
+                               displayname_owner: 'User One',
+                               tags: [OC.TAG_FAVORITE]
                        };
                        expect(fakeServer.requests.length).toEqual(1);
                        request = fakeServer.requests[0];
                        expect(request.url).toEqual(
                                OC.linkToOCS('apps/files_sharing/api/v1') +
-                               'shares?format=json&shared_with_me=false'
+                               'shares?format=json&shared_with_me=false&include_tags=true'
                        );
 
                        fakeServer.requests[0].respond(
@@ -428,6 +445,8 @@ describe('OCA.Sharing.FileList tests', function() {
                        expect($tr.attr('data-mtime')).toEqual('11111000');
                        expect($tr.attr('data-share-owner')).not.toBeDefined();
                        expect($tr.attr('data-share-id')).toEqual('7');
+                       expect($tr.attr('data-favorite')).toEqual('true');
+                       expect($tr.attr('data-tags')).toEqual(OC.TAG_FAVORITE);
                        expect($tr.find('a.name').attr('href')).toEqual(
                                OC.webroot + '/remote.php/webdav/local%20path/local%20name.txt'
                        );
@@ -451,7 +470,8 @@ describe('OCA.Sharing.FileList tests', function() {
                                token: 'abc',
                                mimetype: 'text/plain',
                                uid_owner: 'user1',
-                               displayname_owner: 'User One'
+                               displayname_owner: 'User One',
+                               tags: [OC.TAG_FAVORITE],
                        });
                        // another share of the same file
                        ocsResponse.ocs.data.push({
@@ -473,7 +493,7 @@ describe('OCA.Sharing.FileList tests', function() {
                        request = fakeServer.requests[0];
                        expect(request.url).toEqual(
                                OC.linkToOCS('apps/files_sharing/api/v1') +
-                               'shares?format=json&shared_with_me=false'
+                               'shares?format=json&shared_with_me=false&include_tags=true'
                        );
 
                        fakeServer.requests[0].respond(
@@ -496,6 +516,8 @@ describe('OCA.Sharing.FileList tests', function() {
                        expect($tr.attr('data-mtime')).toEqual('22222000');
                        expect($tr.attr('data-share-owner')).not.toBeDefined();
                        expect($tr.attr('data-share-id')).toEqual('7,8,9');
+                       expect($tr.attr('data-favorite')).toEqual('true');
+                       expect($tr.attr('data-tags')).toEqual(OC.TAG_FAVORITE);
                        expect($tr.find('a.name').attr('href')).toEqual(
                                OC.webroot + '/remote.php/webdav/local%20path/local%20name.txt'
                        );
@@ -540,7 +562,8 @@ describe('OCA.Sharing.FileList tests', function() {
                                                token: 'abc',
                                                mimetype: 'text/plain',
                                                uid_owner: 'user1',
-                                               displayname_owner: 'User One'
+                                               displayname_owner: 'User One',
+                                               tags: [OC.TAG_FAVORITE]
                                        },{
                                                id: 8,
                                                item_type: 'file',
@@ -577,13 +600,14 @@ describe('OCA.Sharing.FileList tests', function() {
                                share_with_displayname: 'User Two',
                                mimetype: 'text/plain',
                                uid_owner: 'user1',
-                               displayname_owner: 'User One'
+                               displayname_owner: 'User One',
+                               tags: [OC.TAG_FAVORITE]
                        });
                        expect(fakeServer.requests.length).toEqual(1);
                        request = fakeServer.requests[0];
                        expect(request.url).toEqual(
                                OC.linkToOCS('apps/files_sharing/api/v1') +
-                               'shares?format=json&shared_with_me=false'
+                               'shares?format=json&shared_with_me=false&include_tags=true'
                        );
 
                        fakeServer.requests[0].respond(
@@ -607,6 +631,8 @@ describe('OCA.Sharing.FileList tests', function() {
                        expect($tr.attr('data-share-recipients')).not.toBeDefined();
                        expect($tr.attr('data-share-owner')).not.toBeDefined();
                        expect($tr.attr('data-share-id')).toEqual('7');
+                       expect($tr.attr('data-favorite')).toEqual('true');
+                       expect($tr.attr('data-tags')).toEqual(OC.TAG_FAVORITE);
                        expect($tr.find('a.name').attr('href')).toEqual(
                                OC.webroot + '/remote.php/webdav/local%20path/local%20name.txt'
                        );
@@ -620,6 +646,8 @@ describe('OCA.Sharing.FileList tests', function() {
                        expect($tr.attr('data-id')).toEqual('50');
                        expect($tr.attr('data-file')).toEqual('local name2.txt');
                        expect($tr.attr('data-expiration')).not.toEqual('0');
+                       expect($tr.attr('data-favorite')).not.toBeDefined();
+                       expect($tr.attr('data-tags')).toEqual('');
                        expect($tr.find('td:last-child span').text()).toEqual('in a day');
                });
                it('does not show virtual token recipient as recipient when password was set', function() {
@@ -632,7 +660,7 @@ describe('OCA.Sharing.FileList tests', function() {
                        request = fakeServer.requests[0];
                        expect(request.url).toEqual(
                                OC.linkToOCS('apps/files_sharing/api/v1') +
-                               'shares?format=json&shared_with_me=false'
+                               'shares?format=json&shared_with_me=false&include_tags=true'
                        );
 
                        fakeServer.requests[0].respond(
@@ -656,6 +684,8 @@ describe('OCA.Sharing.FileList tests', function() {
                        expect($tr.attr('data-share-recipients')).not.toBeDefined();
                        expect($tr.attr('data-share-owner')).not.toBeDefined();
                        expect($tr.attr('data-share-id')).toEqual('7');
+                       expect($tr.attr('data-favorite')).toEqual('true');
+                       expect($tr.attr('data-tags')).toEqual(OC.TAG_FAVORITE);
                        expect($tr.find('a.name').attr('href')).toEqual(
                                        OC.webroot +
                                        '/remote.php/webdav/local%20path/local%20name.txt');