Przeglądaj źródła

Let the platform backup cycle be turned off by its system setting (#604)

* Apply the workshop's forced language on the portal and share pages

The language for customer pages was read from a request header that nothing
sets, so a workshop that forces its own language on customer-facing pages
still got the visitor's browser language there, and staff notices could show
on customer pages. The path now comes from the header the proxy really sets.

* Rebuild the customer portal with themes, chat and photo uploads

The workshop picks one of four themes (Daylight by default), its colour and a
cover photo; customers no longer choose a layout. The home uses the whole
page and carries a live chat with the workshop, which lands in the Messages
inbox as a Portal channel. Customers can book a visit with photos and video,
see stored tyres, and the settings page saves everything with one button.

* Bind portal uploads to their customer and make quote answers atomic

A customer's upload now carries a keyed mark of who uploaded it and is
refused on a message, a booking or a release by anyone else. A quote answer
is one conditional update, so it cannot overwrite a quote converted in the
meantime. Only the messages on screen are marked read, portal writes stop
during a restore, an older backup's portal picture becomes the cover photo,
and a request's preferred day prints on the workshop's clock.

* Let the platform backup cycle be turned off by its system setting
Bernt Christian Egeland 10 godzin temu
rodzic
commit
384bf66805

+ 13 - 0
src/__tests__/lib/cron/backup-runs.test.ts

@@ -567,6 +567,8 @@ describe('platformBackupFrequency', () => {
     expect(await platformBackupFrequency()).toBe('daily')
     h.systemSettings['platformBackup.frequency'] = 'weekly'
     expect(await platformBackupFrequency()).toBe('hourly')
+    h.systemSettings['platformBackup.frequency'] = 'off'
+    expect(await platformBackupFrequency()).toBe('off')
   })
 })
 
@@ -605,6 +607,17 @@ describe('processDuePlatformBackups', () => {
     expect(h.platform.size).toBe(0)
   })
 
+  it('queues nothing and reports nothing overdue while the cycle is off', async () => {
+    h.systemSettings['platformBackup.frequency'] = 'off'
+    addOrg('orga', true)
+    addOrg('orgb', true, { lastScheduledAt: new Date(now.getTime() - 72 * HOUR) })
+
+    expect(await processDuePlatformBackups(now)).toBe(0)
+    expect(queueBackupRun).not.toHaveBeenCalled()
+    expect(reportOverdue).not.toHaveBeenCalled()
+    expect(h.platform.has('orga')).toBe(false)
+  })
+
   it('queues a workshop whose plan includes them, and makes its row with lastScheduledAt', async () => {
     addOrg('orga', true)
 

+ 2 - 2
src/features/integrations/Lib/platform-backup.ts

@@ -77,8 +77,8 @@ export async function platformBackupOverview(
     })
   }
   let nextRunAt: string | null = null
-  if (active) {
-    const frequency = await platformBackupFrequency()
+  const frequency = active ? await platformBackupFrequency() : 'off'
+  if (frequency !== 'off') {
     const settings = { ...BACKUP_SETTING_DEFAULTS, frequency, time: '02:00' }
     const timeZone = await workshopTimeZone(organizationId)
     nextRunAt = nextRunAfter(

+ 11 - 2
src/lib/cron/backup-runs.ts

@@ -224,12 +224,17 @@ async function alertIfOverdue(
   await reportOverdue(connectionId, organizationId, lastGood)
 }
 
-/** How often the platform cycle runs: a system setting, hourly unless changed. */
-export async function platformBackupFrequency(): Promise<BackupFrequency> {
+/**
+ * How often the platform cycle runs: a system setting, hourly unless changed.
+ * 'off' stops the schedule altogether; the torqvoice.com admin offers it for
+ * staging only, where the workshops are test data.
+ */
+export async function platformBackupFrequency(): Promise<BackupFrequency | 'off'> {
   const row = await db.systemSetting.findUnique({
     where: { key: SYSTEM_SETTING_KEYS.PLATFORM_BACKUP_FREQUENCY },
     select: { value: true },
   })
+  if (row?.value === 'off') return 'off'
   const value = row?.value as BackupFrequency | undefined
   return value && PLATFORM_FREQUENCIES.includes(value) ? value : 'hourly'
 }
@@ -243,6 +248,10 @@ export async function platformBackupFrequency(): Promise<BackupFrequency> {
 export async function processDuePlatformBackups(now = new Date()): Promise<number> {
   if (!platformBackupConfig()) return 0
   const frequency = await platformBackupFrequency()
+  // Off: nothing is queued, paused, purged or reported overdue. The
+  // repositories stay as they are, and a backup or restore asked for by
+  // hand still runs.
+  if (frequency === 'off') return 0
   const settings = { ...BACKUP_SETTING_DEFAULTS, frequency, time: '02:00' }
   const organizations = await db.organization.findMany({
     select: { id: true, platformBackup: true },