mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-03-06 12:31:33 +01:00
feat: Allow defining active plugins in config (#10767)
* Revert "Revert "feat: cross origin opener policy options (#10710)"" This reverts commit46050ace1a. * Revert "Revert "chore(i18n): fallback strings for new resources: nodebb.admin-settings-advanced"" This reverts commit9f291c07d3. * feat: closes #10719, don't trim children if category is marked section * feat: fire hook to allow plugins to filter the pids returned in a user profile /cc julianlam/nodebb-plugin-support-forum#14 * fix: use `user.hidePrivateData();` more consistently across user retrieval endpoints * feat: Allow defining active plugins in config resolves #10766 * fix: assign the db result to files properly * test: add tests with plugins in config * feat: better theme change handling * feat: add visual indication that plugins can't be activated * test: correct hooks * test: fix test definitions * test: remove instead of resetting nconf to avoid affecting other tests * test: ... I forgot how nconf worked * fix: remove negation * docs: improve wording of error message * feat: reduce code duplication * style: remove a redundant space * fix: remove unused imports * fix: use nconf instead of requiring config.json * fix: await... * fix: second missed await * fix: move back from getActiveIds to getActive * fix: use paths again? * fix: typo * fix: move require into the function * fix: forgot to change back to getActive * test: getActive returns only id * test: accedently commented out some stuff * feat: added note to top of plugins page if \!canChangeState Co-authored-by: Julian Lam <julian@nodebb.org> Co-authored-by: Barış Soner Uşaklı <barisusakli@gmail.com>
This commit is contained in:
@@ -4,6 +4,7 @@ const winston = require('winston');
|
||||
const childProcess = require('child_process');
|
||||
const CliGraph = require('cli-graph');
|
||||
const chalk = require('chalk');
|
||||
const nconf = require('nconf');
|
||||
|
||||
const build = require('../meta/build');
|
||||
const db = require('../database');
|
||||
@@ -38,6 +39,10 @@ async function activate(plugin) {
|
||||
winston.info('Plugin `%s` already active', plugin);
|
||||
process.exit(0);
|
||||
}
|
||||
if (nconf.get('plugins:active')) {
|
||||
winston.error('Cannot activate plugins while plugin state configuration is set, please change your active configuration (config.json, environmental variables or terminal arguments) instead');
|
||||
process.exit(1);
|
||||
}
|
||||
const numPlugins = await db.sortedSetCard('plugins:active');
|
||||
winston.info('Activating plugin `%s`', plugin);
|
||||
await db.sortedSetAdd('plugins:active', numPlugins, plugin);
|
||||
@@ -57,8 +62,7 @@ async function listPlugins() {
|
||||
await db.init();
|
||||
const installed = await plugins.showInstalled();
|
||||
const installedList = installed.map(plugin => plugin.name);
|
||||
const active = await db.getSortedSetRange('plugins:active', 0, -1);
|
||||
|
||||
const active = await plugins.getActive();
|
||||
// Merge the two sets, defer to plugins in `installed` if already present
|
||||
const combined = installed.concat(active.reduce((memo, cur) => {
|
||||
if (!installedList.includes(cur)) {
|
||||
@@ -108,13 +112,12 @@ async function info() {
|
||||
const hash = childProcess.execSync('git rev-parse HEAD');
|
||||
console.log(` git hash: ${hash}`);
|
||||
|
||||
const config = require('../../config.json');
|
||||
console.log(` database: ${config.database}`);
|
||||
console.log(` database: ${nconf.get('database')}`);
|
||||
|
||||
await db.init();
|
||||
const info = await db.info(db.client);
|
||||
|
||||
switch (config.database) {
|
||||
switch (nconf.get('database')) {
|
||||
case 'redis':
|
||||
console.log(` version: ${info.redis_version}`);
|
||||
console.log(` disk sync: ${info.rdb_last_bgsave_status}`);
|
||||
@@ -124,6 +127,10 @@ async function info() {
|
||||
console.log(` version: ${info.version}`);
|
||||
console.log(` engine: ${info.storageEngine}`);
|
||||
break;
|
||||
case 'postgres':
|
||||
console.log(` version: ${info.version}`);
|
||||
console.log(` uptime: ${info.uptime}`);
|
||||
break;
|
||||
}
|
||||
|
||||
const analyticsData = await analytics.getHourlyStatsForSet('analytics:pageviews', Date.now(), 24);
|
||||
|
||||
@@ -4,6 +4,7 @@ const path = require('path');
|
||||
const winston = require('winston');
|
||||
const fs = require('fs');
|
||||
const chalk = require('chalk');
|
||||
const nconf = require('nconf');
|
||||
|
||||
const db = require('../database');
|
||||
const events = require('../events');
|
||||
@@ -118,6 +119,10 @@ async function resetThemeTo(themeId) {
|
||||
|
||||
async function resetPlugin(pluginId) {
|
||||
try {
|
||||
if (nconf.get('plugins:active')) {
|
||||
winston.error('Cannot reset plugins while plugin state is set in the configuration (config.json, environmental variables or terminal arguments), please modify the configuration instead');
|
||||
process.exit(1);
|
||||
}
|
||||
const isActive = await db.isSortedSetMember('plugins:active', pluginId);
|
||||
if (isActive) {
|
||||
await db.sortedSetRemove('plugins:active', pluginId);
|
||||
@@ -137,6 +142,10 @@ async function resetPlugin(pluginId) {
|
||||
}
|
||||
|
||||
async function resetPlugins() {
|
||||
if (nconf.get('plugins:active')) {
|
||||
winston.error('Cannot reset plugins while plugin state is set in the configuration (config.json, environmental variables or terminal arguments), please modify the configuration instead');
|
||||
process.exit(1);
|
||||
}
|
||||
await db.delete('plugins:active');
|
||||
winston.info('[reset] All Plugins De-activated');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user