Skip to content

Commit

Permalink
feat: TenantUserCustomField model add use_digit_option_id field (#1529)
Browse files Browse the repository at this point in the history
  • Loading branch information
narasux authored Jan 18, 2024
1 parent e692d95 commit 136baf1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/bk-user/bkuser/apis/web/tenant_setting/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,12 @@ def validate(self, attrs):
# 非枚举类型的,更新时候不需要字段迁移映射
attrs["mapping"] = {}

# NOTE: 对于历史迁移的数据,必须保证即使修改,选项 ID 也是可以转换回整数的(向前兼容)
if custom_field.use_digit_option_id and options:
for opt in options:
if not opt["id"].isdigit():
raise ValidationError(_("枚举选项 ID 必须是数字,值 {} 不合法").format(opt["id"]))

return attrs


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.20 on 2024-01-18 11:36

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('tenant', '0005_auto_20231219_1536'),
]

operations = [
migrations.AddField(
model_name='tenantusercustomfield',
name='use_digit_option_id',
field=models.BooleanField(default=False, verbose_name='是否使用数字作为选项ID'),
),
]
2 changes: 2 additions & 0 deletions src/bk-user/bkuser/apps/tenant/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ class TenantUserCustomField(TimestampedModel):
manager_editable = models.BooleanField("租户管理员是否可重复编辑", default=True)
default = models.JSONField("默认值", default="")
options = models.JSONField("配置项", default=list)
# 兼容逻辑,只有老版本迁移过来的枚举类型自定义字段会需要
use_digit_option_id = models.BooleanField("是否使用数字作为选项ID", default=False)

class Meta:
unique_together = [
Expand Down
2 changes: 1 addition & 1 deletion src/idp-plugins/idp_plugins/local/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@


class LocalIdpPluginConfig(BasePluginConfig):
""" "本地账密认证源插件配置"""
"""本地账密认证源插件配置"""

# 开启账密登录的数据源
data_source_ids: List[int] = []
Expand Down

0 comments on commit 136baf1

Please sign in to comment.