-
Notifications
You must be signed in to change notification settings - Fork 144
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
Restore custom error views (but return JSON where desired) #11722 #11784
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{% extends "errors/error_base.htm" %} | ||
{% load i18n %} | ||
{% load static %} | ||
|
||
{% block body %} | ||
<div style="text-align: center"> | ||
<!--===================================================--> | ||
<div class="cls-header"> | ||
<div class="cls-brand"> | ||
<a class="box-inline" href="/index.html"> | ||
<span class="brand-title"><h4>{% trans "Arches" %}</h4></span> | ||
</a> | ||
</div> | ||
</div> | ||
|
||
<!-- CONTENT --> | ||
<!--===================================================--> | ||
<div class="cls-content"> | ||
<h1 class="error-code text-primary">{% trans "Oops!" %}</h1> | ||
<p class="h3 text-uppercase">{% trans "Bad Request" %}</p> | ||
<div class="pad-btm"> | ||
{% trans "Something went wrong and we couldn't process your request." %}" | ||
</div> | ||
|
||
<hr class="new-section-sm bord-no"> | ||
<div class="pad-top"><a class="btn-link" href="/index.html">{% trans "Back to Homepage" %}</a></div> | ||
</div> | ||
</div> | ||
{% endblock body %} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{% extends "errors/error_base.htm" %} | ||
{% load i18n %} | ||
{% load static %} | ||
|
||
{% block body %} | ||
<div style="text-align: center"> | ||
<!--===================================================--> | ||
<div class="cls-header"> | ||
<div class="cls-brand"> | ||
<a class="box-inline" href="/index.html"> | ||
<span class="brand-title"><h4>{% trans "Arches" %}</h4></span> | ||
</a> | ||
</div> | ||
</div> | ||
|
||
<!-- CONTENT --> | ||
<!--===================================================--> | ||
<div class="cls-content"> | ||
<h1 class="error-code text-primary">{% trans "Oops!" %}</h1> | ||
<p class="h3 text-uppercase">{% trans "Access Denied" %}</p> | ||
<div class="pad-btm"> | ||
{% trans "You don't have permission to access this resource." %}" | ||
</div> | ||
|
||
<hr class="new-section-sm bord-no"> | ||
<div class="pad-top"><a class="btn-link" href="/index.html">{% trans "Back to Homepage" %}</a></div> | ||
</div> | ||
</div> | ||
{% endblock body %} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
def looks_like_api_call(request): | ||
known_api_paths_without_api_signposting = [ | ||
# Until these are renamed for consistency, just list them. | ||
"arches.app.views.workflow_history", | ||
] | ||
if "/api/" in request.path: | ||
return True | ||
if not request.resolver_match: | ||
return False | ||
if ".api." in request.resolver_match.func.__module__: | ||
return True | ||
if ( | ||
request.resolver_match.func.__module__ | ||
in known_api_paths_without_api_signposting | ||
): | ||
return True | ||
return False |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -781,9 +781,13 @@ | |
api.SpatialView.as_view(), | ||
name="spatialview_api", | ||
), | ||
re_path("^api", api.API404.as_view(), name="api_404"), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now we don't need this anymore to handle errors, which is good, because it was too fragile in practice (sneaky failures depending on the order in which you included your other URLs) |
||
] | ||
|
||
handler400 = "arches.app.views.main.custom_400" | ||
handler403 = "arches.app.views.main.custom_403" | ||
handler404 = "arches.app.views.main.custom_404" | ||
handler500 = "arches.app.views.main.custom_500" | ||
|
||
# This must be included in core to keep webpack happy, but cannot be appended when running a project. | ||
# See https://github.com/archesproject/arches/pull/10754 | ||
if settings.ROOT_URLCONF == __name__: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import uuid | ||
import datetime | ||
from http import HTTPStatus | ||
|
||
from django.contrib.auth.models import Group, User | ||
from django.urls import reverse | ||
|
@@ -83,8 +84,9 @@ def test_get_workflow_history(self): | |
) | ||
) | ||
|
||
self.assertEqual(response.status_code, 403) | ||
self.assertIn(b"Forbidden", response.content) | ||
self.assertContains( | ||
response, "Permission Denied", status_code=HTTPStatus.FORBIDDEN | ||
) | ||
Comment on lines
-86
to
+89
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because this error condition was already tested, we caught an example of HTML where we should have sent JSON. Before: \n<!doctype html>\n<html lang="en">\n<head>\n <title>403 Forbidden</title>\n</head>\n<body>\n <h1>403 Forbidden</h1><p></p>\n</body>\n</html>\n After: {"message": "Permission Denied", "status": "false", "success": false, "title": "Request Failed"} |
||
|
||
self.client.force_login(self.admin) | ||
response = self.client.get( | ||
|
@@ -93,8 +95,7 @@ def test_get_workflow_history(self): | |
) | ||
) | ||
|
||
self.assertEqual(response.status_code, 200) | ||
self.assertIn(b"sample name", response.content) | ||
self.assertContains(response, "sample name", status_code=HTTPStatus.OK) | ||
|
||
def test_post_workflow_history(self): | ||
"""Partial updates of componentdata and stepdata are allowed.""" | ||
|
@@ -148,8 +149,9 @@ def test_post_workflow_history(self): | |
content_type="application/json", | ||
) | ||
|
||
self.assertEqual(response.status_code, 403) | ||
self.assertIn(b"Forbidden", response.content) | ||
self.assertContains( | ||
response, "Permission Denied", status_code=HTTPStatus.FORBIDDEN | ||
) | ||
|
||
self.client.force_login(self.admin) | ||
response = self.client.post( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can add more as we find them, but I'm considering it out of scope to audit everything right now: that's a lot of views to analyze. See next comment for why this one is here.