From 0290f68ae6bdf65dec1588dfbedd1a7424221d49 Mon Sep 17 00:00:00 2001
From: Hemanth Kumar Veeranki
Date: Mon, 31 Oct 2016 12:23:03 +0530
Subject: [PATCH] Removed redirection for login and help urls
Changed the redirection in state0 template
---
plinth/modules/first_boot/__init__.py | 2 +-
plinth/modules/first_boot/middleware.py | 16 +++++++++++-----
.../first_boot/templates/firstboot_state0.html | 2 +-
plinth/modules/first_boot/views.py | 11 +++++++++--
plinth/modules/users/views.py | 4 +++-
5 files changed, 25 insertions(+), 10 deletions(-)
diff --git a/plinth/modules/first_boot/__init__.py b/plinth/modules/first_boot/__init__.py
index b754507f8..508feb26b 100644
--- a/plinth/modules/first_boot/__init__.py
+++ b/plinth/modules/first_boot/__init__.py
@@ -26,7 +26,7 @@ first_boot_steps = [{'id': 'firstboot_state0',
'url': 'first_boot:state0',
'order': 0
},
- {'id': 'firstboot_state10',
+ {'id': 'firstboot_state10',
'url': 'first_boot:state10',
'order': 10
}
diff --git a/plinth/modules/first_boot/middleware.py b/plinth/modules/first_boot/middleware.py
index c504fcd6a..d2cc7db84 100644
--- a/plinth/modules/first_boot/middleware.py
+++ b/plinth/modules/first_boot/middleware.py
@@ -22,6 +22,7 @@ yet.
from django.http.response import HttpResponseRedirect
from django.urls import reverse
+from django.conf import settings
import logging
from operator import itemgetter
from plinth import kvstore, module_loader
@@ -38,11 +39,15 @@ class FirstBootMiddleware(object):
"""Handle a request as Django middleware request handler."""
state = kvstore.get_default('firstboot_state', 0)
user_requests_firstboot = is_firstboot(request.path)
- if state == 1 and user_requests_firstboot:
- return HttpResponseRedirect(reverse('index'))
- elif state == 0 and not user_requests_firstboot:
- url = next_step()
- return HttpResponseRedirect(reverse(url))
+ user_requests_login = request.path.startswith(reverse(settings.LOGIN_URL))
+ help_index_url = reverse('help:index')
+ user_requests_help = request.path.startswith(help_index_url)
+ if not user_requests_login and not user_requests_help:
+ if state == 1 and user_requests_firstboot:
+ return HttpResponseRedirect(reverse('index'))
+ elif state == 0 and not user_requests_firstboot:
+ url = next_step()
+ return HttpResponseRedirect(reverse(url))
def is_firstboot(path):
@@ -59,6 +64,7 @@ def is_firstboot(path):
def get_firstboot_steps():
+ """Returns all firstboot steps"""
steps = []
modules = module_loader.loaded_modules
for (module_name, module_object) in modules.items():
diff --git a/plinth/modules/first_boot/templates/firstboot_state0.html b/plinth/modules/first_boot/templates/firstboot_state0.html
index bcb3bb76e..ea4951094 100644
--- a/plinth/modules/first_boot/templates/firstboot_state0.html
+++ b/plinth/modules/first_boot/templates/firstboot_state0.html
@@ -37,7 +37,7 @@
- {% trans "Start Setup" %}
diff --git a/plinth/modules/first_boot/views.py b/plinth/modules/first_boot/views.py
index 801362dcb..305597a05 100644
--- a/plinth/modules/first_boot/views.py
+++ b/plinth/modules/first_boot/views.py
@@ -28,14 +28,21 @@ from plinth import kvstore
from plinth import network
from plinth.errors import DomainRegistrationError
from .forms import State1Form, State5Form
-from .middleware import mark_step_done
+from .middleware import mark_step_done, next_step
class State0View(TemplateView):
"""Show the welcome screen."""
- kvstore.set('firstboot_state0', 'done')
+
template_name = 'firstboot_state0.html'
+ def get_context_data(self, **kwargs):
+ """Returns the context data"""
+ context = super(State0View, self).get_context_data(**kwargs)
+ mark_step_done('firstboot_state0')
+ context['next_url'] = next_step()
+ return context
+
def state10(request):
"""State 10 is when all firstboot setup is done.
diff --git a/plinth/modules/users/views.py b/plinth/modules/users/views.py
index 350bf4976..283078af8 100644
--- a/plinth/modules/users/views.py
+++ b/plinth/modules/users/views.py
@@ -31,7 +31,7 @@ from .forms import CreateUserForm, UserChangePasswordForm, UserUpdateForm, State
from plinth import actions
from plinth.errors import ActionError
-from plinth.modules.first_boot.middleware import mark_step_done
+from plinth.modules.first_boot.middleware import mark_step_done, next_step
subsubmenu = [{'url': reverse_lazy('users:index'),
'text': ugettext_lazy('Users')},
@@ -173,12 +173,14 @@ class State1View(CreateView):
"""Create user account and log the user in."""
template_name = 'firstboot_state1.html'
form_class = State1Form
+ success_url = ''
def __init__(self, *args, **kwargs):
"""Initialize the view object."""
if not cfg.danube_edition:
mark_step_done('pagekite_firstboot')
mark_step_done('users_firstboot')
+ self.success_url = next_step()
return super(State1View, self).__init__(*args, **kwargs)
def get_form_kwargs(self):