From cae22bfc7609d00f987e679cf6d048873d268d84 Mon Sep 17 00:00:00 2001 From: Adam Tauber Date: Tue, 10 Mar 2015 20:44:02 +0100 Subject: [PATCH] [enh] per user plugin switch --- searx/plugins/__init__.py | 4 ++-- searx/webapp.py | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/searx/plugins/__init__.py b/searx/plugins/__init__.py index b40d2ee89..9c9c52ae4 100644 --- a/searx/plugins/__init__.py +++ b/searx/plugins/__init__.py @@ -20,7 +20,7 @@ class PluginStore(): self.plugins = [] def __iter__(self): - for plugin in plugins: + for plugin in self.plugins: yield plugin def register(self, *plugins): @@ -33,7 +33,7 @@ class PluginStore(): def call(self, plugin_type, request, *args, **kwargs): ret = True - for plugin in self.plugins: + for plugin in request.user_plugins: if hasattr(plugin, plugin_type): ret = getattr(plugin, plugin_type)(request, *args, **kwargs) if not ret: diff --git a/searx/webapp.py b/searx/webapp.py index f5d779f15..78c0c71f1 100644 --- a/searx/webapp.py +++ b/searx/webapp.py @@ -305,6 +305,18 @@ def render(template_name, override_theme=None, **kwargs): '{}/{}'.format(kwargs['theme'], template_name), **kwargs) +@app.before_request +def pre_request(): + + request.user_plugins = [] + allowed_plugins = request.cookies.get('allowed_plugins', '').split(',') + disabled_plugins = request.cookies.get('disabled_plugins', '').split(',') + for plugin in plugins: + if ((plugin.default_on and plugin.name not in disabled_plugins) + or plugin.name in allowed_plugins): + request.user_plugins.append(plugin) + + @app.route('/search', methods=['GET', 'POST']) @app.route('/', methods=['GET', 'POST']) def index():