feat(users): add user permissions management and enhance theme switcher

This commit is contained in:
Tran Anh Tuan
2026-01-22 13:22:55 +07:00
parent 32a69cb190
commit 0bac8d0f25
22 changed files with 881 additions and 124 deletions

View File

@@ -55,3 +55,20 @@ export async function apiDeleteGroup(group_id: string) {
},
);
}
export async function apiUnassignToGroup(
body: MasterModel.AssignMemberRequest,
) {
return request(`${API_GROUPS}/${body.group_id}/members`, {
method: 'DELETE',
data: body,
getResponse: true,
});
}
export async function apiAssignToGroup(body: MasterModel.AssignMemberRequest) {
return request(`${API_GROUPS}/${body.group_id}/members`, {
method: 'POST',
data: body,
getResponse: true,
});
}

View File

@@ -1,4 +1,4 @@
import { API_USERS, API_USERS_BY_GROUP } from '@/constants/api';
import { API_GROUPS, API_USERS, API_USERS_BY_GROUP } from '@/constants/api';
import { request } from '@umijs/max';
export async function apiQueryUsers(
@@ -9,6 +9,10 @@ export async function apiQueryUsers(
});
}
export async function apiQueryUserById(userId: string) {
return request<MasterModel.ProfileResponse>(`${API_USERS}/${userId}`);
}
export async function apiQueryUsersByGroup(
group_id: string,
): Promise<MasterModel.UserResponse> {
@@ -22,3 +26,19 @@ export async function apiCreateUsers(body: MasterModel.CreateUserBodyRequest) {
getResponse: true,
});
}
export async function apiChangeRoleUser(
userId: string,
role: 'users' | 'admin',
) {
return request(`${API_GROUPS}/${userId}/${role}`, {
method: 'PUT',
getResponse: true,
});
}
export async function apiDeleteUser(userId: string) {
return request(`${API_USERS}/${userId}`, {
method: 'DELETE',
getResponse: true,
});
}

View File

@@ -36,6 +36,7 @@ declare namespace MasterModel {
subtopic?: string;
}
// Auth
interface LoginRequestBody {
guid: string;
email: string;
@@ -66,6 +67,7 @@ declare namespace MasterModel {
user_type?: 'admin' | 'enduser' | 'sysadmin' | 'users';
}
// User
interface CreateUserMetadata extends ProfileMetadata {
group_id?: string;
}
@@ -96,7 +98,7 @@ declare namespace MasterModel {
thing_id?: string;
time?: number;
}
// Alarm
interface Alarm {
name?: string;
time?: number;
@@ -110,6 +112,8 @@ declare namespace MasterModel {
thing_name?: string;
thing_type?: string;
}
// Thing
interface ThingMetadata {
address?: string;
alarm_list?: string;
@@ -155,6 +159,25 @@ declare namespace MasterModel {
metadata?: T;
}
// Thing Policy
interface ThingPolicy {
next_page_token?: string;
relations?: Relation[];
}
interface Relation {
id?: string;
actions?: Action[];
}
enum Action {
Delete = 'delete',
Read = 'read',
Write = 'write',
}
// Group
interface GroupBodyRequest {
id?: string;
name: string;
@@ -200,6 +223,8 @@ declare namespace MasterModel {
[key: string]: any;
}
// Log
type LogTypeRequest = 'user_logs' | undefined;
interface LogResponse {
@@ -222,4 +247,12 @@ declare namespace MasterModel {
time?: number;
string_value?: string;
}
// User
interface AssignMemberRequest {
group_id: string;
type: 'users' | 'admin' | 'things' | undefined;
members: string[];
}
}