From 50829d3db17380eb90ea3b6270eb1bbd18e3b04f Mon Sep 17 00:00:00 2001 From: yflory Date: Mon, 14 Oct 2019 17:37:54 +0200 Subject: [PATCH] Share a folder with a read-only URL --- www/common/common-ui-elements.js | 106 +++++++++++++------------------ www/common/drive-ui.js | 44 +++++-------- www/common/outer/sharedfolder.js | 4 ++ www/common/outer/team.js | 1 + www/drive/inner.html | 3 +- www/drive/inner.js | 3 +- 6 files changed, 71 insertions(+), 90 deletions(-) diff --git a/www/common/common-ui-elements.js b/www/common/common-ui-elements.js index d1e5a87b3..41bcfd5f6 100644 --- a/www/common/common-ui-elements.js +++ b/www/common/common-ui-elements.js @@ -867,6 +867,7 @@ define([ // 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 if (config.teamId && config.teamId === id) { return; } + if (!teamsData[id].secondaryKey) { return; } var t = teamsData[id]; teams[t.edPublic] = { notifications: true, @@ -980,7 +981,7 @@ define([ var hashes = config.hashes; var common = config.common; - if (!hashes) { return; } + if (!hashes || (!hashes.editHash && !hashes.viewHash)) { return; } // Share link tab var hasFriends = Object.keys(config.friends || {}).length !== 0; @@ -988,7 +989,12 @@ define([ var friendsList = hasFriends ? createShareWithFriends(config, onFriendShare) : undefined; 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('br'), UI.createRadio('cp-share-editable', 'cp-share-editable-true', @@ -996,18 +1002,21 @@ define([ UI.createRadio('cp-share-editable', 'cp-share-editable-false', Messages.share_linkView, false, { mark: {tabindex:1} }), h('br'), + ]; + var padContent = [ h('label', Messages.share_linkOptions), h('br'), UI.createCheckbox('cp-share-embed', Messages.share_linkEmbed, false, { mark: {tabindex:1} }), UI.createCheckbox('cp-share-present', Messages.share_linkPresent, false, { mark: {tabindex:1} }), 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); - 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 edit = Util.isChecked($(link).find('#cp-share-editable-true')); var embed = Util.isChecked($(link).find('#cp-share-embed')); @@ -1046,21 +1055,32 @@ define([ if (success) { UI.log(Messages.shareSuccess); } }, keys: [13] - }, { - className: 'primary', - name: Messages.share_linkOpen, - onClick: function () { - saveValue(); - var v = getLinkValue(); - window.open(v); - }, - keys: [[13, 'ctrl']] }]; + if (!config.sharedFolder) { + shareButtons.push({ + className: 'primary', + name: Messages.share_linkOpen, + onClick: function () { + saveValue(); + var v = getLinkValue(); + window.open(v); + }, + keys: [[13, 'ctrl']] + }); + } var $link = $(link); $(mainShareColumn).append(UI.dialog.getButtons(shareButtons, config.onClose)).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('input[type="radio"], input[type="checkbox"]').on('change', function () { $(link).find('#cp-share-link-preview').val(getLinkValue()); @@ -1122,7 +1142,7 @@ define([ } common.getAttribute(['general', 'share'], function (err, 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-true').prop('checked', false); } else { @@ -1131,12 +1151,17 @@ define([ } if (val.embed) { $(link).find('#cp-share-embed').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)); }); common.getMetadataMgr().onChange(function () { // "hashes" is only available is the secure "share" app - hashes = common.getMetadataMgr().getPrivateData().hashes; - if (!hashes) { return; } + var _hashes = common.getMetadataMgr().getPrivateData().hashes; + if (!_hashes) { return; } + hashes = _hashes; $(link).find('#cp-share-link-preview').val(getLinkValue()); }); return tabs; @@ -1238,47 +1263,6 @@ define([ } 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) { var common = config.common; diff --git a/www/common/drive-ui.js b/www/common/drive-ui.js index 1badf239e..7e08a1a72 100644 --- a/www/common/drive-ui.js +++ b/www/common/drive-ui.js @@ -2523,24 +2523,28 @@ define([ $sharedIcon.clone().appendTo($shareBlock); $('').text(Messages.shareButton).appendTo($shareBlock); var data = manager.getSharedFolderData(id); - var parsed = Hash.parsePadUrl(data.href); - // XXX share modal shared folder read only - if (!parsed || !parsed.hash) { return void console.error("Invalid href: "+data.href); } + var parsed = (data.href && data.href.indexOf('#') !== -1) ? Hash.parsePadUrl(data.href) : {}; + var roParsed = Hash.parsePadUrl(data.roHref) || {}; + if (!parsed.hash && !roParsed.hash) { return void console.error("Invalid href: "+(data.href || data.roHref)); } var friends = common.getFriends(); var teams = common.getMetadataMgr().getPrivateData().teams; 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, origin: APP.origin, pathname: "/drive/", friends: friends, title: data.title, password: data.password, + sharedFolder: true, common: common, hashes: { - editHash: parsed.hash + editHash: parsed.hash, + viewHash: ro && roParsed.hash, } }); + modal = UI.dialog.tabs(modal); $shareBlock.click(function () { UI.openCustomModal(modal, { wide: _wide @@ -4018,25 +4022,7 @@ define([ var teams = common.getMetadataMgr().getPrivateData().teams; var _wide = Object.keys(friends).length || Object.keys(teams).length; - if (manager.isSharedFolder(el)) { - 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 (manager.isFolder(el) && !manager.isSharedFolder(el)) { // Folder // if folder is inside SF return UI.warn('ERROR: Temporarily disabled'); // XXX CONVERT /*if (manager.isInSharedFolder(paths[0].path)) { @@ -4071,10 +4057,13 @@ define([ }); }*/ } else { // File - data = manager.getFileData(el); - parsed = Hash.parsePadUrl(data.href); + var sf = manager.isSharedFolder(el); + 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 padType = parsed.type || roParsed.type; + var ro = !sf || (folders[el] && folders[el].version >= 2); + console.log(folders[el]); var padData = { teamId: APP.team, origin: APP.origin, @@ -4083,7 +4072,7 @@ define([ password: data.password, hashes: { editHash: parsed.hash, - viewHash: roParsed.hash, + viewHash: ro && roParsed.hash, fileHash: parsed.hash }, fileData: { @@ -4092,6 +4081,7 @@ define([ }, isTemplate: paths[0].path[0] === 'template', title: data.title, + sharedFolder: sf, common: common }; modal = padType === 'file' ? UIElements.createFileShareModal(padData) diff --git a/www/common/outer/sharedfolder.js b/www/common/outer/sharedfolder.js index c12900c19..d4883bd10 100644 --- a/www/common/outer/sharedfolder.js +++ b/www/common/outer/sharedfolder.js @@ -134,6 +134,10 @@ define([ }; var rt = sf.rt = Listmap.create(listmapConfig); 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) { return; } diff --git a/www/common/outer/team.js b/www/common/outer/team.js index e297dee65..59b56c47e 100644 --- a/www/common/outer/team.js +++ b/www/common/outer/team.js @@ -531,6 +531,7 @@ define([ }; var lm = Listmap.create(config); var proxy = lm.proxy; + proxy.version = 2; // No migration needed proxy.on('ready', function () { // Store keys in our drive var keys = { diff --git a/www/drive/inner.html b/www/drive/inner.html index ce9e5afb4..abbb03414 100644 --- a/www/drive/inner.html +++ b/www/drive/inner.html @@ -16,7 +16,8 @@
-
+ +
diff --git a/www/drive/inner.js b/www/drive/inner.js index 1f53baaf5..5e2527600 100644 --- a/www/drive/inner.js +++ b/www/drive/inner.js @@ -109,6 +109,7 @@ define([ SFCommon.create(waitFor(function (c) { common = c; })); }).nThen(function (waitFor) { $('#cp-app-drive-connection-state').text(Messages.disconnected); + $('#cp-app-drive-edition-state').text(Messages.readonly); var privReady = Util.once(waitFor()); var metadataMgr = common.getMetadataMgr(); if (JSON.stringify(metadataMgr.getPrivateData()) !== '{}') { @@ -214,7 +215,7 @@ define([ }; // Add a "Burn this drive" button - if (!APP.loggedIn) { + if (!APP.loggedIn && !APP.readOnly) { APP.$burnThisDrive = common.createButton(null, true).click(function () { UI.confirm(Messages.fm_burnThisDrive, function (yes) { if (!yes) { return; }