mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-24 23:46:52 +08:00
Feat: Admin UI whitelist management and role management (#10910)
### What problem does this PR solve? Add whitelist management and role management in Admin UI ### Type of change - [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
@ -128,151 +128,20 @@ const {
|
||||
adminUpdateUserRole,
|
||||
|
||||
adminListResources,
|
||||
|
||||
adminListWhitelist,
|
||||
adminCreateWhitelistEntry,
|
||||
adminUpdateWhitelistEntry,
|
||||
adminDeleteWhitelistEntry,
|
||||
adminImportWhitelist,
|
||||
} = api;
|
||||
|
||||
type ResponseData<D = {}> = {
|
||||
type ResponseData<D = NonNullable<unknown>> = {
|
||||
code: number;
|
||||
message: string;
|
||||
data: D;
|
||||
};
|
||||
|
||||
export namespace AdminService {
|
||||
export type LoginData = {
|
||||
access_token: string;
|
||||
avatar: unknown;
|
||||
color_schema: 'Bright' | 'Dark';
|
||||
create_date: string;
|
||||
create_time: number;
|
||||
email: string;
|
||||
id: string;
|
||||
is_active: '0' | '1';
|
||||
is_anonymous: '0' | '1';
|
||||
is_authenticated: '0' | '1';
|
||||
is_superuser: boolean;
|
||||
language: string;
|
||||
last_login_time: string;
|
||||
login_channel: unknown;
|
||||
nickname: string;
|
||||
password: string;
|
||||
status: '0' | '1';
|
||||
timezone: string;
|
||||
update_date: [string];
|
||||
update_time: [number];
|
||||
};
|
||||
|
||||
export type ListUsersItem = {
|
||||
create_date: string;
|
||||
email: string;
|
||||
is_active: '0' | '1';
|
||||
is_superuser: boolean;
|
||||
role: string;
|
||||
nickname: string;
|
||||
};
|
||||
|
||||
export type UserDetail = {
|
||||
create_date: string;
|
||||
email: string;
|
||||
is_active: '0' | '1';
|
||||
is_anonymous: '0' | '1';
|
||||
is_superuser: boolean;
|
||||
language: string;
|
||||
last_login_time: string;
|
||||
login_channel: unknown;
|
||||
status: '0' | '1';
|
||||
update_date: string;
|
||||
role: string;
|
||||
};
|
||||
|
||||
export type ListUserDatasetItem = {
|
||||
chunk_num: number;
|
||||
create_date: string;
|
||||
doc_num: number;
|
||||
language: string;
|
||||
name: string;
|
||||
permission: string;
|
||||
status: '0' | '1';
|
||||
token_num: number;
|
||||
update_date: string;
|
||||
};
|
||||
|
||||
export type ListUserAgentItem = {
|
||||
canvas_category: 'agent';
|
||||
permission: 'string';
|
||||
title: string;
|
||||
};
|
||||
|
||||
export type ListServicesItem = {
|
||||
extra: Record<string, unknown>;
|
||||
host: string;
|
||||
id: number;
|
||||
name: string;
|
||||
port: number;
|
||||
service_type: string;
|
||||
status: 'alive' | 'timeout' | 'fail';
|
||||
};
|
||||
|
||||
export type ServiceDetail = {
|
||||
service_name: string;
|
||||
status: 'alive' | 'timeout';
|
||||
message: string | Record<string, any> | Record<string, any>[];
|
||||
};
|
||||
|
||||
export type PermissionData = {
|
||||
enable: boolean;
|
||||
read: boolean;
|
||||
write: boolean;
|
||||
share: boolean;
|
||||
};
|
||||
|
||||
export type ListRoleItem = {
|
||||
id: string;
|
||||
role_name: string;
|
||||
description: string;
|
||||
create_date: string;
|
||||
update_date: string;
|
||||
};
|
||||
|
||||
export type ListRoleItemWithPermission = ListRoleItem & {
|
||||
permissions: Record<string, PermissionData>;
|
||||
};
|
||||
|
||||
export type RoleDetailWithPermission = {
|
||||
role: {
|
||||
id: string;
|
||||
name: string;
|
||||
description: string;
|
||||
};
|
||||
permissions: Record<string, PermissionData>;
|
||||
};
|
||||
|
||||
export type RoleDetail = {
|
||||
id: string;
|
||||
name: string;
|
||||
descrtiption: string;
|
||||
create_date: string;
|
||||
update_date: string;
|
||||
};
|
||||
|
||||
export type AssignRolePermissionsInput = Record<
|
||||
string,
|
||||
Partial<PermissionData>
|
||||
>;
|
||||
export type RevokeRolePermissionInput = AssignRolePermissionsInput;
|
||||
|
||||
export type UserDetailWithPermission = {
|
||||
user: {
|
||||
id: string;
|
||||
username: string;
|
||||
role: string;
|
||||
};
|
||||
role_permissions: Record<string, PermissionData>;
|
||||
};
|
||||
|
||||
export type ResourceType = {
|
||||
resource_types: string[];
|
||||
};
|
||||
}
|
||||
|
||||
export const login = (params: { email: string; password: string }) =>
|
||||
request.post<ResponseData<AdminService.LoginData>>(adminLogin, params);
|
||||
export const logout = () => request.get<ResponseData<boolean>>(adminLogout);
|
||||
@ -363,15 +232,29 @@ export const getUserPermissions = (username: string) =>
|
||||
export const listResources = () =>
|
||||
request.get<ResponseData<AdminService.ResourceType>>(adminListResources);
|
||||
|
||||
export const whitelistImportFromExcel = (file: File) => {
|
||||
export const listWhitelist = () =>
|
||||
request.get<
|
||||
ResponseData<{
|
||||
total: number;
|
||||
white_list: AdminService.ListWhitelistItem[];
|
||||
}>
|
||||
>(adminListWhitelist);
|
||||
|
||||
export const createWhitelistEntry = (email: string) =>
|
||||
request.post<ResponseData<never>>(adminCreateWhitelistEntry, { email });
|
||||
|
||||
export const updateWhitelistEntry = (id: number, email: string) =>
|
||||
request.put<ResponseData<never>>(adminUpdateWhitelistEntry(id), { email });
|
||||
|
||||
export const deleteWhitelistEntry = (email: string) =>
|
||||
request.delete<ResponseData<never>>(adminDeleteWhitelistEntry(email));
|
||||
|
||||
export const importWhitelistFromExcel = (file: File) => {
|
||||
const fd = new FormData();
|
||||
|
||||
fd.append('file', file);
|
||||
|
||||
return request.post<ResponseData<never>>(
|
||||
'/api/v1/admin/whitelist/import',
|
||||
fd,
|
||||
);
|
||||
return request.post<ResponseData<never>>(adminImportWhitelist, fd);
|
||||
};
|
||||
|
||||
export default {
|
||||
|
||||
145
web/src/services/admin.service.d.ts
vendored
Normal file
145
web/src/services/admin.service.d.ts
vendored
Normal file
@ -0,0 +1,145 @@
|
||||
declare module AdminService {
|
||||
export type LoginData = {
|
||||
access_token: string;
|
||||
avatar: unknown;
|
||||
color_schema: 'Bright' | 'Dark';
|
||||
create_date: string;
|
||||
create_time: number;
|
||||
email: string;
|
||||
id: string;
|
||||
is_active: '0' | '1';
|
||||
is_anonymous: '0' | '1';
|
||||
is_authenticated: '0' | '1';
|
||||
is_superuser: boolean;
|
||||
language: string;
|
||||
last_login_time: string;
|
||||
login_channel: unknown;
|
||||
nickname: string;
|
||||
password: string;
|
||||
status: '0' | '1';
|
||||
timezone: string;
|
||||
update_date: [string];
|
||||
update_time: [number];
|
||||
};
|
||||
|
||||
export type ListUsersItem = {
|
||||
create_date: string;
|
||||
email: string;
|
||||
is_active: '0' | '1';
|
||||
is_superuser: boolean;
|
||||
role: string;
|
||||
nickname: string;
|
||||
};
|
||||
|
||||
export type UserDetail = {
|
||||
create_date: string;
|
||||
email: string;
|
||||
is_active: '0' | '1';
|
||||
is_anonymous: '0' | '1';
|
||||
is_superuser: boolean;
|
||||
language: string;
|
||||
last_login_time: string;
|
||||
login_channel: unknown;
|
||||
status: '0' | '1';
|
||||
update_date: string;
|
||||
role: string;
|
||||
};
|
||||
|
||||
export type ListUserDatasetItem = {
|
||||
chunk_num: number;
|
||||
create_date: string;
|
||||
doc_num: number;
|
||||
language: string;
|
||||
name: string;
|
||||
permission: string;
|
||||
status: '0' | '1';
|
||||
token_num: number;
|
||||
update_date: string;
|
||||
};
|
||||
|
||||
export type ListUserAgentItem = {
|
||||
canvas_category: 'agent';
|
||||
permission: 'string';
|
||||
title: string;
|
||||
};
|
||||
|
||||
export type ListServicesItem = {
|
||||
extra: Record<string, unknown>;
|
||||
host: string;
|
||||
id: number;
|
||||
name: string;
|
||||
port: number;
|
||||
service_type: string;
|
||||
status: 'alive' | 'timeout' | 'fail';
|
||||
};
|
||||
|
||||
export type ServiceDetail = {
|
||||
service_name: string;
|
||||
status: 'alive' | 'timeout';
|
||||
message: string | Record<string, any> | Record<string, any>[];
|
||||
};
|
||||
|
||||
export type PermissionData = {
|
||||
enable: boolean;
|
||||
read: boolean;
|
||||
write: boolean;
|
||||
share: boolean;
|
||||
};
|
||||
|
||||
export type ListRoleItem = {
|
||||
id: string;
|
||||
role_name: string;
|
||||
description: string;
|
||||
create_date: string;
|
||||
update_date: string;
|
||||
};
|
||||
|
||||
export type ListRoleItemWithPermission = ListRoleItem & {
|
||||
permissions: Record<string, PermissionData>;
|
||||
};
|
||||
|
||||
export type RoleDetailWithPermission = {
|
||||
role: {
|
||||
id: string;
|
||||
name: string;
|
||||
description: string;
|
||||
};
|
||||
permissions: Record<string, PermissionData>;
|
||||
};
|
||||
|
||||
export type RoleDetail = {
|
||||
id: string;
|
||||
name: string;
|
||||
descrtiption: string;
|
||||
create_date: string;
|
||||
update_date: string;
|
||||
};
|
||||
|
||||
export type AssignRolePermissionsInput = Record<
|
||||
string,
|
||||
Partial<PermissionData>
|
||||
>;
|
||||
export type RevokeRolePermissionInput = AssignRolePermissionsInput;
|
||||
|
||||
export type UserDetailWithPermission = {
|
||||
user: {
|
||||
id: string;
|
||||
username: string;
|
||||
role: string;
|
||||
};
|
||||
role_permissions: Record<string, PermissionData>;
|
||||
};
|
||||
|
||||
export type ResourceType = {
|
||||
resource_types: string[];
|
||||
};
|
||||
|
||||
export type ListWhitelistItem = {
|
||||
id: number;
|
||||
email: string;
|
||||
create_date: string;
|
||||
createt_time: number;
|
||||
update_date: string;
|
||||
update_time: number;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user