More unit tests and fixes for share
This commit is contained in:
parent
679d10ca00
commit
0944565f60
|
@ -14,119 +14,112 @@
|
||||||
}
|
}
|
||||||
OCA.Sharing.Util = {
|
OCA.Sharing.Util = {
|
||||||
initialize: function(fileActions) {
|
initialize: function(fileActions) {
|
||||||
if (!_.isUndefined(OC.Share) && !_.isUndefined(OCA.Files)) {
|
// TODO: make a separate class for this or a hook or jQuery event ?
|
||||||
// TODO: make a separate class for this or a hook or jQuery event ?
|
if (OCA.Files.FileList) {
|
||||||
if (OCA.Files.FileList) {
|
var oldCreateRow = OCA.Files.FileList.prototype._createRow;
|
||||||
var oldCreateRow = OCA.Files.FileList.prototype._createRow;
|
OCA.Files.FileList.prototype._createRow = function(fileData) {
|
||||||
OCA.Files.FileList.prototype._createRow = function(fileData) {
|
var tr = oldCreateRow.apply(this, arguments);
|
||||||
var tr = oldCreateRow.apply(this, arguments);
|
if (fileData.shareOwner) {
|
||||||
if (fileData.shareOwner) {
|
tr.attr('data-share-owner', fileData.shareOwner);
|
||||||
tr.attr('data-share-owner', fileData.shareOwner);
|
// user should always be able to rename a mount point
|
||||||
// user should always be able to rename a mount point
|
if (fileData.isShareMountPoint) {
|
||||||
if (fileData.isShareMountPoint) {
|
tr.attr('data-permissions', fileData.permissions | OC.PERMISSION_UPDATE);
|
||||||
tr.attr('data-permissions', fileData.permissions | OC.PERMISSION_UPDATE);
|
tr.attr('data-reshare-permissions', fileData.permissions);
|
||||||
tr.attr('data-reshare-permissions', fileData.permissions);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (fileData.recipientsDisplayName) {
|
}
|
||||||
tr.attr('data-share-recipients', fileData.recipientsDisplayName);
|
if (fileData.recipientsDisplayName) {
|
||||||
}
|
tr.attr('data-share-recipients', fileData.recipientsDisplayName);
|
||||||
return tr;
|
}
|
||||||
};
|
return tr;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// use delegate to catch the case with multiple file lists
|
||||||
|
$('#content').delegate('#fileList', 'fileActionsReady',function(ev){
|
||||||
|
// if no share action exists because the admin disabled sharing for this user
|
||||||
|
// we create a share notification action to inform the user about files
|
||||||
|
// shared with him otherwise we just update the existing share action.
|
||||||
|
var fileList = ev.fileList;
|
||||||
|
var $fileList = $(this);
|
||||||
|
$fileList.find('[data-share-owner]').each(function() {
|
||||||
|
var $tr = $(this);
|
||||||
|
var permissions = $tr.data('permissions');
|
||||||
|
if(permissions & OC.PERMISSION_SHARE) {
|
||||||
|
OC.Share.markFileAsShared($tr, true);
|
||||||
|
} else {
|
||||||
|
// TODO: make this work like/with OC.Share.markFileAsShared()
|
||||||
|
var shareNotification = '<a class="action action-share-notification permanent"' +
|
||||||
|
' data-action="Share-Notification" href="#" original-title="">' +
|
||||||
|
' <img class="svg" src="' + OC.imagePath('core', 'actions/share') + '"></img>';
|
||||||
|
$tr.find('.fileactions').append(function() {
|
||||||
|
var owner = $(this).closest('tr').attr('data-share-owner');
|
||||||
|
var shareBy = t('files_sharing', 'Shared by {owner}', {owner: owner});
|
||||||
|
var $result = $(shareNotification + '<span> ' + shareBy + '</span></span>');
|
||||||
|
$result.on('click', function() {
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
return $result;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!OCA.Sharing.sharesLoaded){
|
||||||
|
OC.Share.loadIcons('file', fileList);
|
||||||
|
// assume that we got all shares, so switching directories
|
||||||
|
// will not invalidate that list
|
||||||
|
OCA.Sharing.sharesLoaded = true;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
OC.Share.updateIcons('file', fileList);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
fileActions.register(
|
||||||
|
'all',
|
||||||
|
'Share',
|
||||||
|
OC.PERMISSION_SHARE,
|
||||||
|
OC.imagePath('core', 'actions/share'),
|
||||||
|
function(filename, context) {
|
||||||
|
|
||||||
|
var $tr = context.$file;
|
||||||
|
var itemType = 'file';
|
||||||
|
if ($tr.data('type') === 'dir') {
|
||||||
|
itemType = 'folder';
|
||||||
|
}
|
||||||
|
var possiblePermissions = $tr.data('reshare-permissions');
|
||||||
|
if (_.isUndefined(possiblePermissions)) {
|
||||||
|
possiblePermissions = $tr.data('permissions');
|
||||||
}
|
}
|
||||||
|
|
||||||
// use delegate to catch the case with multiple file lists
|
var appendTo = $tr.find('td.filename');
|
||||||
$('#content').delegate('#fileList', 'fileActionsReady',function(ev){
|
// Check if drop down is already visible for a different file
|
||||||
// if no share action exists because the admin disabled sharing for this user
|
if (OC.Share.droppedDown) {
|
||||||
// we create a share notification action to inform the user about files
|
if ($tr.data('id') !== $('#dropdown').attr('data-item-source')) {
|
||||||
// shared with him otherwise we just update the existing share action.
|
OC.Share.hideDropDown(function () {
|
||||||
var fileList = ev.fileList;
|
$tr.addClass('mouseOver');
|
||||||
var $fileList = $(this);
|
OC.Share.showDropDown(itemType, $tr.data('id'), appendTo, true, possiblePermissions, filename);
|
||||||
$fileList.find('[data-share-owner]').each(function() {
|
});
|
||||||
var $tr = $(this);
|
|
||||||
var permissions = $tr.data('permissions');
|
|
||||||
if(permissions & OC.PERMISSION_SHARE) {
|
|
||||||
OC.Share.markFileAsShared($tr, true);
|
|
||||||
} else {
|
|
||||||
// TODO: make this work like/with OC.Share.markFileAsShared()
|
|
||||||
var shareNotification = '<a class="action action-share-notification permanent"' +
|
|
||||||
' data-action="Share-Notification" href="#" original-title="">' +
|
|
||||||
' <img class="svg" src="' + OC.imagePath('core', 'actions/share') + '"></img>';
|
|
||||||
$tr.find('.fileactions').append(function() {
|
|
||||||
var owner = $(this).closest('tr').attr('data-share-owner');
|
|
||||||
var shareBy = t('files_sharing', 'Shared by {owner}', {owner: owner});
|
|
||||||
var $result = $(shareNotification + '<span> ' + shareBy + '</span></span>');
|
|
||||||
$result.on('click', function() {
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
return $result;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!OCA.Sharing.sharesLoaded){
|
|
||||||
OC.Share.loadIcons('file', fileList);
|
|
||||||
// assume that we got all shares, so switching directories
|
|
||||||
// will not invalidate that list
|
|
||||||
OCA.Sharing.sharesLoaded = true;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
OC.Share.updateIcons('file', fileList);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
fileActions.register(
|
|
||||||
'all',
|
|
||||||
'Share',
|
|
||||||
OC.PERMISSION_SHARE,
|
|
||||||
OC.imagePath('core', 'actions/share'),
|
|
||||||
function(filename, context) {
|
|
||||||
|
|
||||||
var $tr = context.$file;
|
|
||||||
var itemType = 'file';
|
|
||||||
if ($tr.data('type') === 'dir') {
|
|
||||||
itemType = 'folder';
|
|
||||||
}
|
|
||||||
var possiblePermissions = $tr.data('reshare-permissions');
|
|
||||||
if (_.isUndefined(possiblePermissions)) {
|
|
||||||
possiblePermissions = $tr.data('permissions');
|
|
||||||
}
|
|
||||||
|
|
||||||
var appendTo = $tr.find('td.filename');
|
|
||||||
// Check if drop down is already visible for a different file
|
|
||||||
if (OC.Share.droppedDown) {
|
|
||||||
if ($tr.data('id') !== $('#dropdown').attr('data-item-source')) {
|
|
||||||
OC.Share.hideDropDown(function () {
|
|
||||||
$tr.addClass('mouseOver');
|
|
||||||
OC.Share.showDropDown(itemType, $tr.data('id'), appendTo, true, possiblePermissions, filename);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
OC.Share.hideDropDown();
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
$tr.addClass('mouseOver');
|
OC.Share.hideDropDown();
|
||||||
OC.Share.showDropDown(itemType, $tr.data('id'), appendTo, true, possiblePermissions, filename);
|
}
|
||||||
|
} else {
|
||||||
|
$tr.addClass('mouseOver');
|
||||||
|
OC.Share.showDropDown(itemType, $tr.data('id'), appendTo, true, possiblePermissions, filename);
|
||||||
|
}
|
||||||
|
$('#dropdown').on('sharesChanged', function(ev) {
|
||||||
|
// note: we only update the data attribute because updateIcon()
|
||||||
|
// is called automatically after this event
|
||||||
|
var userShares = ev.itemShares[OC.Share.SHARE_TYPE_USER] || [];
|
||||||
|
var groupShares = ev.itemShares[OC.Share.SHARE_TYPE_GROUP] || [];
|
||||||
|
var recipients = _.union(userShares, groupShares);
|
||||||
|
if (recipients.length) {
|
||||||
|
$tr.attr('data-share-recipients', OCA.Sharing.Util.formatRecipients(recipients));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$tr.removeAttr('data-share-recipients');
|
||||||
}
|
}
|
||||||
$('#dropdown').on('sharesChanged', function(ev) {
|
|
||||||
// note: we only update the data attribute because updateIcon()
|
|
||||||
// is called automatically after this event
|
|
||||||
var userShares = ev.itemShares[OC.Share.SHARE_TYPE_USER] || [];
|
|
||||||
var groupShares = ev.itemShares[OC.Share.SHARE_TYPE_GROUP] || [];
|
|
||||||
var recipients = _.union(userShares, groupShares);
|
|
||||||
// only update the recipients if they existed before
|
|
||||||
// (some file lists don't have them)
|
|
||||||
if (!_.isUndefined($tr.attr('data-share-recipients'))) {
|
|
||||||
// FIXME: use display names from users, we currently only got user ids
|
|
||||||
if (recipients.length) {
|
|
||||||
$tr.attr('data-share-recipients', OCA.Sharing.Util.formatRecipients(recipients));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$tr.attr('data-share-recipients', '');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -159,7 +152,9 @@
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
// FIXME: HACK: do not init when running unit tests, need a better way
|
// FIXME: HACK: do not init when running unit tests, need a better way
|
||||||
if (!window.TESTING) {
|
if (!window.TESTING) {
|
||||||
OCA.Sharing.Util.initialize(OCA.Files.fileActions);
|
if (!_.isUndefined(OC.Share) && !_.isUndefined(OCA.Files)) {
|
||||||
|
OCA.Sharing.Util.initialize(OCA.Files.fileActions);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,16 @@ describe('OCA.Sharing.Util tests', function() {
|
||||||
var fileList;
|
var fileList;
|
||||||
var testFiles;
|
var testFiles;
|
||||||
|
|
||||||
|
function getImageUrl($el) {
|
||||||
|
// might be slightly different cross-browser
|
||||||
|
var url = $el.css('background-image');
|
||||||
|
var r = url.match(/url\(['"]?([^'")]*)['"]?\)/);
|
||||||
|
if (!r) {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
return r[1];
|
||||||
|
}
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
// back up prototype, as it will be extended by
|
// back up prototype, as it will be extended by
|
||||||
// the sharing code
|
// the sharing code
|
||||||
|
@ -59,6 +69,7 @@ describe('OCA.Sharing.Util tests', function() {
|
||||||
afterEach(function() {
|
afterEach(function() {
|
||||||
OCA.Files.FileList.prototype = oldFileListPrototype;
|
OCA.Files.FileList.prototype = oldFileListPrototype;
|
||||||
delete OCA.Sharing.sharesLoaded;
|
delete OCA.Sharing.sharesLoaded;
|
||||||
|
delete OC.Share.droppedDown;
|
||||||
OC.Share.statuses = {};
|
OC.Share.statuses = {};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -67,7 +78,121 @@ describe('OCA.Sharing.Util tests', function() {
|
||||||
});
|
});
|
||||||
describe('Share action icon', function() {
|
describe('Share action icon', function() {
|
||||||
it('do not shows share text when not shared', function() {
|
it('do not shows share text when not shared', function() {
|
||||||
var $action;
|
var $action, $tr;
|
||||||
|
OC.Share.statuses = {};
|
||||||
|
fileList.setFiles([{
|
||||||
|
id: 1,
|
||||||
|
type: 'dir',
|
||||||
|
name: 'One',
|
||||||
|
path: '/subdir',
|
||||||
|
mimetype: 'text/plain',
|
||||||
|
size: 12,
|
||||||
|
permissions: 31,
|
||||||
|
etag: 'abc'
|
||||||
|
}]);
|
||||||
|
$tr = fileList.$el.find('tbody tr:first');
|
||||||
|
$action = $tr.find('.action-share');
|
||||||
|
expect($action.hasClass('permanent')).toEqual(false);
|
||||||
|
expect(OC.basename($action.find('img').attr('src'))).toEqual('share.svg');
|
||||||
|
expect(OC.basename(getImageUrl($tr.find('.filename')))).toEqual('folder.svg');
|
||||||
|
expect($action.find('img').length).toEqual(1);
|
||||||
|
});
|
||||||
|
it('shows simple share text with share icon', function() {
|
||||||
|
var $action, $tr;
|
||||||
|
fileList.setFiles([{
|
||||||
|
id: 1,
|
||||||
|
type: 'dir',
|
||||||
|
name: 'One',
|
||||||
|
path: '/subdir',
|
||||||
|
mimetype: 'text/plain',
|
||||||
|
size: 12,
|
||||||
|
permissions: 31,
|
||||||
|
etag: 'abc'
|
||||||
|
}]);
|
||||||
|
$tr = fileList.$el.find('tbody tr:first');
|
||||||
|
$action = $tr.find('.action-share');
|
||||||
|
expect($action.hasClass('permanent')).toEqual(true);
|
||||||
|
expect($action.find('>span').text()).toEqual('Shared');
|
||||||
|
expect(OC.basename($action.find('img').attr('src'))).toEqual('share.svg');
|
||||||
|
expect(OC.basename(getImageUrl($tr.find('.filename')))).toEqual('folder-shared.svg');
|
||||||
|
expect($action.find('img').length).toEqual(1);
|
||||||
|
});
|
||||||
|
it('shows simple share text with public icon when shared with link', function() {
|
||||||
|
var $action, $tr;
|
||||||
|
OC.Share.statuses = {1: {link: true, path: '/subdir'}};
|
||||||
|
fileList.setFiles([{
|
||||||
|
id: 1,
|
||||||
|
type: 'dir',
|
||||||
|
name: 'One',
|
||||||
|
path: '/subdir',
|
||||||
|
mimetype: 'text/plain',
|
||||||
|
size: 12,
|
||||||
|
permissions: 31,
|
||||||
|
etag: 'abc'
|
||||||
|
}]);
|
||||||
|
$tr = fileList.$el.find('tbody tr:first');
|
||||||
|
$action = $tr.find('.action-share');
|
||||||
|
expect($action.hasClass('permanent')).toEqual(true);
|
||||||
|
expect($action.find('>span').text()).toEqual('Shared');
|
||||||
|
expect(OC.basename($action.find('img').attr('src'))).toEqual('public.svg');
|
||||||
|
expect(OC.basename(getImageUrl($tr.find('.filename')))).toEqual('folder-public.svg');
|
||||||
|
expect($action.find('img').length).toEqual(1);
|
||||||
|
});
|
||||||
|
it('shows owner name when owner is available', function() {
|
||||||
|
var $action, $tr;
|
||||||
|
fileList.setFiles([{
|
||||||
|
id: 1,
|
||||||
|
type: 'dir',
|
||||||
|
name: 'One.txt',
|
||||||
|
path: '/subdir',
|
||||||
|
mimetype: 'text/plain',
|
||||||
|
size: 12,
|
||||||
|
permissions: 31,
|
||||||
|
shareOwner: 'User One',
|
||||||
|
etag: 'abc'
|
||||||
|
}]);
|
||||||
|
$tr = fileList.$el.find('tbody tr:first');
|
||||||
|
$action = $tr.find('.action-share');
|
||||||
|
expect($action.hasClass('permanent')).toEqual(true);
|
||||||
|
expect($action.find('>span').text()).toEqual('Shared by User One');
|
||||||
|
expect(OC.basename($action.find('img').attr('src'))).toEqual('share.svg');
|
||||||
|
expect(OC.basename(getImageUrl($tr.find('.filename')))).toEqual('folder-shared.svg');
|
||||||
|
});
|
||||||
|
it('shows recipients when recipients are available', function() {
|
||||||
|
var $action, $tr;
|
||||||
|
fileList.setFiles([{
|
||||||
|
id: 1,
|
||||||
|
type: 'dir',
|
||||||
|
name: 'One.txt',
|
||||||
|
path: '/subdir',
|
||||||
|
mimetype: 'text/plain',
|
||||||
|
size: 12,
|
||||||
|
permissions: 31,
|
||||||
|
recipientsDisplayName: 'User One, User Two',
|
||||||
|
etag: 'abc'
|
||||||
|
}]);
|
||||||
|
$tr = fileList.$el.find('tbody tr:first');
|
||||||
|
$action = $tr.find('.action-share');
|
||||||
|
expect($action.hasClass('permanent')).toEqual(true);
|
||||||
|
expect($action.find('>span').text()).toEqual('Shared with User One, User Two');
|
||||||
|
expect(OC.basename($action.find('img').attr('src'))).toEqual('share.svg');
|
||||||
|
expect(OC.basename(getImageUrl($tr.find('.filename')))).toEqual('folder-shared.svg');
|
||||||
|
expect($action.find('img').length).toEqual(1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe('Share action', function() {
|
||||||
|
var showDropDownStub;
|
||||||
|
|
||||||
|
beforeEach(function() {
|
||||||
|
showDropDownStub = sinon.stub(OC.Share, 'showDropDown', function() {
|
||||||
|
$('#testArea').append($('<div id="dropdown"></div>'));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
afterEach(function() {
|
||||||
|
showDropDownStub.restore();
|
||||||
|
});
|
||||||
|
it('adds share icon after sharing a non-shared file', function() {
|
||||||
|
var $action, $tr;
|
||||||
OC.Share.statuses = {};
|
OC.Share.statuses = {};
|
||||||
fileList.setFiles([{
|
fileList.setFiles([{
|
||||||
id: 1,
|
id: 1,
|
||||||
|
@ -80,11 +205,31 @@ describe('OCA.Sharing.Util tests', function() {
|
||||||
etag: 'abc'
|
etag: 'abc'
|
||||||
}]);
|
}]);
|
||||||
$action = fileList.$el.find('tbody tr:first .action-share');
|
$action = fileList.$el.find('tbody tr:first .action-share');
|
||||||
|
$tr = fileList.$el.find('tr:first');
|
||||||
|
|
||||||
expect($action.hasClass('permanent')).toEqual(false);
|
expect($action.hasClass('permanent')).toEqual(false);
|
||||||
|
|
||||||
|
$tr.find('.action-share').click();
|
||||||
|
|
||||||
|
expect(showDropDownStub.calledOnce).toEqual(true);
|
||||||
|
|
||||||
|
// simulate what the dropdown does
|
||||||
|
var itemShares = {};
|
||||||
|
itemShares[OC.Share.SHARE_TYPE_USER] = ['User One', 'User Two'];
|
||||||
|
itemShares[OC.Share.SHARE_TYPE_GROUP] = ['Group One', 'Group Two'];
|
||||||
|
OC.Share.itemShares = itemShares;
|
||||||
|
$('#dropdown').trigger(new $.Event('sharesChanged', {itemShares: itemShares}));
|
||||||
|
|
||||||
|
expect($tr.attr('data-share-recipients')).toEqual('Group One, Group Two, User One, User Two');
|
||||||
|
|
||||||
|
OC.Share.updateIcon('file', 1);
|
||||||
|
expect($action.hasClass('permanent')).toEqual(true);
|
||||||
|
expect($action.find('>span').text()).toEqual('Shared with Group One, Group Two, User One, User Two');
|
||||||
expect(OC.basename($action.find('img').attr('src'))).toEqual('share.svg');
|
expect(OC.basename($action.find('img').attr('src'))).toEqual('share.svg');
|
||||||
});
|
});
|
||||||
it('shows simple share text with share icon', function() {
|
it('removes share icon after unsharing a shared file', function() {
|
||||||
var $action;
|
var $action, $tr;
|
||||||
|
OC.Share.statuses = {1: {link: false, path: '/subdir'}};
|
||||||
fileList.setFiles([{
|
fileList.setFiles([{
|
||||||
id: 1,
|
id: 1,
|
||||||
type: 'file',
|
type: 'file',
|
||||||
|
@ -96,13 +241,31 @@ describe('OCA.Sharing.Util tests', function() {
|
||||||
etag: 'abc'
|
etag: 'abc'
|
||||||
}]);
|
}]);
|
||||||
$action = fileList.$el.find('tbody tr:first .action-share');
|
$action = fileList.$el.find('tbody tr:first .action-share');
|
||||||
|
$tr = fileList.$el.find('tr:first');
|
||||||
|
|
||||||
expect($action.hasClass('permanent')).toEqual(true);
|
expect($action.hasClass('permanent')).toEqual(true);
|
||||||
expect($action.find('>span').text()).toEqual('Shared');
|
|
||||||
|
$tr.find('.action-share').click();
|
||||||
|
|
||||||
|
expect(showDropDownStub.calledOnce).toEqual(true);
|
||||||
|
|
||||||
|
// simulate what the dropdown does
|
||||||
|
var itemShares = {};
|
||||||
|
itemShares[OC.Share.SHARE_TYPE_USER] = ['User One', 'User Two', 'User Three'];
|
||||||
|
OC.Share.itemShares = itemShares;
|
||||||
|
$('#dropdown').trigger(new $.Event('sharesChanged', {itemShares: itemShares}));
|
||||||
|
|
||||||
|
expect($tr.attr('data-share-recipients')).toEqual('User One, User Three, User Two');
|
||||||
|
|
||||||
|
OC.Share.updateIcon('file', 1);
|
||||||
|
|
||||||
|
expect($action.hasClass('permanent')).toEqual(true);
|
||||||
|
expect($action.find('>span').text()).toEqual('Shared with User One, User Three, User Two');
|
||||||
expect(OC.basename($action.find('img').attr('src'))).toEqual('share.svg');
|
expect(OC.basename($action.find('img').attr('src'))).toEqual('share.svg');
|
||||||
});
|
});
|
||||||
it('shows simple share text with public icon when shared with link', function() {
|
it('updates share icon after modifying shares on a shared file', function() {
|
||||||
var $action;
|
var $action, $tr;
|
||||||
OC.Share.statuses = {1: {link: true, path: '/subdir'}};
|
OC.Share.statuses = {1: {link: false, path: '/subdir'}};
|
||||||
fileList.setFiles([{
|
fileList.setFiles([{
|
||||||
id: 1,
|
id: 1,
|
||||||
type: 'file',
|
type: 'file',
|
||||||
|
@ -111,55 +274,27 @@ describe('OCA.Sharing.Util tests', function() {
|
||||||
mimetype: 'text/plain',
|
mimetype: 'text/plain',
|
||||||
size: 12,
|
size: 12,
|
||||||
permissions: 31,
|
permissions: 31,
|
||||||
etag: 'abc'
|
etag: 'abc',
|
||||||
|
recipients: 'User One, User Two'
|
||||||
}]);
|
}]);
|
||||||
$action = fileList.$el.find('tbody tr:first .action-share');
|
$action = fileList.$el.find('tbody tr:first .action-share');
|
||||||
|
$tr = fileList.$el.find('tr:first');
|
||||||
|
|
||||||
expect($action.hasClass('permanent')).toEqual(true);
|
expect($action.hasClass('permanent')).toEqual(true);
|
||||||
expect($action.find('>span').text()).toEqual('Shared');
|
|
||||||
expect(OC.basename($action.find('img').attr('src'))).toEqual('public.svg');
|
$tr.find('.action-share').click();
|
||||||
});
|
|
||||||
it('shows owner name when owner is available', function() {
|
expect(showDropDownStub.calledOnce).toEqual(true);
|
||||||
var $action;
|
|
||||||
fileList.setFiles([{
|
// simulate what the dropdown does
|
||||||
id: 1,
|
var itemShares = {};
|
||||||
type: 'file',
|
OC.Share.itemShares = itemShares;
|
||||||
name: 'One.txt',
|
$('#dropdown').trigger(new $.Event('sharesChanged', {itemShares: itemShares}));
|
||||||
path: '/subdir',
|
|
||||||
mimetype: 'text/plain',
|
expect($tr.attr('data-share-recipients')).not.toBeDefined();
|
||||||
size: 12,
|
|
||||||
permissions: 31,
|
OC.Share.updateIcon('file', 1);
|
||||||
shareOwner: 'User One',
|
expect($action.hasClass('permanent')).toEqual(false);
|
||||||
etag: 'abc'
|
|
||||||
}]);
|
|
||||||
$action = fileList.$el.find('tbody tr:first .action-share');
|
|
||||||
expect($action.hasClass('permanent')).toEqual(true);
|
|
||||||
expect($action.find('>span').text()).toEqual('Shared by User One');
|
|
||||||
expect(OC.basename($action.find('img').attr('src'))).toEqual('share.svg');
|
|
||||||
});
|
|
||||||
it('shows recipients when recipients are available', function() {
|
|
||||||
var $action;
|
|
||||||
fileList.setFiles([{
|
|
||||||
id: 1,
|
|
||||||
type: 'file',
|
|
||||||
name: 'One.txt',
|
|
||||||
path: '/subdir',
|
|
||||||
mimetype: 'text/plain',
|
|
||||||
size: 12,
|
|
||||||
permissions: 31,
|
|
||||||
recipientsDisplayName: 'User One, User Two',
|
|
||||||
etag: 'abc'
|
|
||||||
}]);
|
|
||||||
$action = fileList.$el.find('tbody tr:first .action-share');
|
|
||||||
expect($action.hasClass('permanent')).toEqual(true);
|
|
||||||
expect($action.find('>span').text()).toEqual('Shared with User One, User Two');
|
|
||||||
expect(OC.basename($action.find('img').attr('src'))).toEqual('share.svg');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
describe('Share action', function() {
|
|
||||||
// TODO: test file action / dropdown trigger
|
|
||||||
it('updates share icon when shares were changed in dropdown', function() {
|
|
||||||
fileList.setFiles(testFiles);
|
|
||||||
fileList.$el.find('tr:first .action-share').click();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
describe('formatRecipients', function() {
|
describe('formatRecipients', function() {
|
||||||
|
|
|
@ -47,6 +47,7 @@ OC.Share={
|
||||||
$fileList = fileList.$fileList;
|
$fileList = fileList.$fileList;
|
||||||
currentDir = fileList.getCurrentDirectory();
|
currentDir = fileList.getCurrentDirectory();
|
||||||
}
|
}
|
||||||
|
// TODO: iterating over the files might be more efficient
|
||||||
for (item in OC.Share.statuses){
|
for (item in OC.Share.statuses){
|
||||||
var image = OC.imagePath('core', 'actions/share');
|
var image = OC.imagePath('core', 'actions/share');
|
||||||
var data = OC.Share.statuses[item];
|
var data = OC.Share.statuses[item];
|
||||||
|
@ -63,7 +64,7 @@ OC.Share={
|
||||||
var shareFolder = OC.imagePath('core', 'filetypes/folder-shared');
|
var shareFolder = OC.imagePath('core', 'filetypes/folder-shared');
|
||||||
var img;
|
var img;
|
||||||
if (file.length > 0) {
|
if (file.length > 0) {
|
||||||
this.markFileAsShared(file, true, image);
|
this.markFileAsShared(file, true, hasLink);
|
||||||
} else {
|
} else {
|
||||||
var dir = currentDir;
|
var dir = currentDir;
|
||||||
if (dir.length > 1) {
|
if (dir.length > 1) {
|
||||||
|
@ -122,7 +123,11 @@ OC.Share={
|
||||||
} else {
|
} else {
|
||||||
var $tr = $('tr').filterAttr('data-id', String(itemSource));
|
var $tr = $('tr').filterAttr('data-id', String(itemSource));
|
||||||
if ($tr.length > 0) {
|
if ($tr.length > 0) {
|
||||||
this.markFileAsShared($tr, shares, image);
|
// it might happen that multiple lists exist in the DOM
|
||||||
|
// with the same id
|
||||||
|
$tr.each(function() {
|
||||||
|
OC.Share.markFileAsShared($(this), shares, link);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (shares) {
|
if (shares) {
|
||||||
|
@ -133,13 +138,14 @@ OC.Share={
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* Marks/unmarks a given file as shared
|
* Marks/unmarks a given file as shared by changing its action icon
|
||||||
|
* and folder icon.
|
||||||
*
|
*
|
||||||
* @param $tr file element to mark as shared
|
* @param $tr file element to mark as shared
|
||||||
* @param state true to mark as shared, false to unmark
|
* @param hasShares whether shares are available
|
||||||
* @param image image to use for the icon
|
* @param hasLink whether link share is available
|
||||||
*/
|
*/
|
||||||
markFileAsShared: function($tr, state, image) {
|
markFileAsShared: function($tr, hasShares, hasLink) {
|
||||||
var action = $tr.find('.fileactions .action[data-action="Share"]');
|
var action = $tr.find('.fileactions .action[data-action="Share"]');
|
||||||
var type = $tr.data('type');
|
var type = $tr.data('type');
|
||||||
var img = action.find('img');
|
var img = action.find('img');
|
||||||
|
@ -147,14 +153,22 @@ OC.Share={
|
||||||
var recipients;
|
var recipients;
|
||||||
var owner;
|
var owner;
|
||||||
var shareFolderIcon;
|
var shareFolderIcon;
|
||||||
if (type === 'dir' && state) {
|
var image = OC.imagePath('core', 'actions/share');
|
||||||
shareFolderIcon = OC.imagePath('core', 'filetypes/folder-shared');
|
// update folder icon
|
||||||
|
if (type === 'dir' && (hasShares || hasLink)) {
|
||||||
|
if (hasLink) {
|
||||||
|
shareFolderIcon = OC.imagePath('core', 'filetypes/folder-public');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
shareFolderIcon = OC.imagePath('core', 'filetypes/folder-shared');
|
||||||
|
}
|
||||||
$tr.children('.filename').css('background-image', 'url(' + shareFolderIcon + ')');
|
$tr.children('.filename').css('background-image', 'url(' + shareFolderIcon + ')');
|
||||||
} else if (type === 'dir') {
|
} else if (type === 'dir') {
|
||||||
shareFolderIcon = OC.imagePath('core', 'filetypes/folder');
|
shareFolderIcon = OC.imagePath('core', 'filetypes/folder');
|
||||||
$tr.children('.filename').css('background-image', 'url(' + shareFolderIcon + ')');
|
$tr.children('.filename').css('background-image', 'url(' + shareFolderIcon + ')');
|
||||||
}
|
}
|
||||||
if (state) {
|
// update share action text / icon
|
||||||
|
if (hasShares) {
|
||||||
recipients = $tr.attr('data-share-recipients');
|
recipients = $tr.attr('data-share-recipients');
|
||||||
owner = $tr.attr('data-share-owner');
|
owner = $tr.attr('data-share-owner');
|
||||||
|
|
||||||
|
@ -162,7 +176,6 @@ OC.Share={
|
||||||
message = t('core', 'Shared');
|
message = t('core', 'Shared');
|
||||||
if (owner && !recipients) {
|
if (owner && !recipients) {
|
||||||
message = t('files_sharing', 'Shared by {owner}', {owner: owner});
|
message = t('files_sharing', 'Shared by {owner}', {owner: owner});
|
||||||
image = image || OC.imagePath('core', 'actions/share');
|
|
||||||
}
|
}
|
||||||
if (recipients) {
|
if (recipients) {
|
||||||
message = t('core', 'Shared with {recipients}', {recipients: recipients});
|
message = t('core', 'Shared with {recipients}', {recipients: recipients});
|
||||||
|
@ -173,6 +186,9 @@ OC.Share={
|
||||||
action.removeClass('permanent');
|
action.removeClass('permanent');
|
||||||
action.html(' <span>'+ escapeHTML(t('core', 'Share'))+'</span>').prepend(img);
|
action.html(' <span>'+ escapeHTML(t('core', 'Share'))+'</span>').prepend(img);
|
||||||
}
|
}
|
||||||
|
if (hasLink) {
|
||||||
|
image = OC.imagePath('core', 'actions/public');
|
||||||
|
}
|
||||||
img.attr('src', image);
|
img.attr('src', image);
|
||||||
},
|
},
|
||||||
loadItem:function(itemType, itemSource) {
|
loadItem:function(itemType, itemSource) {
|
||||||
|
@ -756,6 +772,7 @@ $(document).ready(function() {
|
||||||
if ($('#linkText').val() !== '') {
|
if ($('#linkText').val() !== '') {
|
||||||
OC.Share.unshare(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, '', function() {
|
OC.Share.unshare(itemType, itemSource, OC.Share.SHARE_TYPE_LINK, '', function() {
|
||||||
OC.Share.itemShares[OC.Share.SHARE_TYPE_LINK] = false;
|
OC.Share.itemShares[OC.Share.SHARE_TYPE_LINK] = false;
|
||||||
|
$('#dropdown').trigger(new $.Event('sharesChanged', {itemShares: OC.Share.itemShares}));
|
||||||
OC.Share.updateIcon(itemType, itemSource);
|
OC.Share.updateIcon(itemType, itemSource);
|
||||||
if (typeof OC.Share.statuses[itemSource] === 'undefined') {
|
if (typeof OC.Share.statuses[itemSource] === 'undefined') {
|
||||||
$('#expiration').hide('blind');
|
$('#expiration').hide('blind');
|
||||||
|
|
|
@ -26,13 +26,17 @@ describe('OC.Share tests', function() {
|
||||||
var oldAppConfig;
|
var oldAppConfig;
|
||||||
var loadItemStub;
|
var loadItemStub;
|
||||||
var autocompleteStub;
|
var autocompleteStub;
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
$('#testArea').append($('<div id="shareContainer"></div>'));
|
$('#testArea').append($('<div id="shareContainer"></div>'));
|
||||||
|
// horrible parameters
|
||||||
|
$('#testArea').append('<input id="allowShareWithLink" type="hidden" value="yes">');
|
||||||
$container = $('#shareContainer');
|
$container = $('#shareContainer');
|
||||||
/* jshint camelcase:false */
|
/* jshint camelcase:false */
|
||||||
oldAppConfig = oc_appconfig.core;
|
oldAppConfig = _.extend({}, oc_appconfig.core);
|
||||||
loadItemStub = sinon.stub(OC.Share, 'loadItem');
|
oc_appconfig.core.enforcePasswordForPublicLink = false;
|
||||||
|
|
||||||
|
loadItemStub = sinon.stub(OC.Share, 'loadItem');
|
||||||
loadItemStub.returns({
|
loadItemStub.returns({
|
||||||
reshare: [],
|
reshare: [],
|
||||||
shares: []
|
shares: []
|
||||||
|
@ -89,9 +93,139 @@ describe('OC.Share tests', function() {
|
||||||
oc_appconfig.core.defaultExpireDate = '';
|
oc_appconfig.core.defaultExpireDate = '';
|
||||||
// TODO: expect that default date was NOT set
|
// TODO: expect that default date was NOT set
|
||||||
});
|
});
|
||||||
// TODO: test password field visibility (whenever enforced or not)
|
describe('Share with link', function() {
|
||||||
// TODO: check link share field visibility based on whether it is allowed
|
// TODO: test ajax calls
|
||||||
// TODO: check public upload visibility based on config
|
// TODO: test password field visibility (whenever enforced or not)
|
||||||
|
// TODO: check public upload visibility based on config
|
||||||
|
it('shows share with link checkbox when allowed', function() {
|
||||||
|
$('#allowShareWithLink').val('yes');
|
||||||
|
OC.Share.showDropDown(
|
||||||
|
'file',
|
||||||
|
123,
|
||||||
|
$container,
|
||||||
|
'http://localhost/dummylink',
|
||||||
|
31,
|
||||||
|
'shared_file_name.txt'
|
||||||
|
);
|
||||||
|
expect($('#dropdown #linkCheckbox').length).toEqual(1);
|
||||||
|
});
|
||||||
|
it('does not show share with link checkbox when not allowed', function() {
|
||||||
|
$('#allowShareWithLink').val('no');
|
||||||
|
OC.Share.showDropDown(
|
||||||
|
'file',
|
||||||
|
123,
|
||||||
|
$container,
|
||||||
|
'http://localhost/dummylink',
|
||||||
|
31,
|
||||||
|
'shared_file_name.txt'
|
||||||
|
);
|
||||||
|
expect($('#dropdown #linkCheckbox').length).toEqual(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
describe('"sharesChanged" event', function() {
|
||||||
|
var autocompleteOptions;
|
||||||
|
var handler;
|
||||||
|
beforeEach(function() {
|
||||||
|
handler = sinon.stub();
|
||||||
|
loadItemStub.returns({
|
||||||
|
reshare: [],
|
||||||
|
shares: [{
|
||||||
|
id: 100,
|
||||||
|
item_source: 123,
|
||||||
|
permissions: 31,
|
||||||
|
share_type: OC.Share.SHARE_TYPE_USER,
|
||||||
|
share_with: 'user1',
|
||||||
|
share_with_displayname: 'User One'
|
||||||
|
}]
|
||||||
|
});
|
||||||
|
OC.Share.showDropDown(
|
||||||
|
'file',
|
||||||
|
123,
|
||||||
|
$container,
|
||||||
|
'http://localhost/dummylink',
|
||||||
|
31,
|
||||||
|
'shared_file_name.txt'
|
||||||
|
);
|
||||||
|
$('#dropdown').on('sharesChanged', handler);
|
||||||
|
autocompleteOptions = autocompleteStub.getCall(0).args[0];
|
||||||
|
});
|
||||||
|
afterEach(function() {
|
||||||
|
autocompleteOptions = null;
|
||||||
|
handler = null;
|
||||||
|
});
|
||||||
|
it('triggers "sharesChanged" event when adding shares', function() {
|
||||||
|
// simulate autocomplete selection
|
||||||
|
autocompleteOptions.select(new $.Event('select'), {
|
||||||
|
item: {
|
||||||
|
label: 'User Two',
|
||||||
|
value: {
|
||||||
|
shareType: OC.Share.SHARE_TYPE_USER,
|
||||||
|
shareWith: 'user2'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
fakeServer.requests[0].respond(
|
||||||
|
200,
|
||||||
|
{ 'Content-Type': 'application/json' },
|
||||||
|
JSON.stringify({status: 'success'})
|
||||||
|
);
|
||||||
|
expect(handler.calledOnce).toEqual(true);
|
||||||
|
var itemShares = handler.getCall(0).args[0].itemShares;
|
||||||
|
expect(itemShares).toBeDefined();
|
||||||
|
expect(itemShares[OC.Share.SHARE_TYPE_USER]).toEqual(['user1', 'user2']);
|
||||||
|
expect(itemShares[OC.Share.SHARE_TYPE_GROUP]).not.toBeDefined();
|
||||||
|
expect(itemShares[OC.Share.SHARE_TYPE_LINK]).not.toBeDefined();
|
||||||
|
});
|
||||||
|
it('triggers "sharesChanged" event when deleting shares', function() {
|
||||||
|
$('#dropdown .unshare:eq(0)').click();
|
||||||
|
fakeServer.requests[0].respond(
|
||||||
|
200,
|
||||||
|
{ 'Content-Type': 'application/json' },
|
||||||
|
JSON.stringify({status: 'success'})
|
||||||
|
);
|
||||||
|
expect(handler.calledOnce).toEqual(true);
|
||||||
|
var itemShares = handler.getCall(0).args[0].itemShares;
|
||||||
|
expect(itemShares).toBeDefined();
|
||||||
|
expect(itemShares[OC.Share.SHARE_TYPE_USER]).toEqual([]);
|
||||||
|
expect(itemShares[OC.Share.SHARE_TYPE_GROUP]).not.toBeDefined();
|
||||||
|
expect(itemShares[OC.Share.SHARE_TYPE_LINK]).not.toBeDefined();
|
||||||
|
});
|
||||||
|
it('triggers "sharesChanged" event when toggling link share', function() {
|
||||||
|
// simulate autocomplete selection
|
||||||
|
$('#dropdown #linkCheckbox').click();
|
||||||
|
fakeServer.requests[0].respond(
|
||||||
|
200,
|
||||||
|
{ 'Content-Type': 'application/json' },
|
||||||
|
JSON.stringify({status: 'success', data: { token: 'abc' }})
|
||||||
|
);
|
||||||
|
expect(handler.calledOnce).toEqual(true);
|
||||||
|
var itemShares = handler.getCall(0).args[0].itemShares;
|
||||||
|
expect(itemShares).toBeDefined();
|
||||||
|
expect(itemShares[OC.Share.SHARE_TYPE_USER]).toEqual(['user1']);
|
||||||
|
expect(itemShares[OC.Share.SHARE_TYPE_GROUP]).not.toBeDefined();
|
||||||
|
expect(itemShares[OC.Share.SHARE_TYPE_LINK]).toEqual(true);
|
||||||
|
|
||||||
|
handler.reset();
|
||||||
|
|
||||||
|
// uncheck checkbox
|
||||||
|
$('#dropdown #linkCheckbox').click();
|
||||||
|
fakeServer.requests[1].respond(
|
||||||
|
200,
|
||||||
|
{ 'Content-Type': 'application/json' },
|
||||||
|
JSON.stringify({status: 'success'})
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(handler.calledOnce).toEqual(true);
|
||||||
|
itemShares = handler.getCall(0).args[0].itemShares;
|
||||||
|
expect(itemShares).toBeDefined();
|
||||||
|
expect(itemShares[OC.Share.SHARE_TYPE_USER]).toEqual(['user1']);
|
||||||
|
expect(itemShares[OC.Share.SHARE_TYPE_GROUP]).not.toBeDefined();
|
||||||
|
// currently inconsistent, removing share with link sets it to false
|
||||||
|
// instead of delete
|
||||||
|
expect(itemShares[OC.Share.SHARE_TYPE_LINK]).toBeFalsy();
|
||||||
|
//expect(itemShares[OC.Share.SHARE_TYPE_LINK]).not.toBeDefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue