Share a folder with a read-only URL

pull/1/head
yflory 5 years ago
parent 7c710e57b7
commit 50829d3db1

@ -867,6 +867,7 @@ define([
// config.teamId only exists when we're trying to share a pad from a team drive // config.teamId only exists when we're trying to share a pad from a team drive
// In this case, we don't want to share the pad with the current team // In this case, we don't want to share the pad with the current team
if (config.teamId && config.teamId === id) { return; } if (config.teamId && config.teamId === id) { return; }
if (!teamsData[id].secondaryKey) { return; }
var t = teamsData[id]; var t = teamsData[id];
teams[t.edPublic] = { teams[t.edPublic] = {
notifications: true, notifications: true,
@ -980,7 +981,7 @@ define([
var hashes = config.hashes; var hashes = config.hashes;
var common = config.common; var common = config.common;
if (!hashes) { return; } if (!hashes || (!hashes.editHash && !hashes.viewHash)) { return; }
// Share link tab // Share link tab
var hasFriends = Object.keys(config.friends || {}).length !== 0; var hasFriends = Object.keys(config.friends || {}).length !== 0;
@ -988,7 +989,12 @@ define([
var friendsList = hasFriends ? createShareWithFriends(config, onFriendShare) : undefined; var friendsList = hasFriends ? createShareWithFriends(config, onFriendShare) : undefined;
var friendsUIClass = hasFriends ? '.cp-share-columns' : ''; var friendsUIClass = hasFriends ? '.cp-share-columns' : '';
var mainShareColumn = h('div.cp-share-column.contains-nav', [ var content = [];
var sfContent = [
h('label', Messages.sharedFolders_share),
h('br'),
];
var shareContent = [
h('label', Messages.share_linkAccess), h('label', Messages.share_linkAccess),
h('br'), h('br'),
UI.createRadio('cp-share-editable', 'cp-share-editable-true', UI.createRadio('cp-share-editable', 'cp-share-editable-true',
@ -996,18 +1002,21 @@ define([
UI.createRadio('cp-share-editable', 'cp-share-editable-false', UI.createRadio('cp-share-editable', 'cp-share-editable-false',
Messages.share_linkView, false, { mark: {tabindex:1} }), Messages.share_linkView, false, { mark: {tabindex:1} }),
h('br'), h('br'),
];
var padContent = [
h('label', Messages.share_linkOptions), h('label', Messages.share_linkOptions),
h('br'), h('br'),
UI.createCheckbox('cp-share-embed', Messages.share_linkEmbed, false, { mark: {tabindex:1} }), UI.createCheckbox('cp-share-embed', Messages.share_linkEmbed, false, { mark: {tabindex:1} }),
UI.createCheckbox('cp-share-present', Messages.share_linkPresent, false, { mark: {tabindex:1} }), UI.createCheckbox('cp-share-present', Messages.share_linkPresent, false, { mark: {tabindex:1} }),
h('br'), h('br'),
UI.dialog.selectable('', { id: 'cp-share-link-preview', tabindex: 1 }), ];
]); if (config.sharedFolder) { Array.prototype.push.apply(content, sfContent); }
Array.prototype.push.apply(content, shareContent);
if (!config.sharedFolder) { Array.prototype.push.apply(content, padContent); }
content.push(UI.dialog.selectable('', { id: 'cp-share-link-preview', tabindex: 1 }));
var mainShareColumn = h('div.cp-share-column.contains-nav', content);
var link = h('div.cp-share-modal' + friendsUIClass); var link = h('div.cp-share-modal' + friendsUIClass);
if (!hashes.editHash) {
$(link).find('#cp-share-editable-false').attr('checked', true);
$(link).find('#cp-share-editable-true').removeAttr('checked').attr('disabled', true);
}
var saveValue = function () { var saveValue = function () {
var edit = Util.isChecked($(link).find('#cp-share-editable-true')); var edit = Util.isChecked($(link).find('#cp-share-editable-true'));
var embed = Util.isChecked($(link).find('#cp-share-embed')); var embed = Util.isChecked($(link).find('#cp-share-embed'));
@ -1046,7 +1055,9 @@ define([
if (success) { UI.log(Messages.shareSuccess); } if (success) { UI.log(Messages.shareSuccess); }
}, },
keys: [13] keys: [13]
}, { }];
if (!config.sharedFolder) {
shareButtons.push({
className: 'primary', className: 'primary',
name: Messages.share_linkOpen, name: Messages.share_linkOpen,
onClick: function () { onClick: function () {
@ -1055,12 +1066,21 @@ define([
window.open(v); window.open(v);
}, },
keys: [[13, 'ctrl']] keys: [[13, 'ctrl']]
}]; });
}
var $link = $(link); var $link = $(link);
$(mainShareColumn).append(UI.dialog.getButtons(shareButtons, config.onClose)).appendTo($link); $(mainShareColumn).append(UI.dialog.getButtons(shareButtons, config.onClose)).appendTo($link);
$(friendsList).appendTo($link); $(friendsList).appendTo($link);
if (!hashes.editHash) {
$(link).find('#cp-share-editable-false').attr('checked', true);
$(link).find('#cp-share-editable-true').removeAttr('checked').attr('disabled', true);
} else if (!hashes.viewHash) {
$(link).find('#cp-share-editable-false').removeAttr('checked').attr('disabled', true);
$(link).find('#cp-share-editable-true').attr('checked', true);
}
$(link).find('#cp-share-link-preview').val(getLinkValue()); $(link).find('#cp-share-link-preview').val(getLinkValue());
$(link).find('input[type="radio"], input[type="checkbox"]').on('change', function () { $(link).find('input[type="radio"], input[type="checkbox"]').on('change', function () {
$(link).find('#cp-share-link-preview').val(getLinkValue()); $(link).find('#cp-share-link-preview').val(getLinkValue());
@ -1122,7 +1142,7 @@ define([
} }
common.getAttribute(['general', 'share'], function (err, val) { common.getAttribute(['general', 'share'], function (err, val) {
val = val || {}; val = val || {};
if (val.edit === false || !hashes.editHash) { if ((val.edit === false && hashes.viewHash) || !hashes.editHash) {
$(link).find('#cp-share-editable-false').prop('checked', true); $(link).find('#cp-share-editable-false').prop('checked', true);
$(link).find('#cp-share-editable-true').prop('checked', false); $(link).find('#cp-share-editable-true').prop('checked', false);
} else { } else {
@ -1131,12 +1151,17 @@ define([
} }
if (val.embed) { $(link).find('#cp-share-embed').prop('checked', true); } if (val.embed) { $(link).find('#cp-share-embed').prop('checked', true); }
if (val.present) { $(link).find('#cp-share-present').prop('checked', true); } if (val.present) { $(link).find('#cp-share-present').prop('checked', true); }
if (config.sharedFolder) {
delete val.embed;
delete val.present;
}
$(link).find('#cp-share-link-preview').val(getLinkValue(val)); $(link).find('#cp-share-link-preview').val(getLinkValue(val));
}); });
common.getMetadataMgr().onChange(function () { common.getMetadataMgr().onChange(function () {
// "hashes" is only available is the secure "share" app // "hashes" is only available is the secure "share" app
hashes = common.getMetadataMgr().getPrivateData().hashes; var _hashes = common.getMetadataMgr().getPrivateData().hashes;
if (!hashes) { return; } if (!_hashes) { return; }
hashes = _hashes;
$(link).find('#cp-share-link-preview').val(getLinkValue()); $(link).find('#cp-share-link-preview').val(getLinkValue());
}); });
return tabs; return tabs;
@ -1238,47 +1263,6 @@ define([
} }
return tabs; return tabs;
}; };
UIElements.createSFShareModal = function (config) {
var origin = config.origin;
var pathname = config.pathname;
var hashes = config.hashes;
if (!hashes.editHash) { throw new Error("You must provide a valid hash"); }
var url = origin + pathname + '#' + hashes.editHash;
// Share link tab
var hasFriends = Object.keys(config.friends || {}).length !== 0;
var friendsList = hasFriends ? createShareWithFriends(config) : undefined;
var friendsUIClass = hasFriends ? '.cp-share-columns' : '';
var mainShareColumn = h('div.cp-share-column.contains-nav', [
h('div.cp-share-column', [
h('label', Messages.sharedFolders_share),
h('br'),
hasFriends ? h('p', Messages.share_description) : undefined,
UI.dialog.selectable(url, { id: 'cp-share-link-preview', tabindex: 1 })
])
]);
var link = h('div.cp-share-modal' + friendsUIClass);
var linkButtons = [{
className: 'cancel',
name: Messages.cancel,
onClick: function () {},
keys: [27]
}];
var shareButtons = [{
className: 'primary',
name: Messages.share_linkCopy,
onClick: function () {
var success = Clipboard.copy(url);
if (success) { UI.log(Messages.shareSuccess); }
},
keys: [13]
}];
var $link = $(link);
$(mainShareColumn).append(UI.dialog.getButtons(shareButtons, config.onClose)).appendTo($link);
$(friendsList).appendTo($link);
return UI.dialog.customModal(link, {buttons: linkButtons});
};
UIElements.createInviteTeamModal = function (config) { UIElements.createInviteTeamModal = function (config) {
var common = config.common; var common = config.common;

@ -2523,24 +2523,28 @@ define([
$sharedIcon.clone().appendTo($shareBlock); $sharedIcon.clone().appendTo($shareBlock);
$('<span>').text(Messages.shareButton).appendTo($shareBlock); $('<span>').text(Messages.shareButton).appendTo($shareBlock);
var data = manager.getSharedFolderData(id); var data = manager.getSharedFolderData(id);
var parsed = Hash.parsePadUrl(data.href); var parsed = (data.href && data.href.indexOf('#') !== -1) ? Hash.parsePadUrl(data.href) : {};
// XXX share modal shared folder read only var roParsed = Hash.parsePadUrl(data.roHref) || {};
if (!parsed || !parsed.hash) { return void console.error("Invalid href: "+data.href); } if (!parsed.hash && !roParsed.hash) { return void console.error("Invalid href: "+(data.href || data.roHref)); }
var friends = common.getFriends(); var friends = common.getFriends();
var teams = common.getMetadataMgr().getPrivateData().teams; var teams = common.getMetadataMgr().getPrivateData().teams;
var _wide = Object.keys(friends).length || Object.keys(teams).length; var _wide = Object.keys(friends).length || Object.keys(teams).length;
var modal = UIElements.createSFShareModal({ var ro = folders[id] && folders[id].version >= 2;
var modal = UIElements.createShareModal({
teamId: APP.team, teamId: APP.team,
origin: APP.origin, origin: APP.origin,
pathname: "/drive/", pathname: "/drive/",
friends: friends, friends: friends,
title: data.title, title: data.title,
password: data.password, password: data.password,
sharedFolder: true,
common: common, common: common,
hashes: { hashes: {
editHash: parsed.hash editHash: parsed.hash,
viewHash: ro && roParsed.hash,
} }
}); });
modal = UI.dialog.tabs(modal);
$shareBlock.click(function () { $shareBlock.click(function () {
UI.openCustomModal(modal, { UI.openCustomModal(modal, {
wide: _wide wide: _wide
@ -4018,25 +4022,7 @@ define([
var teams = common.getMetadataMgr().getPrivateData().teams; var teams = common.getMetadataMgr().getPrivateData().teams;
var _wide = Object.keys(friends).length || Object.keys(teams).length; var _wide = Object.keys(friends).length || Object.keys(teams).length;
if (manager.isSharedFolder(el)) { if (manager.isFolder(el) && !manager.isSharedFolder(el)) { // Folder
data = manager.getSharedFolderData(el);
parsed = Hash.parsePadUrl(data.href);
modal = UIElements.createSFShareModal({
teamId: APP.team,
origin: APP.origin,
pathname: "/drive/",
friends: friends,
title: data.title,
common: common,
password: data.password,
hashes: {
editHash: parsed.hash
}
});
return void UI.openCustomModal(modal, {
wide: _wide
});
} else if (manager.isFolder(el)) { // Folder
// if folder is inside SF // if folder is inside SF
return UI.warn('ERROR: Temporarily disabled'); // XXX CONVERT return UI.warn('ERROR: Temporarily disabled'); // XXX CONVERT
/*if (manager.isInSharedFolder(paths[0].path)) { /*if (manager.isInSharedFolder(paths[0].path)) {
@ -4071,10 +4057,13 @@ define([
}); });
}*/ }*/
} else { // File } else { // File
data = manager.getFileData(el); var sf = manager.isSharedFolder(el);
parsed = Hash.parsePadUrl(data.href); data = sf ? manager.getSharedFolderData(el) : manager.getFileData(el);
parsed = (data.href && data.href.indexOf('#') !== -1) ? Hash.parsePadUrl(data.href) : {};
var roParsed = Hash.parsePadUrl(data.roHref); var roParsed = Hash.parsePadUrl(data.roHref);
var padType = parsed.type || roParsed.type; var padType = parsed.type || roParsed.type;
var ro = !sf || (folders[el] && folders[el].version >= 2);
console.log(folders[el]);
var padData = { var padData = {
teamId: APP.team, teamId: APP.team,
origin: APP.origin, origin: APP.origin,
@ -4083,7 +4072,7 @@ define([
password: data.password, password: data.password,
hashes: { hashes: {
editHash: parsed.hash, editHash: parsed.hash,
viewHash: roParsed.hash, viewHash: ro && roParsed.hash,
fileHash: parsed.hash fileHash: parsed.hash
}, },
fileData: { fileData: {
@ -4092,6 +4081,7 @@ define([
}, },
isTemplate: paths[0].path[0] === 'template', isTemplate: paths[0].path[0] === 'template',
title: data.title, title: data.title,
sharedFolder: sf,
common: common common: common
}; };
modal = padType === 'file' ? UIElements.createFileShareModal(padData) modal = padType === 'file' ? UIElements.createFileShareModal(padData)

@ -134,6 +134,10 @@ define([
}; };
var rt = sf.rt = Listmap.create(listmapConfig); var rt = sf.rt = Listmap.create(listmapConfig);
rt.proxy.on('ready', function (info) { rt.proxy.on('ready', function (info) {
if (!Object.keys(rt.proxy).length) {
// New Shared folder: no migration required
rt.proxy.version = 2;
}
if (!sf.queue) { if (!sf.queue) {
return; return;
} }

@ -531,6 +531,7 @@ define([
}; };
var lm = Listmap.create(config); var lm = Listmap.create(config);
var proxy = lm.proxy; var proxy = lm.proxy;
proxy.version = 2; // No migration needed
proxy.on('ready', function () { proxy.on('ready', function () {
// Store keys in our drive // Store keys in our drive
var keys = { var keys = {

@ -16,7 +16,8 @@
</div> </div>
<div id="cp-app-drive-content-container"> <div id="cp-app-drive-content-container">
<div id="cp-app-drive-toolbar"></div> <div id="cp-app-drive-toolbar"></div>
<div id="cp-app-drive-connection-state"></div> <div id="cp-app-drive-connection-state" style="display: none"></div>
<div id="cp-app-drive-edition-state" style="display: none"></div>
<div id="cp-app-drive-content" tabindex="2"></div> <div id="cp-app-drive-content" tabindex="2"></div>
</div> </div>
</div> </div>

@ -109,6 +109,7 @@ define([
SFCommon.create(waitFor(function (c) { common = c; })); SFCommon.create(waitFor(function (c) { common = c; }));
}).nThen(function (waitFor) { }).nThen(function (waitFor) {
$('#cp-app-drive-connection-state').text(Messages.disconnected); $('#cp-app-drive-connection-state').text(Messages.disconnected);
$('#cp-app-drive-edition-state').text(Messages.readonly);
var privReady = Util.once(waitFor()); var privReady = Util.once(waitFor());
var metadataMgr = common.getMetadataMgr(); var metadataMgr = common.getMetadataMgr();
if (JSON.stringify(metadataMgr.getPrivateData()) !== '{}') { if (JSON.stringify(metadataMgr.getPrivateData()) !== '{}') {
@ -214,7 +215,7 @@ define([
}; };
// Add a "Burn this drive" button // Add a "Burn this drive" button
if (!APP.loggedIn) { if (!APP.loggedIn && !APP.readOnly) {
APP.$burnThisDrive = common.createButton(null, true).click(function () { APP.$burnThisDrive = common.createButton(null, true).click(function () {
UI.confirm(Messages.fm_burnThisDrive, function (yes) { UI.confirm(Messages.fm_burnThisDrive, function (yes) {
if (!yes) { return; } if (!yes) { return; }

Loading…
Cancel
Save