diff --git a/apps/files_sharing/appinfo/app.php b/apps/files_sharing/appinfo/app.php index 21b2646c5e..2cd901c07a 100644 --- a/apps/files_sharing/appinfo/app.php +++ b/apps/files_sharing/appinfo/app.php @@ -41,3 +41,12 @@ OC_FileProxy::register(new OCA\Files\Share\Proxy()); "name" => $l->t('Shared with others') ) ); +\OCA\Files\App::getNavigationManager()->add( + array( + "id" => 'sharinglinks', + "appname" => 'files_sharing', + "script" => 'list.php', + "order" => 20, + "name" => $l->t('Shared with link') + ) +); diff --git a/apps/files_sharing/js/app.js b/apps/files_sharing/js/app.js index 3764328a5d..3c7720e239 100644 --- a/apps/files_sharing/js/app.js +++ b/apps/files_sharing/js/app.js @@ -53,6 +53,25 @@ OCA.Sharing.App = { return this._outFileList; }, + initSharingLinks: function($el) { + if (this._linkFileList) { + return this._linkFileList; + } + this._linkFileList = new OCA.Sharing.FileList( + $el, + { + scrollContainer: $('#app-content'), + linksOnly: true, + fileActions: this._createFileActions() + } + ); + + this._extendFileList(this._linkFileList); + this._linkFileList.appName = t('files_sharing', 'Shared with link'); + this._linkFileList.$el.find('#emptycontent').text(t('files_sharing', 'You haven\'t shared any files with link yet.')); + return this._linkFileList; + }, + removeSharingIn: function() { if (this._inFileList) { this._inFileList.$fileList.empty(); @@ -65,6 +84,12 @@ OCA.Sharing.App = { } }, + removeSharingLinks: function() { + if (this._linkFileList) { + this._linkFileList.$fileList.empty(); + } + }, + _createFileActions: function() { // inherit file actions from the files app var fileActions = new OCA.Files.FileActions(); @@ -102,5 +127,11 @@ $(document).ready(function() { $('#app-content-sharingout').on('hide', function() { OCA.Sharing.App.removeSharingOut(); }); + $('#app-content-sharinglinks').on('show', function(e) { + OCA.Sharing.App.initSharingLinks($(e.target)); + }); + $('#app-content-sharinglinks').on('hide', function() { + OCA.Sharing.App.removeSharingLinks(); + }); }); diff --git a/apps/files_sharing/js/sharedfilelist.js b/apps/files_sharing/js/sharedfilelist.js index ef1034ecfd..fa39ded3c3 100644 --- a/apps/files_sharing/js/sharedfilelist.js +++ b/apps/files_sharing/js/sharedfilelist.js @@ -26,6 +26,7 @@ * the files that the user shared with others (false). */ _sharedWithUser: false, + _linksOnly: false, initialize: function($el, options) { OCA.Files.FileList.prototype.initialize.apply(this, arguments); @@ -33,9 +34,13 @@ return; } + // TODO: consolidate both options if (options && options.sharedWithUser) { this._sharedWithUser = true; } + if (options && options.linksOnly) { + this._linksOnly = true; + } }, _createRow: function(fileData) { @@ -130,12 +135,20 @@ * @return array of file info maps */ _makeFilesFromShares: function(data) { + /* jshint camelcase: false */ var self = this; + var files = data; + + if (this._linksOnly) { + files = _.filter(data, function(share) { + return share.share_type === OC.Share.SHARE_TYPE_LINK; + }); + } + // OCS API uses non-camelcased names - var files = _.chain(data) + files = _.chain(files) // convert share data to file data .map(function(share) { - /* jshint camelcase: false */ var file = { id: share.file_source, mimetype: share.mimetype diff --git a/apps/files_sharing/tests/js/sharedfilelistSpec.js b/apps/files_sharing/tests/js/sharedfilelistSpec.js index 7aec8322a4..7967e0f186 100644 --- a/apps/files_sharing/tests/js/sharedfilelistSpec.js +++ b/apps/files_sharing/tests/js/sharedfilelistSpec.js @@ -409,4 +409,95 @@ describe('OCA.Sharing.FileList tests', function() { expect($tr.find('.nametext').text().trim()).toEqual('local name.txt'); }); }); + describe('loading file list for link shares', function() { + var ocsResponse; + + beforeEach(function() { + fileList = new OCA.Sharing.FileList( + $('#app-content-container'), { + linksOnly: true + } + ); + + fileList.reload(); + + ocsResponse = { + ocs: { + meta: { + status: 'ok', + statuscode: 100, + message: null + }, + data: [{ + id: 7, + item_type: 'file', + item_source: 49, + file_source: 49, + path: '/local path/local name.txt', + permissions: 1, + stime: 11111, + share_type: OC.Share.SHARE_TYPE_LINK, + share_with: null, + token: 'abc', + mimetype: 'text/plain', + uid_owner: 'user1', + displayname_owner: 'User One' + }] + } + }; + }); + it('render only link shares', function() { + /* jshint camelcase: false */ + var request; + ocsResponse.ocs.data.push({ + // non-link share + id: 8, + item_type: 'file', + item_source: 49, + file_source: 49, + path: '/local path/local name.txt', + permissions: 27, + stime: 11111, + share_type: OC.Share.SHARE_TYPE_USER, + share_with: 'user2', + share_with_displayname: 'User Two', + mimetype: 'text/plain', + uid_owner: 'user1', + displayname_owner: 'User One' + }); + 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' + ); + + fakeServer.requests[0].respond( + 200, + { 'Content-Type': 'application/json' }, + JSON.stringify(ocsResponse) + ); + + // only renders the link share entry + var $rows = fileList.$el.find('tbody tr'); + 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'); + expect($tr.attr('data-path')).toEqual('/local path'); + expect($tr.attr('data-size')).not.toBeDefined(); + expect($tr.attr('data-permissions')).toEqual('31'); // read and delete + expect($tr.attr('data-mime')).toEqual('text/plain'); + 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.find('a.name').attr('href')).toEqual( + OC.webroot + + '/index.php/apps/files/ajax/download.php' + + '?dir=%2Flocal%20path&files=local%20name.txt'); + + expect($tr.find('.nametext').text().trim()).toEqual('local name.txt'); + }); + }); });