Add the ability to whitelist/blacklist plugins.

This commit is contained in:
JC Brand 2017-02-03 18:12:19 +00:00
parent 1eaf65f8e2
commit ebbde138db
6 changed files with 156 additions and 34 deletions

View File

@ -41977,7 +41977,7 @@ define("polyfill", function(){});
// then the name by which the pluggable object may be referenced on the // then the name by which the pluggable object may be referenced on the
// __super__ object (inside overrides). // __super__ object (inside overrides).
function PluginSocket (plugged, name) { function PluginSocket (plugged, name) {
this.name = name; this.name = name;
this.plugged = plugged; this.plugged = plugged;
if (typeof this.plugged.__super__ === 'undefined') { if (typeof this.plugged.__super__ === 'undefined') {
this.plugged.__super__ = {}; this.plugged.__super__ = {};
@ -42125,6 +42125,10 @@ define("polyfill", function(){});
// `initializePlugin` applies the overrides (if any) defined on all // `initializePlugin` applies the overrides (if any) defined on all
// the registered plugins and then calls the initialize method for each plugin. // the registered plugins and then calls the initialize method for each plugin.
initializePlugin: function (plugin) { initializePlugin: function (plugin) {
if (!_.includes(_.keys(this.allowed_plugins), plugin.__name__)) {
/* Don't initialize disallowed plugins. */
return;
}
if (_.includes(this.initialized_plugins, plugin.__name__)) { if (_.includes(this.initialized_plugins, plugin.__name__)) {
/* Don't initialize plugins twice, otherwise we get /* Don't initialize plugins twice, otherwise we get
* infinite recursion in overridden methods. * infinite recursion in overridden methods.
@ -42154,12 +42158,18 @@ define("polyfill", function(){});
// `initializePlugin` for each. // `initializePlugin` for each.
// The passed in properties variable is an object with attributes and methods // The passed in properties variable is an object with attributes and methods
// which will be attached to the plugins. // which will be attached to the plugins.
initializePlugins: function (properties) { initializePlugins: function (properties, whitelist, blacklist) {
if (!_.size(this.plugins)) { if (!_.size(this.plugins)) {
return; return;
} }
this.properties = properties; this.properties = properties;
_.each(_.values(this.plugins), this.initializePlugin.bind(this)); this.allowed_plugins = _.pickBy(this.plugins,
function (plugin, key) {
return (whitelist.length && _.includes(whitelist, key)) &&
!_.includes(blacklist, key);
}
);
_.each(_.values(this.allowed_plugins), this.initializePlugin.bind(this));
} }
}); });
return { return {
@ -44787,6 +44797,25 @@ return Backbone.BrowserStorage;
_.extend(_converse, Backbone.Events); _.extend(_converse, Backbone.Events);
_converse.emit = _converse.trigger; _converse.emit = _converse.trigger;
_converse.core_plugins = [
'converse-bookmarks',
'converse-chatview',
'converse-controlbox',
'converse-core',
'converse-dragresize',
'converse-headline',
'converse-mam',
'converse-minimize',
'converse-muc',
'converse-muc-embedded',
'converse-notification',
'converse-otr',
'converse-ping',
'converse-register',
'converse-rosterview',
'converse-vcard'
];
// Make converse pluggable // Make converse pluggable
pluggable.enable(_converse, '_converse', 'pluggable'); pluggable.enable(_converse, '_converse', 'pluggable');
@ -44926,7 +44955,8 @@ return Backbone.BrowserStorage;
auto_reconnect: false, auto_reconnect: false,
auto_subscribe: false, auto_subscribe: false,
auto_xa: 0, // Seconds after which user status is set to 'xa' auto_xa: 0, // Seconds after which user status is set to 'xa'
bosh_service_url: undefined, // The BOSH connection manager URL. blacklisted_plugins: [],
bosh_service_url: undefined,
connection_options: {}, connection_options: {},
credentials_url: null, // URL from where login credentials can be fetched credentials_url: null, // URL from where login credentials can be fetched
csi_waiting_time: 0, // Support for XEP-0352. Seconds before client is considered idle and CSI is sent out. csi_waiting_time: 0, // Support for XEP-0352. Seconds before client is considered idle and CSI is sent out.
@ -44940,10 +44970,9 @@ return Backbone.BrowserStorage;
jid: undefined, jid: undefined,
keepalive: false, keepalive: false,
locked_domain: undefined, locked_domain: undefined,
message_carbons: false, // Support for XEP-280 message_carbons: false,
message_storage: 'session', message_storage: 'session',
password: undefined, password: undefined,
prebind: false, // XXX: Deprecated, use "authentication" instead.
prebind_url: null, prebind_url: null,
rid: undefined, rid: undefined,
roster_groups: false, roster_groups: false,
@ -44951,8 +44980,9 @@ return Backbone.BrowserStorage;
sid: undefined, sid: undefined,
storage: 'session', storage: 'session',
strict_plugin_dependencies: false, strict_plugin_dependencies: false,
synchronize_availability: true, // Set to false to not sync with other clients or with resource name of the particular client that it should synchronize with synchronize_availability: true,
websocket_url: undefined, websocket_url: undefined,
whitelisted_plugins: [],
xhr_custom_status: false, xhr_custom_status: false,
xhr_custom_status_url: '', xhr_custom_status_url: '',
}; };
@ -46712,10 +46742,13 @@ return Backbone.BrowserStorage;
// in any case. // in any case.
_converse.pluggable.initialized_plugins = []; _converse.pluggable.initialized_plugins = [];
var whitelist = _converse.core_plugins.concat(_converse.whitelisted_plugins);
_converse.pluggable.initializePlugins({ _converse.pluggable.initializePlugins({
'updateSettings': updateSettings, 'updateSettings': updateSettings,
'_converse': _converse '_converse': _converse
}); }, whitelist, _converse.blacklisted_plugins);
_converse.emit('pluginsInitialized'); _converse.emit('pluginsInitialized');
_converse._initialize(); _converse._initialize();
_converse.registerGlobalEventHandlers(); _converse.registerGlobalEventHandlers();
@ -49918,7 +49951,7 @@ return __p
b64_sha1 = converse.env.b64_sha1, b64_sha1 = converse.env.b64_sha1,
_ = converse.env._; _ = converse.env._;
converse.plugins.add('rosterview', { converse.plugins.add('converse-rosterview', {
overrides: { overrides: {
// Overrides mentioned here will be picked up by converse.js's // Overrides mentioned here will be picked up by converse.js's

View File

@ -3450,7 +3450,7 @@ define("polyfill", function(){});
// then the name by which the pluggable object may be referenced on the // then the name by which the pluggable object may be referenced on the
// __super__ object (inside overrides). // __super__ object (inside overrides).
function PluginSocket (plugged, name) { function PluginSocket (plugged, name) {
this.name = name; this.name = name;
this.plugged = plugged; this.plugged = plugged;
if (typeof this.plugged.__super__ === 'undefined') { if (typeof this.plugged.__super__ === 'undefined') {
this.plugged.__super__ = {}; this.plugged.__super__ = {};
@ -3598,6 +3598,10 @@ define("polyfill", function(){});
// `initializePlugin` applies the overrides (if any) defined on all // `initializePlugin` applies the overrides (if any) defined on all
// the registered plugins and then calls the initialize method for each plugin. // the registered plugins and then calls the initialize method for each plugin.
initializePlugin: function (plugin) { initializePlugin: function (plugin) {
if (!_.includes(_.keys(this.allowed_plugins), plugin.__name__)) {
/* Don't initialize disallowed plugins. */
return;
}
if (_.includes(this.initialized_plugins, plugin.__name__)) { if (_.includes(this.initialized_plugins, plugin.__name__)) {
/* Don't initialize plugins twice, otherwise we get /* Don't initialize plugins twice, otherwise we get
* infinite recursion in overridden methods. * infinite recursion in overridden methods.
@ -3627,12 +3631,18 @@ define("polyfill", function(){});
// `initializePlugin` for each. // `initializePlugin` for each.
// The passed in properties variable is an object with attributes and methods // The passed in properties variable is an object with attributes and methods
// which will be attached to the plugins. // which will be attached to the plugins.
initializePlugins: function (properties) { initializePlugins: function (properties, whitelist, blacklist) {
if (!_.size(this.plugins)) { if (!_.size(this.plugins)) {
return; return;
} }
this.properties = properties; this.properties = properties;
_.each(_.values(this.plugins), this.initializePlugin.bind(this)); this.allowed_plugins = _.pickBy(this.plugins,
function (plugin, key) {
return (whitelist.length && _.includes(whitelist, key)) &&
!_.includes(blacklist, key);
}
);
_.each(_.values(this.allowed_plugins), this.initializePlugin.bind(this));
} }
}); });
return { return {
@ -3710,6 +3720,25 @@ define("polyfill", function(){});
_.extend(_converse, Backbone.Events); _.extend(_converse, Backbone.Events);
_converse.emit = _converse.trigger; _converse.emit = _converse.trigger;
_converse.core_plugins = [
'converse-bookmarks',
'converse-chatview',
'converse-controlbox',
'converse-core',
'converse-dragresize',
'converse-headline',
'converse-mam',
'converse-minimize',
'converse-muc',
'converse-muc-embedded',
'converse-notification',
'converse-otr',
'converse-ping',
'converse-register',
'converse-rosterview',
'converse-vcard'
];
// Make converse pluggable // Make converse pluggable
pluggable.enable(_converse, '_converse', 'pluggable'); pluggable.enable(_converse, '_converse', 'pluggable');
@ -3849,7 +3878,8 @@ define("polyfill", function(){});
auto_reconnect: false, auto_reconnect: false,
auto_subscribe: false, auto_subscribe: false,
auto_xa: 0, // Seconds after which user status is set to 'xa' auto_xa: 0, // Seconds after which user status is set to 'xa'
bosh_service_url: undefined, // The BOSH connection manager URL. blacklisted_plugins: [],
bosh_service_url: undefined,
connection_options: {}, connection_options: {},
credentials_url: null, // URL from where login credentials can be fetched credentials_url: null, // URL from where login credentials can be fetched
csi_waiting_time: 0, // Support for XEP-0352. Seconds before client is considered idle and CSI is sent out. csi_waiting_time: 0, // Support for XEP-0352. Seconds before client is considered idle and CSI is sent out.
@ -3863,10 +3893,9 @@ define("polyfill", function(){});
jid: undefined, jid: undefined,
keepalive: false, keepalive: false,
locked_domain: undefined, locked_domain: undefined,
message_carbons: false, // Support for XEP-280 message_carbons: false,
message_storage: 'session', message_storage: 'session',
password: undefined, password: undefined,
prebind: false, // XXX: Deprecated, use "authentication" instead.
prebind_url: null, prebind_url: null,
rid: undefined, rid: undefined,
roster_groups: false, roster_groups: false,
@ -3874,8 +3903,9 @@ define("polyfill", function(){});
sid: undefined, sid: undefined,
storage: 'session', storage: 'session',
strict_plugin_dependencies: false, strict_plugin_dependencies: false,
synchronize_availability: true, // Set to false to not sync with other clients or with resource name of the particular client that it should synchronize with synchronize_availability: true,
websocket_url: undefined, websocket_url: undefined,
whitelisted_plugins: [],
xhr_custom_status: false, xhr_custom_status: false,
xhr_custom_status_url: '', xhr_custom_status_url: '',
}; };
@ -5635,10 +5665,13 @@ define("polyfill", function(){});
// in any case. // in any case.
_converse.pluggable.initialized_plugins = []; _converse.pluggable.initialized_plugins = [];
var whitelist = _converse.core_plugins.concat(_converse.whitelisted_plugins);
_converse.pluggable.initializePlugins({ _converse.pluggable.initializePlugins({
'updateSettings': updateSettings, 'updateSettings': updateSettings,
'_converse': _converse '_converse': _converse
}); }, whitelist, _converse.blacklisted_plugins);
_converse.emit('pluginsInitialized'); _converse.emit('pluginsInitialized');
_converse._initialize(); _converse._initialize();
_converse.registerGlobalEventHandlers(); _converse.registerGlobalEventHandlers();
@ -8736,7 +8769,7 @@ return __p
b64_sha1 = converse.env.b64_sha1, b64_sha1 = converse.env.b64_sha1,
_ = converse.env._; _ = converse.env._;
converse.plugins.add('rosterview', { converse.plugins.add('converse-rosterview', {
overrides: { overrides: {
// Overrides mentioned here will be picked up by converse.js's // Overrides mentioned here will be picked up by converse.js's

51
dist/converse.js vendored
View File

@ -41977,7 +41977,7 @@ define("polyfill", function(){});
// then the name by which the pluggable object may be referenced on the // then the name by which the pluggable object may be referenced on the
// __super__ object (inside overrides). // __super__ object (inside overrides).
function PluginSocket (plugged, name) { function PluginSocket (plugged, name) {
this.name = name; this.name = name;
this.plugged = plugged; this.plugged = plugged;
if (typeof this.plugged.__super__ === 'undefined') { if (typeof this.plugged.__super__ === 'undefined') {
this.plugged.__super__ = {}; this.plugged.__super__ = {};
@ -42125,6 +42125,10 @@ define("polyfill", function(){});
// `initializePlugin` applies the overrides (if any) defined on all // `initializePlugin` applies the overrides (if any) defined on all
// the registered plugins and then calls the initialize method for each plugin. // the registered plugins and then calls the initialize method for each plugin.
initializePlugin: function (plugin) { initializePlugin: function (plugin) {
if (!_.includes(_.keys(this.allowed_plugins), plugin.__name__)) {
/* Don't initialize disallowed plugins. */
return;
}
if (_.includes(this.initialized_plugins, plugin.__name__)) { if (_.includes(this.initialized_plugins, plugin.__name__)) {
/* Don't initialize plugins twice, otherwise we get /* Don't initialize plugins twice, otherwise we get
* infinite recursion in overridden methods. * infinite recursion in overridden methods.
@ -42154,12 +42158,18 @@ define("polyfill", function(){});
// `initializePlugin` for each. // `initializePlugin` for each.
// The passed in properties variable is an object with attributes and methods // The passed in properties variable is an object with attributes and methods
// which will be attached to the plugins. // which will be attached to the plugins.
initializePlugins: function (properties) { initializePlugins: function (properties, whitelist, blacklist) {
if (!_.size(this.plugins)) { if (!_.size(this.plugins)) {
return; return;
} }
this.properties = properties; this.properties = properties;
_.each(_.values(this.plugins), this.initializePlugin.bind(this)); this.allowed_plugins = _.pickBy(this.plugins,
function (plugin, key) {
return (whitelist.length && _.includes(whitelist, key)) &&
!_.includes(blacklist, key);
}
);
_.each(_.values(this.allowed_plugins), this.initializePlugin.bind(this));
} }
}); });
return { return {
@ -44787,6 +44797,25 @@ return Backbone.BrowserStorage;
_.extend(_converse, Backbone.Events); _.extend(_converse, Backbone.Events);
_converse.emit = _converse.trigger; _converse.emit = _converse.trigger;
_converse.core_plugins = [
'converse-bookmarks',
'converse-chatview',
'converse-controlbox',
'converse-core',
'converse-dragresize',
'converse-headline',
'converse-mam',
'converse-minimize',
'converse-muc',
'converse-muc-embedded',
'converse-notification',
'converse-otr',
'converse-ping',
'converse-register',
'converse-rosterview',
'converse-vcard'
];
// Make converse pluggable // Make converse pluggable
pluggable.enable(_converse, '_converse', 'pluggable'); pluggable.enable(_converse, '_converse', 'pluggable');
@ -44926,7 +44955,8 @@ return Backbone.BrowserStorage;
auto_reconnect: false, auto_reconnect: false,
auto_subscribe: false, auto_subscribe: false,
auto_xa: 0, // Seconds after which user status is set to 'xa' auto_xa: 0, // Seconds after which user status is set to 'xa'
bosh_service_url: undefined, // The BOSH connection manager URL. blacklisted_plugins: [],
bosh_service_url: undefined,
connection_options: {}, connection_options: {},
credentials_url: null, // URL from where login credentials can be fetched credentials_url: null, // URL from where login credentials can be fetched
csi_waiting_time: 0, // Support for XEP-0352. Seconds before client is considered idle and CSI is sent out. csi_waiting_time: 0, // Support for XEP-0352. Seconds before client is considered idle and CSI is sent out.
@ -44940,10 +44970,9 @@ return Backbone.BrowserStorage;
jid: undefined, jid: undefined,
keepalive: false, keepalive: false,
locked_domain: undefined, locked_domain: undefined,
message_carbons: false, // Support for XEP-280 message_carbons: false,
message_storage: 'session', message_storage: 'session',
password: undefined, password: undefined,
prebind: false, // XXX: Deprecated, use "authentication" instead.
prebind_url: null, prebind_url: null,
rid: undefined, rid: undefined,
roster_groups: false, roster_groups: false,
@ -44951,8 +44980,9 @@ return Backbone.BrowserStorage;
sid: undefined, sid: undefined,
storage: 'session', storage: 'session',
strict_plugin_dependencies: false, strict_plugin_dependencies: false,
synchronize_availability: true, // Set to false to not sync with other clients or with resource name of the particular client that it should synchronize with synchronize_availability: true,
websocket_url: undefined, websocket_url: undefined,
whitelisted_plugins: [],
xhr_custom_status: false, xhr_custom_status: false,
xhr_custom_status_url: '', xhr_custom_status_url: '',
}; };
@ -46712,10 +46742,13 @@ return Backbone.BrowserStorage;
// in any case. // in any case.
_converse.pluggable.initialized_plugins = []; _converse.pluggable.initialized_plugins = [];
var whitelist = _converse.core_plugins.concat(_converse.whitelisted_plugins);
_converse.pluggable.initializePlugins({ _converse.pluggable.initializePlugins({
'updateSettings': updateSettings, 'updateSettings': updateSettings,
'_converse': _converse '_converse': _converse
}); }, whitelist, _converse.blacklisted_plugins);
_converse.emit('pluginsInitialized'); _converse.emit('pluginsInitialized');
_converse._initialize(); _converse._initialize();
_converse.registerGlobalEventHandlers(); _converse.registerGlobalEventHandlers();
@ -49918,7 +49951,7 @@ return __p
b64_sha1 = converse.env.b64_sha1, b64_sha1 = converse.env.b64_sha1,
_ = converse.env._; _ = converse.env._;
converse.plugins.add('rosterview', { converse.plugins.add('converse-rosterview', {
overrides: { overrides: {
// Overrides mentioned here will be picked up by converse.js's // Overrides mentioned here will be picked up by converse.js's

View File

@ -59,7 +59,7 @@
"otr": "0.2.16", "otr": "0.2.16",
"phantom-jasmine": "0.1.8", "phantom-jasmine": "0.1.8",
"phantomjs": "~1.9.7-1", "phantomjs": "~1.9.7-1",
"pluggable.js": "https://github.com/jcbrand/pluggable.js.git#d5679e907bfbc8e673f7fa23e75f21cb4a26ae57", "pluggable.js": "https://github.com/jcbrand/pluggable.js.git#078e8898b26954d0744f3e41b894b870675f17e7",
"po2json": "^0.4.4", "po2json": "^0.4.4",
"requirejs": "2.3.2", "requirejs": "2.3.2",
"snyk": "^1.21.2", "snyk": "^1.21.2",

View File

@ -48,6 +48,25 @@
_.extend(_converse, Backbone.Events); _.extend(_converse, Backbone.Events);
_converse.emit = _converse.trigger; _converse.emit = _converse.trigger;
_converse.core_plugins = [
'converse-bookmarks',
'converse-chatview',
'converse-controlbox',
'converse-core',
'converse-dragresize',
'converse-headline',
'converse-mam',
'converse-minimize',
'converse-muc',
'converse-muc-embedded',
'converse-notification',
'converse-otr',
'converse-ping',
'converse-register',
'converse-rosterview',
'converse-vcard'
];
// Make converse pluggable // Make converse pluggable
pluggable.enable(_converse, '_converse', 'pluggable'); pluggable.enable(_converse, '_converse', 'pluggable');
@ -187,7 +206,8 @@
auto_reconnect: false, auto_reconnect: false,
auto_subscribe: false, auto_subscribe: false,
auto_xa: 0, // Seconds after which user status is set to 'xa' auto_xa: 0, // Seconds after which user status is set to 'xa'
bosh_service_url: undefined, // The BOSH connection manager URL. blacklisted_plugins: [],
bosh_service_url: undefined,
connection_options: {}, connection_options: {},
credentials_url: null, // URL from where login credentials can be fetched credentials_url: null, // URL from where login credentials can be fetched
csi_waiting_time: 0, // Support for XEP-0352. Seconds before client is considered idle and CSI is sent out. csi_waiting_time: 0, // Support for XEP-0352. Seconds before client is considered idle and CSI is sent out.
@ -201,10 +221,9 @@
jid: undefined, jid: undefined,
keepalive: false, keepalive: false,
locked_domain: undefined, locked_domain: undefined,
message_carbons: false, // Support for XEP-280 message_carbons: false,
message_storage: 'session', message_storage: 'session',
password: undefined, password: undefined,
prebind: false, // XXX: Deprecated, use "authentication" instead.
prebind_url: null, prebind_url: null,
rid: undefined, rid: undefined,
roster_groups: false, roster_groups: false,
@ -212,8 +231,9 @@
sid: undefined, sid: undefined,
storage: 'session', storage: 'session',
strict_plugin_dependencies: false, strict_plugin_dependencies: false,
synchronize_availability: true, // Set to false to not sync with other clients or with resource name of the particular client that it should synchronize with synchronize_availability: true,
websocket_url: undefined, websocket_url: undefined,
whitelisted_plugins: [],
xhr_custom_status: false, xhr_custom_status: false,
xhr_custom_status_url: '', xhr_custom_status_url: '',
}; };
@ -1973,10 +1993,13 @@
// in any case. // in any case.
_converse.pluggable.initialized_plugins = []; _converse.pluggable.initialized_plugins = [];
var whitelist = _converse.core_plugins.concat(_converse.whitelisted_plugins);
_converse.pluggable.initializePlugins({ _converse.pluggable.initializePlugins({
'updateSettings': updateSettings, 'updateSettings': updateSettings,
'_converse': _converse '_converse': _converse
}); }, whitelist, _converse.blacklisted_plugins);
_converse.emit('pluginsInitialized'); _converse.emit('pluginsInitialized');
_converse._initialize(); _converse._initialize();
_converse.registerGlobalEventHandlers(); _converse.registerGlobalEventHandlers();

View File

@ -30,7 +30,7 @@
b64_sha1 = converse.env.b64_sha1, b64_sha1 = converse.env.b64_sha1,
_ = converse.env._; _ = converse.env._;
converse.plugins.add('rosterview', { converse.plugins.add('converse-rosterview', {
overrides: { overrides: {
// Overrides mentioned here will be picked up by converse.js's // Overrides mentioned here will be picked up by converse.js's