2013-10-28 23:22:06 +04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2014
|
|
|
|
*
|
|
|
|
* This file is licensed under the Affero General Public License version 3
|
|
|
|
* or later.
|
|
|
|
*
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2014-05-28 20:39:29 +04:00
|
|
|
(function() {
|
2016-11-21 17:03:45 +03:00
|
|
|
|
|
|
|
_.extend(OC.Files.Client, {
|
|
|
|
PROPERTY_SHARE_TYPES: '{' + OC.Files.Client.NS_OWNCLOUD + '}share-types',
|
2018-02-09 13:42:47 +03:00
|
|
|
PROPERTY_OWNER_ID: '{' + OC.Files.Client.NS_OWNCLOUD + '}owner-id',
|
2016-11-21 17:03:45 +03:00
|
|
|
PROPERTY_OWNER_DISPLAY_NAME: '{' + OC.Files.Client.NS_OWNCLOUD + '}owner-display-name'
|
|
|
|
});
|
|
|
|
|
2014-05-28 20:39:29 +04:00
|
|
|
if (!OCA.Sharing) {
|
|
|
|
OCA.Sharing = {};
|
|
|
|
}
|
2014-06-24 01:56:10 +04:00
|
|
|
/**
|
|
|
|
* @namespace
|
|
|
|
*/
|
2014-05-28 20:39:29 +04:00
|
|
|
OCA.Sharing.Util = {
|
2014-06-24 01:56:10 +04:00
|
|
|
/**
|
2014-12-01 18:17:28 +03:00
|
|
|
* Initialize the sharing plugin.
|
2014-06-24 01:56:10 +04:00
|
|
|
*
|
|
|
|
* Registers the "Share" file action and adds additional
|
|
|
|
* DOM attributes for the sharing file info.
|
|
|
|
*
|
2014-12-01 18:17:28 +03:00
|
|
|
* @param {OCA.Files.FileList} fileList file list to be extended
|
2014-06-24 01:56:10 +04:00
|
|
|
*/
|
2014-12-01 18:17:28 +03:00
|
|
|
attach: function(fileList) {
|
2015-07-02 15:56:33 +03:00
|
|
|
// core sharing is disabled/not loaded
|
|
|
|
if (!OC.Share) {
|
|
|
|
return;
|
|
|
|
}
|
2015-01-26 19:06:07 +03:00
|
|
|
if (fileList.id === 'trashbin' || fileList.id === 'files.public') {
|
2014-12-01 18:17:28 +03:00
|
|
|
return;
|
2014-06-02 19:23:52 +04:00
|
|
|
}
|
2015-09-14 18:20:51 +03:00
|
|
|
var fileActions = fileList.fileActions;
|
2014-12-01 18:17:28 +03:00
|
|
|
var oldCreateRow = fileList._createRow;
|
|
|
|
fileList._createRow = function(fileData) {
|
2018-06-20 21:32:19 +03:00
|
|
|
|
|
|
|
if (fileData.permissions === 0) {
|
|
|
|
// no permission, disabling sidebar
|
|
|
|
delete fileActions.actions.all.Details;
|
|
|
|
}
|
|
|
|
|
2014-12-01 18:17:28 +03:00
|
|
|
var tr = oldCreateRow.apply(this, arguments);
|
2016-10-10 11:15:42 +03:00
|
|
|
var sharePermissions = OCA.Sharing.Util.getSharePermissions(fileData);
|
2014-12-01 18:17:28 +03:00
|
|
|
tr.attr('data-share-permissions', sharePermissions);
|
|
|
|
if (fileData.shareOwner) {
|
|
|
|
tr.attr('data-share-owner', fileData.shareOwner);
|
2017-11-19 18:38:04 +03:00
|
|
|
tr.attr('data-share-owner-id', fileData.shareOwnerId);
|
2014-12-01 18:17:28 +03:00
|
|
|
// user should always be able to rename a mount point
|
2015-11-02 17:27:58 +03:00
|
|
|
if (fileData.mountType === 'shared-root') {
|
2014-12-01 18:17:28 +03:00
|
|
|
tr.attr('data-permissions', fileData.permissions | OC.PERMISSION_UPDATE);
|
|
|
|
}
|
|
|
|
}
|
2017-11-21 14:45:57 +03:00
|
|
|
if (fileData.recipientData && !_.isEmpty(fileData.recipientData)) {
|
2017-11-19 18:37:37 +03:00
|
|
|
tr.attr('data-share-recipient-data', JSON.stringify(fileData.recipientData));
|
2014-12-01 18:17:28 +03:00
|
|
|
}
|
2016-03-02 20:25:31 +03:00
|
|
|
if (fileData.shareTypes) {
|
|
|
|
tr.attr('data-share-types', fileData.shareTypes.join(','));
|
|
|
|
}
|
2014-12-01 18:17:28 +03:00
|
|
|
return tr;
|
|
|
|
};
|
2013-10-28 23:22:06 +04:00
|
|
|
|
2015-08-14 16:54:27 +03:00
|
|
|
var oldElementToFile = fileList.elementToFile;
|
|
|
|
fileList.elementToFile = function($el) {
|
|
|
|
var fileInfo = oldElementToFile.apply(this, arguments);
|
|
|
|
fileInfo.sharePermissions = $el.attr('data-share-permissions') || undefined;
|
|
|
|
fileInfo.shareOwner = $el.attr('data-share-owner') || undefined;
|
2018-02-09 13:42:47 +03:00
|
|
|
fileInfo.shareOwnerId = $el.attr('data-share-owner-id') || undefined;
|
2016-11-02 22:20:48 +03:00
|
|
|
|
|
|
|
if( $el.attr('data-share-types')){
|
2017-11-19 18:37:37 +03:00
|
|
|
fileInfo.shareTypes = $el.attr('data-share-types').split(',');
|
2016-11-02 22:20:48 +03:00
|
|
|
}
|
|
|
|
|
2016-11-21 17:03:45 +03:00
|
|
|
if( $el.attr('data-expiration')){
|
|
|
|
var expirationTimestamp = parseInt($el.attr('data-expiration'));
|
|
|
|
fileInfo.shares = [];
|
|
|
|
fileInfo.shares.push({expiration: expirationTimestamp});
|
|
|
|
}
|
|
|
|
|
2015-08-14 16:54:27 +03:00
|
|
|
return fileInfo;
|
|
|
|
};
|
|
|
|
|
2015-11-02 17:27:58 +03:00
|
|
|
var oldGetWebdavProperties = fileList._getWebdavProperties;
|
|
|
|
fileList._getWebdavProperties = function() {
|
|
|
|
var props = oldGetWebdavProperties.apply(this, arguments);
|
2018-02-09 13:42:47 +03:00
|
|
|
props.push(OC.Files.Client.PROPERTY_OWNER_ID);
|
2016-11-21 17:03:45 +03:00
|
|
|
props.push(OC.Files.Client.PROPERTY_OWNER_DISPLAY_NAME);
|
|
|
|
props.push(OC.Files.Client.PROPERTY_SHARE_TYPES);
|
2015-11-02 17:27:58 +03:00
|
|
|
return props;
|
|
|
|
};
|
|
|
|
|
|
|
|
fileList.filesClient.addFileInfoParser(function(response) {
|
|
|
|
var data = {};
|
|
|
|
var props = response.propStat[0].properties;
|
2016-11-21 17:03:45 +03:00
|
|
|
var permissionsProp = props[OC.Files.Client.PROPERTY_PERMISSIONS];
|
2015-11-02 17:27:58 +03:00
|
|
|
|
|
|
|
if (permissionsProp && permissionsProp.indexOf('S') >= 0) {
|
2016-11-21 17:03:45 +03:00
|
|
|
data.shareOwner = props[OC.Files.Client.PROPERTY_OWNER_DISPLAY_NAME];
|
2018-02-09 13:42:47 +03:00
|
|
|
data.shareOwnerId = props[OC.Files.Client.PROPERTY_OWNER_ID];
|
2015-11-02 17:27:58 +03:00
|
|
|
}
|
2016-03-02 20:25:31 +03:00
|
|
|
|
2016-11-21 17:03:45 +03:00
|
|
|
var shareTypesProp = props[OC.Files.Client.PROPERTY_SHARE_TYPES];
|
2016-03-02 20:25:31 +03:00
|
|
|
if (shareTypesProp) {
|
|
|
|
data.shareTypes = _.chain(shareTypesProp).filter(function(xmlvalue) {
|
2016-11-21 17:03:45 +03:00
|
|
|
return (xmlvalue.namespaceURI === OC.Files.Client.NS_OWNCLOUD && xmlvalue.nodeName.split(':')[1] === 'share-type');
|
2016-03-02 20:25:31 +03:00
|
|
|
}).map(function(xmlvalue) {
|
|
|
|
return parseInt(xmlvalue.textContent || xmlvalue.text, 10);
|
|
|
|
}).value();
|
|
|
|
}
|
|
|
|
|
2015-11-02 17:27:58 +03:00
|
|
|
return data;
|
|
|
|
});
|
|
|
|
|
2014-06-02 19:23:52 +04:00
|
|
|
// use delegate to catch the case with multiple file lists
|
2014-12-01 18:17:28 +03:00
|
|
|
fileList.$el.on('fileActionsReady', function(ev){
|
2014-07-01 23:32:04 +04:00
|
|
|
var $files = ev.$files;
|
|
|
|
|
2016-03-02 20:25:31 +03:00
|
|
|
_.each($files, function(file) {
|
|
|
|
var $tr = $(file);
|
2016-03-30 19:09:02 +03:00
|
|
|
var shareTypes = $tr.attr('data-share-types') || '';
|
|
|
|
var shareOwner = $tr.attr('data-share-owner');
|
|
|
|
if (shareTypes || shareOwner) {
|
2016-03-02 20:25:31 +03:00
|
|
|
var hasLink = false;
|
|
|
|
var hasShares = false;
|
|
|
|
_.each(shareTypes.split(',') || [], function(shareType) {
|
|
|
|
shareType = parseInt(shareType, 10);
|
|
|
|
if (shareType === OC.Share.SHARE_TYPE_LINK) {
|
|
|
|
hasLink = true;
|
2016-11-28 14:14:27 +03:00
|
|
|
} else if (shareType === OC.Share.SHARE_TYPE_EMAIL) {
|
|
|
|
hasLink = true;
|
2016-03-02 20:25:31 +03:00
|
|
|
} else if (shareType === OC.Share.SHARE_TYPE_USER) {
|
|
|
|
hasShares = true;
|
|
|
|
} else if (shareType === OC.Share.SHARE_TYPE_GROUP) {
|
|
|
|
hasShares = true;
|
2016-03-24 14:16:57 +03:00
|
|
|
} else if (shareType === OC.Share.SHARE_TYPE_REMOTE) {
|
|
|
|
hasShares = true;
|
2017-03-17 22:48:33 +03:00
|
|
|
} else if (shareType === OC.Share.SHARE_TYPE_CIRCLE) {
|
|
|
|
hasShares = true;
|
2016-03-02 20:25:31 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
OCA.Sharing.Util._updateFileActionIcon($tr, hasShares, hasLink);
|
2014-07-01 23:32:04 +04:00
|
|
|
}
|
2016-03-02 20:25:31 +03:00
|
|
|
});
|
2014-06-02 19:23:52 +04:00
|
|
|
});
|
2014-05-19 17:20:44 +04:00
|
|
|
|
2016-03-02 20:25:31 +03:00
|
|
|
|
2016-02-11 13:06:26 +03:00
|
|
|
fileList.$el.on('changeDirectory', function() {
|
|
|
|
OCA.Sharing.sharesLoaded = false;
|
|
|
|
});
|
|
|
|
|
2015-09-14 18:20:51 +03:00
|
|
|
fileActions.registerAction({
|
|
|
|
name: 'Share',
|
|
|
|
displayName: '',
|
2016-09-20 16:49:21 +03:00
|
|
|
altText: t('core', 'Share'),
|
2015-09-14 18:20:51 +03:00
|
|
|
mime: 'all',
|
2015-09-28 17:23:33 +03:00
|
|
|
permissions: OC.PERMISSION_ALL,
|
2017-04-12 16:04:12 +03:00
|
|
|
iconClass: 'icon-shared',
|
2015-09-14 18:20:51 +03:00
|
|
|
type: OCA.Files.FileActions.TYPE_INLINE,
|
2018-06-20 21:32:19 +03:00
|
|
|
actionHandler: function(fileName, context) {
|
2018-07-05 13:43:52 +03:00
|
|
|
// do not open sidebar if permission is set and equal to 0
|
2018-06-20 21:32:19 +03:00
|
|
|
var permissions = parseInt(context.$file.data('share-permissions'), 10);
|
2018-07-05 13:43:52 +03:00
|
|
|
if (isNaN(permissions) || permissions > 0) {
|
2018-06-20 21:32:19 +03:00
|
|
|
fileList.showDetailsView(fileName, 'shareTabView');
|
|
|
|
}
|
2015-09-28 17:23:33 +03:00
|
|
|
},
|
|
|
|
render: function(actionSpec, isDefault, context) {
|
2018-06-20 21:32:19 +03:00
|
|
|
var permissions = parseInt(context.$file.data('permissions'), 10);
|
2015-09-28 17:23:33 +03:00
|
|
|
// if no share permissions but share owner exists, still show the link
|
|
|
|
if ((permissions & OC.PERMISSION_SHARE) !== 0 || context.$file.attr('data-share-owner')) {
|
|
|
|
return fileActions._defaultRenderAction.call(fileActions, actionSpec, isDefault, context);
|
|
|
|
}
|
|
|
|
// don't render anything
|
|
|
|
return null;
|
2015-09-14 18:20:51 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-09-28 13:30:12 +03:00
|
|
|
var shareTab = new OCA.Sharing.ShareTabView('shareTabView', {order: -20});
|
2015-09-14 18:20:51 +03:00
|
|
|
// detect changes and change the matching list entry
|
|
|
|
shareTab.on('sharesChanged', function(shareModel) {
|
|
|
|
var fileInfoModel = shareModel.fileInfoModel;
|
|
|
|
var $tr = fileList.findFileEl(fileInfoModel.get('name'));
|
2016-11-30 11:35:38 +03:00
|
|
|
|
|
|
|
// We count email shares as link share
|
|
|
|
var hasLinkShare = shareModel.hasLinkShare();
|
|
|
|
shareModel.get('shares').forEach(function (share) {
|
|
|
|
if (share.share_type === OC.Share.SHARE_TYPE_EMAIL) {
|
|
|
|
hasLinkShare = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-09-14 18:20:51 +03:00
|
|
|
OCA.Sharing.Util._updateFileListDataAttributes(fileList, $tr, shareModel);
|
2016-11-30 11:35:38 +03:00
|
|
|
if (!OCA.Sharing.Util._updateFileActionIcon($tr, shareModel.hasUserShares(), hasLinkShare)) {
|
2015-09-14 18:20:51 +03:00
|
|
|
// remove icon, if applicable
|
|
|
|
OC.Share.markFileAsShared($tr, false, false);
|
|
|
|
}
|
2016-08-17 13:25:58 +03:00
|
|
|
|
|
|
|
// FIXME: this is too convoluted. We need to get rid of the above updates
|
|
|
|
// and only ever update the model and let the events take care of rerendering
|
|
|
|
fileInfoModel.set({
|
|
|
|
shareTypes: shareModel.getShareTypes(),
|
|
|
|
// in case markFileAsShared decided to change the icon,
|
|
|
|
// we need to modify the model
|
|
|
|
// (FIXME: yes, this is hacky)
|
|
|
|
icon: $tr.attr('data-icon')
|
|
|
|
});
|
2015-09-14 18:20:51 +03:00
|
|
|
});
|
|
|
|
fileList.registerTabView(shareTab);
|
2016-10-04 13:56:04 +03:00
|
|
|
|
2016-10-14 12:21:40 +03:00
|
|
|
var breadCrumbSharingDetailView = new OCA.Sharing.ShareBreadCrumbView({shareTab: shareTab});
|
2016-10-04 13:56:04 +03:00
|
|
|
fileList.registerBreadCrumbDetailView(breadCrumbSharingDetailView);
|
2015-09-14 18:20:51 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update file list data attributes
|
|
|
|
*/
|
|
|
|
_updateFileListDataAttributes: function(fileList, $tr, shareModel) {
|
|
|
|
// files app current cannot show recipients on load, so we don't update the
|
|
|
|
// icon when changed for consistency
|
|
|
|
if (fileList.id === 'files') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var recipients = _.pluck(shareModel.get('shares'), 'share_with_displayname');
|
|
|
|
// note: we only update the data attribute because updateIcon()
|
|
|
|
if (recipients.length) {
|
2017-11-21 13:29:42 +03:00
|
|
|
var recipientData = _.mapObject(shareModel.get('shares'), function (share) {
|
|
|
|
return {shareWith: share.share_with, shareWithDisplayName: share.share_with_displayname};
|
|
|
|
});
|
|
|
|
$tr.attr('data-share-recipient-data', JSON.stringify(recipientData));
|
2015-09-14 18:20:51 +03:00
|
|
|
}
|
|
|
|
else {
|
2017-11-21 13:29:42 +03:00
|
|
|
$tr.removeAttr('data-share-recipient-data');
|
2015-09-14 18:20:51 +03:00
|
|
|
}
|
2014-05-28 20:39:29 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2014-07-01 23:32:04 +04:00
|
|
|
* Update the file action share icon for the given file
|
|
|
|
*
|
|
|
|
* @param $tr file element of the file to update
|
2017-11-21 14:45:57 +03:00
|
|
|
* @param {boolean} hasUserShares true if a user share exists
|
|
|
|
* @param {boolean} hasLinkShare true if a link share exists
|
2015-09-14 18:20:51 +03:00
|
|
|
*
|
2017-11-21 14:45:57 +03:00
|
|
|
* @return {boolean} true if the icon was set, false otherwise
|
2014-07-01 23:32:04 +04:00
|
|
|
*/
|
2015-09-14 18:20:51 +03:00
|
|
|
_updateFileActionIcon: function($tr, hasUserShares, hasLinkShare) {
|
2014-07-01 23:32:04 +04:00
|
|
|
// if the statuses are loaded already, use them for the icon
|
|
|
|
// (needed when scrolling to the next page)
|
2017-11-21 14:45:57 +03:00
|
|
|
if (hasUserShares || hasLinkShare || $tr.attr('data-share-recipient-data') || $tr.attr('data-share-owner')) {
|
2015-09-14 18:20:51 +03:00
|
|
|
OC.Share.markFileAsShared($tr, true, hasLinkShare);
|
|
|
|
return true;
|
2014-07-01 23:32:04 +04:00
|
|
|
}
|
2015-09-14 18:20:51 +03:00
|
|
|
return false;
|
2014-07-01 23:32:04 +04:00
|
|
|
},
|
|
|
|
|
2016-10-10 11:15:42 +03:00
|
|
|
/**
|
|
|
|
* @param {Array} fileData
|
|
|
|
* @returns {String}
|
|
|
|
*/
|
|
|
|
getSharePermissions: function(fileData) {
|
2018-03-08 21:52:37 +03:00
|
|
|
return fileData.sharePermissions;
|
2014-05-28 20:39:29 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
})();
|
|
|
|
|
2014-12-01 18:17:28 +03:00
|
|
|
OC.Plugins.register('OCA.Files.FileList', OCA.Sharing.Util);
|