Skip to content

Node.js based forum software built for the modern web

fixes #5853

Julian Lam4f9cbabec36c
diff --git a/package.json b/package.json
index a069249e79..6c2d79c48b 100644
--- a/package.json
+++ b/package.json
@@ -90,6 +90,7 @@
"socket.io-client": "2.0.1",
"socket.io-redis": "5.0.1",
"socketio-wildcard": "2.0.0",
+ "spdx-license-list": "^3.0.1",
"string": "^3.0.0",
"templates.js": "0.3.11",
"toobusy-js": "^0.5.1",
@@ -137,4 +138,4 @@
"url": "https://github.com/barisusakli"
}
]
-}
\ No newline at end of file
+}
diff --git a/public/language/en-GB/admin/extend/plugins.json b/public/language/en-GB/admin/extend/plugins.json
index cf80583db4..7515f72590 100644
--- a/public/language/en-GB/admin/extend/plugins.json
+++ b/public/language/en-GB/admin/extend/plugins.json
@@ -43,5 +43,9 @@
"alert.suggest-error": "<p>NodeBB could not reach the package manager, proceed with installation of latest version?</p><div class=\"alert alert-danger\"><strong>Server returned (%1)</strong>: %2</div>",
"alert.package-manager-unreachable": "<p>NodeBB could not reach the package manager, an upgrade is not suggested at this time.</p>",
"alert.incompatible": "<p>Your version of NodeBB (v%1) is only cleared to upgrade to v%2 of this plugin. Please update your NodeBB if you wish to install a newer version of this plugin.</p>",
- "alert.possibly-incompatible": "<div class=\"alert alert-warning\"><p><strong>No Compatibility Information Found</strong></p><p>This plugin did not specify a specific version for installation given your NodeBB version. Full compatibility cannot be guaranteed, and may cause your NodeBB to no longer start properly.</p></div><p>In the event that NodeBB cannot boot properly:</p><pre><code>$ ./nodebb reset plugin=\"%1\"</code></pre><p>Continue installation of latest version of this plugin?</p>"
+ "alert.possibly-incompatible": "<div class=\"alert alert-warning\"><p><strong>No Compatibility Information Found</strong></p><p>This plugin did not specify a specific version for installation given your NodeBB version. Full compatibility cannot be guaranteed, and may cause your NodeBB to no longer start properly.</p></div><p>In the event that NodeBB cannot boot properly:</p><pre><code>$ ./nodebb reset plugin=\"%1\"</code></pre><p>Continue installation of latest version of this plugin?</p>",
+
+ "license.title": "Plugin License Information",
+ "license.intro": "The plugin <strong>%1</strong> is licensed under the %2. Please read and understand the license terms prior to activating this plugin.",
+ "license.cta": "Do you wish to continue with activating this plugin?"
}
diff --git a/public/src/admin/extend/plugins.js b/public/src/admin/extend/plugins.js
index 9622b4fbc0..bd8ba1b6cb 100644
--- a/public/src/admin/extend/plugins.js
+++ b/public/src/admin/extend/plugins.js
@@ -21,33 +21,63 @@ define('admin/extend/plugins', ['jqueryui', 'translator'], function (jqueryui, t
var pluginEl = $(this).parents('li');
pluginID = pluginEl.attr('data-plugin-id');
var btn = $('#' + pluginID + ' [data-action="toggleActive"]');
- socket.emit('admin.plugins.toggleActive', pluginID, function (err, status) {
- if (err) {
- return app.alertError(err);
- }
- translator.translate('<i class="fa fa-power-off"></i> [[admin/extend/plugins:plugin-item.' + (status.active ? 'deactivate' : 'activate') + ']]', function (buttonText) {
- btn.html(buttonText);
- btn.toggleClass('btn-warning', status.active).toggleClass('btn-success', !status.active);
+ var pluginData = ajaxify.data.installed[pluginEl.attr('data-plugin-index')];
- // clone it to active plugins tab
- if (status.active && !$('#active #' + pluginID).length) {
- $('#active ul').prepend(pluginEl.clone(true));
+ function toggleActivate () {
+ socket.emit('admin.plugins.toggleActive', pluginID, function (err, status) {
+ if (err) {
+ return app.alertError(err);
}
+ translator.translate('<i class="fa fa-power-off"></i> [[admin/extend/plugins:plugin-item.' + (status.active ? 'deactivate' : 'activate') + ']]', function (buttonText) {
+ btn.html(buttonText);
+ btn.toggleClass('btn-warning', status.active).toggleClass('btn-success', !status.active);
+
+ // clone it to active plugins tab
+ if (status.active && !$('#active #' + pluginID).length) {
+ $('#active ul').prepend(pluginEl.clone(true));
+ }
+
+ // Toggle active state in template data
+ pluginData.active = !pluginData.active;
+
+ app.alert({
+ alert_id: 'plugin_toggled',
+ title: '[[admin/extend/plugins:alert.' + (status.active ? 'enabled' : 'disabled') + ']]',
+ message: '[[admin/extend/plugins:alert.' + (status.active ? 'activate-success' : 'deactivate-success') + ']]',
+ type: status.active ? 'warning' : 'success',
+ timeout: 5000,
+ clickfn: function () {
+ require(['admin/modules/instance'], function (instance) {
+ instance.restart();
+ });
+ },
+ });
+ });
+ });
+ }
- app.alert({
- alert_id: 'plugin_toggled',
- title: '[[admin/extend/plugins:alert.' + (status.active ? 'enabled' : 'disabled') + ']]',
- message: '[[admin/extend/plugins:alert.' + (status.active ? 'activate-success' : 'deactivate-success') + ']]',
- type: status.active ? 'warning' : 'success',
- timeout: 5000,
- clickfn: function () {
- require(['admin/modules/instance'], function (instance) {
- instance.restart();
- });
+ if (pluginData.license && pluginData.active !== true) {
+ templates.parse('admin/partials/plugins/license', pluginData, function (html) {
+ var modal = bootbox.dialog({
+ title: '[[admin/extend/plugins:license.title]]',
+ message: html,
+ size: 'large',
+ buttons: {
+ cancel: {
+ label: '[[modules:bootbox.cancel]]',
+ className: 'btn-link',
+ },
+ save: {
+ label: '[[modules:bootbox.confirm]]',
+ className: 'btn-primary',
+ callback: toggleActivate,
+ }
},
});
});
- });
+ } else {
+ toggleActivate(pluginID);
+ }
});
pluginsList.on('click', 'button[data-action="toggleInstall"]', function () {
diff --git a/src/plugins/data.js b/src/plugins/data.js
index 8591346a7e..ed81eed678 100644
--- a/src/plugins/data.js
+++ b/src/plugins/data.js
@@ -44,9 +44,20 @@ function loadPluginInfo(pluginPath, callback) {
}
var pluginData;
var packageData;
+ var licenseData;
try {
pluginData = JSON.parse(results.plugin);
packageData = JSON.parse(results.package);
+ try {
+ licenseData = require('spdx-license-list/licenses/' + packageData.license);
+ pluginData.license = {
+ name: licenseData.name,
+ text: licenseData.licenseText,
+ };
+ } catch (e) {
+ // No license matched
+ pluginData.license = null;
+ }
pluginData.id = packageData.name;
pluginData.name = packageData.name;
@@ -55,7 +66,6 @@ function loadPluginInfo(pluginPath, callback) {
pluginData.repository = packageData.repository;
pluginData.nbbpm = packageData.nbbpm;
pluginData.path = pluginPath;
- pluginData.license = packageData.license;
} catch (err) {
var pluginDir = path.basename(pluginPath);
diff --git a/src/views/admin/partials/installed_plugin_item.tpl b/src/views/admin/partials/installed_plugin_item.tpl
index 2e95606ef8..0a7524c815 100644
--- a/src/views/admin/partials/installed_plugin_item.tpl
+++ b/src/views/admin/partials/installed_plugin_item.tpl
@@ -1,5 +1,5 @@
<!-- IF !installed.error -->
- <li id="{installed.id}" data-plugin-id="{installed.id}" data-version="{installed.version}" class="clearfix <!-- IF installed.active -->active<!-- ENDIF installed.active -->">
+ <li id="{installed.id}" data-plugin-index="@index" data-plugin-id="{installed.id}" data-version="{installed.version}" class="clearfix <!-- IF installed.active -->active<!-- ENDIF installed.active -->">
<div class="pull-right controls">
<!-- IF installed.isTheme -->
<a href="{config.relative_path}/admin/appearance/themes" class="btn btn-info">[[admin/extend/plugins:plugin-item.themes]]</a>
diff --git a/src/views/admin/partials/plugins/license.tpl b/src/views/admin/partials/plugins/license.tpl
new file mode 100644
index 0000000000..6c1bef8f04
--- /dev/null
+++ b/src/views/admin/partials/plugins/license.tpl
@@ -0,0 +1,5 @@
+[[admin/extend/plugins:license.intro, {name}, {license.name}]]
+
+<blockquote>{license.text}</blockquote>
+
+[[admin/extend/plugins:license.cta]]
\ No newline at end of file