Skip to content

Commit

Permalink
minor: merge tencent/ft_tenant into data_source_base_api
Browse files Browse the repository at this point in the history
  • Loading branch information
narasux committed Sep 4, 2023
2 parents e8b8213 + 46969ee commit 858fd31
Show file tree
Hide file tree
Showing 26 changed files with 514 additions and 249 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@ def validate_department_ids(self, department_ids):

def validate_leader_ids(self, leader_ids):
diff_leader_ids = set(leader_ids) - set(
DataSourceUser.objects.filter(id__in=leader_ids, data_source=self.context["data_source"]).values_list(
"id", flat=True
)
DataSourceUser.objects.filter(
id__in=leader_ids,
data_source=self.context["data_source"],
).values_list("id", flat=True)
)
if diff_leader_ids:
raise serializers.ValidationError(_("传递了错误的上级信息: {}").format(diff_leader_ids))
Expand Down Expand Up @@ -154,7 +155,7 @@ class UserUpdateInputSLZ(serializers.Serializer):
email = serializers.CharField(help_text="邮箱")
phone_country_code = serializers.CharField(help_text="手机国际区号")
phone = serializers.CharField(help_text="手机号")
logo = serializers.CharField(help_text="用户 Logo", allow_blank=True)
logo = serializers.CharField(help_text="用户 Logo", allow_blank=True, required=False, default="")

department_ids = serializers.ListField(help_text="部门ID列表", child=serializers.IntegerField())
leader_ids = serializers.ListField(help_text="上级ID列表", child=serializers.IntegerField())
Expand All @@ -175,9 +176,10 @@ def validate_department_ids(self, department_ids):

def validate_leader_ids(self, leader_ids):
diff_leader_ids = set(leader_ids) - set(
DataSourceUser.objects.filter(id__in=leader_ids, data_source=self.context["data_source"]).values_list(
"id", flat=True
)
DataSourceUser.objects.filter(
id__in=leader_ids,
data_source=self.context["data_source"],
).values_list("id", flat=True)
)
if diff_leader_ids:
raise serializers.ValidationError(_("传递了错误的上级信息: {}").format(diff_leader_ids))
Expand Down
4 changes: 2 additions & 2 deletions src/bk-user/bkuser/apis/web/data_source_organization/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
# 数据源用户
path("<int:id>/users/", views.DataSourceUserListCreateApi.as_view(), name="data_source_user.list_create"),
# 数据源用户 Leader
path("<int:id>/leaders/", views.DataSourceLeadersListApi.as_view(), name="data_source_leaders.list"),
path("<int:id>/leaders/", views.DataSourceLeadersListApi.as_view(), name="data_source_leader.list"),
# 数据源部门
path("<int:id>/departments/", views.DataSourceDepartmentsListApi.as_view(), name="data_source_departments.list"),
path("<int:id>/departments/", views.DataSourceDepartmentsListApi.as_view(), name="data_source_department.list"),
path("users/<int:id>/", views.DataSourceUserRetrieveUpdateApi.as_view(), name="data_source_user.retrieve_update"),
]
4 changes: 3 additions & 1 deletion src/bk-user/bkuser/apis/web/tenant/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ def get_data_sources(self, obj: Tenant) -> List[Dict]:

class TenantUpdateInputSLZ(serializers.Serializer):
name = serializers.CharField(help_text="租户名称")
logo = serializers.CharField(help_text="租户 Logo", required=False, default=settings.DEFAULT_TENANT_LOGO)
logo = serializers.CharField(
help_text="租户 Logo", required=False, allow_blank=True, default=settings.DEFAULT_TENANT_LOGO
)
manager_ids = serializers.ListField(child=serializers.CharField(), help_text="租户用户 ID 列表", allow_empty=False)
feature_flags = TenantFeatureFlagSLZ(help_text="租户特性集")

Expand Down
3 changes: 2 additions & 1 deletion src/bk-user/bkuser/biz/tenant.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from typing import Dict, List, Optional

from django.db import transaction
from django.utils.timezone import now
from pydantic import BaseModel

from bkuser.apps.data_source.models import (
Expand Down Expand Up @@ -308,7 +309,7 @@ def update_with_managers(tenant_id: str, tenant_info: TenantEditableBaseInfo, ma

with transaction.atomic():
# 更新基本信息
Tenant.objects.filter(id=tenant_id).update(**tenant_info.model_dump())
Tenant.objects.filter(id=tenant_id).update(updated_at=now(), **tenant_info.model_dump())

if should_deleted_manager_ids:
TenantManager.objects.filter(
Expand Down
2 changes: 1 addition & 1 deletion src/pages/src/css/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
.span-logo {
display: inline-block;
width: 16px;
margin-right: 8px;
font-size: 12px;
font-weight: 700;
line-height: 16px;
Expand All @@ -60,5 +61,4 @@
background-color: #C4C6CC;
border-radius: 4px;
flex-shrink: 0;
margin-right: 8px;
}
2 changes: 1 addition & 1 deletion src/pages/src/hooks/use-validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default () => {
};

const userName = {
validator: (value: string) => /^([a-zA-Z])([a-zA-Z0-9._-]){0,31}$/.test(value),
validator: (value: string) => /^([a-zA-Z0-9])([a-zA-Z0-9._-]){0,31}$/.test(value),
message: '由1-32位字母、数字、下划线(_)、点(.)、减号(-)字符组成,以字母或数字开头',
trigger: 'blur',
};
Expand Down
15 changes: 14 additions & 1 deletion src/pages/src/hooks/useMenuInfo.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { computed } from 'vue';
import { computed, inject } from 'vue';
import { RouteLocationNormalizedLoaded, RouteRecordRaw, useRoute, useRouter } from 'vue-router';

export const useMenuInfo = () => {
const route = useRoute();
const router = useRouter();
const editLeaveBefore = inject('editLeaveBefore');

// 获取 menu 相关配置
const { children } = route.matched[0];
Expand All @@ -29,6 +30,18 @@ export const useMenuInfo = () => {
router.push({ name: key });
};


router.beforeEach(async (to, from, next) => {
let enableLeave = true;
if (window.changeInput) {
enableLeave = await editLeaveBefore();
}
if (!enableLeave) {
return Promise.resolve(enableLeave);
}
next();
});

return {
activeKey,
openedKeys,
Expand Down
24 changes: 20 additions & 4 deletions src/pages/src/http/dataSourceFiles.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,36 @@
import http from './fetch';
import type {
DataSourceUsersResult,
NewDataSourceUsersParams,
NewDataSourceUserParams,
PutDataSourceUserParams,
} from './types/dataSourceFiles';

/**
* 数据源用户信息列表
*/
export const getDataSourceUsers = (id: string): Promise<DataSourceUsersResult> => http.get(`/api/v1/web/data-sources/${id}/users/`);
export const getDataSourceUsers = (id: string, username: string): Promise<DataSourceUsersResult> => http.get(`/api/v1/web/data-sources/${id}/users/?username=${username}`);

/**
* 新建数据源用户
*/
export const newDataSourceUsers = (params: NewDataSourceUsersParams) => http.post(`/api/v1/web/data-sources/${params.id}/users/`);
export const newDataSourceUser = (params: NewDataSourceUserParams) => http.post(`/api/v1/web/data-sources/${params.id}/users/`, params);

/**
* 数据源创建用户-下拉部门列表
*/
export const getDataSourceDepartments = (id: string) => http.get(`/api/v1/web/data-sources/${id}/departments/`);
export const getDataSourceDepartments = (id: string, name: string) => http.get(`/api/v1/web/data-sources/${id}/departments/?name=${name}`);

/**
* 数据源创建用户-下拉上级列表
*/
export const getDataSourceLeaders = (id: string, keyword: string) => http.get(`/api/v1/web/data-sources/${id}/leaders/?keyword=${keyword}`);

/**
* 数据源用户详情
*/
export const getDataSourceUserDetails = (id: string) => http.get(`/api/v1/web/data-sources/user/${id}/`);

/**
* 更新数据源用户
*/
export const putDataSourceUserDetails = (params: PutDataSourceUserParams) => http.put(`/api/v1/web/data-sources/user/${params.id}/`, params);
9 changes: 9 additions & 0 deletions src/pages/src/http/organizationFiles.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import http from './fetch';
import type {
DepartmentsListParams,
TenantListParams,
UpdateTenantParams,
} from './types/organizationFiles';

Expand Down Expand Up @@ -39,3 +40,11 @@ export const getTenantDepartmentsList = (params: DepartmentsListParams) => {
const { id, keyword, page, pageSize, recursive } = params;
return http.get(`/api/v1/web/tenant-organization/departments/${id}/users/?keyword=${keyword}&page=${page}&page_size=${pageSize}&recursive=${recursive}`);
};

/**
* 租户下用户列表
*/
export const getTenantUsersList = (params: TenantListParams) => {
const { id, keyword, page, pageSize } = params;
return http.get(`/api/v1/web/tenant-organization/tenants/${id}/users/?keyword=${keyword}&page=${page}&page_size=${pageSize}`);
};
16 changes: 15 additions & 1 deletion src/pages/src/http/types/dataSourceFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface DataSourceUsersResult {
/**
* 新建数据源用户参数
*/
export interface NewDataSourceUsersParams {
export interface NewDataSourceUserParams {
id: string,
username: string,
full_name: string,
Expand All @@ -27,3 +27,17 @@ export interface NewDataSourceUsersParams {
department_ids?: [],
leader_ids?: [],
}

/**
* 更新数据源用户参数
*/
export interface PutDataSourceUserParams {
id: string,
full_name: string,
email: string,
phone_country_code: string,
phone: string,
logo?: string,
department_ids?: [],
leader_ids?: [],
}
10 changes: 10 additions & 0 deletions src/pages/src/http/types/organizationFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,13 @@ export interface DepartmentsListParams {
pageSize: number,
recursive: boolean,
}

/**
* 租户下用户列表参数
*/
export interface TenantListParams {
id: string,
keyword: string,
page: number,
pageSize: number,
}
21 changes: 13 additions & 8 deletions src/pages/src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ export default createRouter({
],
},
{
path: '/datasource',
name: 'datasource',
path: '/data-source',
name: 'dataSource',
redirect: {
name: 'local',
},
Expand All @@ -55,46 +55,51 @@ export default createRouter({
path: '',
name: '',
meta: {
routeParentName: 'datasource',
routeParentName: 'data-source',
navName: '数据源管理',
activeMenu: 'local',
},
component: () => import('@/views/data-source/LocalCompany.vue'),
children: [
{
path: 'local',
name: 'local',
meta: {
routeParentName: 'datasource',
routeParentName: 'dataSource',
navName: '数据源管理',
activeMenu: 'local',
},
component: () => import('@/views/data-source/LocalDataSource.vue'),
},
{
path: 'other',
name: 'other',
meta: {
routeParentName: 'datasource',
routeParentName: 'dataSource',
navName: '数据源管理',
activeMenu: 'local',
},
component: () => import('@/views/data-source/OtherDataSource.vue'),
},
],
},
{
path: 'local-details/:name/:type',
path: 'local-details/:name/:type/:id',
name: 'dataConfDetails',
meta: {
routeParentName: 'datasource',
routeParentName: 'dataSource',
navName: '数据源详情',
activeMenu: 'local',
},
component: () => import('@/views/data-source/local-details/index.vue'),
},
{
path: 'new-local/:type',
name: 'newLocal',
meta: {
routeParentName: 'datasource',
routeParentName: 'dataSource',
navName: '新建数据源',
activeMenu: 'local',
},
component: () => import('@/views/data-source/new-data/NewLocalData.vue'),
},
Expand Down
2 changes: 1 addition & 1 deletion src/pages/src/views/Header.vue
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const headerNav = reactive([
},
{
name: '数据源管理',
path: 'datasource',
path: 'dataSource',
},
{
name: '租户管理',
Expand Down
4 changes: 4 additions & 0 deletions src/pages/src/views/data-source/LocalDataSource.vue
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,15 @@ const dropdownList = ref([
const tableData = [
{
id: 2,
name: '联通子公司正式员工',
type: 'local',
status: 'normal',
modified_by: 'v_yutyi',
modified_at: '2022-04-30 22:35:49',
},
{
id: 7,
name: '企业内部',
type: 'local',
status: 'disabled',
Expand All @@ -125,6 +127,7 @@ function handleClick(item) {
params: {
name: item.name,
type: item.type,
id: item.id,
},
});
}
Expand Down Expand Up @@ -178,6 +181,7 @@ function newDataSource(item) {
}
.account-status-icon {
display: inline-block;
width: 16px;
height: 16px;
margin-right: 5px;
Expand Down
Loading

0 comments on commit 858fd31

Please sign in to comment.