Skip to content

Commit

Permalink
fix: minor (#1143)
Browse files Browse the repository at this point in the history
  • Loading branch information
nannan00 authored Aug 7, 2023
1 parent 38b251f commit 4c848df
Show file tree
Hide file tree
Showing 9 changed files with 279 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/bk-user/bkuser/apis/web/tenant/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@

urlpatterns = [
path("", views.TenantListCreateApi.as_view(), name="tenant.list_create"),
path("<str:id>/", views.TenantRetrieveUpdateApi.as_view(), name="tenant.detail"),
path("<str:tenant_id>/users/", views.TenantUsersListApi.as_view(), name="tenant.users"),
path("<str:id>/", views.TenantRetrieveUpdateApi.as_view(), name="tenant.retrieve_update"),
path("<str:tenant_id>/users/", views.TenantUsersListApi.as_view(), name="tenant_users.list"),
]
41 changes: 41 additions & 0 deletions src/bk-user/bkuser/apps/data_source/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Generated by Django 3.2.20 on 2023-08-07 03:28

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='DataSourcePlugin',
fields=[
('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='DataSource',
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)),
('name', models.CharField(max_length=128, unique=True, verbose_name='数据源名称')),
('owner_tenant_id', models.CharField(db_index=True, max_length=64, verbose_name='归属租户')),
('plugin_config', models.JSONField(default=dict, verbose_name='数据源插件配置')),
('sync_config', models.JSONField(default=dict, verbose_name='数据源同步任务配置')),
('field_mapping', models.JSONField(default=dict, verbose_name='用户字段映射')),
('plugin', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='data_source.datasourceplugin')),
],
options={
'ordering': ['id'],
},
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Generated by Django 3.2.20 on 2023-08-07 06:12

from django.db import migrations


def forwards_func(apps, schema_editor):
"""
初始化本地数据源插件
"""
DataSourcePlugin = apps.get_model("data_source", "DataSourcePlugin")
# FIXME: 待数据源插件确定后,重新初始化,国际化,这里暂时不使用枚举等
if not DataSourcePlugin.objects.filter(id="local").exists():
DataSourcePlugin.objects.create(
id="local",
name="本地数据源",
description="支持用户和部门的增删改查,以及用户的登录认证",
)



class Migration(migrations.Migration):

dependencies = [
('data_source', '0001_initial'),
]

operations = [
migrations.RunPython(forwards_func)
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# Generated by Django 3.2.20 on 2023-08-07 03:31

from django.db import migrations, models
import django.db.models.deletion
import mptt.fields


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='DataSourceDepartment',
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_id', models.IntegerField(verbose_name='数据源 ID')),
('code', models.CharField(blank=True, max_length=128, null=True, verbose_name='部门标识')),
('name', models.CharField(max_length=255, verbose_name='部门名称')),
('extras', models.JSONField(default=dict, verbose_name='自定义字段')),
],
options={
'ordering': ['id'],
},
),
migrations.CreateModel(
name='DataSourceUser',
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_id', models.IntegerField(verbose_name='数据源 ID')),
('username', models.CharField(max_length=128, verbose_name='用户名')),
('full_name', models.CharField(max_length=128, verbose_name='姓名')),
('email', models.EmailField(blank=True, default='', max_length=254, null=True, verbose_name='邮箱')),
('phone', models.CharField(max_length=32, verbose_name='手机号')),
('phone_country_code', models.CharField(blank=True, default='86', max_length=16, null=True, verbose_name='手机国际区号')),
('logo', models.TextField(blank=True, default='', max_length=256, null=True, verbose_name='Logo')),
('extras', models.JSONField(default=dict, verbose_name='自定义字段')),
],
options={
'ordering': ['id'],
'unique_together': {('username', 'data_source_id')},
},
),
migrations.CreateModel(
name='DataSourceUserLeaderRelation',
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)),
('user_id', models.IntegerField(db_index=True, verbose_name='数据源用户 ID')),
('leader_id', models.IntegerField(db_index=True, verbose_name='数据源用户 Leader ID')),
],
options={
'ordering': ['id'],
'unique_together': {('user_id', 'leader_id')},
},
),
migrations.CreateModel(
name='DataSourceDepartmentUserRelation',
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)),
('department_id', models.IntegerField(db_index=True, verbose_name='数据源部门 ID')),
('user_id', models.IntegerField(db_index=True, verbose_name='数据源用户 ID')),
],
options={
'ordering': ['id'],
'unique_together': {('department_id', 'user_id')},
},
),
migrations.CreateModel(
name='LocalDataSourceIdentityInfo',
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)),
('password', models.CharField(blank=True, default='', max_length=255, null=True, verbose_name='用户密码')),
('password_updated_at', models.DateTimeField(blank=True, null=True, verbose_name='密码最后更新时间')),
('password_expired_at', models.DateTimeField(blank=True, null=True, verbose_name='密码过期时间')),
('data_source_id', models.IntegerField(verbose_name='数据源 ID')),
('username', models.CharField(max_length=128, verbose_name='用户名')),
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='data_source_organization.datasourceuser')),
],
options={
'unique_together': {('username', 'data_source_id')},
},
),
migrations.CreateModel(
name='DataSourceDepartmentRelation',
fields=[
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('id', models.IntegerField(primary_key=True, serialize=False, verbose_name='部门 ID')),
('data_source_id', models.IntegerField(verbose_name='数据源 ID')),
('lft', models.PositiveIntegerField(editable=False)),
('rght', models.PositiveIntegerField(editable=False)),
('tree_id', models.PositiveIntegerField(db_index=True, editable=False)),
('level', models.PositiveIntegerField(editable=False)),
('parent', mptt.fields.TreeForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='children', to='data_source_organization.datasourcedepartmentrelation')),
],
options={
'index_together': {('tree_id', 'lft', 'rght'), ('parent_id', 'tree_id', 'lft')},
},
),
]
Empty file.
41 changes: 41 additions & 0 deletions src/bk-user/bkuser/apps/tenant/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Generated by Django 3.2.20 on 2023-08-07 03:28

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Tenant',
fields=[
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('id', models.CharField(max_length=128, primary_key=True, serialize=False, verbose_name='租户唯一标识')),
('name', models.CharField(max_length=128, unique=True, verbose_name='租户名称')),
('logo', models.TextField(blank=True, default='', null=True, verbose_name='Logo')),
('is_default', models.BooleanField(default=False, verbose_name='是否默认租户')),
('feature_flags', models.JSONField(default=dict, verbose_name='租户特性标志集')),
],
options={
'ordering': ['created_at'],
},
),
migrations.CreateModel(
name='TenantManager',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('tenant_user_id', models.CharField(db_index=True, max_length=128, verbose_name='租户用户 ID')),
('tenant', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='tenant.tenant')),
],
options={
'unique_together': {('tenant', 'tenant_user_id')},
},
),
]

Large diffs are not rendered by default.

Empty file.
4 changes: 2 additions & 2 deletions src/bk-user/bkuser/common/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def one_line_error(error: ValidationError):
return "param format error"


def _handle_exception(request, exc) -> APIError:
def _handle_exception(request, exc) -> APIError: # noqa: ruff: PLR0911
"""统一处理异常,并转换成api error"""
if isinstance(exc, (NotAuthenticated, AuthenticationFailed)):
return error_codes.UNAUTHENTICATED
Expand All @@ -61,7 +61,7 @@ def _handle_exception(request, exc) -> APIError:
return error_codes.INVALID_ARGUMENT.f(exc.detail)

if isinstance(exc, ValidationError):
error_codes.VALIDATION_ERROR.f(one_line_error(exc)).set_detail({"message": json.dumps(exc.detail)})
return error_codes.VALIDATION_ERROR.f(one_line_error(exc)).set_detail({"message": json.dumps(exc.detail)})

if isinstance(exc, APIError):
# 回滚事务
Expand Down

0 comments on commit 4c848df

Please sign in to comment.