From c74fc9b9cad0c10cc043f6ff82e519758801f3c7 Mon Sep 17 00:00:00 2001 From: Misty Release Bot Date: Thu, 24 Nov 2022 09:06:27 +0000 Subject: [PATCH 1/9] Latest translations and fallbacks --- public/language/bg/admin/settings/advanced.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/language/bg/admin/settings/advanced.json b/public/language/bg/admin/settings/advanced.json index 32caf79de0..7992505008 100644 --- a/public/language/bg/admin/settings/advanced.json +++ b/public/language/bg/admin/settings/advanced.json @@ -21,7 +21,7 @@ "headers.coop": "Cross-Origin-Opener-Policy", "headers.corp": "Cross-Origin-Resource-Policy", "headers.permissions-policy": "Permissions-Policy", - "headers.permissions-policy-help": "Allows setting permissions policy header, for example \"geolocation=*, camera=()\", see this for more info.", + "headers.permissions-policy-help": "Позволява задаването на стойност в заглавката „permissions-policy“ (политика за разрешенията), като например „geolocation=*, camera=()“. Вижте тук за повече информация.", "hsts": "Стриктна транспортна сигурност", "hsts.enabled": "Включване на HSTS (препоръчително)", "hsts.maxAge": "Максимална възраст на HSTS", From 6fe879752549a4d995e2556f3820c86b50ad6804 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Thu, 24 Nov 2022 11:17:06 -0500 Subject: [PATCH 2/9] feat: add ./nodebb install will install the suggested version for current nodebb closes #11060 --- src/cli/index.js | 13 +++++++++---- src/cli/manage.js | 32 +++++++++++++++++++++++++++++++- src/plugins/install.js | 9 +++++++++ 3 files changed, 49 insertions(+), 5 deletions(-) diff --git a/src/cli/index.js b/src/cli/index.js index b1ce151f4c..cad46b4609 100644 --- a/src/cli/index.js +++ b/src/cli/index.js @@ -173,11 +173,16 @@ program }); program - .command('install') - .description('Launch the NodeBB web installer for configuration setup') - .action(() => { - require('./setup').webInstall(); + .command('install [plugin]') + .description('Launch the NodeBB web installer for configuration setup or install a plugin') + .action((plugin) => { + if (plugin) { + require('./manage').install(plugin); + } else { + require('./setup').webInstall(); + } }); + program .command('build [targets...]') .description(`Compile static assets ${chalk.red('(JS, CSS, templates, languages)')}`) diff --git a/src/cli/manage.js b/src/cli/manage.js index 24052e21f6..45480e735f 100644 --- a/src/cli/manage.js +++ b/src/cli/manage.js @@ -12,7 +12,36 @@ const plugins = require('../plugins'); const events = require('../events'); const analytics = require('../analytics'); const reset = require('./reset'); -const { pluginNamePattern, themeNamePattern } = require('../constants'); +const { pluginNamePattern, themeNamePattern, paths } = require('../constants'); + +async function install(plugin) { + try { + await db.init(); + if (!pluginNamePattern.test(plugin)) { + // Allow omission of `nodebb-plugin-` + plugin = `nodebb-plugin-${plugin}`; + } + + plugin = await plugins.autocomplete(plugin); + + const isInstalled = await plugins.isInstalled(plugin); + if (isInstalled) { + throw new Error('plugin already installed'); + } + const nbbVersion = require(paths.currentPackage).version; + const suggested = await plugins.suggest(plugin, nbbVersion); + if (!suggested.version) { + throw new Error(suggested.message); + } + winston.info('Installing Plugin `%s@%s`', plugin, suggested.version); + await plugins.toggleInstall(plugin, suggested.version); + + process.exit(0); + } catch (err) { + winston.error(`An error occurred during plugin installation\n${err.stack}`); + process.exit(1); + } +} async function activate(plugin) { if (themeNamePattern.test(plugin)) { @@ -166,6 +195,7 @@ async function buildWrapper(targets, options) { } exports.build = buildWrapper; +exports.install = install; exports.activate = activate; exports.listPlugins = listPlugins; exports.listEvents = listEvents; diff --git a/src/plugins/install.js b/src/plugins/install.js index 3784df09a0..d358c917a5 100644 --- a/src/plugins/install.js +++ b/src/plugins/install.js @@ -87,6 +87,15 @@ module.exports = function (Plugins) { throw new Error('[[error:plugin-not-whitelisted]]'); }; + Plugins.suggest = async function (pluginId, nbbVersion) { + const body = await request({ + method: 'GET', + url: `https://packages.nodebb.org/api/v1/suggest?package=${encodeURIComponent(pluginId)}&version=${encodeURIComponent(nbbVersion)}`, + json: true, + }); + return body; + }; + Plugins.toggleInstall = async function (id, version) { pubsub.publish('plugins:toggleInstall', { hostname: os.hostname(), id: id, version: version }); return await toggleInstall(id, version); From 07a3cee6d682ad39ff31148185997b8c6faf1b3c Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Wed, 23 Nov 2022 17:23:04 -0500 Subject: [PATCH 3/9] feat: integrating basic client-side form validity checking in settings v1 and v2 --- public/src/admin/settings.js | 7 ++++++- public/src/modules/settings.js | 26 ++++++++++++++++++++++++++ src/views/admin/settings/advanced.tpl | 2 +- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/public/src/admin/settings.js b/public/src/admin/settings.js index beecc17649..7af0babd2a 100644 --- a/public/src/admin/settings.js +++ b/public/src/admin/settings.js @@ -1,7 +1,7 @@ 'use strict'; -define('admin/settings', ['uploader', 'mousetrap', 'hooks', 'alerts'], function (uploader, mousetrap, hooks, alerts) { +define('admin/settings', ['uploader', 'mousetrap', 'hooks', 'alerts', 'settings'], function (uploader, mousetrap, hooks, alerts, settings) { const Settings = {}; Settings.populateTOC = function () { @@ -66,6 +66,11 @@ define('admin/settings', ['uploader', 'mousetrap', 'hooks', 'alerts'], function saveBtn.off('click').on('click', function (e) { e.preventDefault(); + const ok = settings.check(document.querySelectorAll('#content [data-field][pattern]')); + if (!ok) { + return; + } + saveFields(fields, function onFieldsSaved(err) { if (err) { return alerts.alert({ diff --git a/public/src/modules/settings.js b/public/src/modules/settings.js index 57dfa2abee..5c78ede9e7 100644 --- a/public/src/modules/settings.js +++ b/public/src/modules/settings.js @@ -517,6 +517,12 @@ define('settings', ['hooks', 'alerts'], function (hooks, alerts) { save: function (hash, formEl, callback) { formEl = $(formEl); + const controls = formEl.get(0).querySelectorAll('input[name][pattern]'); + const ok = Settings.check(controls); + if (!ok) { + return; + } + if (formEl.length) { const values = helper.serializeForm(formEl); @@ -559,6 +565,26 @@ define('settings', ['hooks', 'alerts'], function (hooks, alerts) { }); } }, + check: function (controls) { + const onTrigger = (e) => { + const wrapper = e.target.closest('.form-group'); + if (wrapper) { + wrapper.classList.add('has-error'); + } + + e.target.removeEventListener('invalid', onTrigger); + }; + + return Array.prototype.map.call(controls, (controlEl) => { + const wrapper = controlEl.closest('.form-group'); + if (wrapper) { + wrapper.classList.remove('has-error'); + } + + controlEl.addEventListener('invalid', onTrigger); + return controlEl.reportValidity(); + }).every(Boolean); + }, }; diff --git a/src/views/admin/settings/advanced.tpl b/src/views/admin/settings/advanced.tpl index 1041848878..860e730790 100644 --- a/src/views/admin/settings/advanced.tpl +++ b/src/views/admin/settings/advanced.tpl @@ -121,7 +121,7 @@
-
+