Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): hide message search from read-only keys

Yudhi Armyndharis67c076a44aa1
diff --git a/dashboard/src/pages/Chats.test.ts b/dashboard/src/pages/Chats.test.ts
index 6eb1488f7..9b36863da 100644
--- a/dashboard/src/pages/Chats.test.ts
+++ b/dashboard/src/pages/Chats.test.ts
@@ -705,6 +705,19 @@ test('a read-only key is offered no status compose trigger', async () => {
}
});
+// GET /search needs an operator key, so a viewer would only ever get "Search failed. Try again."
+test('a read-only key is offered no message search', async () => {
+ const { screen } = rtl;
+ window.sessionStorage.setItem('openwa_user_role', 'viewer');
+ try {
+ renderChats();
+ await screen.findByText('Alice');
+ assert.ok(!screen.queryByLabelText('Search messages…'), 'a viewer key was offered message search');
+ } finally {
+ window.sessionStorage.setItem('openwa_user_role', 'admin');
+ }
+});
+
test('an operator key on whatsapp-web.js posts a status without the admin-only engine route', async () => {
const { screen, fireEvent, within, waitFor } = rtl;
window.sessionStorage.setItem('openwa_user_role', 'operator');
diff --git a/dashboard/src/pages/Chats.tsx b/dashboard/src/pages/Chats.tsx
index d7eb4d9b4..78b3f3f52 100644
--- a/dashboard/src/pages/Chats.tsx
+++ b/dashboard/src/pages/Chats.tsx
@@ -979,7 +979,10 @@ export function Chats() {
<PageHeader
title={t('nav.chats')}
subtitle={t('chats.subtitle')}
- actions={sessions.length > 0 && <GlobalSearch currentSessionId={selectedSessionId} onHit={handleSearchHit} />}
+ actions={
+ sessions.length > 0 &&
+ canWrite && <GlobalSearch currentSessionId={selectedSessionId} onHit={handleSearchHit} />
+ }
/>
{/* Real-time connection permanently dropped — let the user re-establish it instead of