From ee2b32281c538490583955b51614bbfc3bfebff0 Mon Sep 17 00:00:00 2001 From: John McLear Date: Sun, 21 Feb 2021 11:07:13 +0000 Subject: [PATCH] pluginfw: Warn plugins on missing plugin (#4826) * pluginfw: Warn plugins on missing plugin Add functionality to console.warn when a plugin is missing. This will help admins know when people are trying to use plugins that are missing. Resolves https://github.com/ether/etherpad-lite/issues/4730 * pluginfw: importing .etherpad can notify admins of missing plugins Extending .etherpad imports to notify admins if a missing plugin is present * Update ImportEtherpad.js --- src/node/utils/ImportEtherpad.js | 18 ++++++++++++++++++ src/static/js/contentcollector.js | 4 ++++ 2 files changed, 22 insertions(+) diff --git a/src/node/utils/ImportEtherpad.js b/src/node/utils/ImportEtherpad.js index bc46d10bc..6494da56b 100644 --- a/src/node/utils/ImportEtherpad.js +++ b/src/node/utils/ImportEtherpad.js @@ -22,6 +22,13 @@ const hooks = require('../../static/js/pluginfw/hooks'); exports.setPadRaw = (padId, r) => { const records = JSON.parse(r); + const blockElems = ['div', 'br', 'p', 'pre', 'li', 'author', 'lmkr', 'insertorder']; + + // get supported block Elements from plugins, we will use this later. + hooks.callAll('ccRegisterBlockElements').forEach((element) => { + blockElems.push(element); + }); + Object.keys(records).forEach(async (key) => { let value = records[key]; @@ -53,6 +60,17 @@ exports.setPadRaw = (padId, r) => { } else { // Not author data, probably pad data // we can split it to look to see if it's pad data + + // is this an attribute we support or not? If not, tell the admin + if (value.pool) { + for (const attrib of Object.keys(value.pool.numToAttrib)) { + const attribName = value.pool.numToAttrib[attrib][0]; + if(blockElems.indexOf(attribName) === -1) { + console.warn('Plugin missing: ' + + `You might want to install a plugin to support this node name: ${attribName}`); + } + } + } const oldPadId = key.split(':'); // we know it's pad data diff --git a/src/static/js/contentcollector.js b/src/static/js/contentcollector.js index 7ac27168f..1c601cc54 100644 --- a/src/static/js/contentcollector.js +++ b/src/static/js/contentcollector.js @@ -315,6 +315,10 @@ const makeContentCollector = (collectStyles, abrowser, apool, className2Author) const localAttribs = state.localAttribs; state.localAttribs = null; const isBlock = isBlockElement(node); + if (!isBlock && node.name && (node.name !== 'body') && (node.name !== 'br')) { + console.warn('Plugin missing: ' + + `You might want to install a plugin to support this node name: ${node.name}`); + } const isEmpty = _isEmpty(node, state); if (isBlock) _ensureColumnZero(state); const startLine = lines.length() - 1;