-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
68f6f92
commit 594f5af
Showing
6 changed files
with
108 additions
and
0 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
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,34 @@ | ||
# -*- 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 rest_framework import serializers | ||
|
||
from bkuser.apps.data_source.models import DataSourceDepartmentUserRelation | ||
|
||
|
||
class UserSearchInputSLZ(serializers.Serializer): | ||
username = serializers.CharField(required=False, help_text="用户名", allow_blank=True) | ||
|
||
|
||
class UserSearchOutput(serializers.Serializer): | ||
username = serializers.CharField() | ||
full_name = serializers.CharField() | ||
phone = serializers.CharField() | ||
email = serializers.CharField() | ||
departments = serializers.SerializerMethodField() | ||
|
||
def get_departments(self, obj): | ||
department_user_relation_objs = DataSourceDepartmentUserRelation.objects.filter(user=obj) | ||
if department_user_relation_objs: | ||
return [ | ||
{"id": relation_obj.department.id, "name": relation_obj.department.name} | ||
for relation_obj in department_user_relation_objs | ||
] | ||
return [] |
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,17 @@ | ||
# -*- 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.urls import path | ||
|
||
from bkuser.apis.web.data_source import views | ||
|
||
urlpatterns = [ | ||
path("<int:id>/users/", views.DataSourceUserListCreateApi.as_view(), name="data_source.list_create"), | ||
] |
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,45 @@ | ||
# -*- 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 drf_yasg.utils import swagger_auto_schema | ||
from rest_framework import generics, status | ||
|
||
from bkuser.apis.web.data_source.serializers import UserSearchInputSLZ, UserSearchOutput | ||
from bkuser.apps.data_source.models import DataSource, DataSourceUser | ||
from bkuser.common.error_codes import error_codes | ||
|
||
|
||
class DataSourceUserListCreateApi(generics.ListCreateAPIView): | ||
pagination_class = None | ||
serializer_class = UserSearchOutput | ||
|
||
@swagger_auto_schema( | ||
operation_description="数据源用户列表", | ||
query_serializer=UserSearchInputSLZ(), | ||
responses={status.HTTP_200_OK: UserSearchOutput(many=True)}, | ||
) | ||
def get(self, request, *args, **kwargs): | ||
slz = UserSearchInputSLZ(data=self.request.query_params) | ||
slz.is_valid(raise_exception=True) | ||
data = slz.validated_data | ||
data_source_id = kwargs["id"] | ||
|
||
# 校验数据源是否存在 | ||
try: | ||
data_source = DataSource.objects.get(id=data_source_id) | ||
except Exception: | ||
raise error_codes.DATA_SOURCE_NOT_EXIST | ||
|
||
self.queryset = DataSourceUser.objects.filter(data_source=data_source) | ||
|
||
if data.get("username"): | ||
self.queryset = DataSourceUser.objects.filter(username__icontains=data["username"]) | ||
|
||
return self.list(request, *args, **kwargs) |
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