mirror of
https://github.com/open-webui/open-webui
synced 2025-06-26 18:26:48 +00:00
refac
This commit is contained in:
parent
c1fa989cb8
commit
783d409b1d
@ -166,6 +166,34 @@ export const getUsers = async (
|
|||||||
return res;
|
return res;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getAllUsers = async (token: string) => {
|
||||||
|
let error = null;
|
||||||
|
let res = null;
|
||||||
|
|
||||||
|
res = await fetch(`${WEBUI_API_BASE_URL}/users/all`, {
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
Authorization: `Bearer ${token}`
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(async (res) => {
|
||||||
|
if (!res.ok) throw await res.json();
|
||||||
|
return res.json();
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.log(err);
|
||||||
|
error = err.detail;
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
};
|
||||||
|
|
||||||
export const getUserSettings = async (token: string) => {
|
export const getUserSettings = async (token: string) => {
|
||||||
let error = null;
|
let error = null;
|
||||||
const res = await fetch(`${WEBUI_API_BASE_URL}/users/user/settings`, {
|
const res = await fetch(`${WEBUI_API_BASE_URL}/users/user/settings`, {
|
||||||
|
@ -23,13 +23,18 @@
|
|||||||
import GroupItem from './Groups/GroupItem.svelte';
|
import GroupItem from './Groups/GroupItem.svelte';
|
||||||
import AddGroupModal from './Groups/AddGroupModal.svelte';
|
import AddGroupModal from './Groups/AddGroupModal.svelte';
|
||||||
import { createNewGroup, getGroups } from '$lib/apis/groups';
|
import { createNewGroup, getGroups } from '$lib/apis/groups';
|
||||||
import { getUserDefaultPermissions, updateUserDefaultPermissions } from '$lib/apis/users';
|
import {
|
||||||
|
getUserDefaultPermissions,
|
||||||
|
getAllUsers,
|
||||||
|
updateUserDefaultPermissions
|
||||||
|
} from '$lib/apis/users';
|
||||||
|
|
||||||
const i18n = getContext('i18n');
|
const i18n = getContext('i18n');
|
||||||
|
|
||||||
let loaded = false;
|
let loaded = false;
|
||||||
|
|
||||||
export let users = [];
|
let users = [];
|
||||||
|
let total = 0;
|
||||||
|
|
||||||
let groups = [];
|
let groups = [];
|
||||||
let filteredGroups;
|
let filteredGroups;
|
||||||
@ -118,10 +123,22 @@
|
|||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
if ($user?.role !== 'admin') {
|
if ($user?.role !== 'admin') {
|
||||||
await goto('/');
|
await goto('/');
|
||||||
} else {
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const res = await getAllUsers(localStorage.token).catch((error) => {
|
||||||
|
toast.error(`${error}`);
|
||||||
|
return null;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (res) {
|
||||||
|
users = res.users;
|
||||||
|
total = res.total;
|
||||||
|
}
|
||||||
|
|
||||||
await setGroups();
|
await setGroups();
|
||||||
defaultPermissions = await getUserDefaultPermissions(localStorage.token);
|
defaultPermissions = await getUserDefaultPermissions(localStorage.token);
|
||||||
}
|
|
||||||
loaded = true;
|
loaded = true;
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
Reference in New Issue
Block a user