mirror of
https://github.com/cryptpad/cryptpad.git
synced 2026-09-12 19:49:59 +05:00
Change to secure iframe for displaying keys in the UI
This commit is contained in:
parent
9117da0e9a
commit
0e60e29877
@ -2231,13 +2231,14 @@ define([
|
||||
});
|
||||
});
|
||||
});
|
||||
sframeChan.on('Q_GET_EDIT_URL', function (data, cb) {
|
||||
if (!hashes.editHash) { return void cb(); }
|
||||
cb(window.location.origin + Utils.Hash.hashToHref(hashes.editHash, 'form'));
|
||||
});
|
||||
sframeChan.on('Q_GET_VIEW_URL', function (data, cb) {
|
||||
if (!hashes.viewHash) { return void cb(); }
|
||||
cb(window.location.origin + Utils.Hash.hashToHref(hashes.viewHash, 'form'));
|
||||
sframeChan.on('EV_FORM_GUEST_SHARE_OPEN', function (data) {
|
||||
initSecureModal('formGuestShare', data || {}, function (action) {
|
||||
if (action && action.action === 'openView') {
|
||||
var url = Utils.Hash.hashToHref(hashes.viewHash, 'form');
|
||||
var a = window.open(url);
|
||||
if (!a) { sframeChan.event('EV_POPUP_BLOCKED'); }
|
||||
}
|
||||
});
|
||||
});
|
||||
sframeChan.on('EV_OPEN_VIEW_URL', function () {
|
||||
var url = Utils.Hash.hashToHref(hashes.viewHash, 'form');
|
||||
|
||||
@ -1553,12 +1553,3 @@
|
||||
.charts_main();
|
||||
}
|
||||
|
||||
.alertify .cp-form-guest-share-modal {
|
||||
h4, h5, h6, p {
|
||||
color: @cryptpad_text_col;
|
||||
}
|
||||
textarea {
|
||||
color: @cryptpad_text_col;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -17,7 +17,6 @@ define([
|
||||
'/common/common-hash.js',
|
||||
'/common/common-interface.js',
|
||||
'/common/common-ui-elements.js',
|
||||
'/common/clipboard.js',
|
||||
'/common/inner/common-mediatag.js',
|
||||
'/common/hyperscript.js',
|
||||
'/customize/messages.js',
|
||||
@ -66,7 +65,6 @@ define([
|
||||
Hash,
|
||||
UI,
|
||||
UIElements,
|
||||
Clipboard,
|
||||
MT,
|
||||
h,
|
||||
Messages,
|
||||
@ -4913,106 +4911,21 @@ define([
|
||||
if (!APP.isEditor) { return false; }
|
||||
return true;
|
||||
};
|
||||
var showGuestPublicLinkModal = function () {
|
||||
sframeChan.query('Q_GET_VIEW_URL', null, function (urlErr, viewUrl) {
|
||||
if (urlErr || !viewUrl) { return; }
|
||||
var linkInput = UI.dialog.selectableArea(viewUrl, {
|
||||
id: 'cp-form-guest-public-link',
|
||||
rows: 2,
|
||||
'aria-label': Messages.form_guestPublicTitle
|
||||
});
|
||||
var content = h('div.cp-form-guest-share-modal', [
|
||||
h('h4', Messages.form_guestPublicTitle),
|
||||
h('p', Messages.form_guestPublicBody),
|
||||
linkInput
|
||||
]);
|
||||
var frame;
|
||||
var modal = UI.dialog.customModal(content, {
|
||||
buttons: [{
|
||||
className: 'cancel',
|
||||
name: Messages.cancel,
|
||||
onClick: function () {},
|
||||
keys: [27]
|
||||
}, {
|
||||
className: 'primary',
|
||||
name: Messages.form_geturl,
|
||||
iconClass: 'copy',
|
||||
onClick: function () {
|
||||
Clipboard.copy(viewUrl, function (copyErr) {
|
||||
if (!copyErr) {
|
||||
UI.log(Messages.shareSuccess);
|
||||
frame.closeModal();
|
||||
} else {
|
||||
UI.warn(Messages.error);
|
||||
}
|
||||
});
|
||||
return true;
|
||||
},
|
||||
keys: [13]
|
||||
}]
|
||||
});
|
||||
frame = UI.openCustomModal(modal);
|
||||
});
|
||||
};
|
||||
var warnGuestAuthorThen = function (then, opt) {
|
||||
opt = opt || {};
|
||||
if (!shouldWarnGuestAuthor()) { return void then(); }
|
||||
|
||||
var warnGuestAuthorThen = function (next) {
|
||||
if (!shouldWarnGuestAuthor()) { return void next(); }
|
||||
framework._.sfCommon.isPadStored(function (err, stored) {
|
||||
sframeChan.query('Q_GET_EDIT_URL', null, function (urlErr, editUrl) {
|
||||
if (urlErr || !editUrl) { return void then(); }
|
||||
|
||||
var bodyMsg = Messages.form_guestAuthorBody;
|
||||
if (stored) {
|
||||
bodyMsg = Messages.form_guestAuthorBodyStored;
|
||||
}
|
||||
var linkInput = UI.dialog.selectableArea(editUrl, {
|
||||
id: 'cp-form-guest-author-link',
|
||||
rows: 2,
|
||||
'aria-label': Messages.form_guestAuthorTitle
|
||||
});
|
||||
var content = h('div.cp-form-guest-share-modal', [
|
||||
h('h4', Messages.form_guestAuthorTitle),
|
||||
h('p', Messages.form_guestEditLinkDefinition),
|
||||
h('p', bodyMsg),
|
||||
linkInput
|
||||
]);
|
||||
var modal = UI.dialog.customModal(content, {
|
||||
buttons: [{
|
||||
className: 'cancel',
|
||||
name: Messages.cancel,
|
||||
onClick: function () {},
|
||||
keys: [27]
|
||||
}, {
|
||||
className: 'secondary',
|
||||
name: Messages.form_guestAuthorCopy,
|
||||
iconClass: 'copy',
|
||||
onClick: function () {
|
||||
Clipboard.copy(editUrl, function (copyErr) {
|
||||
if (!copyErr) { UI.log(Messages.form_guestAuthorCopied); }
|
||||
else { UI.warn(Messages.error); }
|
||||
});
|
||||
return true;
|
||||
},
|
||||
keys: []
|
||||
}, {
|
||||
className: 'primary',
|
||||
name: opt.publicLinkFlow ? Messages.form_guestAuthorContinuePublic : Messages.continue,
|
||||
onClick: function () {
|
||||
then();
|
||||
},
|
||||
keys: [13]
|
||||
}]
|
||||
});
|
||||
UI.openCustomModal(modal);
|
||||
sframeChan.event('EV_FORM_GUEST_SHARE_OPEN', {
|
||||
next: next,
|
||||
stored: Boolean(stored)
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
$(previewBtn).click(function () {
|
||||
warnGuestAuthorThen(function () {
|
||||
sframeChan.event('EV_OPEN_VIEW_URL');
|
||||
});
|
||||
if (!shouldWarnGuestAuthor()) {
|
||||
return void sframeChan.event('EV_OPEN_VIEW_URL');
|
||||
}
|
||||
warnGuestAuthorThen('preview');
|
||||
});
|
||||
$(participantBtn).click(function () {
|
||||
if (!shouldWarnGuestAuthor()) {
|
||||
@ -5022,7 +4935,7 @@ define([
|
||||
});
|
||||
return;
|
||||
}
|
||||
warnGuestAuthorThen(showGuestPublicLinkModal, { publicLinkFlow: true });
|
||||
warnGuestAuthorThen('public');
|
||||
});
|
||||
|
||||
// Private / public status
|
||||
|
||||
@ -106,4 +106,9 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
.alertify .cp-form-guest-share-modal {
|
||||
h4, h5, h6, p, textarea {
|
||||
color: @cryptpad_text_col;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,6 +46,123 @@ define([
|
||||
};
|
||||
|
||||
var create = {};
|
||||
create['formGuestShare'] = function (data) {
|
||||
data = data || {};
|
||||
require(['/common/clipboard.js'], function (Clipboard) {
|
||||
var priv = metadataMgr.getPrivateData();
|
||||
var hashes = priv.hashes || {};
|
||||
var origin = priv.origin || '';
|
||||
var editUrl = hashes.editHash ?
|
||||
(origin + Hash.hashToHref(hashes.editHash, 'form')) : '';
|
||||
var viewUrl = hashes.viewHash ?
|
||||
(origin + Hash.hashToHref(hashes.viewHash, 'form')) : '';
|
||||
|
||||
var showPublic = function () {
|
||||
if (!viewUrl) { return void hideIframe(); }
|
||||
var frame;
|
||||
var modal = UI.dialog.customModal(h('div.cp-form-guest-share-modal', [
|
||||
h('h4', Messages.form_guestPublicTitle),
|
||||
h('p', Messages.form_guestPublicBody),
|
||||
UI.dialog.selectableArea(viewUrl, {
|
||||
id: 'cp-form-guest-public-link',
|
||||
rows: 2
|
||||
})
|
||||
]), {
|
||||
onClose: function () {
|
||||
if (displayed === frame) { hideIframe(); }
|
||||
},
|
||||
buttons: [{
|
||||
className: 'cancel',
|
||||
name: Messages.cancel,
|
||||
onClick: function () {},
|
||||
keys: [27]
|
||||
}, {
|
||||
className: 'primary',
|
||||
name: Messages.form_geturl,
|
||||
iconClass: 'copy',
|
||||
onClick: function () {
|
||||
Clipboard.copy(viewUrl, function (err) {
|
||||
if (err) { return void UI.warn(Messages.error); }
|
||||
UI.log(Messages.shareSuccess);
|
||||
hideIframe();
|
||||
});
|
||||
return true;
|
||||
},
|
||||
keys: [13]
|
||||
}]
|
||||
});
|
||||
frame = UI.openCustomModal(modal);
|
||||
displayed = frame;
|
||||
};
|
||||
|
||||
var showAuthor = function () {
|
||||
if (!editUrl) {
|
||||
if (data.next === 'public') { return void showPublic(); }
|
||||
if (data.next === 'preview') {
|
||||
sframeChan.event('EV_SECURE_ACTION', { action: 'openView' });
|
||||
}
|
||||
return void hideIframe();
|
||||
}
|
||||
var frame;
|
||||
var stay;
|
||||
var modal = UI.dialog.customModal(h('div.cp-form-guest-share-modal', [
|
||||
h('h4', Messages.form_guestAuthorTitle),
|
||||
h('p', Messages.form_guestEditLinkDefinition),
|
||||
h('p', data.stored ?
|
||||
Messages.form_guestAuthorBodyStored : Messages.form_guestAuthorBody),
|
||||
UI.dialog.selectableArea(editUrl, {
|
||||
id: 'cp-form-guest-author-link',
|
||||
rows: 2
|
||||
})
|
||||
]), {
|
||||
onClose: function () {
|
||||
if (stay || displayed !== frame) { return; }
|
||||
hideIframe();
|
||||
},
|
||||
buttons: [{
|
||||
className: 'cancel',
|
||||
name: Messages.cancel,
|
||||
onClick: function () {},
|
||||
keys: [27]
|
||||
}, {
|
||||
className: 'secondary',
|
||||
name: Messages.form_guestAuthorCopy,
|
||||
iconClass: 'copy',
|
||||
onClick: function () {
|
||||
Clipboard.copy(editUrl, function (err) {
|
||||
if (err) { return void UI.warn(Messages.error); }
|
||||
UI.log(Messages.form_guestAuthorCopied);
|
||||
});
|
||||
return true;
|
||||
},
|
||||
keys: []
|
||||
}, {
|
||||
className: 'primary',
|
||||
name: data.next === 'public' ?
|
||||
Messages.form_guestAuthorContinuePublic : Messages.continue,
|
||||
onClick: function () {
|
||||
if (data.next === 'public') {
|
||||
stay = true;
|
||||
if (frame && frame.closeModal) {
|
||||
frame.closeModal(showPublic);
|
||||
} else {
|
||||
showPublic();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (data.next === 'preview') {
|
||||
sframeChan.event('EV_SECURE_ACTION', { action: 'openView' });
|
||||
}
|
||||
},
|
||||
keys: [13]
|
||||
}]
|
||||
});
|
||||
frame = UI.openCustomModal(modal);
|
||||
displayed = frame;
|
||||
};
|
||||
showAuthor();
|
||||
});
|
||||
};
|
||||
|
||||
// Share modal
|
||||
create['share'] = function (data) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user