fix: temporary chat and delete chat shortcuts show while not allowed (#32978)

* fix: temporary chat and delete chat shortcuts show while not allowed

The keyboard shortcuts list showed "New Temporary Chat" and "Delete Chat" to users who may not use temporary chats or delete chats, and pressing those shortcuts neither opened a temporary chat nor deleted anything for them. Both entries now only show to users with the matching permission, and the settings search skips them otherwise.

Refs #32830

* fix: new temporary chat shortcut does nothing without the permission

Users without the temporary chat permission were sent to a new chat by the New Temporary Chat shortcut; it now does nothing for them.
This commit is contained in:
Classic298 2026-10-24 22:05:31 +02:00 • committed by GitHub
parent a39c50235e
commit 159a29ed06
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 19 additions and 2 deletions

View file

@ -14,7 +14,8 @@
shortcuts
} from '$lib/shortcuts';
import type { KeybindingsMap, ShortcutDefinition } from '$lib/shortcuts';
import { settings } from '$lib/stores';
import { settings, user } from '$lib/stores';
import { canManageChats, canUseTemporaryChats } from '$lib/utils/settings-access';
import Switch from '$lib/components/common/Switch.svelte';
import ShortcutItem from '../ShortcutItem.svelte';
@ -44,7 +45,16 @@
});
$: {
const allShortcuts = Object.entries(shortcuts).filter(([, shortcut]) => {
const allShortcuts = Object.entries(shortcuts).filter(([id, shortcut]) => {
if (
id === Shortcut.NEW_TEMPORARY_CHAT &&
!canUseTemporaryChats({ user: $user, config: null })
) {
return false;
}
if (id === Shortcut.DELETE_CHAT && !canManageChats({ user: $user, config: null }, 'delete')) {
return false;
}
if (!shortcut.setting) {
return true;
}

View file

@ -81,5 +81,8 @@ export function canSearchSetting(
)
return canUseCalls(context);
if (stem === 'settings.personal.interface.webSearchInChat') return !!canUseWebSearch(context);
if (stem === 'settings.personal.shortcuts.newTemporaryChat')
return !!canUseTemporaryChats(context);
if (stem === 'settings.personal.shortcuts.deleteChat') return canManageChats(context, 'delete');
return true;
}

View file

@ -51,6 +51,7 @@
import UpdateInfoToast from '$lib/components/layout/UpdateInfoToast.svelte';
import Spinner from '$lib/components/common/Spinner.svelte';
import { loadKeybindings, matchKeybinding, Shortcut } from '$lib/shortcuts';
import { canUseTemporaryChats } from '$lib/utils/settings-access';
const i18n = getContext('i18n');
@ -350,6 +351,9 @@
} else if (shortcut === Shortcut.NEW_TEMPORARY_CHAT) {
console.log('Shortcut triggered: NEW_TEMPORARY_CHAT');
event.preventDefault();
if (!canUseTemporaryChats({ user: $user, config: null })) {
return;
}
if ($user?.role !== 'admin' && $user?.permissions?.chat?.temporary_enforced) {
temporaryChatEnabled.set(true);
} else {