mirror of
https://github.com/searxng/searxng
synced 2024-01-01 18:24:07 +00:00
[enh] per user plugin switch
This commit is contained in:
parent
00cc4dcbf4
commit
cae22bfc76
@ -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:
|
||||
|
@ -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():
|
||||
|
Loading…
Reference in New Issue
Block a user