first_boot: Fix various issues and refactor

- Fix major regression so that steps can submitted multiple times in
  case of errors.

- Don't serve the welcome page (and other pages) only once.  Show it
  until action is an taken.  This does not apply to the final step.

- Eliminate all coupling of one first boot step on another.

- Move first boot helper methods to __init__.py instead of middleware as
  it is more generic than middleware.

- Implement caching the first boot state to avoid an SQL query on every
  page load.  The down side is that if first boot state is modified in
  the backend DB outside Plinth, Plinth will need to be restarted to
  catch the modified value.

- Mark some methods as private.

- Refactor middleware code for slightly more simplicity.

- Don't show sidebar in pagekite first boot step.  Set width like other
  pages.
This commit is contained in:
Sunil Mohan Adapa authored and James Valleroy committed 2016-12-04 15:24:48 -05:00
1 parent 6cce89ed68
commit f457a0bdd3
9 files changed
+227 -157

No files matched your search

+91
View File
@@ -19,6 +19,11 @@
Plinth module for first boot wizard
"""
from django.urls import reverse
import operator
from plinth import module_loader
version = 1
is_essential = True
@@ -35,3 +40,89 @@ first_boot_steps = [
'order': 10
}
]
_all_first_boot_steps = None
_is_completed = None
def is_firstboot_url(path):
"""Return whether a path is a firstboot step URL.
:param path: path of url to be checked
:return: true if its a first boot URL false otherwise
"""
for step in _get_steps():
if path.startswith(reverse(step['url'])):
return True
return False
def _get_steps():
"""Return list of all firstboot steps."""
global _all_first_boot_steps
if _all_first_boot_steps is not None:
return _all_first_boot_steps
steps = []
modules = module_loader.loaded_modules
for module_object in modules.values():
if getattr(module_object, 'first_boot_steps', None):
steps.extend(module_object.first_boot_steps)
_all_first_boot_steps = sorted(steps, key=operator.itemgetter('order'))
return _all_first_boot_steps
def next_step():
"""Return the resolved next first boot step URL required to go to.
If there are no more step remaining, return index page.
"""
return next_step_or_none() or 'index'
def next_step_or_none():
"""Return the next first boot step required to run.
If there are no more step remaining, return None.
"""
from plinth import kvstore
for step in _get_steps():
done = kvstore.get_default(step['id'], 0)
if not done:
return step.get('url')
def mark_step_done(id):
"""Marks the status of a first boot step as done.
:param id: id of the firstboot step
"""
from plinth import kvstore
kvstore.set(id, 1)
if not next_step_or_none():
kvstore.set('setup_state', 1)
def is_completed():
"""Return whether first boot process is completed."""
from plinth import kvstore
global _is_completed
if _is_completed is None:
_is_completed = kvstore.get_default('setup_state', 0)
return _is_completed
def set_completed():
"""Set the first boot process as completed."""
from plinth import kvstore
global _is_completed
_is_completed = True
kvstore.set('setup_state', 1)