networks: Fixes for networks wizards

- Make first wizard steps for router configuration and Internet connection type
private. Since they run after the admin user page, the steps can run for logged
in users.

- Add option to the Internet connection type wizard, to let the user say that
they don't know the type. This allows them to have a stress-free first setup
experience. The option can act as if they have don't have public IP address at
all. This is an extension of the proposed user experience.

- Implement class based views for simplicity.

- Update various IDs for consistency (even though other IDs in the networks
module don't conform).

- Iron out inconsistent terminology. Setup vs Configuration, Help vs. Wizard,
etc.

Tests performed:

- Run first boot wizard from the beginning. Notice that both the wizard steps
appear properly after the user login step (without permission denied problems).
When not logged in, accessing the wizard steps with URL should redirect to login
page.

- During first boot wizard, select 'Skip this step' in both the steps after
selecting non-default options. Values set should be default options as confirmed
from networks page.

- During first boot wizard, select non-default values, the values should be set
properly as confirmed from networks page.

- From the networks page select each value of the wizard. The option should get
saved properly.

- In case of Internet connection type, when the wizard values changes, the
networks page should reflect the value properly. This should also show properly
after skipping the step during first boot.

- During first boot, the default value for Internet connection type should be 'I
don't know' and router configuration should be 'Not configured'.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Nektarios Katakis <iam@nektarioskatakis.xyz>
This commit is contained in:
Sunil Mohan Adapa 2020-02-24 19:37:18 -05:00 committed by Nektarios Katakis
parent 276893b302
commit b5f6821fd7
No known key found for this signature in database
GPG Key ID: 9CA475E691EBCF76
8 changed files with 97 additions and 95 deletions

View File

@ -21,12 +21,12 @@ managed_packages = ['network-manager', 'batctl']
first_boot_steps = [
{
'id': 'internet_connectivity_type_wizard',
'url': 'networks:firstboot_internet_connection_type',
'url': 'networks:internet-connection-type-first-boot',
'order': 3,
},
{
'id': 'router_setup_wizard',
'url': 'networks:firstboot_router_setup',
'url': 'networks:router-configuration-first-boot',
'order': 4,
},
]

View File

@ -334,13 +334,18 @@ class InternetConnectionTypeForm(forms.Form):
'{box_name} provides many workaround solutions but each '
'solution has some limitations.</p>'),
box_name=cfg.box_name, allow_markup=True)),
('unknown',
format_lazy(
_('I do not know the type of connection my ISP provides '
'<p class="help-block">You will be suggested the most '
'conservative actions.</p>'), allow_markup=True)),
],
required=True,
widget=forms.RadioSelect,
)
class RouterConfigurationWizardForm(forms.Form):
class RouterConfigurationForm(forms.Form):
"""Form to suggest how to configure a router.
Suggest depending on wan connectivity/specific setup. The choice will

View File

@ -8,13 +8,14 @@ from django.template.response import TemplateResponse
from django.urls import reverse_lazy
from django.utils.translation import ugettext as _
from django.views.decorators.http import require_POST
from django.views.generic.edit import FormView
from plinth import kvstore, network
from plinth.modules import first_boot, networks
from .forms import (ConnectionTypeSelectForm, EthernetForm, GenericForm,
InternetConnectionTypeForm, PPPoEForm,
RouterConfigurationWizardForm, WifiForm)
RouterConfigurationForm, WifiForm)
logger = logging.getLogger(__name__)
@ -24,7 +25,7 @@ def index(request):
connections = network.get_connection_list()
internet_connection_type = kvstore.get_default(
networks.INTERNET_CONNECTION_TYPE_KEY, None)
networks.INTERNET_CONNECTION_TYPE_KEY, 'unknown')
return TemplateResponse(
request, 'networks_configuration.html', {
'app_id': 'networks',
@ -405,89 +406,79 @@ def delete(request, uuid):
})
def router_configuration_help_page(request):
"""Show the router configuration wizard page/form.
class RouterConfigurationView(FormView):
"""View for router configuration form."""
template_name = 'router_configuration_update.html'
form_class = RouterConfigurationForm
success_url = reverse_lazy('networks:index')
Used both for fistboot step and same networks page.
"""
is_firstboot = True \
if 'firstboot' in request.build_absolute_uri() else False
if request.method == 'POST' and request.POST['router_config']:
form = RouterConfigurationWizardForm(request.POST)
if form.is_valid():
logger.info('Updating router configuration setup with value: %s' %
request.POST['router_config'])
kvstore.set(networks.ROUTER_CONFIGURATION_TYPE_KEY,
request.POST['router_config'])
if is_firstboot:
resp = reverse_lazy(first_boot.next_step())
else:
resp = reverse_lazy('networks:index')
messages.success(request, _('Router configuration type saved.'))
return redirect(resp)
else:
html = 'router_configuration_update.html'
initial = {
def get_initial(self):
"""Return initial data for the form."""
return {
'router_config':
kvstore.get_default(networks.ROUTER_CONFIGURATION_TYPE_KEY,
'not_configured'),
'not_configured')
}
template_kwargs = {
'form': RouterConfigurationWizardForm(initial=initial),
}
if is_firstboot:
html = 'router_configuration_firstboot.html'
# mark step done on firstboot visit to get the next_step
first_boot.mark_step_done('router_setup_wizard')
template_kwargs.update({
'first_boot_next_step': reverse_lazy(first_boot.next_step()),
})
return TemplateResponse(request, html, template_kwargs)
def form_valid(self, form):
"""Save value to DB and redirect."""
type_ = form.cleaned_data['router_config']
logger.info('Updating router configuration: %s', type_)
kvstore.set(networks.ROUTER_CONFIGURATION_TYPE_KEY, type_)
return super().form_valid(form)
def internet_connection_type_help_page(request):
"""Show the internet connection type page.
class RouterConfigurationFirstBootView(RouterConfigurationView):
"""View for router configuration form during first wizard."""
template_name = 'router_configuration_firstboot.html'
Used for first boot step and networks page.
def get_success_url(self):
"""Return the next wizard step after this one."""
return reverse_lazy(first_boot.next_step())
"""
is_firstboot = True \
if 'firstboot' in request.build_absolute_uri() else False
def form_valid(self, form):
"""Mark the first wizard step as done, save value and redirect."""
first_boot.mark_step_done('router_setup_wizard')
if 'skip' in form.data:
return FormView.form_valid(self, form)
if request.method == 'POST' and request.POST['internet_connection_type']:
form = InternetConnectionTypeForm(request.POST)
if form.is_valid():
logger.info('Updating internet connectivity type with value: %s' %
request.POST['internet_connection_type'])
kvstore.set(
networks.INTERNET_CONNECTION_TYPE_KEY,
request.POST['internet_connection_type'],
)
if is_firstboot:
return redirect(reverse_lazy(first_boot.next_step()))
else:
messages.success(request, _('Internet connection type saved.'))
return redirect(reverse_lazy('networks:index'))
else:
html = 'internet_connectivity_type.html'
initial = {
return super().form_valid(form)
class InternetConnectionTypeView(FormView):
"""View for Internet connection type form."""
template_name = 'internet_connectivity_type.html'
form_class = InternetConnectionTypeForm
success_url = reverse_lazy('networks:index')
def get_initial(self):
"""Return initial data for the form."""
return {
'internet_connection_type':
kvstore.get_default(networks.INTERNET_CONNECTION_TYPE_KEY,
None)
'unknown')
}
template_kwargs = {'form': InternetConnectionTypeForm(initial=initial)}
if is_firstboot:
html = 'internet_connectivity_firstboot.html'
# mark step done on firstboot visit to get the next_step
first_boot.mark_step_done('internet_connectivity_type_wizard')
template_kwargs.update({
'first_boot_next_step': reverse_lazy(first_boot.next_step()),
})
def form_valid(self, form):
"""Save value to DB and redirect."""
type_ = form.cleaned_data['internet_connection_type']
logger.info('Updating internet connectivity type: %s', type_)
kvstore.set(networks.INTERNET_CONNECTION_TYPE_KEY, type_)
return super().form_valid(form)
return TemplateResponse(request, html, template_kwargs)
class InternetConnectionTypeFirstBootView(InternetConnectionTypeView):
"""View to show Internet connection type form during first wizard."""
template_name = 'internet_connectivity_firstboot.html'
def get_success_url(self):
"""Return the next wizard step after this one."""
return reverse_lazy(first_boot.next_step())
def form_valid(self, form):
"""Mark the first wizard step as done, save value and redirect."""
first_boot.mark_step_done('internet_connectivity_type_wizard')
if 'skip' in form.data:
return FormView.form_valid(self, form)
return super().form_valid(form)

View File

@ -15,7 +15,9 @@
{{ form|bootstrap }}
<a href='{{ first_boot_next_step }}'>{% trans "Skip this step" %}</a>
<input type="submit" class="btn btn-primary pull-right" value="{% trans "Next" %}"/>
<input type="submit" class="btn btn-link" name="skip"
value="{% trans "Skip this step" %}"/>
<input type="submit" class="btn btn-primary pull-right" name="next"
value="{% trans "Next" %}"/>
</form>
{% endblock %}

View File

@ -27,12 +27,16 @@
{% blocktrans trimmed %}
My ISP provides a public IP address that may change over time.
{% endblocktrans %}
{% else %}
{% elif internet_connectivity_type == "private_ip" %}
{% blocktrans trimmed %}
My ISP does not provide a public IP address.
{% endblocktrans %}
{% else %}
{% blocktrans trimmed %}
I do not know the type of connection my ISP provides.
{% endblocktrans %}
{% endif %}
<a href="{% url 'networks:internet_connection_type_setup' %}" class="btn btn-default"
<a href="{% url 'networks:internet-connection-type' %}" class="btn btn-default"
role="button">
{% trans 'Update...' %}
</a>

View File

@ -15,8 +15,10 @@
{{ form|bootstrap }}
<a href='{{ first_boot_next_step }}'>{% trans "Skip this step" %}</a>
<input type="submit" class="btn btn-primary pull-right" value="{% trans "Next" %}"/>
<input type="submit" class="btn btn-link" name="skip"
value="{% trans "Skip this step" %}"/>
<input type="submit" class="btn btn-primary pull-right" name="next"
value="{% trans "Next" %}"/>
</form>
{% endblock %}

View File

@ -24,7 +24,7 @@
Your {{ box_name }} gets its Internet from your Router via Wi-Fi or
Ethernet cable. This is a typical home setup.
{% endblocktrans %}
<a href="{% url 'networks:router_setup' %}" class="btn btn-default"
<a href="{% url 'networks:router-configuration' %}" class="btn btn-default"
role="button">
{% trans 'Update...' %}
</a>

View File

@ -4,7 +4,6 @@ URLs for the Network module
"""
from django.conf.urls import url
from stronghold.decorators import public
from . import networks as views
@ -27,16 +26,15 @@ urlpatterns = [
r'(?P<interface_name>[^/]+)/)?$', views.add_wifi, name='add_wifi'),
url(r'^sys/networks/(?P<uuid>[\w.@+-]+)/delete/$', views.delete,
name='delete'),
url(r'^sys/networks/router-setup-guide/$',
views.router_configuration_help_page,
name='router_setup'),
url(r'^sys/networks/firstboot/router_setup/$',
public(views.router_configuration_help_page),
name='firstboot_router_setup'),
url(r'^sys/networks/router-configuration/$',
views.RouterConfigurationView.as_view(), name='router-configuration'),
url(r'^sys/networks/firstboot/router-configuration/$',
views.RouterConfigurationFirstBootView.as_view(),
name='router-configuration-first-boot'),
url(r'^sys/networks/internet-connection-type/$',
views.internet_connection_type_help_page,
name='internet_connection_type_setup'),
url(r'^sys/networks/firstboot/internet_connection_type/$',
public(views.internet_connection_type_help_page),
name='firstboot_internet_connection_type'),
views.InternetConnectionTypeView.as_view(),
name='internet-connection-type'),
url(r'^sys/networks/firstboot/internet-connection-type/$',
views.InternetConnectionTypeFirstBootView.as_view(),
name='internet-connection-type-first-boot'),
]