Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added query display name for frontend #2047

Merged
merged 28 commits into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
7cc4bed
feat: added query display name for frontend
rolin999 Feb 12, 2025
b13e2d3
feat: added query display name for frontend
rolin999 Feb 12, 2025
5cbc3ad
feat: added query display name for frontend
rolin999 Feb 13, 2025
655ab27
feat: added query display name for frontend
rolin999 Feb 13, 2025
7405f2f
feat: added query display name for frontend
rolin999 Feb 13, 2025
d826328
feat: added query display name for frontend
rolin999 Feb 13, 2025
5c312ed
feat: added query display name for frontend
rolin999 Feb 13, 2025
6aac22a
feat: added query display name for frontend
rolin999 Feb 13, 2025
94af97e
feat: added query display name for frontend
rolin999 Feb 13, 2025
19e8432
feat: added query display name for frontend
rolin999 Feb 13, 2025
97c34ed
resolve: fix some problems
rolin999 Feb 18, 2025
a4135ce
resolve: fix some problems
rolin999 Feb 18, 2025
81b31a9
resolve: fix some problems
rolin999 Feb 18, 2025
1a4e6fe
resolve: fix some problems
rolin999 Feb 19, 2025
a3b9bd6
resolve: fix some problems
rolin999 Feb 19, 2025
85f940f
resolve: fix some problems
rolin999 Feb 19, 2025
82434d1
resolve: fix some problems
rolin999 Feb 19, 2025
5cc94bb
resolve: fix some problems
rolin999 Feb 19, 2025
8abe023
resolve: fix some problems
rolin999 Feb 19, 2025
70eb717
resolve: fix some problems
rolin999 Feb 19, 2025
08626b4
resolve: fix some problems
rolin999 Feb 21, 2025
cbe1cf9
resolve: fix some problems
rolin999 Feb 21, 2025
299d509
resolve: fix some problems
rolin999 Feb 24, 2025
3b7a53b
resolve: fix some problems
rolin999 Feb 24, 2025
c6216c4
resolve: fix some problems
rolin999 Feb 24, 2025
fd23281
resolve: fix some problems
rolin999 Feb 24, 2025
6b6a2e9
resolve: fix some problems
rolin999 Feb 24, 2025
51ef7b6
resolve: fix some problems
rolin999 Feb 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/bk-user/bin/post_migrate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ set -e
# 自动化同步网关
if [ "$ENABLE_SYNC_APIGW" = true ]; then
sh ./support-files/bin/sync-apigateway.sh
sh ./bkuser/apis/open_v3/frontend/support-files/bin/sync-apigateway.sh
fi

# 注册到蓝鲸通知中心
Expand Down
16 changes: 16 additions & 0 deletions src/bk-user/bkuser/apis/open_v3/frontend/__init__.py
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 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.
#
# We undertake not to change the open source license (MIT license) applicable
# to the current version of the project delivered to anyone in the future.
24 changes: 24 additions & 0 deletions src/bk-user/bkuser/apis/open_v3/frontend/mixins.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
# TencentBlueKing is pleased to support the open source community by making
# 蓝鲸智云 - 用户管理 (bk-user) available.
# Copyright (C) 2017 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.
#
# We undertake not to change the open source license (MIT license) applicable
# to the current version of the project delivered to anyone in the future.

from bkuser.apis.open_v3.mixins import OpenApiCommonMixin

from .permissions import ApiGatewayUserVerifiedPermission


class FrontendApiMixin(OpenApiCommonMixin):
permission_classes = [ApiGatewayUserVerifiedPermission]
24 changes: 24 additions & 0 deletions src/bk-user/bkuser/apis/open_v3/frontend/permissions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
# TencentBlueKing is pleased to support the open source community by making
# 蓝鲸智云 - 用户管理 (bk-user) available.
# Copyright (C) 2017 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.
#
# We undertake not to change the open source license (MIT license) applicable
# to the current version of the project delivered to anyone in the future.
from rest_framework import permissions


class ApiGatewayUserVerifiedPermission(permissions.BasePermission):
"""校验来源 APIGateway JWT 的用户是否认证"""

def has_permission(self, request, view):
return request.user and request.user.is_authenticated
44 changes: 44 additions & 0 deletions src/bk-user/bkuser/apis/open_v3/frontend/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# -*- coding: utf-8 -*-
# TencentBlueKing is pleased to support the open source community by making
# 蓝鲸智云 - 用户管理 (bk-user) available.
# Copyright (C) 2017 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.
#
# We undertake not to change the open source license (MIT license) applicable
# to the current version of the project delivered to anyone in the future.
from django.conf import settings
from rest_framework import serializers

from bkuser.apps.tenant.models import TenantUser
from bkuser.biz.tenant import TenantUserHandler
from bkuser.common.serializers import StringArrayField


class TenantUserDisplayNameRetrieveOutputSLZ(serializers.Serializer):
display_name = serializers.SerializerMethodField(help_text="用户展示名称")

def get_display_name(self, obj: TenantUser) -> str:
return TenantUserHandler.generate_tenant_user_display_name(obj)


class TenantUserDisplayNameListInputSLZ(serializers.Serializer):
bk_usernames = StringArrayField(
help_text="蓝鲸用户唯一标识,多个使用逗号分隔",
max_items=settings.BATCH_QUERY_USER_DISPLAY_NAME_BY_BK_USERNAME_LIMIT,
)


class TenantUserDisplayNameListOutputSLZ(serializers.Serializer):
bk_username = serializers.CharField(help_text="蓝鲸用户唯一标识", source="id")
display_name = serializers.SerializerMethodField(help_text="用户展示名称")

def get_display_name(self, obj: TenantUser) -> str:
return TenantUserHandler.generate_tenant_user_display_name(obj)
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

set -e

gateway_name="bk-user-frontend-api"

# 待同步网关、资源定义文件,需调整为实际的配置文件地址
definition_file="bkuser/apis/open_v3/frontend/support-files/definition.yaml"
resources_file="bkuser/apis/open_v3/frontend/support-files/resources.yaml"

echo "gateway sync definition start ..."

# 同步网关基本信息
echo "gateway sync definition start ..."
python manage.py sync_apigw_config --gateway-name=${gateway_name} --file="${definition_file}"

# 同步网关环境信息
python manage.py sync_apigw_stage --gateway-name=${gateway_name} --file="${definition_file}"

# 同步网关资源
python manage.py sync_apigw_resources --delete --gateway-name=${gateway_name} --file="${resources_file}"

# 同步资源文档
python manage.py sync_resource_docs_by_archive --gateway-name=${gateway_name} --file="${definition_file}"

# 创建资源版本、发布
python manage.py create_version_and_release_apigw --gateway-name=${gateway_name} --file="${definition_file}"

## 为应用主动授权
#python manage.py grant_apigw_permissions --gateway-name=${gateway_name} --file="${definition_file}"

# 获取网关公钥
python manage.py fetch_apigw_public_key --gateway-name=${gateway_name}

echo "gateway sync definition end"
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
spec_version: 2

release:
# 发布版本号
version: 0.0.1
title: "bk-user-frontend-api"
comment: "bk-user-frontend-api"

apigateway:
description: "用户管理前端服务 API 网关"
description_en: "User Management API Gateway for Frontend Service"
is_public: true
api_type: 1
user_config:
from_bk_token: true
maintainers:
- "admin"

stages:
- name: "prod"
description: "生产环境"
description_en: "environment of production"
backends:
- name: "default"
config:
timeout: 30
loadbalance: "roundrobin"
hosts:
# 网关调用后端服务的默认域名或IP,不包含Path,比如:http://api.example.com
- host: "http://bkuser"
weight: 100

plugin_configs:
- type: bk-cors
yaml: |-
allow_origins: "{{ settings.CORS_ALLOW_APIGW_ORIGINS }}"
allow_methods: 'GET,OPTIONS'
allow_headers: 'Accept,Accept-Encoding,Accept-Language,Cookie,Content-Length,Content-Type,X-Bk-Tenant-Id,X-Csrftoken,X-Requested-With'
expose_headers: ''
max_age: 86400
allow_credential: true

# 资源文档
# 资源文档的目录格式样例如下,en 为英文文档,zh 为中文文档:
# ./
# - en
# - anything.md
# - zh
# - anything.md
resource_docs:
basedir: "bkuser/apis/open_v3/frontend/support-files/docs"
# 主动授权,网关主动给应用,添加访问网关所有资源的权限
#grant_permissions:
# - bk_app_code: "{{ settings.BK_APP_CODE }}"
# grant_dimension: "gateway"
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
### Description

Batch query user's display_name

### Parameters

| Name | Type | Required | Description |
|--------------|--------|----------|-------------------------------------------------------------------------------------------------------|
| bk_usernames | string | Yes | Blueking user's unique identifier, multiple identifiers are separated by commas, and the limit is 100 |

### Request Example

```
// URL Query Parameters
bk_usernames=7idwx3b7nzk6xigs,0wngfim3uzhadh1w
```

### Response Example for Status Code 200

```json5
{
"data": [
{
"bk_username": "7idwx3b7nzk6xigs",
"display_name": "张三"
},
{
"bk_username": "0wngfim3uzhadh1w",
"display_name": "李四"
}
]
}
```

### Response Parameters Description

| Name | Type | Description |
|--------------|--------|-----------------------------------|
| bk_username | string | Blueking user's unique identifier |
| display_name | string | User's display_name |
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
### Description

Query user's display_name

### Parameters

| Name | Type | Required | Description |
|-------------|--------|----------|-----------------------------------|
| bk_username | string | Yes | Blueking user's unique identifier |

### Request Example

```
// URL Path Parameters
/api/v3/open/frontend/tenant/users/7idwx3b7nzk6xigs/display_name
```

### Response Example for Status Code 200

```json5
{
"data": {
"display_name": "张三"
}
}
```

### Response Parameters Description

| Name | Type | Description |
|--------------|--------|---------------------|
| display_name | string | User's display_name |
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
### 描述

批量查询用户展示名

### 输入参数

| 参数名称 | 参数类型 | 必选 | 描述 |
|--------------|--------|----|----------------------------|
| bk_usernames | string | 是 | 蓝鲸用户唯一标识,多个以逗号分隔,限制数量为 100 |

### 请求示例

```
// URL Query 参数
bk_usernames=7idwx3b7nzk6xigs,0wngfim3uzhadh1w
```

### 状态码 200 的响应示例

```json5
{
"data": [
{
"bk_username": "7idwx3b7nzk6xigs",
"display_name": "张三"
},
{
"bk_username": "0wngfim3uzhadh1w",
"display_name": "李四"
}
]
}
```

### 响应参数说明

| 参数名称 | 参数类型 | 描述 |
|--------------|--------|----------|
| bk_username | string | 蓝鲸用户唯一标识 |
| display_name | string | 用户展示名 |
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
### 描述

查询用户展示名

### 输入参数

| 参数名称 | 参数类型 | 必选 | 描述 |
|-------------|--------|----|----------|
| bk_username | string | 是 | 蓝鲸用户唯一标识 |

### 请求示例

```
// URL Path 参数
/api/v3/open/frontend/tenant/users/7idwx3b7nzk6xigs/display_name
```

### 状态码 200 的响应示例

```json5
{
"data": {
"display_name": "张三"
}
}
```


### 响应参数说明

| 参数名称 | 参数类型 | 描述 |
|--------------|--------|-------|
| display_name | string | 用户展示名 |
Loading