Merge branch 'staging' of github.com:xwiki-labs/cryptpad into staging
This commit is contained in:
@@ -1621,7 +1621,19 @@ define([
|
||||
if (!data) {
|
||||
return void UI.alert(Messages.autostore_notAvailable);
|
||||
}
|
||||
sframeChan.event('EV_PROPERTIES_OPEN');
|
||||
var metadataMgr = common.getMetadataMgr();
|
||||
sframeChan.query('Q_PROPERTIES_OPEN', {
|
||||
metadata: metadataMgr.getMetadata()
|
||||
}, function (err, data) {
|
||||
if (!data || !data.cmd) { return; }
|
||||
if (data.cmd === "UPDATE_METADATA") {
|
||||
if (!data.key) { return; }
|
||||
var md = Util.clone(metadataMgr.getMetadata());
|
||||
md[data.key] = data.value;
|
||||
if (!data.value) { delete md[data.key]; }
|
||||
metadataMgr.updateMetadata(md);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
break;
|
||||
|
||||
@@ -284,10 +284,12 @@ define([
|
||||
'data-crypto-key': key
|
||||
});
|
||||
$inner.append(tag);
|
||||
MediaTag(tag).on('error', function () {
|
||||
locked = false;
|
||||
$spinner.hide();
|
||||
UI.log(Messages.error);
|
||||
setTimeout(function () {
|
||||
MediaTag(tag).on('error', function () {
|
||||
locked = false;
|
||||
$spinner.hide();
|
||||
UI.log(Messages.error);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -50,6 +50,56 @@ define([
|
||||
// File and history size...
|
||||
var owned = Modal.isOwned(Env, data);
|
||||
|
||||
var metadataMgr = common.getMetadataMgr();
|
||||
var priv = metadataMgr.getPrivateData();
|
||||
if (owned && priv.app === 'code') {
|
||||
(function () {
|
||||
var sframeChan = common.getSframeChannel();
|
||||
var md = (opts.data && opts.data.metadata) || {};
|
||||
var div = h('div');
|
||||
var hint = h('div.cp-app-prop-hint', Messages.cba_hint);
|
||||
var $div = $(div);
|
||||
var setButton = function (state) {
|
||||
var button = h('button.btn');
|
||||
var $button = $(button);
|
||||
$div.html('').append($button);
|
||||
if (state) {
|
||||
// Add "enable" button
|
||||
$button.addClass('btn-secondary').text(Messages.cba_enable);
|
||||
UI.confirmButton(button, {
|
||||
classes: 'btn-primary'
|
||||
}, function () {
|
||||
$button.remove();
|
||||
sframeChan.event("EV_SECURE_ACTION", {
|
||||
cmd: 'UPDATE_METADATA',
|
||||
key: 'enableColors',
|
||||
value: true
|
||||
});
|
||||
common.setAttribute(['code', 'enableColors'], true);
|
||||
setButton(false);
|
||||
});
|
||||
return;
|
||||
}
|
||||
// Add "disable" button
|
||||
$button.addClass('btn-danger-alt').text(Messages.cba_disable);
|
||||
UI.confirmButton(button, {
|
||||
classes: 'btn-danger'
|
||||
}, function () {
|
||||
$button.remove();
|
||||
sframeChan.event("EV_SECURE_ACTION", {
|
||||
cmd: 'UPDATE_METADATA',
|
||||
key: 'enableColors',
|
||||
value: false
|
||||
});
|
||||
common.setAttribute(['code', 'enableColors'], false);
|
||||
setButton(true);
|
||||
});
|
||||
};
|
||||
setButton(!md.enableColors);
|
||||
$d.append(h('div.cp-app-prop', [Messages.cba_properties, hint, div]));
|
||||
})();
|
||||
}
|
||||
|
||||
// check the size of this file, including additional channels
|
||||
var bytes = 0;
|
||||
var historyBytes;
|
||||
|
||||
@@ -48,7 +48,6 @@ define(['json.sortify'], function (Sortify) {
|
||||
//title: meta.doc.defaultTitle,
|
||||
type: meta.doc.type,
|
||||
users: {},
|
||||
authors: {}
|
||||
};
|
||||
metadataLazyObj = JSON.parse(JSON.stringify(metadataObj));
|
||||
}
|
||||
@@ -69,6 +68,10 @@ define(['json.sortify'], function (Sortify) {
|
||||
}
|
||||
metadataObj.users = mdo;
|
||||
|
||||
// Clean old data
|
||||
delete metadataObj.authors;
|
||||
delete metadataLazyObj.authors;
|
||||
|
||||
// Always update the userlist in the lazy object, otherwise it may be outdated
|
||||
// and metadataMgr.updateMetadata() won't do anything, and so we won't push events
|
||||
// to the userlist UI ==> phantom viewers
|
||||
@@ -96,27 +99,6 @@ define(['json.sortify'], function (Sortify) {
|
||||
checkUpdate(lazy);
|
||||
});
|
||||
};
|
||||
var addAuthor = function () {
|
||||
if (!meta.user || !meta.user.netfluxId || !priv || !priv.edPublic) { return; }
|
||||
var authors = metadataObj.authors || {};
|
||||
var old = Sortify(authors);
|
||||
if (!authors[priv.edPublic]) {
|
||||
authors[priv.edPublic] = {
|
||||
nId: [meta.user.netfluxId],
|
||||
name: meta.user.name
|
||||
};
|
||||
} else {
|
||||
authors[priv.edPublic].name = meta.user.name;
|
||||
if (authors[priv.edPublic].nId.indexOf(meta.user.netfluxId) === -1) {
|
||||
authors[priv.edPublic].nId.push(meta.user.netfluxId);
|
||||
}
|
||||
}
|
||||
if (Sortify(authors) !== old) {
|
||||
metadataObj.authors = authors;
|
||||
metadataLazyObj.authors = JSON.parse(JSON.stringify(authors));
|
||||
change();
|
||||
}
|
||||
};
|
||||
|
||||
var netfluxId;
|
||||
var isReady = false;
|
||||
@@ -225,7 +207,6 @@ define(['json.sortify'], function (Sortify) {
|
||||
if (isReady) { return void f(); }
|
||||
readyHandlers.push(f);
|
||||
},
|
||||
addAuthor: addAuthor,
|
||||
});
|
||||
};
|
||||
return Object.freeze({ create: create });
|
||||
|
||||
@@ -1890,7 +1890,15 @@ define([
|
||||
if (msg) {
|
||||
msg = msg.replace(/cp\|(([A-Za-z0-9+\/=]+)\|)?/, '');
|
||||
//var decryptedMsg = crypto.decrypt(msg, true);
|
||||
msgs.push(msg);
|
||||
if (data.debug) {
|
||||
msgs.push({
|
||||
msg: msg,
|
||||
author: parsed[1][1],
|
||||
time: parsed[1][5]
|
||||
});
|
||||
} else {
|
||||
msgs.push(msg);
|
||||
}
|
||||
}
|
||||
};
|
||||
network.on('message', onMsg);
|
||||
|
||||
@@ -290,7 +290,7 @@ define([
|
||||
}
|
||||
|
||||
if (padChange && hasChanged(content)) {
|
||||
cpNfInner.metadataMgr.addAuthor();
|
||||
//cpNfInner.metadataMgr.addAuthor();
|
||||
}
|
||||
oldContent = content;
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ define([
|
||||
], function ($, Modes, Themes, Messages, UIElements, MT, Hash, Util, TextCursor, ChainPad) {
|
||||
var module = {};
|
||||
|
||||
var cursorToPos = function(cursor, oldText) {
|
||||
var cursorToPos = module.cursorToPos = function(cursor, oldText) {
|
||||
var cLine = cursor.line;
|
||||
var cCh = cursor.ch;
|
||||
var pos = 0;
|
||||
@@ -28,7 +28,7 @@ define([
|
||||
return pos;
|
||||
};
|
||||
|
||||
var posToCursor = function(position, newText) {
|
||||
var posToCursor = module.posToCursor = function(position, newText) {
|
||||
var cursor = {
|
||||
line: 0,
|
||||
ch: 0
|
||||
@@ -415,8 +415,7 @@ define([
|
||||
|
||||
/////
|
||||
|
||||
var canonicalize = function (t) { return t.replace(/\r\n/g, '\n'); };
|
||||
|
||||
var canonicalize = exp.canonicalize = function (t) { return t.replace(/\r\n/g, '\n'); };
|
||||
|
||||
|
||||
exp.contentUpdate = function (newContent) {
|
||||
@@ -424,6 +423,7 @@ define([
|
||||
var remoteDoc = newContent.content;
|
||||
// setValueAndCursor triggers onLocal, even if we don't make any change to the content
|
||||
// and it may revert other changes (metadata)
|
||||
|
||||
if (oldDoc === remoteDoc) { return; }
|
||||
exp.setValueAndCursor(oldDoc, remoteDoc);
|
||||
};
|
||||
|
||||
@@ -71,7 +71,10 @@ define([
|
||||
lastKnownHash = data.lastKnownHash;
|
||||
isComplete = data.isFull;
|
||||
var messages = (data.messages || []).map(function (obj) {
|
||||
return obj.msg;
|
||||
if (!config.debug) {
|
||||
return obj.msg;
|
||||
}
|
||||
return obj;
|
||||
});
|
||||
if (config.debug) { console.log(data.messages); }
|
||||
Array.prototype.unshift.apply(allMessages, messages); // Destructive concat
|
||||
|
||||
@@ -838,17 +838,26 @@ define([
|
||||
sframeChan.on('Q_GET_FULL_HISTORY', function (data, cb) {
|
||||
var crypto = Crypto.createEncryptor(secret.keys);
|
||||
Cryptpad.getFullHistory({
|
||||
debug: data && data.debug,
|
||||
channel: secret.channel,
|
||||
validateKey: secret.keys.validateKey
|
||||
}, function (encryptedMsgs) {
|
||||
var nt = nThen;
|
||||
var decryptedMsgs = [];
|
||||
var total = encryptedMsgs.length;
|
||||
encryptedMsgs.forEach(function (msg, i) {
|
||||
encryptedMsgs.forEach(function (_msg, i) {
|
||||
nt = nt(function (waitFor) {
|
||||
// The 3rd parameter "true" means we're going to skip signature validation.
|
||||
// We don't need it since the message is already validated serverside by hk
|
||||
decryptedMsgs.push(crypto.decrypt(msg, true, true));
|
||||
if (typeof(_msg) === "object") {
|
||||
decryptedMsgs.push({
|
||||
author: _msg.author,
|
||||
time: _msg.time,
|
||||
msg: crypto.decrypt(_msg.msg, true, true)
|
||||
});
|
||||
} else {
|
||||
decryptedMsgs.push(crypto.decrypt(_msg, true, true));
|
||||
}
|
||||
setTimeout(waitFor(function () {
|
||||
sframeChan.event('EV_FULL_HISTORY_STATUS', (i+1)/total);
|
||||
}));
|
||||
@@ -992,12 +1001,12 @@ define([
|
||||
config.onAction = function (data) {
|
||||
if (typeof(SecureModal.cb) !== "function") { return; }
|
||||
SecureModal.cb(data);
|
||||
SecureModal.$iframe.hide();
|
||||
};
|
||||
config.onClose = function () {
|
||||
SecureModal.$iframe.hide();
|
||||
};
|
||||
config.data = {
|
||||
app: parsed.type,
|
||||
hashes: hashes,
|
||||
password: password,
|
||||
isTemplate: isTemplate
|
||||
@@ -1010,12 +1019,12 @@ define([
|
||||
};
|
||||
SecureModal.$iframe = $('<iframe>', {id: 'sbox-secure-iframe'}).appendTo($('body'));
|
||||
SecureModal.modal = SecureIframe.create(config);
|
||||
} else if (!cfg.hidden) {
|
||||
}
|
||||
if (!cfg.hidden) {
|
||||
SecureModal.modal.refresh(cfg, function () {
|
||||
SecureModal.$iframe.show();
|
||||
});
|
||||
}
|
||||
if (cfg.hidden) {
|
||||
} else {
|
||||
SecureModal.$iframe.hide();
|
||||
return;
|
||||
}
|
||||
@@ -1026,8 +1035,8 @@ define([
|
||||
initSecureModal('filepicker', data || {}, cb);
|
||||
});
|
||||
|
||||
sframeChan.on('EV_PROPERTIES_OPEN', function (data) {
|
||||
initSecureModal('properties', data || {}, null);
|
||||
sframeChan.on('Q_PROPERTIES_OPEN', function (data, cb) {
|
||||
initSecureModal('properties', data || {}, cb);
|
||||
});
|
||||
|
||||
sframeChan.on('EV_ACCESS_OPEN', function (data) {
|
||||
|
||||
Reference in New Issue
Block a user