Pad: Plumb author ID through mutation operations

This commit is contained in:
Richard Hansen 2022-02-17 00:01:07 -05:00
parent 5f60b3aab2
commit 3b8549342a
7 changed files with 35 additions and 30 deletions

View file

@ -74,7 +74,7 @@ const tmpDirectory = os.tmpdir();
/**
* do a requested import
*/
const doImport = async (req, res, padId) => {
const doImport = async (req, res, padId, authorId) => {
// pipe to a file
// convert file to html via abiword or soffice
// set html in the pad
@ -140,7 +140,7 @@ const doImport = async (req, res, padId) => {
let directDatabaseAccess = false;
if (fileIsEtherpad) {
// Use '\n' to avoid the default pad text if the pad doesn't yet exist.
const pad = await padManager.getPad(padId, '\n');
const pad = await padManager.getPad(padId, '\n', authorId);
const headCount = pad.head;
if (headCount >= 10) {
logger.warn('Aborting direct database import attempt of a pad that already has content');
@ -148,7 +148,7 @@ const doImport = async (req, res, padId) => {
}
const text = await fs.readFile(srcFile, 'utf8');
directDatabaseAccess = true;
await importEtherpad.setPadRaw(padId, text);
await importEtherpad.setPadRaw(padId, text, authorId);
}
// convert file to html if necessary
@ -205,12 +205,12 @@ const doImport = async (req, res, padId) => {
if (!directDatabaseAccess) {
if (importHandledByPlugin || useConverter || fileIsHTML) {
try {
await importHtml.setPadHTML(pad, text);
await importHtml.setPadHTML(pad, text, authorId);
} catch (err) {
logger.warn(`Error importing, possibly caused by malformed HTML: ${err.stack || err}`);
}
} else {
await pad.setText(text);
await pad.setText(text, authorId);
}
}
@ -233,13 +233,13 @@ const doImport = async (req, res, padId) => {
return false;
};
exports.doImport = async (req, res, padId) => {
exports.doImport = async (req, res, padId, authorId = '') => {
let httpStatus = 200;
let code = 0;
let message = 'ok';
let directDatabaseAccess;
try {
directDatabaseAccess = await doImport(req, res, padId);
directDatabaseAccess = await doImport(req, res, padId, authorId);
} catch (err) {
const known = err instanceof ImportError && err.status;
if (!known) logger.error(`Internal error during import: ${err.stack || err}`);