From 4826f703430b80ef54a313a0e19a32966524eed8 Mon Sep 17 00:00:00 2001 From: Joseph Nuthalapati Date: Mon, 22 Jan 2018 11:51:37 +0530 Subject: [PATCH] firstboot: Fix caching issue in collecting first_boot steps - Created a django singal to indicate that a setup happened - Clearing the cached list of firstboot_steps each time the above signal is sent Closes #1193. Signed-off-by: Joseph Nuthalapati Reviewed-by: Sunil Mohan Adapa --- plinth/modules/first_boot/__init__.py | 16 ++++++++++++++-- plinth/modules/pagekite/views.py | 5 ++--- plinth/setup.py | 9 +++++++-- plinth/signals.py | 1 + 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/plinth/modules/first_boot/__init__.py b/plinth/modules/first_boot/__init__.py index c9648c008..023a787f0 100644 --- a/plinth/modules/first_boot/__init__.py +++ b/plinth/modules/first_boot/__init__.py @@ -14,15 +14,16 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . # - """ Plinth module for first boot wizard """ -from django.urls import reverse import operator +from django.urls import reverse + from plinth import module_loader +from plinth.signals import post_setup version = 1 @@ -47,6 +48,17 @@ _all_first_boot_steps = None _is_completed = None +def init(): + """Initialize the first boot module.""" + post_setup.connect(_clear_first_boot_steps) + + +def _clear_first_boot_steps(sender, module_name, **kwargs): + """Flush the cache of first boot steps so it is recreated.""" + global _all_first_boot_steps + _all_first_boot_steps = None + + def is_firstboot_url(path): """Return whether a path is a firstboot step URL. diff --git a/plinth/modules/pagekite/views.py b/plinth/modules/pagekite/views.py index 0f3ddc612..7753a1b94 100644 --- a/plinth/modules/pagekite/views.py +++ b/plinth/modules/pagekite/views.py @@ -141,10 +141,9 @@ class FirstBootView(FormView): form_class = FirstBootForm def get(self, request, *args, **kwargs): - """Skip if this first boot step if it is not relavent.""" + """Skip this first boot step if it is not relevant.""" if not cfg.danube_edition: - first_boot.mark_step_done('pagekite_firstboot') - return HttpResponseRedirect(reverse(first_boot.next_step())) + return first_boot_skip(request) return super().get(request, *args, **kwargs) diff --git a/plinth/setup.py b/plinth/setup.py index fa8862d41..7dae8f5bf 100644 --- a/plinth/setup.py +++ b/plinth/setup.py @@ -18,14 +18,17 @@ Plinth module with utilites for performing application setup operations. """ -import apt import logging import threading import time +import apt + +import plinth +from plinth.signals import post_setup + from . import package from .errors import PackageNotInstalledError -import plinth logger = logging.getLogger(__name__) @@ -91,6 +94,8 @@ class Helper(object): raise exception else: self.set_setup_version(self.module.version) + post_setup.send_robust(sender=self.__class__, + module_name=self.module_name) finally: self.is_finished = True self.current_operation = None diff --git a/plinth/signals.py b/plinth/signals.py index f6473f9e2..47b34e13a 100644 --- a/plinth/signals.py +++ b/plinth/signals.py @@ -25,6 +25,7 @@ from django.dispatch import Signal service_enabled = Signal(providing_args=['service_id', 'enabled']) pre_module_loading = Signal() post_module_loading = Signal() +post_setup = Signal(providing_args=['module_name']) pre_hostname_change = Signal(providing_args=['old_hostname', 'new_hostname']) post_hostname_change = Signal(providing_args=['old_hostname', 'new_hostname']) domainname_change = Signal(providing_args=['old_domainname', 'new_domainname'])