can i control the plugin enabled status in other plugin?
If the plugin you're trying to disable is an app with an icon in the sidebar, you can also simply remove the item from the navLink
, like so:
module.exports = function (kibana) {
var AppToDisable = 'myApp';
return new kibana.Plugin({
require: [AppToDisable],
init: function (server, options) {
kibana.uiExports.navLinks.inOrder.forEach((navLink) => {
if (navLink.title === AppToDisable) {
kibana.uiExports.navLinks.delete(navLink);
}
});
}
});
}
You should also be able to delete apps with kibana.uiExports.apps.delete
, like so:
return new kibana.Plugin({
require: ['myApp'],
init: function (server, options) {
kibana.uiExports.apps.delete('myApp');
}
});
Note that I'm using the require
property to make sure the app has been loaded in both cases.
I haven't actually tried to do this myself, but it looks like ought to work. Also, this is all true for Kibana 5, but it doesn't look like the navLinks
stuff is in Kibana 4.
thanks
"kibana.uiExports.apps.delete" , this method dose not work.
first one works
yeah,but you can still access the app by typing the url in browser manually.
make some workaround by intercepting the url.
how did you do that?
do you have email?
One of the things we've done internally is to add some kind of validation in the plugin init step, which will set a variable (usually exposed on the server
instance) that we can just check when we go to set up the routes.
module.exports = function (kibana) {
var AppToDisable = 'myApp';
return new kibana.Plugin({
require: [AppToDisable],
init: function (server, options) {
server.expose('isDisabled', true);
kibana.uiExports.navLinks.inOrder.forEach((navLink) => {
if (navLink.title === AppToDisable) {
kibana.uiExports.navLinks.delete(navLink);
}
});
}
});
}
Then in your route handler, just add a conditional based on server.plugins.<myplugin>.isDisabled
, and don't set up the routes if it's true.
This, of course, works if you are trying to make the plugin disable itself, not so much if you are trying to make one plugin disable another, unless you start coupling plugins to other plugs (we've done this as well - using some universal setup plugin that controls which other plugins are disabled). You might be able to use hapi's preRoute hook (or whatever it's actually called) to abort early too, but I haven't tried this personally.
@whoami if you could share your solution here, even in summary, it would be helpful for others searching for a solution. Cheers!
YES, kibana is based on hapi , so we can use hapi's prehook to do this, and i have tried, it works;
in kibana, plugin A's route is like /app/{A}/..., so we can prehook the url in node layer. and i use PostAuth finish this