Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): leave out a built-in flag beside a pinned host

Yudhi Armyndharis9e5fb821b47e
diff --git a/dashboard/src/hooks/useInfraConfigForm.test.ts b/dashboard/src/hooks/useInfraConfigForm.test.ts
index 978a1fd6e..9335ecc77 100644
--- a/dashboard/src/hooks/useInfraConfigForm.test.ts
+++ b/dashboard/src/hooks/useInfraConfigForm.test.ts
@@ -371,3 +371,39 @@ test('editing a field of a pinned database or storage card sends its type, a Red
assert.deepEqual([database?.type, redis?.enabled, storage?.type], ['postgres', undefined, 's3']);
});
+
+// A pinned host decides the built-in mode at every boot, so the flag the toggle shows is no choice either. Sent, a
+// flag of true writes the bundled credentials over stored ones the pinned host may still need; untouched, it is left
+// out and the gateway keeps the stored flag.
+const PINNED_HOSTS: InfraStatus = { ...RUNNING, envPinned: ['DATABASE_HOST', 'REDIS_HOST', 'S3_ENDPOINT'] };
+
+test('a built-in flag beside a pinned host is left out of a save until its toggle is used', () => {
+ const { result } = renderForm({ status: PINNED_HOSTS, saved: SAVED });
+
+ const untouched = result.current.buildSavePayload();
+ assert.deepEqual(
+ [untouched.database?.builtIn, untouched.redis?.builtIn, untouched.storage?.builtIn],
+ [undefined, undefined, undefined],
+ );
+
+ rtl.act(() => {
+ result.current.updateDbConfig('builtIn', true);
+ result.current.updateRedisConfig('builtIn', true);
+ result.current.updateStorageConfig('builtIn', true);
+ });
+ const touched = result.current.buildSavePayload();
+ assert.deepEqual([touched.database?.builtIn, touched.redis?.builtIn, touched.storage?.builtIn], [true, true, true]);
+});
+
+test('another edit in the card keeps a built-in flag beside a pinned host out', () => {
+ const { result } = renderForm({ status: PINNED_HOSTS, saved: SAVED });
+
+ rtl.act(() => {
+ result.current.updateDbConfig('sslEnabled', false);
+ result.current.updateRedisConfig('port', '6390');
+ result.current.updateStorageConfig('s3Bucket', 'media-2');
+ });
+ const { database, redis, storage } = result.current.buildSavePayload();
+
+ assert.deepEqual([database?.builtIn, redis?.builtIn, storage?.builtIn], [undefined, undefined, undefined]);
+});
diff --git a/dashboard/src/hooks/useInfraConfigForm.ts b/dashboard/src/hooks/useInfraConfigForm.ts
index fad0d8497..a3d588c01 100644
--- a/dashboard/src/hooks/useInfraConfigForm.ts
+++ b/dashboard/src/hooks/useInfraConfigForm.ts
@@ -142,6 +142,10 @@ export function useInfraConfigForm(
const dbTouched = useRef(false);
const storageTouched = useRef(false);
const redisEnabledTouched = useRef(false);
+ // Whether the operator has used each Use Built-in toggle here; beside a pinned host an unused one is left out.
+ const dbBuiltInTouched = useRef(false);
+ const redisBuiltInTouched = useRef(false);
+ const storageBuiltInTouched = useRef(false);
/** Whether engineConfig.type reflects a real value (seeded from the saved config or user-picked)
* rather than the useState default — the save payload omits `type` when it doesn't. */
@@ -218,12 +222,16 @@ export function useInfraConfigForm(
const updateDbConfig = (key: keyof DatabaseConfig, value: string | number | boolean) => {
dbTouched.current = true;
+ if (key === 'builtIn') dbBuiltInTouched.current = true;
setDbConfig(prev => ({ ...prev, [key]: value }));
};
- const updateRedisConfig = (key: keyof RedisConfig, value: string | boolean) =>
+ const updateRedisConfig = (key: keyof RedisConfig, value: string | boolean) => {
+ if (key === 'builtIn') redisBuiltInTouched.current = true;
setRedisConfig(prev => ({ ...prev, [key]: value }));
+ };
const updateStorageConfig = (key: keyof StorageConfig, value: string | boolean) => {
storageTouched.current = true;
+ if (key === 'builtIn') storageBuiltInTouched.current = true;
setStorageConfig(prev => ({ ...prev, [key]: value }));
};
const updateEngineConfig = (key: keyof EngineConfig, value: string | boolean) => {
@@ -245,7 +253,9 @@ export function useInfraConfigForm(
// reveal (#1082), and drop the stored settings of the mode it replaces. Untouched, it is left out, and the
// gateway keeps the stored selection. Any edit in the database or storage card sends it: the edited fields belong
// to the mode the card shows, and a stored selection of the other mode would drop them. Read at save time, like
- // the engine pin below.
+ // the engine pin below. A pinned host decides the built-in mode the same way, and a flag of true sent beside it
+ // writes the bundled credentials over stored ones the pinned host may still need, so an unused toggle there is
+ // left out too and the gateway keeps the stored flag.
const pinnedSeed = (key: string, touched: { current: boolean }) =>
!touched.current && !!infraStatus?.envPinned?.includes(key);
@@ -256,6 +266,7 @@ export function useInfraConfigForm(
database: {
...dbConfig,
type: pinnedSeed('DATABASE_TYPE', dbTouched) ? undefined : dbConfig.type,
+ builtIn: pinnedSeed('DATABASE_HOST', dbBuiltInTouched) ? undefined : dbConfig.builtIn,
password: dbConfig.builtIn ? '' : dbConfig.password,
poolSize: Number.isInteger(dbConfig.poolSize) ? dbConfig.poolSize : undefined,
},
@@ -263,7 +274,7 @@ export function useInfraConfigForm(
// whitelisted backend DTO so a valid dashboard save cannot be rejected as an unknown field.
redis: {
enabled: pinnedSeed('REDIS_ENABLED', redisEnabledTouched) ? undefined : redisEnabled,
- builtIn: redisConfig.builtIn,
+ builtIn: pinnedSeed('REDIS_HOST', redisBuiltInTouched) ? undefined : redisConfig.builtIn,
host: redisConfig.host,
port: redisConfig.port,
password: redisConfig.builtIn ? '' : redisConfig.password,
@@ -272,6 +283,7 @@ export function useInfraConfigForm(
storage: {
...storageConfig,
type: pinnedSeed('STORAGE_TYPE', storageTouched) ? undefined : storageConfig.type,
+ builtIn: pinnedSeed('S3_ENDPOINT', storageBuiltInTouched) ? undefined : storageConfig.builtIn,
},
// Only send `type` once we actually know it — either the radio seeded from /config or the
// operator picked one. If /config never resolved, engineConfig.type still holds its useState
diff --git a/dashboard/src/pages/Infrastructure.test.ts b/dashboard/src/pages/Infrastructure.test.ts
index 01b403ce9..7453b3654 100644
--- a/dashboard/src/pages/Infrastructure.test.ts
+++ b/dashboard/src/pages/Infrastructure.test.ts
@@ -1464,9 +1464,11 @@ COMBOS.forEach((_, i) => {
redis?: { builtIn?: boolean };
storage?: { builtIn?: boolean };
};
+ // A pinned host decides the mode whatever the flag says, so the untouched flag beside it is left out.
+ const sentFlag = (c: Combo) => (c.pin === 'none' ? shownMode(c) : undefined);
assert.deepEqual(
[body.database?.builtIn, body.redis?.builtIn, body.storage?.builtIn],
- [shownMode(database), shownMode(redis), shownMode(storage)],
+ [sentFlag(database), sentFlag(redis), sentFlag(storage)],
'the flags the save sends',
);
// Only a database or storage the next boot connects to somewhere else starts empty after the restart.
diff --git a/src/modules/infra/infra-config.controller.spec.ts b/src/modules/infra/infra-config.controller.spec.ts
index 36138eb6a..7dc21117c 100644
--- a/src/modules/infra/infra-config.controller.spec.ts
+++ b/src/modules/infra/infra-config.controller.spec.ts
@@ -966,6 +966,35 @@ describe('InfraConfigController.saveConfig per-key merge (partial payloads)', ()
expect(env).not.toMatch(/^DATABASE_HOST=/m);
});
+ // The page leaves out an untouched flag beside a pinned host. The stored external flag is inherited then, so the
+ // credentials the pinned host may need stay as stored, where a flag of true would write the bundled ones.
+ it('keeps stored external credentials when the flag is left out beside a pinned bundled host', () => {
+ pin({ DATABASE_TYPE: 'postgres', DATABASE_HOST: 'postgres', S3_ENDPOINT: 'http://minio:9000' });
+ const stored = STORED_EXTERNAL.replace('S3_ENDPOINT=https://s3.example.com\n', '') + 'POSTGRES_SCHEMA=custom\n';
+
+ const env = written(
+ {
+ database: { host: 'postgres', username: 'app', database: 'appdb', schema: 'custom', password: '' },
+ storage: { s3Bucket: 'media', s3Endpoint: 'http://minio:9000', s3AccessKey: '', s3SecretKey: '' },
+ },
+ stored,
+ );
+
+ for (const line of [
+ 'POSTGRES_BUILTIN=false',
+ 'DATABASE_USERNAME=app',
+ 'DATABASE_PASSWORD=Str0ng!Passw0rd',
+ 'DATABASE_NAME=appdb',
+ 'POSTGRES_SCHEMA=custom',
+ 'MINIO_BUILTIN=false',
+ 'S3_BUCKET=media',
+ 'S3_ACCESS_KEY_ID=ak-strong',
+ 'S3_SECRET_ACCESS_KEY=sk-strong',
+ ]) {
+ expect(env).toContain(line);
+ }
+ });
+
it('still writes a type that is sent', () => {
pin({ DATABASE_TYPE: 'sqlite', STORAGE_TYPE: 'local' });