Skip to content

Commit

Permalink
Do not allow OnlyOffice comments in view mode
Browse files Browse the repository at this point in the history
  • Loading branch information
wginolas committed Mar 4, 2024
1 parent 5b4d1fd commit dd0c559
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 102 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ module.exports = {

// TODO remove these exceptions from the eslint defaults
'no-irregular-whitespace': ['off'],
'no-unused-vars': ['off'],
'no-unused-vars': ['warn'],
'no-self-assign': ['off'],
'no-empty': ['off'],
'no-useless-escape': ['off'],
Expand Down
195 changes: 94 additions & 101 deletions www/common/onlyoffice/inner.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ define([
// This structure is used for caching media data and blob urls for each media cryptpad url
var mediasData = {};

var startOO = function () {};
let startOO = function () {};

var supportsXLSX = function () {
return privateData.supportsWasm;
Expand Down Expand Up @@ -681,51 +681,51 @@ define([
}
return new Blob([newText], {type: 'text/plain'});
};
var loadLastDocument = function (lastCp, onCpError, cb) {
if (!lastCp || !lastCp.file) {
return void onCpError('EEMPTY');
}
ooChannel.cpIndex = lastCp.index || 0;
ooChannel.lastHash = lastCp.hash;
var parsed = Hash.parsePadUrl(lastCp.file);
var secret = Hash.getSecrets('file', parsed.hash);
if (!secret || !secret.channel) { return; }
var hexFileName = secret.channel;
var fileHost = privateData.fileHost || privateData.origin;
var src = fileHost + Hash.getBlobPathFromHex(hexFileName);
var key = secret.keys && secret.keys.cryptKey;
var xhr = new XMLHttpRequest();
xhr.open('GET', src, true);
if (window.sendCredentials) { xhr.withCredentials = true; }
xhr.responseType = 'arraybuffer';
xhr.onload = function () {
if (/^4/.test('' + this.status)) {
onCpError(this.status);
return void console.error('XHR error', this.status);

const loadLastDocument = function (lastCp) {
return new Promise((resolve, reject) => {
if (!lastCp || !lastCp.file) {
return void reject('EEMPTY');
}
var arrayBuffer = xhr.response;
if (arrayBuffer) {
var u8 = new Uint8Array(arrayBuffer);
FileCrypto.decrypt(u8, key, function (err, decrypted) {
if (err) {
if (err === "DECRYPTION_ERROR") {
console.warn(err);
return void onCpError(err);
ooChannel.cpIndex = lastCp.index || 0;
ooChannel.lastHash = lastCp.hash;
var parsed = Hash.parsePadUrl(lastCp.file);
var secret = Hash.getSecrets('file', parsed.hash);
if (!secret || !secret.channel) { return; }
var hexFileName = secret.channel;
var fileHost = privateData.fileHost || privateData.origin;
var src = fileHost + Hash.getBlobPathFromHex(hexFileName);
var key = secret.keys && secret.keys.cryptKey;
var xhr = new XMLHttpRequest();
xhr.open('GET', src, true);
if (window.sendCredentials) { xhr.withCredentials = true; }
xhr.responseType = 'arraybuffer';
xhr.onload = function () {
if (/^4/.test('' + this.status)) {
reject(this.status);
return void console.error('XHR error', this.status);
}
var arrayBuffer = xhr.response;
if (arrayBuffer) {
var u8 = new Uint8Array(arrayBuffer);
FileCrypto.decrypt(u8, key, function (err, decrypted) {
if (err) {
if (err === "DECRYPTION_ERROR") {
console.warn(err);
return void reject(err);
}
return void console.error(err);
}
return void console.error(err);
}
var blob = new Blob([decrypted.content], {type: 'plain/text'});
if (cb) {
return cb(blob, getFileType());
}
startOO(blob, getFileType());
});
}
};
xhr.onerror = function (err) {
onCpError(err);
};
xhr.send(null);
var blob = new Blob([decrypted.content], {type: 'plain/text'});
resolve({blob, fileType: getFileType()});
});
}
};
xhr.onerror = function (err) {
reject(err);
};
xhr.send(null);
});
};

/*
Expand Down Expand Up @@ -825,26 +825,28 @@ define([

if (!exists) { return void UI.removeLoadingScreen(); }

loadLastDocument(cp, function () {
if (cp.hash && vHashEl) {
// We requested a checkpoint but we can't find it...
loadLastDocument(cp)
.then(({blob, fileType}) => {
ooChannel.queue = messages;
resetData(blob, fileType);
UI.removeLoadingScreen();
vHashEl.innerText = Messages.oo_deletedVersion;
$(vHashEl).removeClass('alert-warning').addClass('alert-danger');
return;
}
var file = getFileType();
var type = common.getMetadataMgr().getPrivateData().ooType;
if (APP.downloadType) { type = APP.downloadType; }
var blob = loadInitDocument(type, true);
ooChannel.queue = messages;
resetData(blob, file);
UI.removeLoadingScreen();
}, function (blob, file) {
ooChannel.queue = messages;
resetData(blob, file);
UI.removeLoadingScreen();
});
})
.catch(() => {
if (cp.hash && vHashEl) {
// We requested a checkpoint but we can't find it...
UI.removeLoadingScreen();
vHashEl.innerText = Messages.oo_deletedVersion;
$(vHashEl).removeClass('alert-warning').addClass('alert-danger');
return;
}
var file = getFileType();
var type = common.getMetadataMgr().getPrivateData().ooType;
if (APP.downloadType) { type = APP.downloadType; }
var blob = loadInitDocument(type, true);
ooChannel.queue = messages;
resetData(blob, file);
UI.removeLoadingScreen();
});
});
};

Expand Down Expand Up @@ -1675,7 +1677,8 @@ define([
chat: false,
logo: {
url: "/bounce/#" + encodeURIComponent('https://www.onlyoffice.com')
}
},
comments: !lock && !readOnly
},
"user": {
"id": String(myOOId), //"c0c3bf82-20d7-4663-bf6d-7fa39c598b1d",
Expand Down Expand Up @@ -1998,14 +2001,13 @@ define([
APP.themeRemote = true;
*/
};
APP.changeTheme = function (id) {
APP.changeTheme = function (/*id*/) {
/*
// disabled:
Uncaught TypeError: Cannot read property 'calculatedType' of null
at CPresentation.changeTheme (sdk-all.js?ver=4.11.0-1633612942653-1633619288217:15927)
*/

id = id;
/*
APP.themeChanged = {
id: id
Expand Down Expand Up @@ -2359,25 +2361,15 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null
// If the last checkpoint is empty, load the "initial" doc instead
if (!lastCp || !lastCp.file) { return void loadDocument(true, useNewDefault); }
// Load latest checkpoint
return void loadLastDocument(lastCp, function () {
// Checkpoint error: load the previous one
i = i || 0;
loadDocument(noCp, useNewDefault, ++i);
});
}
var newText;
switch (type) {
case 'sheet' :
newText = EmptyCell(useNewDefault);
break;
case 'doc':
newText = EmptyDoc();
break;
case 'presentation':
newText = EmptySlide();
break;
default:
newText = '';
loadLastDocument(lastCp)
.then(({blob, fileType}) => {
startOO(blob, fileType);
})
.catch(() => {
// Checkpoint error: load the previous one
i = i || 0;
loadDocument(noCp, useNewDefault, ++i);
});
}
var blob = loadInitDocument(type, useNewDefault);
startOO(blob, file);
Expand Down Expand Up @@ -2427,7 +2419,6 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null
}
};

var wasEditing = false;
var setStrictEditing = function () {
if (APP.isFast) { return; }
var editor = getEditor();
Expand All @@ -2437,12 +2428,10 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null
} else {
evOnSync.fire();
}
wasEditing = Boolean(editing);
};
APP.onFastChange = function (isFast) {
APP.isFast = isFast;
if (isFast) {
wasEditing = false;
if (APP.hasChangedInterval) {
window.clearInterval(APP.hasChangedInterval);
}
Expand All @@ -2464,20 +2453,21 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null
pinImages();
};

var loadCp = function (cp, keepQueue) {
const loadCp = async function (cp, keepQueue) {
if (!isLockedModal.modal) {
isLockedModal.modal = UI.openCustomModal(isLockedModal.content);
}
loadLastDocument(cp, function () {
try {
const {blob, fileType} = await loadLastDocument(cp);
if (!keepQueue) { ooChannel.queue = []; }
resetData(blob, fileType);
} catch (e) {
var file = getFileType();
var type = common.getMetadataMgr().getPrivateData().ooType;
var blob = loadInitDocument(type, true);
if (!keepQueue) { ooChannel.queue = []; }
resetData(blob, file);
}, function (blob, file) {
if (!keepQueue) { ooChannel.queue = []; }
resetData(blob, file);
});
}
};

var loadTemplate = function (href, pw, parsed) {
Expand Down Expand Up @@ -2678,6 +2668,7 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null
};
var onCheckpoint = function (cp) {
// We want to load a checkpoint:
console.log('XXX onCheckpoint', JSON.stringify(cp));
loadCp(cp);
};
var setHistoryMode = function (bool) {
Expand Down Expand Up @@ -3213,13 +3204,15 @@ Uncaught TypeError: Cannot read property 'calculatedType' of null
isLockedModal.modal = UI.openCustomModal(isLockedModal.content);
}
var lastCp = getLastCp();
loadLastDocument(lastCp, function (err) {
console.error(err);
// On error, do nothing
// FIXME lock the document or ask for a page reload?
}, function (blob, type) {
resetData(blob, type);
});
loadLastDocument(lastCp)
.then(({blob, fileType}) => {
resetData(blob, fileType);
})
.catch((err) => {
console.error(err);
// On error, do nothing
// FIXME lock the document or ask for a page reload?
});
};

config.onRemote = function () {
Expand Down

0 comments on commit dd0c559

Please sign in to comment.