Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): do not read the address book for a read-only menu

Yudhi Armyndharis9d5a9d535c39
diff --git a/dashboard/src/pages/Chats.features.test.ts b/dashboard/src/pages/Chats.features.test.ts
index 5d0caea45..2b4485219 100644
--- a/dashboard/src/pages/Chats.features.test.ts
+++ b/dashboard/src/pages/Chats.features.test.ts
@@ -2147,6 +2147,18 @@ test("a group's menu has no use for the address book and does not read it", asyn
assert.equal(contactReads().length, 0, "a group's menu read the address book");
});
+test("a read-only key's room menu has no entry that reads the address book, so it does not read it", async () => {
+ const { screen, fireEvent, waitFor } = rtl;
+ window.sessionStorage.setItem('openwa_user_role', 'viewer');
+ const { container } = renderPage();
+ fireEvent.click(await screen.findByText('Alice'));
+ await waitFor(() => assert.ok(container.querySelector('.room-header'), 'the room did not open'));
+ fireEvent.click(container.querySelector('.room-menu-trigger') as HTMLElement);
+ await screen.findByRole('button', { name: 'Copy chat ID' });
+ await settle();
+ assert.equal(contactReads().length, 0, 'a viewer key walked the address book to open a menu that cannot use it');
+});
+
test("the room's menu asks for the address book as well", async () => {
const { screen, fireEvent, waitFor } = rtl;
const { container } = renderPage();
diff --git a/dashboard/src/pages/Chats.tsx b/dashboard/src/pages/Chats.tsx
index 270dd600f..c109ec06a 100644
--- a/dashboard/src/pages/Chats.tsx
+++ b/dashboard/src/pages/Chats.tsx
@@ -1448,7 +1448,8 @@ export function Chats() {
const isSavedContact = (chat: Chat) => savedContactKeys?.has(contactKey(chat.id)) ?? false;
const rowActions: ChatRowActions = {
- onMenuOpen: () => setMenuOpened(true),
+ // Only what a key that can write offers reads the address book (Save or Rename); a read-only menu has no such entry.
+ onMenuOpen: canWrite ? () => setMenuOpened(true) : undefined,
onGroupInfo: setGroupDialogChat,
onSaveContact: canWrite ? setContactDialogChat : undefined,
canSaveContact: chat => addressbookIdOf(chat) !== null,