From 95a81d17ced9766d40447364de12925b51c844fd Mon Sep 17 00:00:00 2001 From: Kailash Nadh Date: Sun, 16 May 2021 16:54:55 +0530 Subject: [PATCH] Add option on UI to toggle update checks. Closes #326 --- cmd/init.go | 4 ++-- cmd/main.go | 6 ++++-- cmd/settings.go | 1 + frontend/src/views/Settings.vue | 6 ++++++ i18n/de.json | 2 ++ i18n/en.json | 2 ++ i18n/es.json | 2 ++ i18n/fr.json | 2 ++ i18n/it.json | 2 ++ i18n/ml.json | 2 ++ i18n/pl.json | 2 ++ i18n/pt-BR.json | 2 ++ i18n/pt.json | 2 ++ i18n/ru.json | 2 ++ internal/migrations/v1.0.0.go | 15 +++++++++++++-- schema.sql | 1 + 16 files changed, 47 insertions(+), 6 deletions(-) diff --git a/cmd/init.go b/cmd/init.go index aa983e6..a51f20d 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -222,9 +222,9 @@ func initQueries(sqlFile string, db *sqlx.DB, fs stuffbin.FileSystem, prepareQue } // initSettings loads settings from the DB. -func initSettings(q *Queries) { +func initSettings(q *sqlx.Stmt) { var s types.JSONText - if err := q.GetSettings.Get(&s); err != nil { + if err := q.Get(&s); err != nil { lo.Fatalf("error reading settings from DB: %s", pqErrMsg(err)) } diff --git a/cmd/main.go b/cmd/main.go index 0e98223..a55684d 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -135,7 +135,7 @@ func init() { _, queries := initQueries(queryFilePath, db, fs, true) // Load settings from DB. - initSettings(queries) + initSettings(queries.GetSettings) } func main() { @@ -180,7 +180,9 @@ func main() { srv := initHTTPServer(app) // Star the update checker. - go checkUpdates(versionString, time.Hour*24, app) + if ko.Bool("app.check_updates") { + go checkUpdates(versionString, time.Hour*24, app) + } // Wait for the reload signal with a callback to gracefully shut down resources. // The `wait` channel is passed to awaitReload to wait for the callback to finish diff --git a/cmd/settings.go b/cmd/settings.go index 5b2af27..72e9412 100644 --- a/cmd/settings.go +++ b/cmd/settings.go @@ -20,6 +20,7 @@ type settings struct { AppFromEmail string `json:"app.from_email"` AppNotifyEmails []string `json:"app.notify_emails"` EnablePublicSubPage bool `json:"app.enable_public_subscription_page"` + CheckUpdates bool `json:"app.check_updates"` AppLang string `json:"app.lang"` AppBatchSize int `json:"app.batch_size"` diff --git a/frontend/src/views/Settings.vue b/frontend/src/views/Settings.vue index ad9a3d6..40ba896 100644 --- a/frontend/src/views/Settings.vue +++ b/frontend/src/views/Settings.vue @@ -59,6 +59,12 @@ name="app.enable_public_subscription_page" /> + + + +
diff --git a/i18n/de.json b/i18n/de.json index a99acaa..baa256b 100644 --- a/i18n/de.json +++ b/i18n/de.json @@ -279,6 +279,8 @@ "settings.errorNoSMTP": "Mindestens ein SMTP Block muss aktiviert sein", "settings.general.adminNotifEmails": "Admin Benachrichtigungen", "settings.general.adminNotifEmailsHelp": "Komma getrennte Liste von E-Mail Adressen welche Admin Benachrichtigungen erhalten. Wie Importupdates, Fertigstellung von Kapganen, Fehler usw.", + "settings.general.checkUpdates": "Check for updates", + "settings.general.checkUpdatesHelp": "Periodically check for new app releases and notify.", "settings.general.enablePublicSubPage": "Enable public subscription page", "settings.general.enablePublicSubPageHelp": "Show a public subscription page with all the public lists for people to subscribe.", "settings.general.faviconURL": "Favicon URL", diff --git a/i18n/en.json b/i18n/en.json index 7c63602..8c088ad 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -279,6 +279,8 @@ "settings.errorNoSMTP": "At least one SMTP block should be enabled", "settings.general.adminNotifEmails": "Admin notification e-mails", "settings.general.adminNotifEmailsHelp": "Comma separated list of e-mail addresses to which admin notifications such as import updates, campaign completion, failure etc. should be sent.", + "settings.general.checkUpdates": "Check for updates", + "settings.general.checkUpdatesHelp": "Periodically check for new app releases and notify.", "settings.general.enablePublicSubPage": "Enable public subscription page", "settings.general.enablePublicSubPageHelp": "Show a public subscription page with all the public lists for people to subscribe.", "settings.general.faviconURL": "Favicon URL", diff --git a/i18n/es.json b/i18n/es.json index 3eebf1c..3d478ef 100644 --- a/i18n/es.json +++ b/i18n/es.json @@ -279,6 +279,8 @@ "settings.errorNoSMTP": "Al menos un bloque SMTP debe estar habilitado", "settings.general.adminNotifEmails": "Correos electrónicos para notificacion de administradores", "settings.general.adminNotifEmailsHelp": "Lista de correos electrónicos separados por comas, a donde las notificaciones como actualizaciones de importación, campañas completadas, fallas, etc deben ser enviadas.", + "settings.general.checkUpdates": "Check for updates", + "settings.general.checkUpdatesHelp": "Periodically check for new app releases and notify.", "settings.general.enablePublicSubPage": "Habilitar pagina publica de subscripción", "settings.general.enablePublicSubPageHelp": "Muestra una página con todas las listas públicas para subscribirse.", "settings.general.faviconURL": "Favicon URL", diff --git a/i18n/fr.json b/i18n/fr.json index a861961..f6b9289 100644 --- a/i18n/fr.json +++ b/i18n/fr.json @@ -279,6 +279,8 @@ "settings.errorNoSMTP": "Au moins un bloc SMTP doit être activé", "settings.general.adminNotifEmails": "Emails pour les notifications admin", "settings.general.adminNotifEmailsHelp": "Liste d'adresses email (séparées par des virgules) auxquelles les notifications d'admin telles que les mises à jour d'importation, fins de campagnes, échecs, etc. seront envoyées.", + "settings.general.checkUpdates": "Check for updates", + "settings.general.checkUpdatesHelp": "Periodically check for new app releases and notify.", "settings.general.enablePublicSubPage": "Activer la page d'abonnement publique", "settings.general.enablePublicSubPageHelp": "Afficher une page d'abonnement publique avec toutes les listes publiques auxquelles les personnes peuvent s'abonner.", "settings.general.faviconURL": "URL du favicon", diff --git a/i18n/it.json b/i18n/it.json index ba8c375..ff37f49 100644 --- a/i18n/it.json +++ b/i18n/it.json @@ -279,6 +279,8 @@ "settings.errorNoSMTP": "Devi attivare almeno un blocco SMTP", "settings.general.adminNotifEmails": "Mail di notifica amministratore", "settings.general.adminNotifEmailsHelp": "Lista indirizzi mail separati da virgole ai quali saranno inviate notifiche di amministrazione come gli aggiornamenti di importazione, la fine della campagna, eventuali problemi ecc.", + "settings.general.checkUpdates": "Check for updates", + "settings.general.checkUpdatesHelp": "Periodically check for new app releases and notify.", "settings.general.enablePublicSubPage": "Attiva la pagina di iscrizione pubblica", "settings.general.enablePublicSubPageHelp": "Visualizza una pagina di iscrizione pubblica con tutte le liste pubbliche a cui è possibile iscriversi.", "settings.general.faviconURL": "URL della favicon", diff --git a/i18n/ml.json b/i18n/ml.json index 79b46b7..db7cd96 100644 --- a/i18n/ml.json +++ b/i18n/ml.json @@ -279,6 +279,8 @@ "settings.errorNoSMTP": "കുറഞ്ഞപക്ഷം ഒരു എസ്. എം. ടീ. പീ ബ്ലൊക്കെങ്കിലും പ്രവർത്തനക്ഷമയിരിക്കണം", "settings.general.adminNotifEmails": "കാര്യനിര്‍വ്വാഹകർക്കുള്ള അറിയിപ്പ് ഇ-മെയിലുകൾ", "settings.general.adminNotifEmailsHelp": "ഇംപോർട്ട് ചെയ്തതിലുള്ള വിവരങ്ങൾ, ക്യാമ്പേയ്ൻ പൂർത്തീകരണം, പ്രശ്നങ്ങൾ എന്നിങ്ങനെയുള്ള പ്രധാനപ്പെട്ട കാര്യനിര്‍വ്വാഹകർക്കുള്ള അറിയിപ്പിനായുള്ള കോമാ ഉപയോഗിച്ച് വേർതിരിച്ച ഇ-മെയിൽ വിലാസങ്ങൾ.", + "settings.general.checkUpdates": "Check for updates", + "settings.general.checkUpdatesHelp": "Periodically check for new app releases and notify.", "settings.general.enablePublicSubPage": "Enable public subscription page", "settings.general.enablePublicSubPageHelp": "Show a public subscription page with all the public lists for people to subscribe.", "settings.general.faviconURL": "ഫാവ് ഐക്കൺ യൂ. ആർ. എൽ", diff --git a/i18n/pl.json b/i18n/pl.json index 40d7b81..e89fdd8 100644 --- a/i18n/pl.json +++ b/i18n/pl.json @@ -279,6 +279,8 @@ "settings.errorNoSMTP": "Co najmniej jeden blok SMTP powinien być aktywowany", "settings.general.adminNotifEmails": "Adres email do powiadomień admina", "settings.general.adminNotifEmailsHelp": "Lista maili oddzielona przecinkami do adminów, którym przesyłać informacje o importach, zakończonych kampaniach, błędach itd. ", + "settings.general.checkUpdates": "Check for updates", + "settings.general.checkUpdatesHelp": "Periodically check for new app releases and notify.", "settings.general.enablePublicSubPage": "Włącz publiczną stronę subskrypcji", "settings.general.enablePublicSubPageHelp": "Pokaż publiczną stronę do zapisu na subskrypcje publicznych list.", "settings.general.faviconURL": "URL Favicony", diff --git a/i18n/pt-BR.json b/i18n/pt-BR.json index 78b6583..be1e2b8 100644 --- a/i18n/pt-BR.json +++ b/i18n/pt-BR.json @@ -279,6 +279,8 @@ "settings.errorNoSMTP": "Pelo menos um bloco SMTP deve estar habilitado", "settings.general.adminNotifEmails": "E-mails de notificação de administrador", "settings.general.adminNotifEmailsHelp": "Lista de e-mails separados por vírgula para os quais as notificações de administração, como atualizações de importação, conclusão da campanha, falha, etc. devem ser enviadas.", + "settings.general.checkUpdates": "Check for updates", + "settings.general.checkUpdatesHelp": "Periodically check for new app releases and notify.", "settings.general.enablePublicSubPage": "Habilitar a página pública de inscrição", "settings.general.enablePublicSubPageHelp": "Habilitar a página pública de inscrição com todas as listas públicas para as pessoas se inscreverem.", "settings.general.faviconURL": "URL do Favicon", diff --git a/i18n/pt.json b/i18n/pt.json index 42fadb3..4a12eb2 100644 --- a/i18n/pt.json +++ b/i18n/pt.json @@ -279,6 +279,8 @@ "settings.errorNoSMTP": "Pelo menos um bloco SMTP deve estar ativo", "settings.general.adminNotifEmails": "Emails de notificação de administração", "settings.general.adminNotifEmailsHelp": "Lista separada por vírgulas dos endereços de email para os quais devem ser enviadas notificações de administração como updates importantes, conclusão de campanhas, falhas, etc.", + "settings.general.checkUpdates": "Check for updates", + "settings.general.checkUpdatesHelp": "Periodically check for new app releases and notify.", "settings.general.enablePublicSubPage": "Ativar página de subscrição pública", "settings.general.enablePublicSubPageHelp": "Mostrar uma página de subscrição pública com todas as listas públicas para as pessoas se subscreverem.", "settings.general.faviconURL": "URL do Favicon", diff --git a/i18n/ru.json b/i18n/ru.json index c8b798c..8ff8899 100644 --- a/i18n/ru.json +++ b/i18n/ru.json @@ -279,6 +279,8 @@ "settings.errorNoSMTP": "Должен быть включён минимум один блок SMTP", "settings.general.adminNotifEmails": "Письма с уведомлениями для администратора", "settings.general.adminNotifEmailsHelp": "Список адресов электронной почты, разделенных запятыми, на которые следует отправлять уведомления администратора, такие как обновления импорта, завершение кампании, сбой и т.д. ", + "settings.general.checkUpdates": "Check for updates", + "settings.general.checkUpdatesHelp": "Periodically check for new app releases and notify.", "settings.general.enablePublicSubPage": "Включить публичную страницу подписки", "settings.general.enablePublicSubPageHelp": "Показать страницу общедоступной подписки со всеми общедоступными списками, на которые можно подписаться.", "settings.general.faviconURL": "Favicon URL", diff --git a/internal/migrations/v1.0.0.go b/internal/migrations/v1.0.0.go index a593060..3a9a8ef 100644 --- a/internal/migrations/v1.0.0.go +++ b/internal/migrations/v1.0.0.go @@ -8,6 +8,17 @@ import ( // V1_0_0 performs the DB migrations for v.1.0.0. func V1_0_0(db *sqlx.DB, fs stuffbin.FileSystem, ko *koanf.Koanf) error { - _, err := db.Exec(`ALTER TYPE content_type ADD VALUE IF NOT EXISTS 'markdown'`) - return err + if _, err := db.Exec(`ALTER TYPE content_type ADD VALUE IF NOT EXISTS 'markdown'`); err != nil { + return err + } + + if _, err := db.Exec(` + INSERT INTO settings (key, value) VALUES + ('app.check_updates', 'true') + ON CONFLICT DO NOTHING; + `); err != nil { + return err + } + + return nil } diff --git a/schema.sql b/schema.sql index bd4f221..8a68b65 100644 --- a/schema.sql +++ b/schema.sql @@ -178,6 +178,7 @@ INSERT INTO settings (key, value) VALUES ('app.message_sliding_window_duration', '"1h"'), ('app.message_sliding_window_rate', '10000'), ('app.enable_public_subscription_page', 'true'), + ('app.check_updates', 'true'), ('app.notify_emails', '["admin1@mysite.com", "admin2@mysite.com"]'), ('app.lang', '"en"'), ('privacy.individual_tracking', 'false'),