mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-28 08:03:36 +00:00
- Identify Freedbombox admin who installed the app to be zoph admin. - Implement backup and restore. - Photos directory should remain at /var/lib/zoph, for proper operation of backups. - There remains an issue that the App is enabled before it is configured but will not work correctly until configuration. - OpenStreetMap mapping is enabled. These should be configurable before installation. - Add initial forms.py and views.py to Zoph app, however these are currently unused as urls.py does not invoke the view. When the view is not invoked the Zoph App installs, with single signon, currently as the first LDAP user, rather than the plinth user. - The first user's preferences are not set, and need to be manually set to avoid other errors. * Sunil's changes - Squash commits and re-split them. - Drop documentation as it will be auto populated from wiki later. - Remove outdated validation code from manifest. - Drop some dead code. - Don't send MySQL password over command line for improved security. Instead rely on Unix authentication of root user similar to backup/restore process. - Use JSON for exchanging configuration dump to avoid encoding errors. - Add username validation to avoid a potential SQL injection. - Update description for neural tone and brevity. Add information about how user accounts work in FreedomBox - Fix functional tests. - Drop all code related to changing photos path until it is ready. - Update URL from /zoph to /zoph/ to avoid another redirect. - Fix disabling the app. - Use icon that Zoph uses for favicon as logo. Update copyright file. - Fix spelling unzip. - Minor refactors. Run yapf and isort. - Use subprocess.run() instead of os.popen() everywhere for better security with argument parsing. - Enable OpenStreetMap by default. User have a choice to disable it before using the app. Add label to explain privacy concerns. - Fix dropping database by using --force argument. - Cleanup enabling the app to not enable the app when updating configuration. - Use AppView's default template instead of overriding. - Update functional tests to just check if the app is enabled/disabled as expected. Checking that Zoph site is available will require reliable handling of admin user. Signed-off-by: John Lines <john@paladyn.org> Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
75 lines
2.4 KiB
Python
75 lines
2.4 KiB
Python
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
"""
|
|
FreedomBox app for configuring Zoph photo organiser.
|
|
"""
|
|
|
|
import logging
|
|
|
|
from django.contrib import messages
|
|
from django.http import HttpResponseRedirect
|
|
from django.shortcuts import redirect
|
|
from django.urls import reverse_lazy
|
|
from django.utils.translation import ugettext as _
|
|
from django.views.generic import TemplateView
|
|
|
|
from plinth import views
|
|
from plinth.errors import ActionError
|
|
from plinth.modules import zoph
|
|
|
|
from .forms import ZophForm
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class SetupView(TemplateView):
|
|
"""Show zoph setup page."""
|
|
template_name = 'zoph-pre-setup.html'
|
|
success_url = reverse_lazy('zoph:index')
|
|
|
|
def get_context_data(self, *args, **kwargs):
|
|
"""Provide context data to the template."""
|
|
context = super().get_context_data(**kwargs)
|
|
context['title'] = zoph.app.info.name
|
|
context['app_info'] = zoph.app.info
|
|
return context
|
|
|
|
def post(self, _request, *args, **kwargs):
|
|
"""Handle form submission."""
|
|
admin_user = self.request.user.get_username()
|
|
zoph.set_configuration(admin_user=admin_user)
|
|
return HttpResponseRedirect(reverse_lazy('zoph:index'))
|
|
|
|
|
|
class ZophAppView(views.AppView):
|
|
"""App configuration page."""
|
|
form_class = ZophForm
|
|
app_id = 'zoph'
|
|
|
|
def dispatch(self, request, *args, **kwargs):
|
|
"""Redirect to setup page if setup is not done yet."""
|
|
if not zoph.is_configured():
|
|
return redirect('zoph:setup')
|
|
|
|
return super().dispatch(request, *args, **kwargs)
|
|
|
|
def get_initial(self):
|
|
"""Get the current settings from Zoph."""
|
|
status = super().get_initial()
|
|
config = zoph.get_configuration()
|
|
status['enable_osm'] = (config['maps.provider'] == 'osm')
|
|
return status
|
|
|
|
def form_valid(self, form):
|
|
"""Apply the changes submitted in the form."""
|
|
old_status = form.initial
|
|
new_status = form.cleaned_data
|
|
if old_status['enable_osm'] != new_status['enable_osm']:
|
|
try:
|
|
zoph.set_configuration(enable_osm=new_status['enable_osm'])
|
|
messages.success(self.request, _('Configuration updated.'))
|
|
except ActionError:
|
|
messages.error(self.request,
|
|
_('An error occurred during configuration.'))
|
|
|
|
return super().form_valid(form)
|