Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): hide session create and proxy save from scoped keys

Yudhi Armyndharis18e5e2b03240
diff --git a/dashboard/src/pages/Sessions.test.ts b/dashboard/src/pages/Sessions.test.ts
index 9e65363fb..9d940264d 100644
--- a/dashboard/src/pages/Sessions.test.ts
+++ b/dashboard/src/pages/Sessions.test.ts
@@ -584,6 +584,29 @@ test('an operator key is not offered proxy writes, in the create modal or the pr
}
});
+// Creating a session and changing its proxy are refused for any session-scoped key, admin included,
+// so neither is offered; the proxy settings stay readable.
+test('a session-scoped admin key is offered neither New Session nor a proxy Save', async () => {
+ const { screen, fireEvent, within, waitFor } = rtl;
+ resetFetchCalls();
+ window.sessionStorage.setItem('openwa_key_scoped', 'true');
+ try {
+ renderSessions();
+ await screen.findByText('new-device');
+ assert.equal(screen.queryByRole('button', { name: 'New Session' }) === null, true);
+
+ const qrCard = screen.getByText('new-device').closest('.session-card') as HTMLElement;
+ fireEvent.click(within(qrCard).getByRole('button', { name: 'Proxy' }));
+ const dialog = await screen.findByRole('dialog');
+ await waitFor(() => assert.ok(findFetchCall('GET', '/api/sessions/sess-qr-1/proxy')));
+ const toggle = (await within(dialog).findByRole('checkbox')) as HTMLInputElement;
+ assert.equal(toggle.disabled, true);
+ assert.equal(within(dialog).queryByRole('button', { name: 'Save' }) === null, true);
+ } finally {
+ window.sessionStorage.removeItem('openwa_key_scoped');
+ }
+});
+
test('a typed pairing phone number survives toggling to the QR tab and back', async () => {
const { screen, fireEvent, within } = rtl;
resetFetchCalls();
diff --git a/dashboard/src/pages/Sessions.tsx b/dashboard/src/pages/Sessions.tsx
index 172d49773..be41d3157 100644
--- a/dashboard/src/pages/Sessions.tsx
+++ b/dashboard/src/pages/Sessions.tsx
@@ -70,7 +70,10 @@ export function Sessions() {
const { t } = useTranslation();
useDocumentTitle(t('sessions.title'));
const toast = useToast();
- const { canWrite, isAdmin } = useRole();
+ const { canWrite, isAdmin, scoped } = useRole();
+ // Creating a session and changing its proxy are refused for any session-scoped key, whatever its role.
+ const canCreate = canWrite && !scoped;
+ const canEditProxy = isAdmin && !scoped;
const queryClient = useQueryClient();
const [sessions, setSessions] = useState<Session[]>([]);
const [loading, setLoading] = useState(true);
@@ -673,7 +676,7 @@ export function Sessions() {
title={t('sessions.title')}
subtitle={t('sessions.subtitle')}
actions={
- canWrite && (
+ canCreate && (
<button className="btn-primary" onClick={() => setShowCreateModal(true)}>
<Plus size={18} />
{t('sessions.newSession')}
@@ -774,7 +777,7 @@ export function Sessions() {
)}
{nameIssues.includes('duplicate') && <p className="input-error">{t('sessions.create.duplicate')}</p>}
{/* The API refuses proxyUrl from a key below ADMIN, so the section is not offered. */}
- {isAdmin && (
+ {canEditProxy && (
<div className="proxy-form-section">
<label className="detail-toggle-row" htmlFor="create-use-proxy">
<span>{t('sessions.proxy.enabled')}</span>
@@ -1033,7 +1036,7 @@ export function Sessions() {
<button className="btn-secondary" onClick={() => setProxySession(null)}>
{t('common.cancel')}
</button>
- {isAdmin && !proxyLoadFailed && (
+ {canEditProxy && !proxyLoadFailed && (
<button
className="btn-primary"
onClick={() => void handleProxySave()}
@@ -1083,7 +1086,7 @@ export function Sessions() {
type="checkbox"
aria-labelledby="proxy-enabled-label"
checked={proxyEnabled}
- disabled={!isAdmin || proxySaving}
+ disabled={!canEditProxy || proxySaving}
onChange={e => setProxyEnabled(e.target.checked)}
/>
<span className="toggle-slider"></span>
@@ -1105,7 +1108,7 @@ export function Sessions() {
: t('sessions.proxy.urlPlaceholder')
}
value={proxyUrl}
- disabled={!isAdmin || proxySaving}
+ disabled={!canEditProxy || proxySaving}
onChange={e => {
setProxyUrl(e.target.value);
setProxyUrlError(null);