mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
backups: When restoring, only list apps included in backup
Signed-off-by: James Valleroy <jvalleroy@mailbox.org> Reviewed-by: Joseph Nuthalapati <njoseph@thoughtworks.com>
This commit is contained in:
1 parent
2a9a220770
commit
481a299250
4 files changed
+60
-4
No files matched your search
@@ -140,7 +140,7 @@ def get_export_files():
|
||||
return export_files
|
||||
|
||||
|
||||
def _find_exported_archive(disk_label, archive_name):
|
||||
def find_exported_archive(disk_label, archive_name):
|
||||
"""Return the full path for the exported archive file."""
|
||||
path = None
|
||||
locations = get_export_locations()
|
||||
@@ -155,9 +155,16 @@ def _find_exported_archive(disk_label, archive_name):
|
||||
return path
|
||||
|
||||
|
||||
def get_export_apps(filename):
|
||||
"""Get list of apps included in exported archive file."""
|
||||
output = actions.superuser_run(
|
||||
'backups', ['get-export-apps', '--filename', filename])
|
||||
return output.splitlines()
|
||||
|
||||
|
||||
def restore_exported(label, name, apps=None):
|
||||
"""Restore files from exported backup archive."""
|
||||
filename = _find_exported_archive(label, name)
|
||||
filename = find_exported_archive(label, name)
|
||||
if filename:
|
||||
# TODO: Use backups API.
|
||||
actions.superuser_run(
|
||||
|
||||
@@ -67,9 +67,8 @@ class RestoreForm(forms.Form):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
"""Initialize the form with selectable apps."""
|
||||
apps = kwargs.pop('apps')
|
||||
super().__init__(*args, **kwargs)
|
||||
apps = _list_of_all_apps_for_backup()
|
||||
# TODO: Only list apps included in the backup file.
|
||||
self.fields['selected_apps'].choices = [
|
||||
(app[0], app[1].name) for app in apps]
|
||||
self.fields['selected_apps'].initial = [app[0] for app in apps]
|
||||
@@ -30,6 +30,7 @@ from django.views.generic import FormView, TemplateView
|
||||
from urllib.parse import unquote
|
||||
|
||||
from plinth.modules import backups
|
||||
from . import find_exported_archive, get_export_apps
|
||||
from .backups import _list_of_all_apps_for_backup
|
||||
from .forms import CreateArchiveForm, ExportArchiveForm, RestoreForm
|
||||
|
||||
@@ -133,6 +134,31 @@ class RestoreView(SuccessMessageMixin, FormView):
|
||||
success_url = reverse_lazy('backups:index')
|
||||
success_message = _('Restored files from backup.')
|
||||
|
||||
def collect_data(self, label, name):
|
||||
"""Save some data used to instantiate the form."""
|
||||
self.label = unquote(label)
|
||||
self.name = unquote(name)
|
||||
self.filename = find_exported_archive(self.label, self.name)
|
||||
self.installed_apps = _list_of_all_apps_for_backup()
|
||||
self.included_apps = get_export_apps(self.filename)
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
"""Save request parameters for later."""
|
||||
self.collect_data(kwargs['label'], kwargs['name'])
|
||||
return super().get(request, *args, **kwargs)
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
"""Save request parameters for later."""
|
||||
self.collect_data(kwargs['label'], kwargs['name'])
|
||||
return super().post(request, *args, **kwargs)
|
||||
|
||||
def get_form_kwargs(self):
|
||||
"""Pass additional keyword args for instantiating the form."""
|
||||
kwargs = super().get_form_kwargs()
|
||||
kwargs['apps'] = [
|
||||
x for x in self.installed_apps if x[0] in self.included_apps]
|
||||
return kwargs
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
"""Return additional context for rendering the template."""
|
||||
context = super().get_context_data(**kwargs)
|
||||
|
||||
Reference in new issue
Block a user