Revert "Resolving unused settings bug when plugin is disabled"

This reverts commit c829139732.
This commit is contained in:
kobelb 2017-02-08 17:16:45 -05:00
parent c829139732
commit 81538f444d
3 changed files with 35 additions and 0 deletions

View file

@ -238,5 +238,24 @@ describe('lib/config/config', function () {
});
});
describe('#removeSchema(key)', function () {
it('should completely remove the key', function () {
const config = new Config(Joi.object().keys({
a: Joi.number().default(1)
}));
expect(config.get('a')).to.be(1);
config.removeSchema('a');
expect(() => config.get('a')).to.throwException('Unknown config key');
});
it('only removes existing keys', function () {
const config = new Config(Joi.object());
expect(() => config.removeSchema('b')).to.throwException('Unknown schema');
});
});
});
});

View file

@ -42,6 +42,16 @@ module.exports = class Config {
this.set(key, settings);
}
removeSchema(key) {
if (!_.has(this[schemaExts], key)) {
throw new TypeError(`Unknown schema key: ${key}`);
}
this[schema] = null;
unset(this[schemaExts], key);
unset(this[vals], key);
}
resetTo(obj) {
this._commit(obj);
}

View file

@ -24,6 +24,11 @@ async function addPluginConfig(pluginCollection, plugin) {
config.extendSchema(configSchema, transformedPluginSettings, plugin.configPrefix);
}
function removePluginConfig(pluginCollection, plugin) {
const { config } = pluginCollection.kbnServer;
config.removeSchema(plugin.configPrefix);
}
module.exports = class Plugins extends Collection {
constructor(kbnServer) {
@ -55,6 +60,7 @@ module.exports = class Plugins extends Collection {
}
async disable(plugin) {
removePluginConfig(this, plugin);
this.delete(plugin);
}