-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(db model): add idp and natural user (#1234)
- Loading branch information
Showing
16 changed files
with
304 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-用户管理(Bk-User) available. | ||
Copyright (C) 2017-2021 THL A29 Limited, a Tencent company. All rights reserved. | ||
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at http://opensource.org/licenses/MIT | ||
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations under the License. | ||
""" | ||
from django.apps import AppConfig | ||
|
||
|
||
class IdpConfig(AppConfig): | ||
default_auto_field = "django.db.models.BigAutoField" | ||
name = "bkuser.apps.idp" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-用户管理(Bk-User) available. | ||
Copyright (C) 2017-2021 THL A29 Limited, a Tencent company. All rights reserved. | ||
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at http://opensource.org/licenses/MIT | ||
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations under the License. | ||
""" | ||
from blue_krill.data_types.enum import EnumField, StructuredEnum | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
|
||
class IdpCategory(str, StructuredEnum): | ||
"""认证源分类""" | ||
|
||
ENTERPRISE = EnumField("enterprise", label=_("企业")) | ||
SOCIAL = EnumField("social", label=_("社交")) | ||
|
||
|
||
class IdpStatus(str, StructuredEnum): | ||
"""认证源状态""" | ||
|
||
ENABLED = EnumField("enabled", label=_("启用")) | ||
DISABLED = EnumField("disabled", label=_("未启用")) | ||
|
||
|
||
class AllowBindScopeObjectType(str, StructuredEnum): | ||
"""社会化认证源,允许绑定的范围对象类型""" | ||
|
||
USER = EnumField("user", label=_("用户")) | ||
DEPARTMENT = EnumField("department", label=_("部门")) | ||
DATA_SOURCE = EnumField("data_source", label=_("数据源")) | ||
TENANT = EnumField("tenant", label=_("租户")) | ||
ANY = EnumField("*", label=_("任意")) | ||
|
||
|
||
# 社会化认证源,允许绑定的范围为任意对象ID | ||
ANY_ALLOW_BIND_SCOPE_OBJECT_ID = "*" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-用户管理(Bk-User) available. | ||
Copyright (C) 2017-2021 THL A29 Limited, a Tencent company. All rights reserved. | ||
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at http://opensource.org/licenses/MIT | ||
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations under the License. | ||
""" | ||
from pydantic import BaseModel | ||
|
||
from .constants import AllowBindScopeObjectType | ||
|
||
|
||
class DataSourceMatchRule(BaseModel): | ||
"""认证源与数据源匹配规则""" | ||
|
||
# 认证源原始字段 | ||
source_field: str | ||
# 匹配的数据源 ID | ||
data_source_id: int | ||
# 匹配的数据源字段 | ||
target_field: str | ||
|
||
|
||
class AllowBindScope(BaseModel): | ||
"""允许关联社会化认证源的租户组织架构范围""" | ||
|
||
# 范围对象的类型 | ||
type: AllowBindScopeObjectType | ||
# 范围对象的ID | ||
id: str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Generated by Django 3.2.20 on 2023-09-13 08:36 | ||
|
||
import bkuser.apps.idp.constants | ||
import bkuser.utils.uuid | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='IdpPlugin', | ||
fields=[ | ||
('category', models.CharField(choices=[('enterprise', '企业'), ('social', '社交')], max_length=32, verbose_name='分类')), | ||
('id', models.CharField(max_length=128, primary_key=True, serialize=False, verbose_name='认证源插件唯一标识')), | ||
('name', models.CharField(max_length=128, unique=True, verbose_name='认证源插件名称')), | ||
('description', models.TextField(blank=True, default='', verbose_name='描述')), | ||
('logo', models.TextField(blank=True, default='', null=True, verbose_name='Logo')), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name='Idp', | ||
fields=[ | ||
('created_at', models.DateTimeField(auto_now_add=True)), | ||
('updated_at', models.DateTimeField(auto_now=True)), | ||
('creator', models.CharField(blank=True, max_length=128, null=True)), | ||
('updater', models.CharField(blank=True, max_length=128, null=True)), | ||
('id', models.CharField(default=bkuser.utils.uuid.generate_uuid, max_length=128, primary_key=True, serialize=False, verbose_name='认证源标识')), | ||
('name', models.CharField(max_length=128, unique=True, verbose_name='认证源名称')), | ||
('owner_tenant_id', models.CharField(db_index=True, max_length=64, verbose_name='归属租户')), | ||
('status', models.CharField(choices=[('enabled', '启用'), ('disabled', '未启用')], default=bkuser.apps.idp.constants.IdpStatus['ENABLED'], max_length=32, verbose_name='认证源状态')), | ||
('plugin_config', models.JSONField(default=dict, verbose_name='插件配置')), | ||
('data_source_match_rules', models.JSONField(default=list, verbose_name='匹配规则')), | ||
('allow_bind_scopes', models.JSONField(default=list, verbose_name='允许范围')), | ||
('plugin', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='idp.idpplugin')), | ||
], | ||
options={ | ||
'abstract': False, | ||
}, | ||
), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-用户管理(Bk-User) available. | ||
Copyright (C) 2017-2021 THL A29 Limited, a Tencent company. All rights reserved. | ||
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at http://opensource.org/licenses/MIT | ||
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations under the License. | ||
""" | ||
from django.db import models | ||
|
||
from bkuser.common.models import AuditedModel | ||
from bkuser.utils.uuid import generate_uuid | ||
|
||
from .constants import IdpCategory, IdpStatus | ||
|
||
|
||
class IdpPlugin(models.Model): | ||
"""认证源插件""" | ||
|
||
category = models.CharField("分类", max_length=32, choices=IdpCategory.get_choices()) | ||
id = models.CharField("认证源插件唯一标识", primary_key=True, max_length=128) | ||
name = models.CharField("认证源插件名称", max_length=128, unique=True) | ||
description = models.TextField("描述", default="", blank=True) | ||
logo = models.TextField("Logo", null=True, blank=True, default="") | ||
|
||
|
||
class Idp(AuditedModel): | ||
"""认证源""" | ||
|
||
# 登录回调场景下,该 ID 是 URL Path 的一部分 | ||
id = models.CharField("认证源标识", primary_key=True, max_length=128, default=generate_uuid) | ||
name = models.CharField("认证源名称", max_length=128, unique=True) | ||
owner_tenant_id = models.CharField("归属租户", max_length=64, db_index=True) | ||
status = models.CharField("认证源状态", max_length=32, choices=IdpStatus.get_choices(), default=IdpStatus.ENABLED) | ||
# Note: 认证源插件被删除的前提是,插件没有被任何认证源使用 | ||
plugin = models.ForeignKey(IdpPlugin, on_delete=models.PROTECT) | ||
plugin_config = models.JSONField("插件配置", default=dict) | ||
# 认证源与数据源的匹配规则 | ||
data_source_match_rules = models.JSONField("匹配规则", default=list) | ||
# 允许关联社会化认证源的租户组织架构范围 | ||
allow_bind_scopes = models.JSONField("允许范围", default=list) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-用户管理(Bk-User) available. | ||
Copyright (C) 2017-2021 THL A29 Limited, a Tencent company. All rights reserved. | ||
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at http://opensource.org/licenses/MIT | ||
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations under the License. | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-用户管理(Bk-User) available. | ||
Copyright (C) 2017-2021 THL A29 Limited, a Tencent company. All rights reserved. | ||
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at http://opensource.org/licenses/MIT | ||
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations under the License. | ||
""" | ||
from django.apps import AppConfig | ||
|
||
|
||
class NaturalUserConfig(AppConfig): | ||
default_auto_field = "django.db.models.BigAutoField" | ||
name = "bkuser.apps.natural_user" |
43 changes: 43 additions & 0 deletions
43
src/bk-user/bkuser/apps/natural_user/migrations/0001_initial.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Generated by Django 3.2.20 on 2023-09-13 08:37 | ||
|
||
import bkuser.utils.uuid | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
('data_source', '0003_auto_20230831_1552'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='NaturalUser', | ||
fields=[ | ||
('created_at', models.DateTimeField(auto_now_add=True)), | ||
('updated_at', models.DateTimeField(auto_now=True)), | ||
('id', models.CharField(default=bkuser.utils.uuid.generate_uuid, max_length=128, primary_key=True, serialize=False, verbose_name='自然人标识')), | ||
('full_name', models.CharField(max_length=128, verbose_name='姓名')), | ||
], | ||
options={ | ||
'abstract': False, | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name='DataSourceUserNaturalUserRelation', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('created_at', models.DateTimeField(auto_now_add=True)), | ||
('updated_at', models.DateTimeField(auto_now=True)), | ||
('data_source_user', models.ForeignKey(db_constraint=False, on_delete=django.db.models.deletion.CASCADE, to='data_source.datasourceuser')), | ||
('natural_user', models.ForeignKey(db_constraint=False, on_delete=django.db.models.deletion.DO_NOTHING, to='natural_user.naturaluser')), | ||
], | ||
options={ | ||
'ordering': ['id'], | ||
'unique_together': {('data_source_user', 'natural_user')}, | ||
}, | ||
), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
TencentBlueKing is pleased to support the open source community by making 蓝鲸智云-用户管理(Bk-User) available. | ||
Copyright (C) 2017-2021 THL A29 Limited, a Tencent company. All rights reserved. | ||
Licensed under the MIT License (the "License"); you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at http://opensource.org/licenses/MIT | ||
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations under the License. | ||
""" | ||
from django.db import models | ||
|
||
from bkuser.apps.data_source.models import DataSourceUser | ||
from bkuser.common.models import TimestampedModel | ||
from bkuser.utils.uuid import generate_uuid | ||
|
||
|
||
class NaturalUser(TimestampedModel): | ||
id = models.CharField("自然人标识", primary_key=True, max_length=128, default=generate_uuid) | ||
full_name = models.CharField("姓名", max_length=128) | ||
|
||
|
||
class DataSourceUserNaturalUserRelation(TimestampedModel): | ||
data_source_user = models.ForeignKey(DataSourceUser, on_delete=models.CASCADE, db_constraint=False) | ||
natural_user = models.ForeignKey(NaturalUser, on_delete=models.DO_NOTHING, db_constraint=False) | ||
|
||
class Meta: | ||
ordering = ["id"] | ||
unique_together = [ | ||
("data_source_user", "natural_user"), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters