mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-07-09 04:20:17 +02:00
Add 500 and 400, 403, 404 error redirects back to dashboard with basic message
This commit is contained in:
parent
8addd483c2
commit
d7dcacb899
@ -4,3 +4,8 @@ from allianceauth import urls
|
||||
urlpatterns = [
|
||||
url(r'', include(urls)),
|
||||
]
|
||||
|
||||
handler500 = 'allianceauth.views.Generic500Redirect'
|
||||
handler404 = 'allianceauth.views.Generic404Redirect'
|
||||
handler403 = 'allianceauth.views.Generic403Redirect'
|
||||
handler400 = 'allianceauth.views.Generic400Redirect'
|
||||
|
@ -27,7 +27,12 @@ class DiscordViewsTestCase(WebTest):
|
||||
self.login()
|
||||
manager.generate_oauth_redirect_url.return_value = '/example.com/oauth/'
|
||||
response = self.app.get('/discord/activate/', auto_follow=False)
|
||||
self.assertRedirects(response, expected_url='/example.com/oauth/', target_status_code=404)
|
||||
self.assertRedirects(
|
||||
response,
|
||||
expected_url="/example.com/oauth/",
|
||||
target_status_code=404,
|
||||
fetch_redirect_response=False,
|
||||
)
|
||||
|
||||
@mock.patch(MODULE_PATH + '.tasks.DiscordOAuthManager')
|
||||
def test_callback(self, manager):
|
||||
|
@ -1,13 +1,15 @@
|
||||
from django.views.generic.base import View
|
||||
from django.http import HttpResponseRedirect
|
||||
from django.shortcuts import redirect
|
||||
from django.contrib import messages
|
||||
|
||||
|
||||
class NightModeRedirectView(View):
|
||||
SESSION_VAR = 'NIGHT_MODE'
|
||||
SESSION_VAR = "NIGHT_MODE"
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
request.session[self.SESSION_VAR] = not self.night_mode_state(request)
|
||||
return HttpResponseRedirect(request.GET.get('next', '/'))
|
||||
return HttpResponseRedirect(request.GET.get("next", "/"))
|
||||
|
||||
@classmethod
|
||||
def night_mode_state(cls, request):
|
||||
@ -17,3 +19,39 @@ class NightModeRedirectView(View):
|
||||
# Session is middleware
|
||||
# Sometimes request wont have a session attribute
|
||||
return False
|
||||
|
||||
|
||||
def Generic500Redirect(request):
|
||||
messages.error(
|
||||
request,
|
||||
"Auth encountered an error processing your request, please try again. "
|
||||
"If the error persists, please contact the administrators. (500 Internal Server Error)",
|
||||
)
|
||||
return redirect("authentication:dashboard")
|
||||
|
||||
|
||||
def Generic404Redirect(request, exception):
|
||||
messages.error(
|
||||
request,
|
||||
"Page does not exist. If you believe this is in error please contact the administrators. "
|
||||
"(404 Page Not Found)",
|
||||
)
|
||||
return redirect("authentication:dashboard")
|
||||
|
||||
|
||||
def Generic403Redirect(request, exception):
|
||||
messages.error(
|
||||
request,
|
||||
"You do not have permission to access the requested page. "
|
||||
"If you believe this is in error please contact the administrators. (403 Permission Denied)",
|
||||
)
|
||||
return redirect("authentication:dashboard")
|
||||
|
||||
|
||||
def Generic400Redirect(request, exception):
|
||||
messages.error(
|
||||
request,
|
||||
"Auth encountered an error processing your request, please try again. "
|
||||
"If the error persists, please contact the administrators. (400 Bad Request)",
|
||||
)
|
||||
return redirect("authentication:dashboard")
|
||||
|
@ -12,4 +12,7 @@ urlpatterns += [
|
||||
url(r'^second-page/$', views.page, name='p1'),
|
||||
]
|
||||
|
||||
|
||||
handler500 = 'allianceauth.views.Generic500Redirect'
|
||||
handler404 = 'allianceauth.views.Generic404Redirect'
|
||||
handler403 = 'allianceauth.views.Generic403Redirect'
|
||||
handler400 = 'allianceauth.views.Generic400Redirect'
|
||||
|
Loading…
x
Reference in New Issue
Block a user