diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2015-10-02 14:48:12 +0200 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2015-10-02 14:48:12 +0200 |
commit | 54e19d7ca3031c0f5975c698b95be4377fa9980f (patch) | |
tree | 8f13e305befbf6f0c35bf2d2b8617053bd56f74f /apps | |
parent | c64101ff6e31f5302ea026b61505c877c6f804f0 (diff) | |
parent | 4adc78b78b3f6a659d79eaf17dff3ae5d7f79db7 (diff) | |
download | nextcloud-server-54e19d7ca3031c0f5975c698b95be4377fa9980f.tar.gz nextcloud-server-54e19d7ca3031c0f5975c698b95be4377fa9980f.zip |
Merge pull request #19514 from owncloud/list_remote_shares_in_shared_with_you
List remote shares in shared with you
Diffstat (limited to 'apps')
-rw-r--r-- | apps/files_sharing/js/sharedfilelist.js | 73 | ||||
-rw-r--r-- | apps/files_sharing/tests/js/sharedfilelistSpec.js | 115 |
2 files changed, 171 insertions, 17 deletions
diff --git a/apps/files_sharing/js/sharedfilelist.js b/apps/files_sharing/js/sharedfilelist.js index 98dbd4c6702..2e798a92578 100644 --- a/apps/files_sharing/js/sharedfilelist.js +++ b/apps/files_sharing/js/sharedfilelist.js @@ -122,7 +122,9 @@ if (this._reloadCall) { this._reloadCall.abort(); } - this._reloadCall = $.ajax({ + + var promises = []; + var shares = $.ajax({ url: OC.linkToOCS('apps/files_sharing/api/v1') + 'shares', /* jshint camelcase: false */ data: { @@ -132,25 +134,84 @@ type: 'GET', beforeSend: function(xhr) { xhr.setRequestHeader('OCS-APIREQUEST', 'true'); - } + }, }); + promises.push(shares); + + if (!!this._sharedWithUser) { + var remoteShares = $.ajax({ + url: OC.linkToOCS('apps/files_sharing/api/v1') + 'remote_shares', + /* jshint camelcase: false */ + data: { + format: 'json' + }, + type: 'GET', + beforeSend: function(xhr) { + xhr.setRequestHeader('OCS-APIREQUEST', 'true'); + }, + }); + promises.push(remoteShares); + } else { + //Push empty promise so callback gets called the same way + promises.push($.Deferred().resolve()); + } + + this._reloadCall = $.when.apply($, promises); var callBack = this.reloadCallback.bind(this); return this._reloadCall.then(callBack, callBack); }, - reloadCallback: function(result) { + reloadCallback: function(shares, remoteShares) { delete this._reloadCall; this.hideMask(); this.$el.find('#headerSharedWith').text( t('files_sharing', this._sharedWithUser ? 'Shared by' : 'Shared with') ); - if (result.ocs && result.ocs.data) { - this.setFiles(this._makeFilesFromShares(result.ocs.data)); + + var files = []; + + if (shares[0].ocs && shares[0].ocs.data) { + files = files.concat(this._makeFilesFromShares(shares[0].ocs.data)); + } else { + // TODO: error handling } - else { + + if (remoteShares && remoteShares[0].ocs && remoteShares[0].ocs.data) { + files = files.concat(this._makeFilesFromRemoteShares(remoteShares[0].ocs.data)); + } else { // TODO: error handling } + + this.setFiles(files); + }, + + _makeFilesFromRemoteShares: function(data) { + var self = this; + var files = data; + + files = _.chain(files) + // convert share data to file data + .map(function(share) { + var file = { + shareOwner: share.owner + '@' + share.remote.replace(/.*?:\/\//g, ""), + name: OC.basename(share.mountpoint), + mtime: share.mtime * 1000, + mimetype: share.mimetype, + type: share.type, + id: share.file_id, + path: OC.dirname(share.mountpoint), + permissions: share.permissions + }; + + file.shares = [{ + id: share.id, + type: OC.Share.SHARE_TYPE_REMOTE + }]; + return file; + }) + .value(); + return files; }, /** diff --git a/apps/files_sharing/tests/js/sharedfilelistSpec.js b/apps/files_sharing/tests/js/sharedfilelistSpec.js index 7fdc6345e38..90ae9c2d6da 100644 --- a/apps/files_sharing/tests/js/sharedfilelistSpec.js +++ b/apps/files_sharing/tests/js/sharedfilelistSpec.js @@ -57,6 +57,7 @@ describe('OCA.Sharing.FileList tests', function() { describe('loading file list for incoming shares', function() { var ocsResponse; + var ocsResponseRemote; beforeEach(function() { fileList = new OCA.Sharing.FileList( @@ -95,26 +96,64 @@ describe('OCA.Sharing.FileList tests', function() { }] } }; + + /* jshint camelcase: false */ + ocsResponseRemote = { + ocs: { + meta: { + status: 'ok', + statuscode: 100, + message: null + }, + data: [{ + id: 8, + remote: 'https://foo.bar/', + remote_id: 42, + share_token: 'abc', + name: '/a.txt', + owner: 'user3', + user: 'user1', + mountpoint: '/b.txt', + mountpoint_hash: 'def', + accepted: 1, + mimetype: 'text/plain', + mtime: 22222, + permissions: 31, + type: 'file', + file_id: 1337 + }] + } + }; + }); it('render file shares', function() { - var request; - - expect(fakeServer.requests.length).toEqual(1); - request = fakeServer.requests[0]; - expect(request.url).toEqual( + 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' ); + expect(fakeServer.requests[1].url).toEqual( + OC.linkToOCS('apps/files_sharing/api/v1') + + 'remote_shares?format=json' + ); + fakeServer.requests[0].respond( 200, { 'Content-Type': 'application/json' }, JSON.stringify(ocsResponse) ); + fakeServer.requests[1].respond( + 200, + { 'Content-Type': 'application/json' }, + JSON.stringify(ocsResponseRemote) + ); + var $rows = fileList.$el.find('tbody tr'); + expect($rows.length).toEqual(2); + var $tr = $rows.eq(0); - expect($rows.length).toEqual(1); expect($tr.attr('data-id')).toEqual('49'); expect($tr.attr('data-type')).toEqual('file'); expect($tr.attr('data-file')).toEqual('local name.txt'); @@ -132,32 +171,66 @@ describe('OCA.Sharing.FileList tests', function() { '?dir=%2Flocal%20path&files=local%20name.txt' ); expect($tr.find('.nametext').text().trim()).toEqual('local name.txt'); + + $tr = $rows.eq(1); + expect($tr.attr('data-id')).toEqual('1337'); + expect($tr.attr('data-type')).toEqual('file'); + expect($tr.attr('data-file')).toEqual('b.txt'); + expect($tr.attr('data-path')).toEqual(''); + expect($tr.attr('data-size')).not.toBeDefined(); + expect(parseInt($tr.attr('data-permissions'), 10)) + .toEqual(OC.PERMISSION_ALL); // read and delete + expect($tr.attr('data-mime')).toEqual('text/plain'); + 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.find('a.name').attr('href')).toEqual( + OC.webroot + + '/index.php/apps/files/ajax/download.php' + + '?dir=%2F&files=b.txt' + ); + expect($tr.find('.nametext').text().trim()).toEqual('b.txt'); }); it('render folder shares', function() { /* jshint camelcase: false */ - var request; ocsResponse.ocs.data[0] = _.extend(ocsResponse.ocs.data[0], { item_type: 'folder', file_target: '/local path/local name', path: 'files/something shared', }); - expect(fakeServer.requests.length).toEqual(1); - request = fakeServer.requests[0]; - expect(request.url).toEqual( + ocsResponseRemote.ocs.data[0] = _.extend(ocsResponseRemote.ocs.data[0], { + type: 'dir', + mimetype: 'httpd/unix-directory', + name: '/a', + mountpoint: '/b' + }); + + 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' ); + expect(fakeServer.requests[1].url).toEqual( + OC.linkToOCS('apps/files_sharing/api/v1') + + 'remote_shares?format=json' + ); fakeServer.requests[0].respond( 200, { 'Content-Type': 'application/json' }, JSON.stringify(ocsResponse) ); + fakeServer.requests[1].respond( + 200, + { 'Content-Type': 'application/json' }, + JSON.stringify(ocsResponseRemote) + ); var $rows = fileList.$el.find('tbody tr'); + expect($rows.length).toEqual(2); + var $tr = $rows.eq(0); - expect($rows.length).toEqual(1); expect($tr.attr('data-id')).toEqual('49'); expect($tr.attr('data-type')).toEqual('dir'); expect($tr.attr('data-file')).toEqual('local name'); @@ -175,6 +248,26 @@ describe('OCA.Sharing.FileList tests', function() { '?dir=/local%20path/local%20name' ); expect($tr.find('.nametext').text().trim()).toEqual('local name'); + + $tr = $rows.eq(1); + expect($tr.attr('data-id')).toEqual('1337'); + expect($tr.attr('data-type')).toEqual('dir'); + expect($tr.attr('data-file')).toEqual('b'); + expect($tr.attr('data-path')).toEqual(''); + expect($tr.attr('data-size')).not.toBeDefined(); + expect(parseInt($tr.attr('data-permissions'), 10)) + .toEqual(OC.PERMISSION_ALL); // read and delete + expect($tr.attr('data-mime')).toEqual('httpd/unix-directory'); + 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.find('a.name').attr('href')).toEqual( + OC.webroot + + '/index.php/apps/files' + + '?dir=/b' + ); + expect($tr.find('.nametext').text().trim()).toEqual('b'); + }); }); describe('loading file list for outgoing shares', function() { |