Skip to content

Commit 971f584

Browse files
authored
WIP fix: only geographic timezones can be allowed (#2317)
1 parent 6ca9c43 commit 971f584

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

src/bk-user/bkuser/common/constants.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,21 @@ class BKNonEntityUser(StrStructuredEnum):
4343
# 敏感信息掩码(7 位 * 是故意的,避免遇到用户输入 6/8 位 * 的情况)
4444
SENSITIVE_MASK = "*******"
4545

46-
TIME_ZONE_CHOICES = [(i, i) for i in list(pytz.all_timezones)]
46+
_GEOGRAPHIC_PREFIX = (
47+
"Africa/",
48+
"America/",
49+
"Antarctica/",
50+
"Arctic/",
51+
"Asia/",
52+
"Atlantic/",
53+
"Australia/",
54+
"Europe/",
55+
"Indian/",
56+
"Pacific/",
57+
)
58+
59+
# 时区选项,排除非地理时区
60+
TIME_ZONE_CHOICES = [(i, i) for i in pytz.common_timezones if i.startswith(_GEOGRAPHIC_PREFIX)]
4761

4862
# datetime 对比时允许最大偏移的秒数内认为是相等的,默认 2 分钟
4963
ALLOWED_DATETIME_MAX_OFFSET = 120

src/bk-user/tests/apis/web/personal_center/test_personal_center.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def test_update_illegal_lanague(self, api_client, tenant_user, language):
132132

133133

134134
class TestTenantUserTimeZoneUpdateApi:
135-
@pytest.mark.parametrize(("time_zone"), [("Asia/Shanghai"), ("UTC")])
135+
@pytest.mark.parametrize(("time_zone"), [("Asia/Shanghai"), ("America/New_York")])
136136
def test_update_legal_timezone(self, api_client, tenant_user, time_zone):
137137
resp = api_client.put(
138138
reverse("personal_center.tenant_users.time_zone.update", kwargs={"id": tenant_user.id}),

0 commit comments

Comments
 (0)