From f33dd382698bb8b37493e09a4d2ed24118eee8a3 Mon Sep 17 00:00:00 2001 From: cuom1999 Date: Fri, 27 Jan 2023 17:25:41 -0600 Subject: [PATCH] Add better responses for subdomains --- judge/middleware.py | 17 ++++++++++++++--- locale/vi/LC_MESSAGES/django.po | 14 +++++++++++++- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/judge/middleware.py b/judge/middleware.py index 73fb2c9..159860e 100644 --- a/judge/middleware.py +++ b/judge/middleware.py @@ -4,8 +4,10 @@ from django.urls import Resolver404, resolve, reverse from django.utils.http import urlquote from django.contrib.sites.shortcuts import get_current_site from django.core.exceptions import ObjectDoesNotExist +from django.utils.translation import gettext as _ from judge.models import Organization +from judge.utils.views import generic_message class ShortCircuitMiddleware: @@ -108,12 +110,21 @@ class SubdomainMiddleware(object): request.organization = organization else: if request.profile: - raise Http404 + return generic_message( + request, + _("No permission"), + _("You need to join this group first"), + status=404, + ) if not request.GET.get("next", None): return HttpResponseRedirect( reverse("auth_login") + "?next=" + urlquote(request.path) ) except ObjectDoesNotExist: - scheme = "https" if settings.DMOJ_SSL > 0 else "http" - return HttpResponseRedirect(scheme + "://" + site) + return generic_message( + request, + _("No such group"), + _("No such group"), + status=404, + ) return self.get_response(request) diff --git a/locale/vi/LC_MESSAGES/django.po b/locale/vi/LC_MESSAGES/django.po index a65496f..aa96e18 100644 --- a/locale/vi/LC_MESSAGES/django.po +++ b/locale/vi/LC_MESSAGES/django.po @@ -2,7 +2,7 @@ msgid "" msgstr "" "Project-Id-Version: lqdoj2\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2023-01-28 06:15+0700\n" +"POT-Creation-Date: 2023-01-28 06:23+0700\n" "PO-Revision-Date: 2021-07-20 03:44\n" "Last-Translator: Icyene\n" "Language-Team: Vietnamese\n" @@ -546,6 +546,18 @@ msgstr "{time}" msgid "on {time}" msgstr "vào {time}" +#: judge/middleware.py:114 +msgid "No permission" +msgstr "Không có quyền truy cập" + +#: judge/middleware.py:115 +msgid "You need to join this group first" +msgstr "Bạn phải là thành viên của nhóm." + +#: judge/middleware.py:125 judge/middleware.py:126 +msgid "No such group" +msgstr "Nhóm không tồn tại" + #: judge/models/bookmark.py:17 judge/models/comment.py:49 #: judge/models/comment.py:226 judge/models/pagevote.py:13 msgid "associated page"