mirror of
https://github.com/open-webui/open-webui
synced 2025-04-02 12:09:06 +00:00
refac: $user
This commit is contained in:
parent
1b7c125f00
commit
e0ec2cdeb0
@ -136,7 +136,7 @@
|
||||
};
|
||||
|
||||
onMount(async () => {
|
||||
if ($user.role === 'admin') {
|
||||
if ($user?.role === 'admin') {
|
||||
let ollamaConfig = {};
|
||||
let openaiConfig = {};
|
||||
|
||||
|
@ -77,7 +77,7 @@
|
||||
};
|
||||
|
||||
onMount(async () => {
|
||||
if ($user.role === 'admin') {
|
||||
if ($user?.role === 'admin') {
|
||||
evaluationConfig = await getConfig(localStorage.token).catch((err) => {
|
||||
toast.error(err);
|
||||
return null;
|
||||
|
@ -176,7 +176,7 @@
|
||||
};
|
||||
|
||||
onMount(async () => {
|
||||
if ($user.role === 'admin') {
|
||||
if ($user?.role === 'admin') {
|
||||
const res = await getConfig(localStorage.token).catch((error) => {
|
||||
toast.error(`${error}`);
|
||||
return null;
|
||||
|
@ -380,7 +380,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{#if $user.role === 'admin'}
|
||||
{#if $user?.role === 'admin'}
|
||||
<div class=" space-y-3">
|
||||
<div class="flex w-full justify-between mb-2">
|
||||
<div class=" self-center text-sm font-semibold">
|
||||
|
@ -19,7 +19,7 @@
|
||||
let ollamaConfig = null;
|
||||
|
||||
onMount(async () => {
|
||||
if ($user.role === 'admin') {
|
||||
if ($user?.role === 'admin') {
|
||||
await Promise.all([
|
||||
(async () => {
|
||||
ollamaConfig = await getOllamaConfig(localStorage.token);
|
||||
|
@ -106,7 +106,7 @@
|
||||
messages[idx] = data;
|
||||
}
|
||||
} else if (type === 'typing' && event.message_id === null) {
|
||||
if (event.user.id === $user.id) {
|
||||
if (event.user.id === $user?.id) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -132,7 +132,7 @@
|
||||
if (
|
||||
(message?.reactions ?? [])
|
||||
.find((reaction) => reaction.name === name)
|
||||
?.user_ids?.includes($user.id) ??
|
||||
?.user_ids?.includes($user?.id) ??
|
||||
false
|
||||
) {
|
||||
messages = messages.map((m) => {
|
||||
@ -140,7 +140,7 @@
|
||||
const reaction = m.reactions.find((reaction) => reaction.name === name);
|
||||
|
||||
if (reaction) {
|
||||
reaction.user_ids = reaction.user_ids.filter((id) => id !== $user.id);
|
||||
reaction.user_ids = reaction.user_ids.filter((id) => id !== $user?.id);
|
||||
reaction.count = reaction.user_ids.length;
|
||||
|
||||
if (reaction.count === 0) {
|
||||
@ -167,12 +167,12 @@
|
||||
const reaction = m.reactions.find((reaction) => reaction.name === name);
|
||||
|
||||
if (reaction) {
|
||||
reaction.user_ids.push($user.id);
|
||||
reaction.user_ids.push($user?.id);
|
||||
reaction.count = reaction.user_ids.length;
|
||||
} else {
|
||||
m.reactions.push({
|
||||
name: name,
|
||||
user_ids: [$user.id],
|
||||
user_ids: [$user?.id],
|
||||
count: 1
|
||||
});
|
||||
}
|
||||
|
@ -106,7 +106,7 @@
|
||||
</Tooltip>
|
||||
{/if}
|
||||
|
||||
{#if message.user_id === $user.id || $user.role === 'admin'}
|
||||
{#if message.user_id === $user?.id || $user?.role === 'admin'}
|
||||
<Tooltip content={$i18n.t('Edit')}>
|
||||
<button
|
||||
class="hover:bg-gray-100 dark:hover:bg-gray-800 transition rounded-lg p-1"
|
||||
@ -265,7 +265,7 @@
|
||||
<Tooltip content={`:${reaction.name}:`}>
|
||||
<button
|
||||
class="flex items-center gap-1.5 transition rounded-xl px-2 py-1 cursor-pointer {reaction.user_ids.includes(
|
||||
$user.id
|
||||
$user?.id
|
||||
)
|
||||
? ' bg-blue-300/10 outline outline-blue-500/50 outline-1'
|
||||
: 'bg-gray-300/10 dark:bg-gray-500/10 hover:outline hover:outline-gray-700/30 dark:hover:outline-gray-300/30 hover:outline-1'}"
|
||||
|
@ -58,7 +58,7 @@
|
||||
{#if $user !== undefined}
|
||||
<UserMenu
|
||||
className="max-w-[200px]"
|
||||
role={$user.role}
|
||||
role={$user?.role}
|
||||
on:show={(e) => {
|
||||
if (e.detail === 'archived-chat') {
|
||||
showArchivedChats.set(true);
|
||||
@ -71,7 +71,7 @@
|
||||
>
|
||||
<div class=" self-center">
|
||||
<img
|
||||
src={$user.profile_image_url}
|
||||
src={$user?.profile_image_url}
|
||||
class="size-6 object-cover rounded-full"
|
||||
alt="User profile"
|
||||
draggable="false"
|
||||
|
@ -89,7 +89,7 @@
|
||||
}
|
||||
}
|
||||
} else if (type === 'typing' && event.message_id === threadId) {
|
||||
if (event.user.id === $user.id) {
|
||||
if (event.user.id === $user?.id) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1498,7 +1498,7 @@
|
||||
role: 'system',
|
||||
content: `${promptTemplate(
|
||||
params?.system ?? $settings?.system ?? '',
|
||||
$user.name,
|
||||
$user?.name,
|
||||
$settings?.userLocation
|
||||
? await getAndUpdateUserLocation(localStorage.token).catch((err) => {
|
||||
console.error(err);
|
||||
@ -1572,23 +1572,23 @@
|
||||
features: {
|
||||
image_generation:
|
||||
$config?.features?.enable_image_generation &&
|
||||
($user.role === 'admin' || $user?.permissions?.features?.image_generation)
|
||||
($user?.role === 'admin' || $user?.permissions?.features?.image_generation)
|
||||
? imageGenerationEnabled
|
||||
: false,
|
||||
code_interpreter:
|
||||
$config?.features?.enable_code_interpreter &&
|
||||
($user.role === 'admin' || $user?.permissions?.features?.code_interpreter)
|
||||
($user?.role === 'admin' || $user?.permissions?.features?.code_interpreter)
|
||||
? codeInterpreterEnabled
|
||||
: false,
|
||||
web_search:
|
||||
$config?.features?.enable_web_search &&
|
||||
($user.role === 'admin' || $user?.permissions?.features?.web_search)
|
||||
($user?.role === 'admin' || $user?.permissions?.features?.web_search)
|
||||
? webSearchEnabled || ($settings?.webSearch ?? false) === 'always'
|
||||
: false
|
||||
},
|
||||
variables: {
|
||||
...getPromptVariables(
|
||||
$user.name,
|
||||
$user?.name,
|
||||
$settings?.userLocation
|
||||
? await getAndUpdateUserLocation(localStorage.token).catch((err) => {
|
||||
console.error(err);
|
||||
|
@ -86,7 +86,7 @@
|
||||
{#if models[selectedModelIdx]?.name}
|
||||
{models[selectedModelIdx]?.name}
|
||||
{:else}
|
||||
{$i18n.t('Hello, {{name}}', { name: $user.name })}
|
||||
{$i18n.t('Hello, {{name}}', { name: $user?.name })}
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
|
@ -67,7 +67,7 @@
|
||||
</div>
|
||||
</Collapsible>
|
||||
|
||||
{#if $user.role === 'admin' || $user?.permissions.chat?.controls}
|
||||
{#if $user?.role === 'admin' || $user?.permissions.chat?.controls}
|
||||
<hr class="my-2 border-gray-50 dark:border-gray-700/10" />
|
||||
|
||||
<Collapsible title={$i18n.t('System Prompt')} open={true} buttonClassName="w-full">
|
||||
|
@ -86,7 +86,7 @@
|
||||
|
||||
if (command.content.includes('{{USER_NAME}}')) {
|
||||
console.log($user);
|
||||
const name = $user.name || 'User';
|
||||
const name = $user?.name || 'User';
|
||||
text = text.replaceAll('{{USER_NAME}}', name);
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,7 @@
|
||||
}
|
||||
|
||||
let fileUploadEnabled = true;
|
||||
$: fileUploadEnabled = $user.role === 'admin' || $user?.permissions?.chat?.file_upload;
|
||||
$: fileUploadEnabled = $user?.role === 'admin' || $user?.permissions?.chat?.file_upload;
|
||||
|
||||
const init = async () => {
|
||||
if ($_tools === null) {
|
||||
|
@ -920,7 +920,7 @@
|
||||
|
||||
{#if message.done}
|
||||
{#if !readOnly}
|
||||
{#if $user.role === 'user' ? ($user?.permissions?.chat?.edit ?? true) : true}
|
||||
{#if $user?.role === 'user' ? ($user?.permissions?.chat?.edit ?? true) : true}
|
||||
<Tooltip content={$i18n.t('Edit')} placement="bottom">
|
||||
<button
|
||||
class="{isLastMessage
|
||||
@ -1053,7 +1053,7 @@
|
||||
</button>
|
||||
</Tooltip>
|
||||
|
||||
{#if $config?.features.enable_image_generation && ($user.role === 'admin' || $user?.permissions?.features?.image_generation) && !readOnly}
|
||||
{#if $config?.features.enable_image_generation && ($user?.role === 'admin' || $user?.permissions?.features?.image_generation) && !readOnly}
|
||||
<Tooltip content={$i18n.t('Generate Image')} placement="bottom">
|
||||
<button
|
||||
class="{isLastMessage
|
||||
|
@ -45,7 +45,7 @@
|
||||
label: model.name,
|
||||
model: model
|
||||
}))}
|
||||
showTemporaryChatControl={$user.role === 'user'
|
||||
showTemporaryChatControl={$user?.role === 'user'
|
||||
? ($user?.permissions?.chat?.temporary ?? true) &&
|
||||
!($user?.permissions?.chat?.temporary_enforced ?? false)
|
||||
: true}
|
||||
|
@ -634,7 +634,7 @@
|
||||
</div>
|
||||
{/each}
|
||||
|
||||
{#if !(searchValue.trim() in $MODEL_DOWNLOAD_POOL) && searchValue && ollamaVersion && $user.role === 'admin'}
|
||||
{#if !(searchValue.trim() in $MODEL_DOWNLOAD_POOL) && searchValue && ollamaVersion && $user?.role === 'admin'}
|
||||
<Tooltip
|
||||
content={$i18n.t(`Pull "{{searchValue}}" from Ollama.com`, {
|
||||
searchValue: searchValue
|
||||
|
@ -147,10 +147,10 @@
|
||||
</button>
|
||||
</Tooltip>
|
||||
|
||||
{#if $user !== undefined}
|
||||
{#if $user !== undefined && $user !== null}
|
||||
<UserMenu
|
||||
className="max-w-[200px]"
|
||||
role={$user.role}
|
||||
role={$user?.role}
|
||||
on:show={(e) => {
|
||||
if (e.detail === 'archived-chat') {
|
||||
showArchivedChats.set(true);
|
||||
@ -163,7 +163,7 @@
|
||||
>
|
||||
<div class=" self-center">
|
||||
<img
|
||||
src={$user.profile_image_url}
|
||||
src={$user?.profile_image_url}
|
||||
class="size-6 object-cover rounded-full"
|
||||
alt="User profile"
|
||||
draggable="false"
|
||||
|
@ -142,7 +142,7 @@
|
||||
{#if models[selectedModelIdx]?.name}
|
||||
{models[selectedModelIdx]?.name}
|
||||
{:else}
|
||||
{$i18n.t('Hello, {{name}}', { name: $user.name })}
|
||||
{$i18n.t('Hello, {{name}}', { name: $user?.name })}
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
@ -31,8 +31,8 @@
|
||||
let profileImageInputElement: HTMLInputElement;
|
||||
|
||||
const submitHandler = async () => {
|
||||
if (name !== $user.name) {
|
||||
if (profileImageUrl === generateInitialsImage($user.name) || profileImageUrl === '') {
|
||||
if (name !== $user?.name) {
|
||||
if (profileImageUrl === generateInitialsImage($user?.name) || profileImageUrl === '') {
|
||||
profileImageUrl = generateInitialsImage(name);
|
||||
}
|
||||
}
|
||||
@ -75,8 +75,8 @@
|
||||
};
|
||||
|
||||
onMount(async () => {
|
||||
name = $user.name;
|
||||
profileImageUrl = $user.profile_image_url;
|
||||
name = $user?.name;
|
||||
profileImageUrl = $user?.profile_image_url;
|
||||
webhookUrl = $settings?.notifications?.webhook_url ?? '';
|
||||
|
||||
APIKey = await getAPIKey(localStorage.token).catch((error) => {
|
||||
@ -214,7 +214,7 @@
|
||||
<button
|
||||
class=" text-xs text-center text-gray-800 dark:text-gray-400 rounded-full px-4 py-0.5 bg-gray-100 dark:bg-gray-850"
|
||||
on:click={async () => {
|
||||
const url = await getGravatarUrl(localStorage.token, $user.email);
|
||||
const url = await getGravatarUrl(localStorage.token, $user?.email);
|
||||
|
||||
profileImageUrl = url;
|
||||
}}>{$i18n.t('Use Gravatar')}</button
|
||||
|
@ -308,7 +308,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{#if $user.role === 'admin' || $user?.permissions.chat?.controls}
|
||||
{#if $user?.role === 'admin' || $user?.permissions.chat?.controls}
|
||||
<hr class="border-gray-100 dark:border-gray-850 my-3" />
|
||||
|
||||
<div>
|
||||
|
@ -441,7 +441,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{#if $user.role === 'admin'}
|
||||
{#if $user?.role === 'admin'}
|
||||
<div>
|
||||
<div class=" py-0.5 flex w-full justify-between">
|
||||
<div class=" self-center text-xs">
|
||||
|
@ -462,7 +462,7 @@
|
||||
<div class=" self-center">{$i18n.t('Interface')}</div>
|
||||
</button>
|
||||
{:else if tabId === 'connections'}
|
||||
{#if $user.role === 'admin' || ($user.role === 'user' && $config?.features?.enable_direct_connections)}
|
||||
{#if $user?.role === 'admin' || ($user?.role === 'user' && $config?.features?.enable_direct_connections)}
|
||||
<button
|
||||
class="px-0.5 py-1 min-w-fit rounded-lg flex-1 md:flex-none flex text-left transition {selectedTab ===
|
||||
'connections'
|
||||
@ -488,7 +488,7 @@
|
||||
</button>
|
||||
{/if}
|
||||
{:else if tabId === 'tools'}
|
||||
{#if $user.role === 'admin' || ($user.role === 'user' && $config?.features?.enable_direct_tools)}
|
||||
{#if $user?.role === 'admin' || ($user?.role === 'user' && $config?.features?.enable_direct_tools)}
|
||||
<button
|
||||
class="px-0.5 py-1 min-w-fit rounded-lg flex-1 md:flex-none flex text-left transition {selectedTab ===
|
||||
'tools'
|
||||
@ -636,7 +636,7 @@
|
||||
<div class=" self-center">{$i18n.t('About')}</div>
|
||||
</button>
|
||||
{:else if tabId === 'admin'}
|
||||
{#if $user.role === 'admin'}
|
||||
{#if $user?.role === 'admin'}
|
||||
<button
|
||||
class="px-0.5 py-1 min-w-fit rounded-lg flex-1 md:flex-none flex text-left transition {selectedTab ===
|
||||
'admin'
|
||||
|
@ -167,7 +167,7 @@
|
||||
{#if $user !== undefined}
|
||||
<UserMenu
|
||||
className="max-w-[200px]"
|
||||
role={$user.role}
|
||||
role={$user?.role}
|
||||
on:show={(e) => {
|
||||
if (e.detail === 'archived-chat') {
|
||||
showArchivedChats.set(true);
|
||||
@ -180,7 +180,7 @@
|
||||
>
|
||||
<div class=" self-center">
|
||||
<img
|
||||
src={$user.profile_image_url}
|
||||
src={$user?.profile_image_url}
|
||||
class="size-6 object-cover rounded-full"
|
||||
alt="User profile"
|
||||
draggable="false"
|
||||
|
@ -446,7 +446,7 @@
|
||||
});
|
||||
|
||||
if (res) {
|
||||
$socket.emit('join-channels', { auth: { token: $user.token } });
|
||||
$socket.emit('join-channels', { auth: { token: $user?.token } });
|
||||
await initChannels();
|
||||
showCreateChannel = false;
|
||||
}
|
||||
@ -627,13 +627,13 @@
|
||||
? 'opacity-20'
|
||||
: ''}"
|
||||
>
|
||||
{#if $config?.features?.enable_channels && ($user.role === 'admin' || $channels.length > 0) && !search}
|
||||
{#if $config?.features?.enable_channels && ($user?.role === 'admin' || $channels.length > 0) && !search}
|
||||
<Folder
|
||||
className="px-2 mt-0.5"
|
||||
name={$i18n.t('Channels')}
|
||||
dragAndDrop={false}
|
||||
onAdd={async () => {
|
||||
if ($user.role === 'admin') {
|
||||
if ($user?.role === 'admin') {
|
||||
await tick();
|
||||
|
||||
setTimeout(() => {
|
||||
@ -891,9 +891,9 @@
|
||||
|
||||
<div class="px-2">
|
||||
<div class="flex flex-col font-primary">
|
||||
{#if $user !== undefined}
|
||||
{#if $user !== undefined && $user !== null}
|
||||
<UserMenu
|
||||
role={$user.role}
|
||||
role={$user?.role}
|
||||
on:show={(e) => {
|
||||
if (e.detail === 'archived-chat') {
|
||||
showArchivedChats.set(true);
|
||||
@ -908,12 +908,12 @@
|
||||
>
|
||||
<div class=" self-center mr-3">
|
||||
<img
|
||||
src={$user.profile_image_url}
|
||||
src={$user?.profile_image_url}
|
||||
class=" max-w-[30px] object-cover rounded-full"
|
||||
alt="User profile"
|
||||
/>
|
||||
</div>
|
||||
<div class=" self-center font-medium">{$user.name}</div>
|
||||
<div class=" self-center font-medium">{$user?.name}</div>
|
||||
</button>
|
||||
</UserMenu>
|
||||
{/if}
|
||||
|
@ -55,9 +55,9 @@
|
||||
let version;
|
||||
|
||||
onMount(async () => {
|
||||
if ($user === undefined) {
|
||||
if ($user === undefined || $user === null) {
|
||||
await goto('/auth');
|
||||
} else if (['user', 'admin'].includes($user.role)) {
|
||||
} else if (['user', 'admin'].includes($user?.role)) {
|
||||
try {
|
||||
// Check if IndexedDB exists
|
||||
DB = await openDB('Chats', 1);
|
||||
@ -191,7 +191,7 @@
|
||||
}
|
||||
});
|
||||
|
||||
if ($user.role === 'admin' && ($settings?.showChangelog ?? true)) {
|
||||
if ($user?.role === 'admin' && ($settings?.showChangelog ?? true)) {
|
||||
showChangelog.set($settings?.version !== $config.version);
|
||||
}
|
||||
|
||||
@ -199,14 +199,14 @@
|
||||
temporaryChatEnabled.set(true);
|
||||
}
|
||||
|
||||
console.log($user.permissions);
|
||||
console.log($user?.permissions);
|
||||
|
||||
if ($user?.permissions?.chat?.temporary_enforced) {
|
||||
temporaryChatEnabled.set(true);
|
||||
}
|
||||
|
||||
// Check for version updates
|
||||
if ($user.role === 'admin') {
|
||||
if ($user?.role === 'admin') {
|
||||
// Check if the user has dismissed the update toast in the last 24 hours
|
||||
if (localStorage.dismissedUpdateToast) {
|
||||
const dismissedUpdateToast = new Date(Number(localStorage.dismissedUpdateToast));
|
||||
@ -255,7 +255,7 @@
|
||||
class=" text-gray-700 dark:text-gray-100 bg-white dark:bg-gray-900 h-screen max-h-[100dvh] overflow-auto flex flex-row justify-end"
|
||||
>
|
||||
{#if loaded}
|
||||
{#if !['user', 'admin'].includes($user.role)}
|
||||
{#if !['user', 'admin'].includes($user?.role)}
|
||||
<AccountPending />
|
||||
{:else if localDBChats.length > 0}
|
||||
<div class="fixed w-full h-full flex z-50">
|
||||
|
Loading…
Reference in New Issue
Block a user