Secure share modal
This commit is contained in:
@@ -351,6 +351,9 @@ define([
|
||||
var close = function (el) {
|
||||
var $el = $(el).fadeOut(150, function () {
|
||||
$el.detach();
|
||||
if (opt.onClose) {
|
||||
opt.onClose();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -205,7 +205,7 @@ define([
|
||||
if (content === oldThumbnailState) { return; }
|
||||
oldThumbnailState = content;
|
||||
Thumb.fromDOM(opts, function (err, b64) {
|
||||
Thumb.setPadThumbnail(common, opts.href, null, b64);
|
||||
Thumb.setPadThumbnail(common, opts.type, null, b64);
|
||||
});
|
||||
};
|
||||
var nafa = Util.notAgainForAnother(mkThumbnail, Thumb.UPDATE_INTERVAL);
|
||||
@@ -243,11 +243,10 @@ define([
|
||||
var getKey = function (type, channel) {
|
||||
return 'thumbnail-' + type + '-' + channel;
|
||||
};
|
||||
Thumb.setPadThumbnail = function (common, href, channel, b64, cb) {
|
||||
Thumb.setPadThumbnail = function (common, type, channel, b64, cb) {
|
||||
cb = cb || function () {};
|
||||
var parsed = Hash.parsePadUrl(href);
|
||||
channel = channel || common.getMetadataMgr().getPrivateData().channel;
|
||||
var k = getKey(parsed.type, channel);
|
||||
var k = getKey(type, channel);
|
||||
common.setThumbnail(k, b64, cb);
|
||||
};
|
||||
Thumb.displayThumbnail = function (common, href, channel, password, $container, cb) {
|
||||
@@ -270,7 +269,7 @@ define([
|
||||
if (!v) {
|
||||
v = 'EMPTY';
|
||||
}
|
||||
Thumb.setPadThumbnail(common, href, hexFileName, v, function (err) {
|
||||
Thumb.setPadThumbnail(common, parsed.type, hexFileName, v, function (err) {
|
||||
if (!metadata.thumbnail) { return; }
|
||||
addThumbnail(err, metadata.thumbnail, $container, cb);
|
||||
});
|
||||
|
||||
@@ -322,6 +322,8 @@ define([
|
||||
var hashes = config.hashes;
|
||||
var common = config.common;
|
||||
|
||||
if (!hashes) { return; }
|
||||
|
||||
// Share link tab
|
||||
var link = h('div.cp-share-modal', [
|
||||
h('label', Messages.share_linkAccess),
|
||||
@@ -403,7 +405,10 @@ define([
|
||||
},
|
||||
keys: [[13, 'ctrl']]
|
||||
}];
|
||||
var frameLink = UI.dialog.customModal(link, {buttons: linkButtons});
|
||||
var frameLink = UI.dialog.customModal(link, {
|
||||
buttons: linkButtons,
|
||||
onClose: config.onClose
|
||||
});
|
||||
|
||||
// Embed tab
|
||||
var getEmbedValue = function () {
|
||||
@@ -464,7 +469,9 @@ define([
|
||||
$(link).find('#cp-share-link-preview').val(getLinkValue(val));
|
||||
});
|
||||
common.getMetadataMgr().onChange(function () {
|
||||
hashes = common.getMetadataMgr().getPrivateData().availableHashes;
|
||||
// "hashes" is only available is the secure "share" app
|
||||
hashes = common.getMetadataMgr().getPrivateData().hashes;
|
||||
if (!hashes) { return; }
|
||||
$(link).find('#cp-share-link-preview').val(getLinkValue());
|
||||
});
|
||||
return tabs;
|
||||
|
||||
@@ -357,16 +357,14 @@ define([
|
||||
UI.removeLoadingScreen(emitResize);
|
||||
|
||||
var privateDat = cpNfInner.metadataMgr.getPrivateData();
|
||||
var hash = privateDat.availableHashes.editHash ||
|
||||
privateDat.availableHashes.viewHash;
|
||||
var href = privateDat.pathname + '#' + hash;
|
||||
var type = privateDat.app;
|
||||
if (AppConfig.textAnalyzer && textContentGetter) {
|
||||
AppConfig.textAnalyzer(textContentGetter, privateDat.channel);
|
||||
}
|
||||
|
||||
if (options.thumbnail && privateDat.thumbnails) {
|
||||
if (hash) {
|
||||
options.thumbnail.href = href;
|
||||
if (type) {
|
||||
options.thumbnail.type = type;
|
||||
options.thumbnail.getContent = function () {
|
||||
if (!cpNfInner.chainpad) { return; }
|
||||
return cpNfInner.chainpad.getUserDoc();
|
||||
|
||||
@@ -19,6 +19,7 @@ define([
|
||||
var SFrameChannel;
|
||||
var sframeChan;
|
||||
var FilePicker;
|
||||
var Share;
|
||||
var Messaging;
|
||||
var Notifier;
|
||||
var Utils = {
|
||||
@@ -38,6 +39,7 @@ define([
|
||||
'/common/cryptget.js',
|
||||
'/common/outer/worker-channel.js',
|
||||
'/filepicker/main.js',
|
||||
'/share/main.js',
|
||||
'/common/common-messaging.js',
|
||||
'/common/common-notifier.js',
|
||||
'/common/common-hash.js',
|
||||
@@ -49,7 +51,7 @@ define([
|
||||
'/customize/application_config.js',
|
||||
'/common/test.js',
|
||||
], waitFor(function (_CpNfOuter, _Cryptpad, _Crypto, _Cryptget, _SFrameChannel,
|
||||
_FilePicker, _Messaging, _Notifier, _Hash, _Util, _Realtime,
|
||||
_FilePicker, _Share, _Messaging, _Notifier, _Hash, _Util, _Realtime,
|
||||
_Constants, _Feedback, _LocalStore, _AppConfig, _Test) {
|
||||
CpNfOuter = _CpNfOuter;
|
||||
Cryptpad = _Cryptpad;
|
||||
@@ -57,6 +59,7 @@ define([
|
||||
Cryptget = _Cryptget;
|
||||
SFrameChannel = _SFrameChannel;
|
||||
FilePicker = _FilePicker;
|
||||
Share = _Share;
|
||||
Messaging = _Messaging;
|
||||
Notifier = _Notifier;
|
||||
Utils.Hash = _Hash;
|
||||
@@ -269,9 +272,6 @@ define([
|
||||
sessionStorage[Utils.Constants.displayPadCreationScreen];
|
||||
delete sessionStorage[Utils.Constants.displayPadCreationScreen];
|
||||
var updateMeta = function () {
|
||||
// TODO availableHashes in privateData may need updates once we have
|
||||
// a better privileges workflow
|
||||
|
||||
//console.log('EV_METADATA_UPDATE');
|
||||
var metaObj, isTemplate;
|
||||
nThen(function (waitFor) {
|
||||
@@ -290,12 +290,12 @@ define([
|
||||
type: cfg.type || parsed.type
|
||||
};
|
||||
var additionalPriv = {
|
||||
app: parsed.type,
|
||||
accountName: Utils.LocalStore.getAccountName(),
|
||||
origin: window.location.origin,
|
||||
pathname: window.location.pathname,
|
||||
fileHost: ApiConfig.fileHost,
|
||||
readOnly: readOnly,
|
||||
availableHashes: hashes,
|
||||
isTemplate: isTemplate,
|
||||
feedbackAllowed: Utils.Feedback.state,
|
||||
isPresent: parsed.hashData && parsed.hashData.present,
|
||||
@@ -326,6 +326,10 @@ define([
|
||||
additionalPriv.registeredOnly = true;
|
||||
}
|
||||
|
||||
if (['debug', 'profile'].indexOf(parsed.type) !== -1) {
|
||||
additionalPriv.hashes = hashes;
|
||||
}
|
||||
|
||||
for (var k in additionalPriv) { metaObj.priv[k] = additionalPriv[k]; }
|
||||
|
||||
if (cfg.addData) {
|
||||
@@ -380,6 +384,19 @@ define([
|
||||
});
|
||||
});
|
||||
|
||||
sframeChan.on('Q_GET_ATTRIBUTE', function (data, cb) {
|
||||
Cryptpad.getAttribute(data.key, function (e, data) {
|
||||
cb({
|
||||
error: e,
|
||||
data: data
|
||||
});
|
||||
});
|
||||
});
|
||||
sframeChan.on('Q_SET_ATTRIBUTE', function (data, cb) {
|
||||
Cryptpad.setAttribute(data.key, data.value, function (e) {
|
||||
cb({error:e});
|
||||
});
|
||||
});
|
||||
};
|
||||
addCommonRpc(sframeChan);
|
||||
|
||||
@@ -589,20 +606,6 @@ define([
|
||||
}, href);
|
||||
});
|
||||
|
||||
sframeChan.on('Q_GET_ATTRIBUTE', function (data, cb) {
|
||||
Cryptpad.getAttribute(data.key, function (e, data) {
|
||||
cb({
|
||||
error: e,
|
||||
data: data
|
||||
});
|
||||
});
|
||||
});
|
||||
sframeChan.on('Q_SET_ATTRIBUTE', function (data, cb) {
|
||||
Cryptpad.setAttribute(data.key, data.value, function (e) {
|
||||
cb({error:e});
|
||||
});
|
||||
});
|
||||
|
||||
sframeChan.on('Q_DRIVE_GETDELETED', function (data, cb) {
|
||||
Cryptpad.getDeletedPads(data, function (err, obj) {
|
||||
if (err) { return void console.error(err); }
|
||||
@@ -711,6 +714,44 @@ define([
|
||||
initFilePicker(data);
|
||||
});
|
||||
|
||||
// Share modal
|
||||
var ShareModal = {};
|
||||
var initShareModal = function (cfg) {
|
||||
cfg.hashes = hashes;
|
||||
cfg.password = password;
|
||||
// cfg.hidden means pre-loading the filepicker while keeping it hidden.
|
||||
// if cfg.hidden is true and the iframe already exists, do nothing
|
||||
if (!ShareModal.$iframe) {
|
||||
var config = {};
|
||||
config.onShareAction = function (data) {
|
||||
sframeChan.event('EV_SHARE_ACTION', data);
|
||||
};
|
||||
config.onClose = function () {
|
||||
ShareModal.$iframe.hide();
|
||||
};
|
||||
config.data = cfg;
|
||||
config.addCommonRpc = addCommonRpc;
|
||||
config.modules = {
|
||||
Cryptpad: Cryptpad,
|
||||
SFrameChannel: SFrameChannel,
|
||||
Utils: Utils
|
||||
};
|
||||
ShareModal.$iframe = $('<iframe>', {id: 'sbox-share-iframe'}).appendTo($('body'));
|
||||
ShareModal.modal = Share.create(config);
|
||||
} else if (!cfg.hidden) {
|
||||
ShareModal.$iframe.show();
|
||||
ShareModal.modal.refresh(cfg);
|
||||
}
|
||||
if (cfg.hidden) {
|
||||
ShareModal.$iframe.hide();
|
||||
return;
|
||||
}
|
||||
ShareModal.$iframe.focus();
|
||||
};
|
||||
sframeChan.on('EV_SHARE_OPEN', function (data) {
|
||||
initShareModal(data || {});
|
||||
});
|
||||
|
||||
sframeChan.on('Q_TEMPLATE_USE', function (data, cb) {
|
||||
Cryptpad.useTemplate(data, Cryptget, cb);
|
||||
});
|
||||
|
||||
@@ -121,13 +121,9 @@ define([
|
||||
return '<script src="' + origin + '/common/media-tag-nacl.min.js"></script>';
|
||||
};
|
||||
funcs.getMediatagFromHref = function (obj) {
|
||||
if (!obj || !obj.hash) { return; }
|
||||
var data = ctx.metadataMgr.getPrivateData();
|
||||
var secret;
|
||||
if (obj) {
|
||||
secret = Hash.getSecrets('file', obj.hash, obj.password);
|
||||
} else {
|
||||
secret = Hash.getSecrets('file', data.availableHashes.fileHash, data.password);
|
||||
}
|
||||
var secret = Hash.getSecrets('file', obj.hash, obj.password);
|
||||
if (secret.keys && secret.channel) {
|
||||
var key = Hash.encodeBase64(secret.keys && secret.keys.cryptKey);
|
||||
var hexFileName = secret.channel;
|
||||
@@ -391,12 +387,6 @@ define([
|
||||
}
|
||||
};
|
||||
|
||||
funcs.isStrongestStored = function () {
|
||||
var data = ctx.metadataMgr.getPrivateData();
|
||||
if (data.availableHashes.fileHash) { return true; }
|
||||
return !data.readOnly || !data.availableHashes.editHash;
|
||||
};
|
||||
|
||||
funcs.setDisplayName = function (name, cb) {
|
||||
cb = cb || $.noop;
|
||||
ctx.sframeChan.query('Q_SETTINGS_SET_DISPLAY_NAME', name, cb);
|
||||
|
||||
@@ -523,23 +523,16 @@ MessengerUI, Messages) {
|
||||
if (!config.metadataMgr) {
|
||||
throw new Error("You must provide a `metadataMgr` to display the userlist");
|
||||
}
|
||||
var metadataMgr = config.metadataMgr;
|
||||
var origin = config.metadataMgr.getPrivateData().origin;
|
||||
var pathname = config.metadataMgr.getPrivateData().pathname;
|
||||
var hashes = metadataMgr.getPrivateData().availableHashes;
|
||||
|
||||
var $shareBlock = $('<button>', {
|
||||
'class': 'fa fa-shhare-alt cp-toolbar-share-button',
|
||||
title: Messages.shareButton
|
||||
});
|
||||
var modal = UIElements.createShareModal({
|
||||
origin: origin,
|
||||
pathname: pathname,
|
||||
hashes: hashes,
|
||||
common: Common
|
||||
Common.getSframeChannel().event('EV_SHARE_OPEN', {
|
||||
hidden: true
|
||||
});
|
||||
$shareBlock.click(function () {
|
||||
UI.openCustomModal(UI.dialog.tabs(modal));
|
||||
Common.getSframeChannel().event('EV_SHARE_OPEN', {});
|
||||
});
|
||||
|
||||
toolbar.$leftside.append($shareBlock);
|
||||
@@ -552,23 +545,19 @@ MessengerUI, Messages) {
|
||||
if (!config.metadataMgr) {
|
||||
throw new Error("You must provide a `metadataMgr` to display the userlist");
|
||||
}
|
||||
var metadataMgr = config.metadataMgr;
|
||||
var origin = config.metadataMgr.getPrivateData().origin;
|
||||
var pathname = config.metadataMgr.getPrivateData().pathname;
|
||||
var hashes = metadataMgr.getPrivateData().availableHashes;
|
||||
|
||||
var $shareBlock = $('<button>', {
|
||||
'class': 'fa fa-shhare-alt cp-toolbar-share-button',
|
||||
title: Messages.shareButton
|
||||
});
|
||||
var modal = UIElements.createFileShareModal({
|
||||
origin: origin,
|
||||
pathname: pathname,
|
||||
hashes: hashes,
|
||||
common: Common
|
||||
Common.getSframeChannel().event('EV_SHARE_OPEN', {
|
||||
hidden: true,
|
||||
file: true
|
||||
});
|
||||
$shareBlock.click(function () {
|
||||
UI.openCustomModal(UI.dialog.tabs(modal));
|
||||
Common.getSframeChannel().event('EV_SHARE_OPEN', {
|
||||
file: true
|
||||
});
|
||||
});
|
||||
|
||||
toolbar.$leftside.append($shareBlock);
|
||||
|
||||
Reference in New Issue
Block a user