Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions sdks/bkpaas-auth/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# 版本历史

## 4.1.1

- fix: 修复 DjangoAuthUserCompatibleBackend 未传递 time_zone 字段的问题

## 4.1.0

- 支持 python 3.14
Expand Down
2 changes: 1 addition & 1 deletion sdks/bkpaas-auth/bkpaas_auth/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
__version__ = "4.1.0"
__version__ = "4.1.1"


def get_user_by_user_id(user_id: str, username_only: bool = True):
Expand Down
1 change: 1 addition & 0 deletions sdks/bkpaas-auth/bkpaas_auth/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ def connect_to_django_user(self, user: User):
db_user.token = user.token
db_user.display_name = getattr(user, "display_name", user.username)
db_user.tenant_id = getattr(user, "tenant_id", None)
db_user.time_zone = getattr(user, "time_zone", None)

return db_user

Expand Down
2 changes: 1 addition & 1 deletion sdks/bkpaas-auth/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ classifiers = ["License :: OSI Approved :: MIT License"]
# PEP 621 project metadata
# See https://www.python.org/dev/peps/pep-0621/
name = "bkpaas-auth"
version = "4.1.0"
version = "4.1.1"
description = "User authentication django app for blueking internal projects"
readme = "README.md"
authors = [{ name = "blueking", email = "blueking@tencent.com" }]
Expand Down
26 changes: 26 additions & 0 deletions sdks/bkpaas-auth/tests/test_middlewares.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,32 @@ def test_auth(self, db, bk_token, dj_request):
assert not isinstance(user, User)
assert isinstance(user.pk, int)

@override_settings(
AUTHENTICATION_BACKENDS=["bkpaas_auth.backends.DjangoAuthUserCompatibleBackend"],
TIME_ZONE="UTC",
)
def test_time_zone_propagated_to_django_user(self, db, bk_token, dj_request):
"""time_zone should survive connect_to_django_user."""
middleware = CookieLoginMiddleware(MagicMock())
dj_request.COOKIES["bk_token"] = bk_token

# Create a bkpaas_auth User with time_zone
user = create_uin_user(bk_token)
user.time_zone = "Asia/Shanghai"

with patch("bkpaas_auth.backends.UniversalAuthBackend.authenticate") as mocked_authenticate:
mocked_authenticate.return_value = user
middleware(dj_request)

# time_zone should be propagated from bkpaas_auth.User to Django AuthUser
assert getattr(dj_request.user, "time_zone", None) == "Asia/Shanghai"

# UserTimezoneMiddleware should activate the timezone
tz_middleware = UserTimezoneMiddleware(MagicMock())
dj_timezone.deactivate()
tz_middleware.process_request(dj_request)
assert dj_timezone.get_current_timezone_name() == "Asia/Shanghai"


class TestUserTimezoneMiddleware:
"""Test cases for UserTimezoneMiddleware"""
Expand Down
Loading