mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-06-03 10:50:20 +00:00
searx: Preserve public_access setting
- Preserve the setting during enable/disable as well as during backup/restore. - Show setting as disabled when application is disabled but restore user's original preference value on enable. - Add functional test for this. Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
2d85b61199
commit
7e1e5182cc
@ -28,6 +28,8 @@ import augeas
|
||||
import yaml
|
||||
|
||||
from plinth import action_utils
|
||||
from plinth.modules.searx import is_public_access_enabled
|
||||
from plinth.modules.searx.manifest import PUBLIC_ACCESS_SETTING_FILE
|
||||
from plinth.utils import gunzip
|
||||
|
||||
SETTINGS_FILE = '/etc/searx/settings.yml'
|
||||
@ -160,7 +162,8 @@ def subcommand_enable(_):
|
||||
"""Enable web configuration and reload."""
|
||||
action_utils.uwsgi_enable('searx')
|
||||
action_utils.webserver_enable('searx-freedombox')
|
||||
action_utils.webserver_enable('searx-freedombox-auth')
|
||||
if not is_public_access_enabled():
|
||||
action_utils.webserver_enable('searx-freedombox-auth')
|
||||
|
||||
|
||||
def subcommand_disable(_):
|
||||
@ -172,11 +175,13 @@ def subcommand_disable(_):
|
||||
|
||||
def subcommand_enable_public_access(_):
|
||||
"""Enable public access to the SearX application."""
|
||||
open(PUBLIC_ACCESS_SETTING_FILE, 'w').close()
|
||||
action_utils.webserver_disable('searx-freedombox-auth')
|
||||
|
||||
|
||||
def subcommand_disable_public_access(_):
|
||||
"""Disable public access to the SearX application."""
|
||||
os.remove(PUBLIC_ACCESS_SETTING_FILE)
|
||||
action_utils.webserver_enable('searx-freedombox-auth')
|
||||
|
||||
|
||||
|
||||
@ -53,3 +53,12 @@ Scenario: Disable public access
|
||||
Then searx app should not be visible on the front page
|
||||
And the searx site should not be available
|
||||
|
||||
Scenario: Preserve public access setting
|
||||
Given the searx application is enabled
|
||||
And I enable public access in searx
|
||||
When I disable the searx application
|
||||
And I enable the searx application
|
||||
And I log out
|
||||
Then searx app should be visible on the front page
|
||||
And the searx site should be available
|
||||
|
||||
|
||||
@ -443,6 +443,6 @@ def app_visible_on_front_page(browser, app_name):
|
||||
|
||||
@then(
|
||||
parsers.parse('{app_name:w} app should not be visible on the front page'))
|
||||
def app_visible_on_front_page(browser, app_name):
|
||||
def app_not_visible_on_front_page(browser, app_name):
|
||||
shortcuts = application.find_on_front_page(browser, app_name)
|
||||
assert len(shortcuts) == 0
|
||||
|
||||
@ -29,6 +29,7 @@ def logged_in_user(browser):
|
||||
config['DEFAULT']['password'])
|
||||
|
||||
|
||||
@when("I log out")
|
||||
@given("I'm a logged out user")
|
||||
def logged_out_user(browser):
|
||||
browser.visit(default_url + '/plinth/accounts/logout/')
|
||||
|
||||
@ -18,6 +18,8 @@
|
||||
FreedomBox app to configure Searx.
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from plinth import action_utils, actions
|
||||
@ -26,7 +28,7 @@ from plinth import frontpage, menu
|
||||
from plinth import service as service_module
|
||||
from plinth.modules.users import register_group
|
||||
|
||||
from .manifest import backup, clients
|
||||
from .manifest import PUBLIC_ACCESS_SETTING_FILE, backup, clients
|
||||
|
||||
clients = clients
|
||||
|
||||
@ -126,7 +128,7 @@ def get_safe_search_setting():
|
||||
|
||||
def is_public_access_enabled():
|
||||
"""Check whether public access is enabled for Searx."""
|
||||
return not action_utils.webserver_is_enabled('searx-freedombox-auth')
|
||||
return os.path.exists(PUBLIC_ACCESS_SETTING_FILE)
|
||||
|
||||
|
||||
def is_enabled():
|
||||
@ -156,3 +158,15 @@ def diagnose():
|
||||
check_certificate=False))
|
||||
|
||||
return results
|
||||
|
||||
|
||||
def enable_public_access():
|
||||
"""Allow Searx app to be accessed by anyone with access."""
|
||||
actions.superuser_run('searx', ['enable-public-access'])
|
||||
add_shortcut()
|
||||
|
||||
|
||||
def disable_public_access():
|
||||
"""Allow Searx app to be accessed by logged-in users only."""
|
||||
actions.superuser_run('searx', ['disable-public-access'])
|
||||
add_shortcut()
|
||||
|
||||
@ -30,7 +30,8 @@ class SearxForm(ServiceForm):
|
||||
label=_('Safe Search'), help_text=_(
|
||||
'Select the default family filter to apply to your search results.'
|
||||
), choices=((0, _('None')), (1, _('Moderate')), (2, _('Strict'))))
|
||||
|
||||
public_access = forms.BooleanField(
|
||||
label=_('Public Access'), help_text=_(
|
||||
label=_('Allow Public Access'), help_text=_(
|
||||
'Allow this application to be used by anyone who can reach it.'),
|
||||
required=False)
|
||||
|
||||
@ -28,4 +28,6 @@ clients = validate([{
|
||||
}]
|
||||
}])
|
||||
|
||||
backup = validate_backup({})
|
||||
PUBLIC_ACCESS_SETTING_FILE = '/etc/searx/allow_public_access'
|
||||
|
||||
backup = validate_backup({'config': {'files': [PUBLIC_ACCESS_SETTING_FILE]}})
|
||||
|
||||
@ -23,8 +23,9 @@ from django.utils.translation import ugettext as _
|
||||
|
||||
from plinth import actions, views
|
||||
from plinth.errors import ActionError
|
||||
from plinth.modules.searx import (add_shortcut, clients, description,
|
||||
get_safe_search_setting,
|
||||
from plinth.modules.searx import (clients, description, disable_public_access,
|
||||
enable_public_access,
|
||||
get_safe_search_setting, is_enabled,
|
||||
is_public_access_enabled, manual_page)
|
||||
|
||||
from .forms import SearxForm
|
||||
@ -44,7 +45,7 @@ class SearxServiceView(views.ServiceView):
|
||||
"""Return the status of the service to fill in the form."""
|
||||
initial = super().get_initial()
|
||||
initial['safe_search'] = get_safe_search_setting()
|
||||
initial['public_access'] = is_public_access_enabled()
|
||||
initial['public_access'] = is_public_access_enabled() and is_enabled()
|
||||
return initial
|
||||
|
||||
def form_valid(self, form):
|
||||
@ -57,19 +58,18 @@ class SearxServiceView(views.ServiceView):
|
||||
actions.superuser_run(
|
||||
'searx', ['set-safe-search', form_data['safe_search']])
|
||||
messages.success(self.request, _('Configuration updated.'))
|
||||
except ActionError as e:
|
||||
except ActionError:
|
||||
messages.error(self.request,
|
||||
_('An error occurred during configuration.'))
|
||||
|
||||
if old_data['public_access'] != form_data['public_access']:
|
||||
try:
|
||||
if form_data['public_access']:
|
||||
actions.superuser_run('searx', ['enable-public-access'])
|
||||
enable_public_access()
|
||||
else:
|
||||
actions.superuser_run('searx', ['disable-public-access'])
|
||||
add_shortcut()
|
||||
disable_public_access()
|
||||
messages.success(self.request, _('Configuration updated.'))
|
||||
except ActionError as e:
|
||||
except ActionError:
|
||||
messages.error(self.request,
|
||||
_('An error occurred during configuration.'))
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user