Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle backend provisioning errors. #7024

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions kolibri/core/device/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ def url(self):

def plugin_url(self, plugin_class, url_name):
return plugin_url(plugin_class, url_name)

@classmethod
def provision_url(cls):
return next(hook.url for hook in cls.registered_hooks)
16 changes: 16 additions & 0 deletions kolibri/core/device/middleware.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
from django.conf import settings
from django.http import HttpResponseRedirect
from django.shortcuts import redirect
from django.urls import is_valid_path
from django.utils import translation

from .translation import get_language_from_request_and_is_from_path
from kolibri.core.device.hooks import SetupHook
from kolibri.core.device.utils import DeviceNotProvisioned
from kolibri.utils.conf import OPTIONS


Expand Down Expand Up @@ -79,3 +82,16 @@ def __call__(self, request):
response["Content-Language"] = language

return response


class ProvisioningErrorHandler(object):
def __init__(self, get_response):
self.get_response = get_response

def process_exception(self, request, exception):
if isinstance(exception, DeviceNotProvisioned) and SetupHook.provision_url():
return redirect(SetupHook.provision_url())
return None

def __call__(self, request):
return self.get_response(request)
6 changes: 2 additions & 4 deletions kolibri/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,8 @@ def get(self, request):
Redirects user based on the highest role they have for which a redirect is defined.
"""
# If it has not been provisioned and we have something that can handle setup, redirect there.
if not is_provisioned():
SETUP_WIZARD_URLS = [hook.url for hook in SetupHook.registered_hooks]
if SETUP_WIZARD_URLS:
return redirect(SETUP_WIZARD_URLS[0])
if not is_provisioned() and SetupHook.provision_url:
return redirect(SetupHook.provision_url())

if request.user.is_authenticated():
url = None
Expand Down
1 change: 1 addition & 0 deletions kolibri/deployment/default/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@

MIDDLEWARE = [
"kolibri.core.analytics.middleware.cherrypy_access_log_middleware",
"kolibri.core.device.middleware.ProvisioningErrorHandler",
"django.middleware.cache.UpdateCacheMiddleware",
"kolibri.core.analytics.middleware.MetricsMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
Expand Down