From 51712dd07f2fb4abf60da286914627185e8a9ca4 Mon Sep 17 00:00:00 2001 From: rangelbruno Date: Wed, 11 Feb 2026 06:27:31 -0300 Subject: [PATCH] =?UTF-8?q?Fix(404/iframe):=20P=C3=A1gina=20404=20customiz?= =?UTF-8?q?ada,=20prote=C3=A7=C3=A3o=20resolver=5Fmatch=20e=20has=5Fiframe?= =?UTF-8?q?=20com=20querystring?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Redesign da página 404 com layout responsivo e navegação - Redireciona usuários não autenticados para /login/ no 404 - Protege nav_run contra resolver_match None - Mescla has_iframe: getattr seguro + leitura/gravação do parâmetro ?iframe= na sessão --- sapl/base/templatetags/common_tags.py | 15 ++- sapl/base/templatetags/menus.py | 2 + sapl/templates/404.html | 149 ++++++++++++++++++++++++-- sapl/urls.py | 12 +++ 4 files changed, 171 insertions(+), 7 deletions(-) diff --git a/sapl/base/templatetags/common_tags.py b/sapl/base/templatetags/common_tags.py index 718fb2b81..a5c36b66d 100644 --- a/sapl/base/templatetags/common_tags.py +++ b/sapl/base/templatetags/common_tags.py @@ -266,7 +266,20 @@ def has_iframe(obj): session = getattr(obj, "session", None) if not session: return False - return bool(session.get("iframe", False)) + + iframe = session.get('iframe', False) + if not iframe and hasattr(obj, 'GET') and 'iframe' in obj.GET: + ival = obj.GET['iframe'] + if ival and int(ival) == 1: + session['iframe'] = True + return True + elif hasattr(obj, 'GET') and 'iframe' in obj.GET: + ival = obj.GET['iframe'] + if ival and int(ival) == 0: + del session['iframe'] + return False + + return iframe @register.filter diff --git a/sapl/base/templatetags/menus.py b/sapl/base/templatetags/menus.py index 8763d484a..93a2f6c28 100644 --- a/sapl/base/templatetags/menus.py +++ b/sapl/base/templatetags/menus.py @@ -64,6 +64,8 @@ def nav_run(context, path=None): """ rm = request.resolver_match + if rm is None: + return {} app_template = rm.app_name.rsplit('.', 1)[-1] if path: diff --git a/sapl/templates/404.html b/sapl/templates/404.html index b174f7a4f..68ca03c03 100644 --- a/sapl/templates/404.html +++ b/sapl/templates/404.html @@ -1,12 +1,149 @@ {% extends "base.html" %} {% load i18n %} -{% block head_title %}{% trans 'Página não encontrada! Erro 404' %}{% endblock %} +{% block head_title %}{% trans 'Página não encontrada' %} - 404{% endblock %} {% block base_content %} -
-

{% trans 'Página não encontrada! Erro 404' %}

-

{% trans 'A página que você está procurando não foi encontrada.' %}

- {% trans 'Voltar para a página inicial' %} + + +
+
+ +
+ +

404

+

{% trans 'Página não encontrada' %}

+ +

+ {% trans 'A página que você está procurando não existe ou foi movida.' %} +

+ +
-{% endblock %} + +{% endblock base_content %} diff --git a/sapl/urls.py b/sapl/urls.py index 5f90008c5..3d2a44478 100644 --- a/sapl/urls.py +++ b/sapl/urls.py @@ -122,3 +122,15 @@ def custom_permission_denied_view(request, exception=None): handler403 = custom_permission_denied_view + + +def custom_page_not_found_view(request, exception=None): + from django.shortcuts import redirect, render + + if not request.user.is_authenticated: + return redirect('/login/') + + return render(request, '404.html', status=404) + + +handler404 = custom_page_not_found_view