Skip to content

Commit

Permalink
minor: DataSource add is_username_frozen property
Browse files Browse the repository at this point in the history
  • Loading branch information
narasux committed Dec 15, 2023
1 parent 0e65f52 commit 1a906ab
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/bk-user/bkuser/apps/data_source/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ def is_local(self) -> bool:
"""检查类型是否为本地数据源"""
return self.plugin.id == DataSourcePluginEnum.LOCAL

@property
def is_username_frozen(self) -> bool:
"""用户名在初始化后不可再次更新,对于租户用户 ID 为 uuid 的数据源无效"""
return bool(self.owner_tenant_user_id_rule != TenantUserIdRuleEnum.UUID4_HEX)

def get_plugin_cfg(self) -> BasePluginConfig:
"""获取插件配置
Expand Down
3 changes: 1 addition & 2 deletions src/bk-user/bkuser/apps/sync/syncers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

from django.utils import timezone

from bkuser.apps.data_source.constants import TenantUserIdRuleEnum
from bkuser.apps.data_source.models import (
DataSource,
DataSourceDepartment,
Expand Down Expand Up @@ -215,7 +214,7 @@ def __init__(
self.converter = DataSourceUserConverter(data_source, ctx.logger)
# 由于在部分老版本迁移过来的数据源中租户用户 ID 会由 username + 规则 拼接生成,
# 该类数据源同步时候不可更新 username,而全新数据源对应租户 ID 都是 uuid 则不受影响
self.enable_update_username = bool(data_source.owner_tenant_user_id_rule == TenantUserIdRuleEnum.UUID4_HEX)
self.enable_update_username = not data_source.is_username_frozen

def sync(self):
self.ctx.logger.info(f"receive {len(self.raw_users)} users from data source plugin") # noqa: G004
Expand Down

0 comments on commit 1a906ab

Please sign in to comment.