kopia lustrzana https://github.com/wagtail/wagtail
Fix time zone activation leaking into subsequent requests in require_admin_access()
The timezone of an admin user was only activated, but never deactivated, so it leaks into following requests of the current thread. For example, this affected tests executed AFTER wagtail.admin.tests.test_account_management (see #9628). This commit changes the timezone activation to use the override() context manager from django.utils.timezone, which calls deactivate() when the context manager is closed. This is similar to how we use the override() from django.utils.translation for locale activation in the same decorator.pull/9628/head
rodzic
b7c7f689e6
commit
ec6397af01
|
@ -2,12 +2,13 @@ import types
|
|||
from functools import wraps
|
||||
|
||||
import l18n
|
||||
from django.conf import settings
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.core.exceptions import PermissionDenied
|
||||
from django.db.models import Q
|
||||
from django.shortcuts import redirect
|
||||
from django.urls import reverse
|
||||
from django.utils.timezone import activate as activate_tz
|
||||
from django.utils.timezone import override as override_tz
|
||||
from django.utils.translation import gettext as _
|
||||
from django.utils.translation import override
|
||||
|
||||
|
@ -175,8 +176,9 @@ def require_admin_access(view_func):
|
|||
)
|
||||
l18n.set_language(preferred_language)
|
||||
time_zone = user.wagtail_userprofile.get_current_time_zone()
|
||||
activate_tz(time_zone)
|
||||
with LogContext(user=user):
|
||||
else:
|
||||
time_zone = settings.TIME_ZONE
|
||||
with override_tz(time_zone), LogContext(user=user):
|
||||
if preferred_language:
|
||||
with override(preferred_language):
|
||||
response = view_func(request, *args, **kwargs)
|
||||
|
|
Ładowanie…
Reference in New Issue