upgrades: Show notification to remind user to run updates manually

- This is needed as we don't have software updates step during first setup
anymore.

Tests:

- Trigger first setup by removing /var/lib/plinth/plinth.sqlite3 and re-running
the service. After completing the setup, a notification is shown with correct
severity, title, app icon, message and options. Dismiss remove the
notifications. 'Go to Software Updates' takes us to updates app.

- After dismissing the notification, re-running the service does not show
notification again.

- Increasing the app version number also does not show notification again.

- Re-running the app setup does not show notification again.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Veiko Aasa <veiko17@disroot.org>
This commit is contained in:
Sunil Mohan Adapa 2024-10-07 11:09:30 -07:00 committed by Veiko Aasa
parent ed3363105a
commit 7033b7cf1e
No known key found for this signature in database
GPG Key ID: 478539CAE680674E

View File

@ -132,6 +132,31 @@ class UpgradesApp(app_module.App):
group='admin')
note.dismiss(should_dismiss=dismiss)
def _show_first_manual_update_notification(self):
"""After first setup, show notification to manually run updates."""
from plinth.notification import Notification
title = gettext_noop('Run software update manually')
message = gettext_noop(
'Automatic software update runs daily by default. For the first '
'time, manually run it now.')
data = {
'app_name': 'translate:' + gettext_noop('Software Update'),
'app_icon': 'fa-refresh'
}
actions = [{
'type': 'link',
'class': 'primary',
'text': gettext_noop('Go to {app_name}'),
'url': 'upgrades:index'
}, {
'type': 'dismiss'
}]
Notification.update_or_create(id='upgrades-first-manual-update',
app_id='upgrades', severity='info',
title=title, message=message,
actions=actions, data=data,
group='admin', dismissed=False)
def setup(self, old_version):
"""Install and configure the app."""
super().setup(old_version)
@ -140,6 +165,10 @@ class UpgradesApp(app_module.App):
if not old_version and not cfg.develop:
privileged.enable_auto()
# Request user to run manual update as a one time activity
if not old_version:
self._show_first_manual_update_notification()
# Update apt preferences whenever on first install and on version
# increment.
privileged.setup()