mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-13 10:30:16 +00:00
backups: Add a notification to suggest users to enable schedules
Tests performed: - Ensure that backups module is setup from version zero by deleting entry in DB. Start FreedomBox. Observe the notification comes up. - Dismiss button dismiss the notification. - Go to button takes us to the backups module. - Incrementing the version number of the backups app does not show the notification again. - Starting with old code, the notification show up when FreedomBox is run. Incrementing the version number of the backups app after that does not show the notification again. - Enable a schedule and the notification should be dismissed. Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
eb526275c7
commit
d4e9e7a965
@ -12,6 +12,7 @@ import re
|
||||
import paramiko
|
||||
from django.utils.text import get_valid_filename
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils.translation import ugettext_noop
|
||||
|
||||
from plinth import actions
|
||||
from plinth import app as app_module
|
||||
@ -21,7 +22,7 @@ from . import api
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
version = 2
|
||||
version = 3
|
||||
|
||||
is_essential = True
|
||||
|
||||
@ -73,6 +74,10 @@ def setup(helper, old_version=None):
|
||||
['setup', '--path', repository.RootBorgRepository.PATH])
|
||||
helper.call('post', app.enable)
|
||||
|
||||
# First time setup or upgrading from older versions.
|
||||
if old_version <= 2:
|
||||
_show_schedule_setup_notification()
|
||||
|
||||
|
||||
def _backup_handler(packet, encryption_passphrase=None):
|
||||
"""Performs backup operation on packet."""
|
||||
@ -181,3 +186,41 @@ def split_path(path):
|
||||
|
||||
"""
|
||||
return re.findall(r'^(.*)@([^/]*):(.*)$', path)[0]
|
||||
|
||||
|
||||
def _show_schedule_setup_notification():
|
||||
"""Show a notification hinting to setup a remote backup schedule."""
|
||||
from plinth.notification import Notification
|
||||
message = ugettext_noop(
|
||||
'Enable an automatic backup schedule for data safety. Prefer an '
|
||||
'encrypted remote backup location or an extra attached disk.')
|
||||
data = {
|
||||
'app_name': 'translate:' + ugettext_noop('Backups'),
|
||||
'app_icon': 'fa-files-o'
|
||||
}
|
||||
title = ugettext_noop('Enable a Backup Schedule')
|
||||
actions_ = [{
|
||||
'type': 'link',
|
||||
'class': 'primary',
|
||||
'text': ugettext_noop('Go to {app_name}'),
|
||||
'url': 'backups:index'
|
||||
}, {
|
||||
'type': 'dismiss'
|
||||
}]
|
||||
Notification.update_or_create(id='backups-remote-schedule',
|
||||
app_id='backups', severity='info',
|
||||
title=title, message=message,
|
||||
actions=actions_, data=data, group='admin')
|
||||
|
||||
|
||||
def on_schedule_save(repository):
|
||||
"""Dismiss notification. Called when repository's schedule is updated."""
|
||||
if not repository.schedule.enabled:
|
||||
return
|
||||
|
||||
from plinth.notification import Notification
|
||||
try:
|
||||
note = Notification.get('backups-remote-schedule')
|
||||
note.dismiss()
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
@ -93,6 +93,7 @@ class ScheduleView(SuccessMessageMixin, FormView):
|
||||
schedule.unselected_apps = unselected_apps
|
||||
|
||||
repository.save()
|
||||
backups.on_schedule_save(repository)
|
||||
return super().form_valid(form)
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user