From 2a7707802237dad5f0be039bdf1d495f1bfd30aa Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Wed, 11 Apr 2018 21:38:27 -0400 Subject: [PATCH] Capture menu resolution errors on invalid URLs. Closes GitLab issue #420. Signed-off-by: Roberto Rosario --- HISTORY.rst | 1 + docs/releases/3.0.rst | 2 ++ mayan/apps/navigation/classes.py | 10 ++++++++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 0fd4a55894..c6f0f14866 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -152,6 +152,7 @@ - Add a new setting option to enable automatic parsing for each new document type created. - Add support for HTML bodies to the user mailers. - Production ALLOWED_HOSTS settings now defaults to a safer ['127.0.0.1', 'localhost', '[::1]'] +- Capture menu resolution errors on invalid URLs. Closes GitLab issue #420. 2.7.3 (2017-09-11) ================== diff --git a/docs/releases/3.0.rst b/docs/releases/3.0.rst index 00deb74a98..e1ef656ea6 100644 --- a/docs/releases/3.0.rst +++ b/docs/releases/3.0.rst @@ -471,6 +471,7 @@ Other changes worth mentioning - Add a new setting option to enable automatic parsing for each new document type created. - Add support for HTML bodies to the user mailers. - Production ALLOWED_HOSTS settings now defaults to a safer ['127.0.0.1', 'localhost', '[::1]'] +- Capture menu resolution errors on invalid URLs. Closes GitLab issue #420. Removals -------- @@ -539,6 +540,7 @@ Bugs fixed or issues closed * `GitLab issue #405 `_ Add wizard steps from external apps * `GitLab issue #407 `_ Improve search syntax to support search query types: AND, OR * `GitLab issue #408 `_ Improve document checkbox selection. +* `GitLab issue #420 `_ Mayan raises a 500 instead of 404 in production mode * `GitLab issue #437 `_ Record users who upload or edit documents * `GitLab issue #439 `_ Toastr library missing after update * `GitLab issue #447 `_ API Security Bug Chinese wall breach diff --git a/mayan/apps/navigation/classes.py b/mayan/apps/navigation/classes.py index 944587b9ce..245c1d837f 100644 --- a/mayan/apps/navigation/classes.py +++ b/mayan/apps/navigation/classes.py @@ -11,7 +11,7 @@ from django.core.exceptions import PermissionDenied from django.shortcuts import resolve_url from django.template import VariableDoesNotExist, Variable from django.template.defaulttags import URLNode -from django.urls import resolve +from django.urls import Resolver404, resolve from django.utils.encoding import force_str, force_text from common.utils import return_attrib @@ -152,7 +152,13 @@ class Menu(object): current_path = request.META['PATH_INFO'] # Get sources: view name, view objects - current_view = resolve(current_path).view_name + try: + current_view = resolve(current_path).view_name + except Resolver404: + # Can't figure out which view corresponds to this URL. + # Most likely it is an invalid URL. + logger.warning('Can\'t figure out which view corresponds to this URL: %s; aborting menu resolution.', current_path) + return () resolved_navigation_object_list = self.get_resolved_navigation_object_list( context=context, source=source