diff --git a/apps/files_sharing/js/sharedfilelist.js b/apps/files_sharing/js/sharedfilelist.js index da0f957ed99b8..ca87acd6cebc5 100644 --- a/apps/files_sharing/js/sharedfilelist.js +++ b/apps/files_sharing/js/sharedfilelist.js @@ -79,6 +79,42 @@ var permission = parseInt($tr.attr('data-permissions')) | OC.PERMISSION_DELETE; $tr.attr('data-permissions', permission); } + + // 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) { + expirationTimestamp = moment(fileData.shares[0].expiration).valueOf(); + } + $tr.attr('data-expiration', expirationTimestamp); + + // date column (1000 milliseconds to seconds, 60 seconds, 60 minutes, 24 hours) + // difference in days multiplied by 5 - brightest shade for expiry dates in more than 32 days (160/5) + var modifiedColor = Math.round((expirationTimestamp - (new Date()).getTime()) / 1000 / 60 / 60 / 24 * 5); + // ensure that the brightest color is still readable + if (modifiedColor >= 160) { + modifiedColor = 160; + } + + if (expirationTimestamp > 0) { + formatted = OC.Util.formatDate(expirationTimestamp); + text = OC.Util.relativeModifiedDate(expirationTimestamp); + } else { + formatted = t('files_sharing', 'No expiration date set'); + text = t('files_sharing', 'Never'); + modifiedColor = 160; + } + td = $('').attr({"class": "date"}); + td.append($('').attr({ + "class": "modified", + "title": formatted, + "style": 'color:rgb(' + modifiedColor + ',' + modifiedColor + ',' + modifiedColor + ')' + }).text(text) + .tooltip({placement: 'top'}) + ); + + $tr.append(td); + } return $tr; }, @@ -98,6 +134,11 @@ // root has special permissions this.$el.find('#emptycontent').toggleClass('hidden', !this.isEmpty); this.$el.find('#filestable thead th').toggleClass('hidden', this.isEmpty); + + // hide expiration date header for non link only shares + if (!this._linksOnly) { + this.$el.find('th.column-expiration').addClass('hidden'); + } } else { OCA.Files.FileList.prototype.updateEmptyContent.apply(this, arguments); @@ -249,6 +290,7 @@ type: share.share_type, target: share.share_with, stime: share.stime * 1000, + expiration: share.expiration, }; if (self._sharedWithUser) { file.shareOwner = share.displayname_owner; diff --git a/apps/files_sharing/templates/list.php b/apps/files_sharing/templates/list.php index fa0365c749c42..f59cb7653d888 100644 --- a/apps/files_sharing/templates/list.php +++ b/apps/files_sharing/templates/list.php @@ -22,6 +22,9 @@ t( 'Share time' )); ?> + + t( 'Expiration date' )); ?> + diff --git a/apps/files_sharing/tests/js/sharedfilelistSpec.js b/apps/files_sharing/tests/js/sharedfilelistSpec.js index 0b0676a19e638..a4448a1c0e2c0 100644 --- a/apps/files_sharing/tests/js/sharedfilelistSpec.js +++ b/apps/files_sharing/tests/js/sharedfilelistSpec.js @@ -38,6 +38,9 @@ describe('OCA.Sharing.FileList tests', function() { '' + '' + '' + + '' + + 'Expiration date' + + '' + '' + '' + '' + @@ -512,6 +515,15 @@ describe('OCA.Sharing.FileList tests', function() { fileList.reload(); + var currentdate = new Date(); + var expirationDateInADay = + + currentdate.getFullYear() + "-" + + ((currentdate.getMonth()+1 < 10) ? "0" : "") + (currentdate.getMonth()+1) + "-" + + ((currentdate.getDate()+1 < 10) ? "0" : "") + (currentdate.getDate()+1) + " " + + ((currentdate.getHours()+1 < 10) ? "0" : "") + currentdate.getHours() + ":" + + ((currentdate.getMinutes()+1 < 10) ? "0" : "") + currentdate.getMinutes() + ":" + + ((currentdate.getSeconds()+1 < 10) ? "0" : "") + currentdate.getSeconds(); + /* jshint camelcase: false */ ocsResponse = { ocs: { @@ -528,12 +540,28 @@ describe('OCA.Sharing.FileList tests', function() { path: '/local path/local name.txt', permissions: 1, stime: 11111, + expiration: null, share_type: OC.Share.SHARE_TYPE_LINK, share_with: null, token: 'abc', mimetype: 'text/plain', uid_owner: 'user1', displayname_owner: 'User One' + },{ + id: 8, + item_type: 'file', + item_source: 50, + file_source: 50, + path: '/local path2/local name2.txt', + permissions: 1, + stime: 11112, + expiration: expirationDateInADay, + share_type: OC.Share.SHARE_TYPE_LINK, + share_with: null, + token: 'abcd', + mimetype: 'text/plain2', + uid_owner: 'user2', + displayname_owner: 'User One2' }] } }; @@ -570,10 +598,10 @@ describe('OCA.Sharing.FileList tests', function() { JSON.stringify(ocsResponse) ); - // only renders the link share entry + // only renders the link share entries var $rows = fileList.$el.find('tbody tr'); var $tr = $rows.eq(0); - expect($rows.length).toEqual(1); + expect($rows.length).toEqual(2); expect($tr.attr('data-id')).toEqual('49'); expect($tr.attr('data-type')).toEqual('file'); expect($tr.attr('data-file')).toEqual('local name.txt'); @@ -588,8 +616,17 @@ describe('OCA.Sharing.FileList tests', function() { expect($tr.find('a.name').attr('href')).toEqual( OC.webroot + '/remote.php/webdav/local%20path/local%20name.txt' ); + expect($tr.attr('data-expiration')).toEqual('0'); + expect($tr.find('td:last-child span').text()).toEqual('Never'); expect($tr.find('.nametext').text().trim()).toEqual('local name.txt'); + + // change to next row + $tr = $rows.eq(1); + 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.find('td:last-child span').text()).toEqual('in a day'); }); it('does not show virtual token recipient as recipient when password was set', function() { /* jshint camelcase: false */ @@ -613,7 +650,7 @@ describe('OCA.Sharing.FileList tests', function() { // only renders the link share entry var $rows = fileList.$el.find('tbody tr'); var $tr = $rows.eq(0); - expect($rows.length).toEqual(1); + expect($rows.length).toEqual(2); expect($tr.attr('data-id')).toEqual('49'); expect($tr.attr('data-type')).toEqual('file'); expect($tr.attr('data-file')).toEqual('local name.txt');