fix: hide chat delete actions when the chat delete permission is disabled (#27714)

The chat delete endpoints gate on chat.delete for non-admins, but none of
the UI affordances that reach them were conditioned on it, so a user
without the permission is offered controls that always fail with
"Access prohibited".

Gates every entry point on the same condition the backend enforces,
matching the existing chat.share / chat.export / chat.import gates in the
same components:

- Sidebar chat menu (ChatMenu) Delete item — also covers the Search
  modal's menu, which reuses ChatMenu
- Sidebar Shift+hover inline Delete button (ChatItem)
- Sidebar hidden #delete-chat-button keyboard-shortcut target (ChatItem)
- Chat navbar menu Delete item (Navbar/Menu)
- Search modal Shift-held inline Delete button (SearchModal)
- Settings -> Data Controls -> Delete All Chats
- Settings -> Archived Chats per-row Delete
This commit is contained in:
G30 authored and GitHub committed 2026-08-10 23:24:02 -06:00
1 parent fe62934be7
commit a3d33b4cf3
6 files changed
+14 -2

No files matched your search

@@ -19,7 +19,7 @@
getArchivedChatList, getArchivedChatList,
unarchiveAllChats unarchiveAllChats
} from '$lib/apis/chats'; } from '$lib/apis/chats';
import { chatId, showSettings } from '$lib/stores'; import { chatId, showSettings, user } from '$lib/stores';
import { refreshChatList } from '$lib/stores/chatList'; import { refreshChatList } from '$lib/stores/chatList';
import { formatNumber } from '$lib/utils'; import { formatNumber } from '$lib/utils';
import ConfirmDialog from '$lib/components/common/ConfirmDialog.svelte'; import ConfirmDialog from '$lib/components/common/ConfirmDialog.svelte';
@@ -348,6 +348,7 @@
<UndoAction className="size-3.5" strokeWidth="1.5" /> <UndoAction className="size-3.5" strokeWidth="1.5" />
</button> </button>
</Tooltip> </Tooltip>
{#if $user?.role === 'admin' || ($user?.permissions?.chat?.delete ?? true)}
<Tooltip content={$i18n.t('Delete Chat')}> <Tooltip content={$i18n.t('Delete Chat')}>
<button <button
class="rounded-lg p-1 text-gray-400 transition-colors hover:text-gray-700 dark:text-gray-600 dark:hover:text-gray-300" class="rounded-lg p-1 text-gray-400 transition-colors hover:text-gray-700 dark:text-gray-600 dark:hover:text-gray-300"
@@ -361,6 +362,7 @@
<Trash className="size-3.5" strokeWidth="1.5" /> <Trash className="size-3.5" strokeWidth="1.5" />
</button> </button>
</Tooltip> </Tooltip>
{/if}
</div> </div>
</div> </div>
{/each} {/each}
@@ -216,6 +216,7 @@
</button> </button>
</UserSettingRow> </UserSettingRow>
{#if $user?.role === 'admin' || ($user?.permissions?.chat?.delete ?? true)}
<UserSettingRow <UserSettingRow
label={$i18n.t('Delete All Chats')} label={$i18n.t('Delete All Chats')}
description={$i18n.t('Permanently delete every chat after confirmation.')} description={$i18n.t('Permanently delete every chat after confirmation.')}
@@ -230,6 +231,7 @@
{$i18n.t('Delete All')} {$i18n.t('Delete All')}
</button> </button>
</UserSettingRow> </UserSettingRow>
{/if}
</UserSettingSection> </UserSettingSection>
<UserSettingSection title={$i18n.t('Files')}> <UserSettingSection title={$i18n.t('Files')}>
@@ -487,6 +487,7 @@
<div class="flex items-center">{$i18n.t('Archive')}</div> <div class="flex items-center">{$i18n.t('Archive')}</div>
</button> </button>
{#if $user?.role === 'admin' || ($user?.permissions?.chat?.delete ?? true)}
<button <button
draggable="false" draggable="false"
class="flex h-[1.6875rem] w-full items-center gap-2 rounded-xl px-2 text-[0.8125rem] cursor-pointer select-none hover:bg-gray-50/40 dark:hover:bg-gray-800/40" class="flex h-[1.6875rem] w-full items-center gap-2 rounded-xl px-2 text-[0.8125rem] cursor-pointer select-none hover:bg-gray-50/40 dark:hover:bg-gray-800/40"
@@ -497,6 +498,7 @@
<GarbageBin className="size-3.5" strokeWidth="1.5" /> <GarbageBin className="size-3.5" strokeWidth="1.5" />
<div class="flex items-center">{$i18n.t('Delete')}</div> <div class="flex items-center">{$i18n.t('Delete')}</div>
</button> </button>
{/if}
<hr class="border-gray-50/30 dark:border-gray-800/30 mx-1 my-0.5" /> <hr class="border-gray-50/30 dark:border-gray-800/30 mx-1 my-0.5" />
@@ -786,6 +786,7 @@
</button> </button>
</Tooltip> </Tooltip>
{#if $user?.role === 'admin' || ($user?.permissions?.chat?.delete ?? true)}
<Tooltip content={$i18n.t('Delete')}> <Tooltip content={$i18n.t('Delete')}>
<button <button
class="self-center dark:hover:text-white transition" class="self-center dark:hover:text-white transition"
@@ -797,6 +798,7 @@
<GarbageBin strokeWidth="2" /> <GarbageBin strokeWidth="2" />
</button> </button>
</Tooltip> </Tooltip>
{/if}
</div> </div>
{:else} {:else}
<div class="flex items-center"> <div class="flex items-center">
@@ -705,6 +705,7 @@
</button> </button>
</Tooltip> </Tooltip>
{#if $user?.role === 'admin' || ($user?.permissions?.chat?.delete ?? true)}
<Tooltip content={$i18n.t('Delete')}> <Tooltip content={$i18n.t('Delete')}>
<button <button
class=" self-center dark:hover:text-white transition disabled:cursor-not-allowed" class=" self-center dark:hover:text-white transition disabled:cursor-not-allowed"
@@ -717,6 +718,7 @@
<GarbageBinIcon className="size-3.5" strokeWidth="1.7" /> <GarbageBinIcon className="size-3.5" strokeWidth="1.7" />
</button> </button>
</Tooltip> </Tooltip>
{/if}
</div> </div>
{:else} {:else}
<div class="flex self-center z-10 items-end"> <div class="flex self-center z-10 items-end">
@@ -756,7 +758,7 @@
</button> </button>
</ChatMenu> </ChatMenu>
{#if id === $chatId} {#if id === $chatId && ($user?.role === 'admin' || ($user?.permissions?.chat?.delete ?? true))}
<!-- Shortcut support using "delete-chat-button" id --> <!-- Shortcut support using "delete-chat-button" id -->
<button <button
id="delete-chat-button" id="delete-chat-button"
@@ -456,6 +456,7 @@
<div class="flex items-center">{$i18n.t('Archive')}</div> <div class="flex items-center">{$i18n.t('Archive')}</div>
</button> </button>
{#if $user?.role === 'admin' || ($user?.permissions?.chat?.delete ?? true)}
<button <button
draggable="false" draggable="false"
class="flex h-[1.6875rem] gap-2 items-center rounded-xl px-2 text-[0.8125rem] cursor-pointer hover:bg-gray-50/40 dark:hover:bg-gray-800/40 w-full" class="flex h-[1.6875rem] gap-2 items-center rounded-xl px-2 text-[0.8125rem] cursor-pointer hover:bg-gray-50/40 dark:hover:bg-gray-800/40 w-full"
@@ -466,6 +467,7 @@
<TrashIcon className="size-3.5" strokeWidth="1.5" /> <TrashIcon className="size-3.5" strokeWidth="1.5" />
<div class="flex items-center">{$i18n.t('Delete')}</div> <div class="flex items-center">{$i18n.t('Delete')}</div>
</button> </button>
{/if}
</DropdownMenu> </DropdownMenu>
</div> </div>
</Dropdown> </Dropdown>