Skip to content

Commit

Permalink
code conflict 解决
Browse files Browse the repository at this point in the history
  • Loading branch information
neronkl committed Aug 23, 2023
2 parents e512bdf + 8426434 commit e4fcd62
Show file tree
Hide file tree
Showing 78 changed files with 3,685 additions and 883 deletions.
1 change: 1 addition & 0 deletions src/bk-user/bkuser/apis/web/basic/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@

class CurrentUserRetrieveOutputSLZ(serializers.Serializer):
username = serializers.CharField(help_text="用户名")
tenant_id = serializers.CharField(help_text="租户 ID")
1 change: 1 addition & 0 deletions src/bk-user/bkuser/apis/web/basic/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def get(self, request, *args, **kwargs):
current_user = request.user
info = {
"username": current_user.username,
"tenant_id": current_user.get_property("tenant_id"),
}

return Response(CurrentUserRetrieveOutputSLZ(instance=info).data)
6 changes: 6 additions & 0 deletions src/bk-user/bkuser/apis/web/organization/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,9 @@ def get_departments(self, instance: Tenant):
if not departments:
return []
return [item.model_dump(include={"id", "name", "has_children"}) for item in departments]


class TenantDepartmentChildrenListOutputSLZ(serializers.Serializer):
id = serializers.IntegerField(help_text="租户部门ID")
name = serializers.CharField(help_text="部门名称")
has_children = serializers.BooleanField(help_text="是否有子部门")
5 changes: 5 additions & 0 deletions src/bk-user/bkuser/apis/web/organization/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@
# 租户
path("tenants/", views.TenantListApi.as_view(), name="organization.tenant.list"),
path("tenants/<str:id>/", views.TenantRetrieveUpdateApi.as_view(), name="organization.tenant.retrieve_update"),
path(
"departments/<int:id>/children/",
views.TenantDepartmentChildrenListApi.as_view(),
name="organization.children.list",
),
]
18 changes: 17 additions & 1 deletion src/bk-user/bkuser/apis/web/organization/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from rest_framework import generics, status
from rest_framework.response import Response

from bkuser.apis.web.organization.serializers import TenantListOutputSLZ
from bkuser.apis.web.organization.serializers import TenantDepartmentChildrenListOutputSLZ, TenantListOutputSLZ
from bkuser.apis.web.tenant.serializers import TenantRetrieveOutputSLZ, TenantUpdateInputSLZ
from bkuser.apps.tenant.models import Tenant
from bkuser.biz.tenant import (
Expand Down Expand Up @@ -92,3 +92,19 @@ def put(self, request, *args, **kwargs):

TenantHandler.update_with_managers(instance.id, should_updated_info, data["manager_ids"])
return Response()


class TenantDepartmentChildrenListApi(generics.ListAPIView):
pagination_class = None
serializer_class = TenantDepartmentChildrenListOutputSLZ

@swagger_auto_schema(
operation_description="租户部门的二级子部门列表",
responses={status.HTTP_200_OK: TenantDepartmentChildrenListOutputSLZ(many=True)},
)
def get(self, request, *args, **kwargs):
tenant_department_id = self.kwargs["id"]
# 拉取子部门信息列表
tenant_department_children = TenantDepartmentHandler.get_tenant_department_children_by_id(tenant_department_id)
data = [item.model_dump(include={"id", "name", "has_children"}) for item in tenant_department_children]
return Response(self.get_serializer(data, many=True).data)
12 changes: 6 additions & 6 deletions src/bk-user/bkuser/apis/web/tenant/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ class TenantSearchInputSLZ(serializers.Serializer):
name = serializers.CharField(required=False, help_text="租户名", allow_blank=True)


class TenantSearchManagerOutputSchema(serializers.Serializer):
class TenantSearchManagerOutputSLZ(serializers.Serializer):
id = serializers.CharField(help_text="用户 ID")
username = serializers.CharField(help_text="用户名")
full_name = serializers.CharField(help_text="姓名")


class TenantSearchDataSourceOutputSchema(serializers.Serializer):
class TenantSearchDataSourceOutputSLZ(serializers.Serializer):
id = serializers.CharField(help_text="数据源 ID")
name = serializers.CharField(help_text="数据源名称")

Expand All @@ -79,7 +79,7 @@ def get_logo(self, obj: Tenant) -> str:
def get_created_at(self, obj: Tenant) -> str:
return obj.created_at_display

@swagger_serializer_method(serializer_or_field=TenantSearchManagerOutputSchema(many=True))
@swagger_serializer_method(serializer_or_field=TenantSearchManagerOutputSLZ(many=True))
def get_managers(self, obj: Tenant) -> List[Dict]:
tenant_manager_map: Dict[str, List[TenantUserWithInheritedInfo]] = self.context["tenant_manager_map"]
managers = tenant_manager_map.get(obj.id) or []
Expand All @@ -91,7 +91,7 @@ def get_managers(self, obj: Tenant) -> List[Dict]:
for i in managers
]

@swagger_serializer_method(serializer_or_field=TenantSearchDataSourceOutputSchema(many=True))
@swagger_serializer_method(serializer_or_field=TenantSearchDataSourceOutputSLZ(many=True))
def get_data_sources(self, obj: Tenant) -> List[Dict]:
data_source_map: Dict[str, List[DataSourceSimpleInfo]] = self.context["data_source_map"]
data_sources = data_source_map.get(obj.id) or []
Expand All @@ -105,7 +105,7 @@ class TenantUpdateInputSLZ(serializers.Serializer):
feature_flags = TenantFeatureFlagSLZ(help_text="租户特性集")


class TenantRetrieveManagerOutputSchema(serializers.Serializer):
class TenantRetrieveManagerOutputSLZ(serializers.Serializer):
id = serializers.CharField(help_text="用户 ID")
username = serializers.CharField(help_text="租户用户名")
full_name = serializers.CharField(help_text="用户姓名")
Expand All @@ -123,7 +123,7 @@ class TenantRetrieveOutputSLZ(serializers.Serializer):
feature_flags = TenantFeatureFlagSLZ(help_text="租户特性集")
managers = serializers.SerializerMethodField()

@swagger_serializer_method(serializer_or_field=TenantRetrieveManagerOutputSchema(many=True))
@swagger_serializer_method(serializer_or_field=TenantRetrieveManagerOutputSLZ(many=True))
def get_managers(self, obj: Tenant) -> List[Dict]:
# 根据当前登录的租户用户,获取租户ID
# NOTE 因协同数据源而展示的租户,不返回管理员
Expand Down
5 changes: 5 additions & 0 deletions src/bk-user/bkuser/auth/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import logging
import traceback

from django.conf import settings
from django.contrib.auth import get_user_model
from django.contrib.auth.backends import BaseBackend
from django.db import IntegrityError
Expand Down Expand Up @@ -43,6 +44,10 @@ def authenticate(self, request=None, bk_token=None):
user.set_property(key="language", value=user_info.get("language", ""))
user.set_property(key="time_zone", value=user_info.get("time_zone", ""))

# FIXME: 新版登录后删除该MOCK逻辑
tenant_id = settings.MOCK_USER_TENANTS.get(username) or settings.MOCK_USER_DEFAULT_TENANT
user.set_property(key="tenant_id", value=tenant_id)

return user

except IntegrityError:
Expand Down
13 changes: 12 additions & 1 deletion src/bk-user/bkuser/biz/tenant.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def get_tenant_manager_map(tenant_ids: Optional[List[str]] = None) -> Dict[str,
@staticmethod
def retrieve_tenant_managers(tenant_id: str) -> List[TenantUserWithInheritedInfo]:
"""
查询单个租户的
查询单个租户的租户管理员
"""
tenant_managers = TenantManager.objects.filter(tenant_id=tenant_id)
# 查询管理员对应的信息
Expand Down Expand Up @@ -273,3 +273,14 @@ def get_tenant_root_departments_by_id(
)
tenant_root_department_map[tenant_id] = tenant_root_department
return tenant_root_department_map

@staticmethod
def get_tenant_department_children_by_id(tenant_department_id: int) -> List[TenantDepartmentBaseInfo]:
tenant_department = TenantDepartment.objects.get(id=tenant_department_id)
# 获取二级组织
children = DataSourceDepartmentRelation.objects.get(
department=tenant_department.data_source_department
).get_children()
return TenantDepartmentHandler.convert_data_source_department_to_tenant_department(
tenant_department.tenant_id, children.values_list("department_id", flat=True)
)
3 changes: 3 additions & 0 deletions src/bk-user/bkuser/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,3 +468,6 @@
DEFAULT_DATA_SOURCE_USER_LOGO = ""
# 默认手机国际区号
DEFAULT_PHONE_COUNTRY_CODE = env.str("DEFAULT_PHONE_COUNTRY_CODE", default="86")
# FIXME: 待新版登录完成后删除Mock用户租户数据,格式:key1=value1;key2=value2
MOCK_USER_TENANTS = env.dict("MOCK_USER_TENANTS", default={})
MOCK_USER_DEFAULT_TENANT = env.str("MOCK_USER_DEFAULT_TENANT", default="")
30 changes: 8 additions & 22 deletions src/pages/.bk.development.env
Original file line number Diff line number Diff line change
@@ -1,25 +1,4 @@
# .bk.development.env 生产模式生效

# 网站前缀
BK_SITE_URL = ''

# 静态资源路径
BK_STATIC_URL = ''

# 当前应用的环境,预发布环境为 stag,正式环境为 prod
BK_PAAS_ENVIRONMENT = ''

# EngineApp名称,拼接规则:bkapp-{appcode}-{BKPAAS_ENVIRONMENT}
BK_PAAS_ENGINE_APP_NAME = ''

# 内部版对应ieod,外部版对应tencent,混合云版对应clouds
BK_PAAS_ENGINE_REGION = ''

# APP ID
BK_PAAS_APP_ID = ''

# APP SECRET
BK_PAAS_APP_SECRET = ''
# .bk.production.env 开发模式生效,开发时,复制并保存为.bk.local.env,然后把具体值填上

# 登录地址
BK_LOGIN_URL = ''
Expand All @@ -29,3 +8,10 @@ BK_APP_HOST = ''

# 开发 port
BK_APP_PORT = 5002

# 静态资源路径
BK_STATIC_URL = ''

BK_AJAX_BASE_URL = ''

BK_CSRF_COOKIE_NAME = ''
7 changes: 0 additions & 7 deletions src/pages/.bk.env

This file was deleted.

22 changes: 4 additions & 18 deletions src/pages/.bk.production.env
Original file line number Diff line number Diff line change
@@ -1,25 +1,11 @@
# .bk.production.env 生产模式生效

# 网站前缀
BK_SITE_URL = '{{ SITE_URL }}'
# 登录地址
BK_LOGIN_URL = '{{ BK_LOGIN_URL }}'

# 静态资源路径
BK_STATIC_URL = '{{ BK_STATIC_URL }}'

# 当前应用的环境,预发布环境为 stag,正式环境为 prod
BK_PAAS_ENVIRONMENT = '{{ BKPAAS_ENVIRONMENT }}'

# EngineApp名称,拼接规则:bkapp-{appcode}-{BKPAAS_ENVIRONMENT}
BK_PAAS_ENGINE_APP_NAME = '{{ BKPAAS_ENGINE_APP_NAME }}'

# 内部版对应ieod,外部版对应tencent,混合云版对应clouds
BK_PAAS_ENGINE_REGION = '{{ BKPAAS_ENGINE_REGION }}'
BK_AJAX_BASE_URL = '{{ AJAX_BASE_URL }}'

# APP ID
BK_PAAS_APP_ID = '{{ BKPAAS_APP_ID }}'

# APP SECRET
BK_PAAS_APP_SECRET = '{{ BKPAAS_APP_SECRET }}'

# 登录地址
BK_LOGIN_URL = '{{ BK_LOGIN_URL }}'
BK_CSRF_COOKIE_NAME = '{{ CSRF_COOKIE_NAME }}'
19 changes: 16 additions & 3 deletions src/pages/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
module.exports = {
root: true,
extends: ['@blueking/eslint-config-bk/tsvue3'],
plugins: [
'simple-import-sort',
],
rules: {
'simple-import-sort/imports': ['error', {
groups: [
['^[a-zA-Z]'],
['^@\\w'],
['^\\.\\.'],
['^\\.'],
],
}],
'no-param-reassign': 'off',
},
parserOptions: {
project: [
'./tsconfig.json',
],
project: 'tsconfig.eslint.json',
tsconfigRootDir: __dirname,
},
};
2 changes: 2 additions & 0 deletions src/pages/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,5 @@ test/unit/coverage
*.njsproj
*.sln
dist/

.bk.local.env
2 changes: 2 additions & 0 deletions src/pages/.stylelintignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
node_modules/
dist
static/
4 changes: 0 additions & 4 deletions src/pages/.stylelintrc.js

This file was deleted.

4 changes: 3 additions & 1 deletion src/pages/bk.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ module.exports = {
return {
devServer: {
setupMiddlewares: mockServer,
https: true,
proxy: {
'/api': {
target: '',
target: process.env.AJAX_BASE_URL,
changeOrigin: true,
secure: false,
},
},
},
Expand Down
12 changes: 6 additions & 6 deletions src/pages/index.html
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<!DOCTYPE html>
<html>
<head>
<link rel="icon" href="{{ BK_STATIC_URL }}/images/favicon.png" type="image/x-icon" />
<link rel="shortcut icon" href="{{ BK_STATIC_URL }}/images/favicon.png" type="image/x-icon" />
<link rel="icon" href="<%= process.env.BK_STATIC_URL %>/images/logo.ico" type="image/x-icon" />
<link rel="shortcut icon" href="<%= process.env.BK_STATIC_URL %>/images/logo.ico" type="image/x-icon" />
<meta charset="utf-8">
<title> {{ TITLE }} </title>
</head>
<body>
<div class="app"></div>
<script>
// 登录页面
window.BK_LOGIN_URL = '{{ BK_LOGIN_URL }}'
window.BK_LOGIN_URL = '<%= process.env.BK_LOGIN_URL %>';
// 开发环境域名
window.AJAX_BASE_URL = '{{ AJAX_BASE_URL }}'
window.AJAX_BASE_URL = '<%= process.env.BK_AJAX_BASE_URL %>';
// 静态资源路径
window.BK_STATIC_URL = '{{ BK_STATIC_URL }}'
window.CSRF_COOKIE_NAME = '{{ CSRF_COOKIE_NAME }}'
window.BK_STATIC_URL = '<%= process.env.BK_STATIC_URL %>';
window.CSRF_COOKIE_NAME = '<%= process.env.BK_CSRF_COOKIE_NAME %>';
</script>
</body>
</html>
17 changes: 14 additions & 3 deletions src/pages/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
{
"name": "bkuicli-vue3",
"name": "bk-user",
"version": "1.0.0",
"description": "",
"scripts": {
"dev": "bk-cli-service-webpack dev",
"build": "bk-cli-service-webpack build",
"server": "node ./paas-server/index.js",
"lint:style": "stylelint **/*.{html,vue,css,sass,scss,less} --fix"
"lint": "eslint --ext .js,.vue,.ts ./src",
"lint:fix": "eslint --fix --ext .js,.vue,.ts ./src",
"lint:style": "stylelint \"./**/*.{css,less,vue,html}\" --fix"
},
"keywords": [
"bk-ci",
Expand Down Expand Up @@ -39,19 +41,28 @@
},
"devDependencies": {
"@blueking/babel-preset-bk": "^2.1.0-beta7",
"@blueking/cli-service-webpack": "0.0.0-beta.73",
"@blueking/cli-service-webpack": "0.0.0-beta.87",
"@blueking/eslint-config-bk": "2.1.0-beta.12",
"@blueking/stylelint-config-bk": "^2.1.0-beta.9",
"@types/node": "^20.5.1",
"enhanced-resolve": "^5.10.0",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-simple-import-sort": "^10.0.0",
"less-loader": "7.3.0",
"postcss": "~8.4.16",
"postcss-html": "^1.5.0",
"postcss-import": "^15.0.0",
"postcss-less": "^6.0.0",
"postcss-mixins": "^9.0.4",
"postcss-nested": "^6.0.0",
"postcss-nested-ancestors": "^3.0.0",
"postcss-preset-env": "^7.8.2",
"postcss-simple-vars": "^7.0.0",
"postcss-url": "^10.1.3",
"stylelint": "^15.10.3",
"stylelint-config-standard": "^34.0.0",
"stylelint-less": "^1.0.8",
"stylelint-order": "^6.0.3",
"typescript": "^4.8.4"
},
"engines": {
Expand Down
14 changes: 8 additions & 6 deletions src/pages/src/app.vue
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
<script setup lang="ts">
import { Message } from 'bkui-vue';
import {
ref,
} from 'vue';
import { useUser } from '@/store/user';
import { getUser } from '@/http/api';
import { Message } from 'bkui-vue';
import HeaderBox from './views/Header.vue';
import { currentUser } from '@/http/api';
import { useUser } from '@/store/user';
// 加载完用户数据才会展示页面
const isLoading = ref(false);
// 获取用户数据
const user = useUser();
getUser()
.then((data) => {
user.setUser(data);
currentUser()
.then((res) => {
user.setUser(res.data);
isLoading.value = false;
})
.catch(() => {
Expand Down
Loading

0 comments on commit e4fcd62

Please sign in to comment.