Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): compare the storage bucket the save writes

Yudhi Armyndharisd502e31eeee1
diff --git a/dashboard/src/hooks/useConfigSave.ts b/dashboard/src/hooks/useConfigSave.ts
index c1a3cb0e8..614904675 100644
--- a/dashboard/src/hooks/useConfigSave.ts
+++ b/dashboard/src/hooks/useConfigSave.ts
@@ -5,8 +5,8 @@ import { useToast } from './useToast';
export interface UseConfigSaveArgs {
buildPayload: () => SaveConfigPayload;
- /** Called with the profile list from a successful save. One-way: this hook never reads restart state. */
- onSaved: (profiles: string[]) => void;
+ /** Called with the profile list from a successful save and the payload it sent. One-way: this hook never reads restart state. */
+ onSaved: (profiles: string[], payload: SaveConfigPayload) => void;
}
export interface ConfigSave {
@@ -27,9 +27,10 @@ export function useConfigSave({ buildPayload, onSaved }: UseConfigSaveArgs): Con
const saveConfig = async () => {
setSaving(true);
try {
- const result = await infraApi.saveConfig(buildPayload());
+ const payload = buildPayload();
+ const result = await infraApi.saveConfig(payload);
if (result.saved) {
- onSaved(result.profiles || []);
+ onSaved(result.profiles || [], payload);
} else {
toast.error(t('infrastructure.toasts.saveFailed'), result.message);
}
diff --git a/dashboard/src/pages/Infrastructure.test.ts b/dashboard/src/pages/Infrastructure.test.ts
index 7453b3654..08327acee 100644
--- a/dashboard/src/pages/Infrastructure.test.ts
+++ b/dashboard/src/pages/Infrastructure.test.ts
@@ -1216,6 +1216,41 @@ test('changing a database or storage type the environment pins warns of no switc
assert.equal(within(dialog).queryByText(STORAGE_WARNING, { exact: false }) === null, true, 'storage warning');
});
+// Beside a pinned bundled endpoint the toggle reads on from what runs, but the save leaves the flag out and the
+// gateway keeps the stored bucket, so an unrelated save moves no media.
+test('an unrelated save beside a pinned bundled endpoint warns of no storage switch', async () => {
+ const { screen, fireEvent, within } = rtl;
+ resetFetchCalls();
+ overrides = {
+ status: {
+ ...INFRA_STATUS,
+ storage: { type: 's3', bucket: 'media', endpoint: 'http://minio:9000', builtIn: true, s3Available: true },
+ envPinned: ['S3_ENDPOINT'],
+ },
+ saved: {
+ ...SAVED_CONFIG,
+ storage: {
+ ...SAVED_CONFIG.storage,
+ type: 's3',
+ builtIn: true,
+ builtInSet: false,
+ s3Bucket: 'media',
+ s3Endpoint: 'http://minio:9000',
+ },
+ },
+ };
+ const { container } = renderInfrastructure();
+
+ await screen.findByText('Database Configuration');
+ await awaitSeeded(container);
+ assert.equal(toggleInput(container, 'Use Built-in MinIO Container').checked, true);
+ fireEvent.click(toggleInput(container, 'Headless Mode'));
+ fireEvent.click(screen.getByRole('button', { name: 'Save Configuration' }));
+
+ const dialog = await screen.findByRole('dialog');
+ assert.equal(within(dialog).queryByText(STORAGE_WARNING, { exact: false }) === null, true, 'storage warning');
+});
+
// A pinned external host outranks the toggle, so turning Use Built-in on moves nothing.
test('turning Use Built-in on under a pinned external host warns of no switch', async () => {
const { screen, fireEvent, within } = rtl;
diff --git a/dashboard/src/pages/Infrastructure.tsx b/dashboard/src/pages/Infrastructure.tsx
index c63cf7230..b3cf7b378 100644
--- a/dashboard/src/pages/Infrastructure.tsx
+++ b/dashboard/src/pages/Infrastructure.tsx
@@ -64,7 +64,7 @@ export function Infrastructure() {
// to open — the one-way edge between the save and restart hooks.
const configSave = useConfigSave({
buildPayload: configForm.buildSavePayload,
- onSaved: profiles => {
+ onSaved: (profiles, sent) => {
// Flag a backend switch so the restart modal can warn about the empty-database / orphaned-media data
// move before it happens. A switch is a next boot that connects somewhere else than the server does
// now: another type, host, port or database name, or another S3 endpoint or bucket. The next boot
@@ -90,9 +90,12 @@ export function Infrastructure() {
(dbType === 'postgres' && (dbHost !== infraStatus.database.host || dbExternalRetarget)));
const storage = configForm.storageConfig;
const storageType = pinned('STORAGE_TYPE')?.storage.type ?? storage.type;
+ // The storage section takes the bundled bucket for a flag sent as true only: beside a pinned endpoint an untouched
+ // toggle is left out of the save, and the stored bucket stays.
+ const storageBuiltIn = sent.storage?.builtIn === true;
const endpoint =
- pinned('S3_ENDPOINT')?.storage.s3Endpoint ?? (storage.builtIn ? 'http://minio:9000' : storage.s3Endpoint);
- const bucket = (storage.builtIn ? 'openwa' : storage.s3Bucket) || 'openwa';
+ pinned('S3_ENDPOINT')?.storage.s3Endpoint ?? (storageBuiltIn ? 'http://minio:9000' : storage.s3Endpoint);
+ const bucket = (storageBuiltIn ? 'openwa' : storage.s3Bucket) || 'openwa';
const storageSwitch =
!!infraStatus &&
(storageType !== infraStatus.storage.type ||