mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-05-06 15:06:38 +02:00
fix: closes #13458, check if plugin is system
plugin before activate/deactive/install/uninstall
This commit is contained in:
@@ -156,6 +156,16 @@ module.exports = function (Plugins) {
|
||||
}
|
||||
};
|
||||
|
||||
Plugins.isSystemPlugin = async function (id) {
|
||||
const pluginDir = path.join(paths.nodeModules, id, 'plugin.json');
|
||||
try {
|
||||
const pluginData = JSON.parse(await fs.readFile(pluginDir, 'utf8'));
|
||||
return pluginData && pluginData.system === true;
|
||||
} catch (err) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
Plugins.isActive = async function (id) {
|
||||
if (nconf.get('plugins:active')) {
|
||||
return nconf.get('plugins:active').includes(id);
|
||||
|
||||
@@ -11,6 +11,9 @@ const { pluginNamePattern } = require('../../constants');
|
||||
const Plugins = module.exports;
|
||||
|
||||
Plugins.toggleActive = async function (socket, plugin_id) {
|
||||
if (await plugins.isSystemPlugin(plugin_id)) {
|
||||
throw new Error('[[error:cannot-toggle-system-plugin]]');
|
||||
}
|
||||
postsCache.reset();
|
||||
const data = await plugins.toggleActive(plugin_id);
|
||||
await events.log({
|
||||
@@ -22,6 +25,9 @@ Plugins.toggleActive = async function (socket, plugin_id) {
|
||||
};
|
||||
|
||||
Plugins.toggleInstall = async function (socket, data) {
|
||||
if (await plugins.isSystemPlugin(data.id)) {
|
||||
throw new Error('[[error:cannot-toggle-system-plugin]]');
|
||||
}
|
||||
const isInstalled = await plugins.isInstalled(data.id);
|
||||
const isStarterPlan = nconf.get('saas_plan') === 'starter';
|
||||
if ((isStarterPlan || nconf.get('acpPluginInstallDisabled')) && !isInstalled) {
|
||||
|
||||
Reference in New Issue
Block a user