From fc459be5315580c296e0cd8c6d34649b9caea7eb Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Wed, 23 Dec 2020 23:29:07 +0000 Subject: [PATCH] Deprecate editorTheme.palette.editable for externalModules.palette.allowInstall Also deprecates editorTheme.palette.editable for externalModules.palette.allowUpload --- .../@node-red/editor-client/src/js/red.js | 6 +++--- .../editor-client/src/js/settings.js | 11 +++++----- .../editor-client/src/js/ui/palette-editor.js | 10 +++++----- .../src/js/ui/projects/projectSettings.js | 2 +- .../@node-red/registry/lib/installer.js | 20 +++++++++++++++++-- .../@node-red/runtime/lib/api/settings.js | 11 +++++++--- 6 files changed, 40 insertions(+), 20 deletions(-) diff --git a/packages/node_modules/@node-red/editor-client/src/js/red.js b/packages/node_modules/@node-red/editor-client/src/js/red.js index ff8dad5bf..97159e6d2 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/red.js +++ b/packages/node_modules/@node-red/editor-client/src/js/red.js @@ -269,7 +269,7 @@ var RED = (function() { } } ] - // } else if (RED.settings.theme('palette.editable') !== false) { + // } else if (RED.settings.get('externalModules.palette.allowInstall', true) !== false) { } else { options.buttons = [ { @@ -509,7 +509,7 @@ var RED = (function() { ]}); menuOptions.push(null); - if (RED.settings.theme('palette.editable') !== false) { + if (RED.settings.get('externalModules.palette.allowInstall', true) !== false) { menuOptions.push({id:"menu-item-edit-palette",label:RED._("menu.label.editPalette"),onselect:"core:manage-palette"}); menuOptions.push(null); } @@ -544,7 +544,7 @@ var RED = (function() { RED.palette.init(); RED.eventLog.init(); - if (RED.settings.theme('palette.editable') !== false) { + if (RED.settings.get('externalModules.palette.allowInstall', true) !== false) { RED.palette.editor.init(); } else { console.log("Palette editor disabled"); diff --git a/packages/node_modules/@node-red/editor-client/src/js/settings.js b/packages/node_modules/@node-red/editor-client/src/js/settings.js index 760165581..109554418 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/settings.js +++ b/packages/node_modules/@node-red/editor-client/src/js/settings.js @@ -57,12 +57,11 @@ RED.settings = (function () { return JSON.parse(localStorage.getItem(key)); } else { var v; - try { - v = RED.utils.getMessageProperty(userSettings,key); - if (v === undefined) { - v = defaultIfUndefined; - } - } catch(err) { + try { v = RED.utils.getMessageProperty(userSettings,key); } catch(err) {} + if (v === undefined) { + try { v = RED.utils.getMessageProperty(RED.settings,key); } catch(err) {} + } + if (v === undefined) { v = defaultIfUndefined; } return v; diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/palette-editor.js b/packages/node_modules/@node-red/editor-client/src/js/ui/palette-editor.js index b0aeed0fe..147789940 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/palette-editor.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/palette-editor.js @@ -439,7 +439,7 @@ RED.palette.editor = (function() { function init() { - if (RED.settings.theme('palette.editable') === false) { + if (RED.settings.get('externalModules.palette.allowInstall', true) === false) { return; } createSettingsPane(); @@ -880,7 +880,7 @@ RED.palette.editor = (function() { } }); - if (RED.settings.theme('palette.upload') !== false) { + if (RED.settings.get('externalModules.palette.allowUpload', true) !== false) { var uploadSpan = $('').prependTo(toolBar); var uploadButton = $('').appendTo(uploadSpan); @@ -962,7 +962,7 @@ RED.palette.editor = (function() { } function update(entry,version,url,container,done) { - if (RED.settings.theme('palette.editable') === false) { + if (RED.settings.get('externalModules.palette.allowInstall', true) === false) { done(new Error('Palette not editable')); return; } @@ -1021,7 +1021,7 @@ RED.palette.editor = (function() { }) } function remove(entry,container,done) { - if (RED.settings.theme('palette.editable') === false) { + if (RED.settings.get('externalModules.palette.allowInstall', true) === false) { done(new Error('Palette not editable')); return; } @@ -1078,7 +1078,7 @@ RED.palette.editor = (function() { }) } function install(entry,container,done) { - if (RED.settings.theme('palette.editable') === false) { + if (RED.settings.get('externalModules.palette.allowInstall', true) === false) { done(new Error('Palette not editable')); return; } diff --git a/packages/node_modules/@node-red/editor-client/src/js/ui/projects/projectSettings.js b/packages/node_modules/@node-red/editor-client/src/js/ui/projects/projectSettings.js index fdd106e23..c39ac97be 100644 --- a/packages/node_modules/@node-red/editor-client/src/js/ui/projects/projectSettings.js +++ b/packages/node_modules/@node-red/editor-client/src/js/ui/projects/projectSettings.js @@ -465,7 +465,7 @@ RED.projects.settings = (function() { metaRow = $('
').appendTo(headerRow); var buttons = $('
').appendTo(metaRow); if (RED.user.hasPermission("projects.write")) { - if (!entry.installed && RED.settings.theme('palette.editable') !== false) { + if (!entry.installed && RED.settings.get('externalModules.palette.allowInstall', true) !== false) { $('' + RED._("sidebar.project.projectSettings.install") + '').appendTo(buttons) .on("click", function(evt) { evt.preventDefault(); diff --git a/packages/node_modules/@node-red/registry/lib/installer.js b/packages/node_modules/@node-red/registry/lib/installer.js index 0c3359382..f94ebbad4 100644 --- a/packages/node_modules/@node-red/registry/lib/installer.js +++ b/packages/node_modules/@node-red/registry/lib/installer.js @@ -335,7 +335,24 @@ function uninstallModule(module) { return activePromise; } -function checkPrereq() { +async function checkPrereq() { + + try { + if (settings.editorTheme.palette.editable === false) { + log.info(log._("server.palette-editor.disabled")); + installerEnabled = false; + return + } + } catch(err) {} + + try { + if (settings.externalModules.palette.allowInstall === false) { + log.info(log._("server.palette-editor.disabled")); + installerEnabled = false; + return + } + } catch(err) {} + if (settings.hasOwnProperty('editorTheme') && settings.editorTheme.hasOwnProperty('palette') && settings.editorTheme.palette.hasOwnProperty('editable') && @@ -343,7 +360,6 @@ function checkPrereq() { ) { log.info(log._("server.palette-editor.disabled")); installerEnabled = false; - return Promise.resolve(); } else { return new Promise(resolve => { child_process.execFile(npmCommand,['-v'],function(err,stdout) { diff --git a/packages/node_modules/@node-red/runtime/lib/api/settings.js b/packages/node_modules/@node-red/runtime/lib/api/settings.js index 067a8e83a..8b52d4587 100644 --- a/packages/node_modules/@node-red/runtime/lib/api/settings.js +++ b/packages/node_modules/@node-red/runtime/lib/api/settings.js @@ -90,10 +90,15 @@ var api = module.exports = { safeSettings.flowFilePretty = runtime.settings.flowFilePretty; } + if (runtime.settings.externalModules) { + safeSettings.externalModules = runtime.settings.externalModules; + } + if (!runtime.nodes.installerEnabled()) { - safeSettings.editorTheme = safeSettings.editorTheme || {}; - safeSettings.editorTheme.palette = safeSettings.editorTheme.palette || {}; - safeSettings.editorTheme.palette.editable = false; + safeSettings.externalModules = safeSettings.externalModules || {}; + safeSettings.externalModules.palette = safeSettings.externalModules.palette || {}; + safeSettings.externalModules.palette.allowInstall = false; + safeSettings.externalModules.palette.allowUpload = false; } if (runtime.storage.projects) { var activeProject = runtime.storage.projects.getActiveProject();