feat: Implement cross-tenant access functionality
- Added configuration for enabling cross-tenant access in the application. - Introduced new API endpoints for listing and searching tenants, accessible only to users with the appropriate permissions. - Updated user and tenant models to include the `can_access_all_tenants` field. - Enhanced the authentication middleware to handle cross-tenant requests and validate user permissions. - Created a new TenantSelector component for selecting tenants in the frontend, improving user experience. - Updated internationalization files to support new tenant-related strings and messages.
This commit is contained in:
@@ -15,6 +15,7 @@ export interface LoginResponse {
|
||||
email: string
|
||||
avatar?: string
|
||||
tenant_id: number
|
||||
can_access_all_tenants?: boolean
|
||||
is_active: boolean
|
||||
created_at: string
|
||||
updated_at: string
|
||||
@@ -66,6 +67,7 @@ export interface UserInfo {
|
||||
email: string
|
||||
avatar?: string
|
||||
tenant_id: string
|
||||
can_access_all_tenants?: boolean
|
||||
created_at: string
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
import { get } from '@/utils/request'
|
||||
|
||||
// 租户信息接口
|
||||
export interface TenantInfo {
|
||||
id: number
|
||||
name: string
|
||||
description?: string
|
||||
api_key?: string
|
||||
status?: string
|
||||
business?: string
|
||||
storage_quota?: number
|
||||
storage_used?: number
|
||||
created_at: string
|
||||
updated_at: string
|
||||
}
|
||||
|
||||
// 搜索租户参数
|
||||
export interface SearchTenantsParams {
|
||||
keyword?: string
|
||||
tenant_id?: number
|
||||
page?: number
|
||||
page_size?: number
|
||||
}
|
||||
|
||||
// 搜索租户响应
|
||||
export interface SearchTenantsResponse {
|
||||
success: boolean
|
||||
data?: {
|
||||
items: TenantInfo[]
|
||||
total: number
|
||||
page: number
|
||||
page_size: number
|
||||
}
|
||||
message?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有租户列表(需要跨租户访问权限)
|
||||
* @deprecated 建议使用 searchTenants 代替,支持分页和搜索
|
||||
*/
|
||||
export async function listAllTenants(): Promise<{ success: boolean; data?: { items: TenantInfo[] }; message?: string }> {
|
||||
try {
|
||||
const response = await get('/api/v1/tenants/all')
|
||||
return response as unknown as { success: boolean; data?: { items: TenantInfo[] }; message?: string }
|
||||
} catch (error: any) {
|
||||
return {
|
||||
success: false,
|
||||
message: error.message || '获取租户列表失败'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索租户(支持分页、关键词搜索和租户ID过滤)
|
||||
*/
|
||||
export async function searchTenants(params: SearchTenantsParams = {}): Promise<SearchTenantsResponse> {
|
||||
try {
|
||||
const queryParams = new URLSearchParams()
|
||||
if (params.keyword) {
|
||||
queryParams.append('keyword', params.keyword)
|
||||
}
|
||||
if (params.tenant_id) {
|
||||
queryParams.append('tenant_id', String(params.tenant_id))
|
||||
}
|
||||
if (params.page) {
|
||||
queryParams.append('page', String(params.page))
|
||||
}
|
||||
if (params.page_size) {
|
||||
queryParams.append('page_size', String(params.page_size))
|
||||
}
|
||||
|
||||
const queryString = queryParams.toString()
|
||||
const url = `/api/v1/tenants/search${queryString ? '?' + queryString : ''}`
|
||||
const response = await get(url)
|
||||
return response as unknown as SearchTenantsResponse
|
||||
} catch (error: any) {
|
||||
return {
|
||||
success: false,
|
||||
message: error.message || '搜索租户失败'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user