mirror of
https://github.com/ansible/awx.git
synced 2024-10-31 06:51:10 +03:00
short-circuit middleware if migration loading url
* Had to monkey patch django middleware logic. * Left checks to tell coders to use new middleware behavior in favor of monkey patching.
This commit is contained in:
parent
f907995374
commit
746a2c1eea
@ -20,6 +20,7 @@ from django.shortcuts import get_object_or_404, redirect
|
||||
from django.apps import apps
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.urls import resolve
|
||||
|
||||
from awx.main.models import ActivityStream
|
||||
from awx.main.utils.named_url_graph import generate_graph, GraphNode
|
||||
@ -193,5 +194,6 @@ class MigrationRanCheckMiddleware(object):
|
||||
def process_request(self, request):
|
||||
executor = MigrationExecutor(connection)
|
||||
plan = executor.migration_plan(executor.loader.graph.leaf_nodes())
|
||||
if bool(plan) and 'migrations_notran' not in request.path:
|
||||
if bool(plan) and \
|
||||
getattr(resolve(request.path), 'url_name', '') != 'migrations_notran':
|
||||
return redirect(reverse("ui:migrations_notran"))
|
||||
|
34
awx/wsgi.py
34
awx/wsgi.py
@ -8,7 +8,13 @@ from awx import __version__ as tower_version
|
||||
from awx import prepare_env, MODE
|
||||
prepare_env()
|
||||
|
||||
|
||||
from django.core.handlers.base import BaseHandler # NOQA
|
||||
from django.core.wsgi import get_wsgi_application # NOQA
|
||||
import django # NOQA
|
||||
from django.conf import settings # NOQA
|
||||
from django.urls import resolve # NOQA
|
||||
|
||||
|
||||
"""
|
||||
WSGI config for AWX project.
|
||||
@ -29,5 +35,33 @@ if MODE == 'production':
|
||||
logger.error("Missing or incorrect metadata for Tower version. Ensure Tower was installed using the setup playbook.")
|
||||
raise Exception("Missing or incorrect metadata for Tower version. Ensure Tower was installed using the setup playbook.")
|
||||
|
||||
|
||||
if django.__version__ != '1.11.7':
|
||||
raise RuntimeError("Django version other than 1.11.7 detected {}. \
|
||||
Monkey Patch to support short-circuit Django Middelware \
|
||||
is known to work for Django 1.11.7 and may not work with other, \
|
||||
even minor, versions.".format(django.__version__))
|
||||
|
||||
|
||||
if settings.MIDDLEWARE:
|
||||
raise RuntimeError("MIDDLEWARE setting detected. \
|
||||
The 'migration in progress' view feature short-circuits OLD Django \
|
||||
MIDDLEWARE_CLASSES behavior. With the new Django MIDDLEWARE beahvior \
|
||||
it's possible to short-ciruit the middleware onion through supported \
|
||||
middleware mechanisms. The monkey patch wrapper below should be removed.")
|
||||
|
||||
|
||||
def _wrapper_legacy_get_response(self, request):
|
||||
# short-circuit middleware
|
||||
if getattr(resolve(request.path), 'url_name', '') == 'migrations_notran':
|
||||
return self._get_response(request)
|
||||
# fall through to middle-ware
|
||||
else:
|
||||
return self._real_legacy_get_response(request)
|
||||
|
||||
|
||||
BaseHandler._real_legacy_get_response = BaseHandler._legacy_get_response
|
||||
BaseHandler._legacy_get_response = _wrapper_legacy_get_response
|
||||
|
||||
# Return the default Django WSGI application.
|
||||
application = get_wsgi_application()
|
||||
|
Loading…
Reference in New Issue
Block a user