Skip to content

Commit c2f5cb5

Browse files
committed
refac
1 parent 1034b74 commit c2f5cb5

File tree

6 files changed

+17
-33
lines changed

6 files changed

+17
-33
lines changed

backend/open_webui/models/users.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ class UserInfoResponse(UserStatus):
184184
name: str
185185
email: str
186186
role: str
187+
bio: Optional[str] = None
188+
groups: Optional[list] = []
189+
is_active: bool = False
187190

188191

189192
class UserIdNameResponse(BaseModel):

backend/open_webui/routers/users.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,14 @@ async def get_user_info_by_id(
484484
):
485485
user = Users.get_user_by_id(user_id, db=db)
486486
if user:
487-
return user
487+
groups = Groups.get_groups_by_member_id(user_id, db=db)
488+
return UserInfoResponse(
489+
**{
490+
**user.model_dump(),
491+
"groups": [{"id": group.id, "name": group.name} for group in groups],
492+
"is_active": Users.is_user_active(user_id, db=db),
493+
}
494+
)
488495
else:
489496
raise HTTPException(
490497
status_code=status.HTTP_400_BAD_REQUEST,

src/lib/apis/users/index.ts

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -300,32 +300,6 @@ export const updateUserSettings = async (token: string, settings: object) => {
300300
return res;
301301
};
302302

303-
export const getUserById = async (token: string, userId: string) => {
304-
let error = null;
305-
306-
const res = await fetch(`${WEBUI_API_BASE_URL}/users/${userId}`, {
307-
method: 'GET',
308-
headers: {
309-
'Content-Type': 'application/json',
310-
Authorization: `Bearer ${token}`
311-
}
312-
})
313-
.then(async (res) => {
314-
if (!res.ok) throw await res.json();
315-
return res.json();
316-
})
317-
.catch((err) => {
318-
console.error(err);
319-
error = err.detail;
320-
return null;
321-
});
322-
323-
if (error) {
324-
throw error;
325-
}
326-
327-
return res;
328-
};
329303

330304
export const getUserInfoById = async (token: string, userId: string) => {
331305
let error = null;

src/lib/components/channel/Messages/Message/UserStatusLinkPreview.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import { LinkPreview } from 'bits-ui';
44
55
const i18n = getContext('i18n');
6-
import { getUserById } from '$lib/apis/users';
6+
import { getUserInfoById } from '$lib/apis/users';
77
88
import UserStatus from './UserStatus.svelte';
99
@@ -16,7 +16,7 @@
1616
let user = null;
1717
onMount(async () => {
1818
if (id) {
19-
user = await getUserById(localStorage.token, id).catch((error) => {
19+
user = await getUserInfoById(localStorage.token, id).catch((error) => {
2020
console.error('Error fetching user by ID:', error);
2121
return null;
2222
});

src/lib/components/workspace/common/MemberSelector.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
const i18n = getContext('i18n');
66
77
import { user as _user } from '$lib/stores';
8-
import { getUserById, searchUsers } from '$lib/apis/users';
8+
import { getUserInfoById, searchUsers } from '$lib/apis/users';
99
import { WEBUI_API_BASE_URL } from '$lib/constants';
1010
1111
import XMark from '$lib/components/icons/XMark.svelte';
@@ -84,7 +84,7 @@
8484
8585
if (userIds.length > 0) {
8686
userIds.forEach(async (id) => {
87-
const res = await getUserById(localStorage.token, id).catch((error) => {
87+
const res = await getUserInfoById(localStorage.token, id).catch((error) => {
8888
console.error(error);
8989
return null;
9090
});

src/routes/s/[id]/+page.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
1313
import Messages from '$lib/components/chat/Messages.svelte';
1414
15-
import { getUserById, getUserSettings } from '$lib/apis/users';
15+
import { getUserInfoById, getUserSettings } from '$lib/apis/users';
1616
import { getModels } from '$lib/apis';
1717
import { toast } from 'svelte-sonner';
1818
import localizedFormat from 'dayjs/plugin/localizedFormat';
@@ -92,7 +92,7 @@
9292
});
9393
9494
if (chat) {
95-
user = await getUserById(localStorage.token, chat.user_id).catch((error) => {
95+
user = await getUserInfoById(localStorage.token, chat.user_id).catch((error) => {
9696
console.error(error);
9797
return null;
9898
});

0 commit comments

Comments
 (0)