From da1b9ccac715bc4d26f434f9b03b0b77e357e3f8 Mon Sep 17 00:00:00 2001 From: Harvey Tindall Date: Tue, 25 Jan 2022 18:02:04 +0000 Subject: [PATCH] ombi: add migration to link telegram/discord --- migrations.go | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/migrations.go b/migrations.go index 8510ad5..58f7c94 100644 --- a/migrations.go +++ b/migrations.go @@ -14,6 +14,7 @@ func runMigrations(app *appContext) { migrateBootstrap(app) migrateEmailStorage(app) migrateNotificationMethods(app) + linkExistingOmbiDiscordTelegram(app) // migrateHyphens(app) } @@ -158,6 +159,41 @@ func migrateNotificationMethods(app *appContext) error { return nil } +// Pre-0.3.10, Ombi users were created without linking their Discord & Telegram accounts. This will add them. +func linkExistingOmbiDiscordTelegram(app *appContext) error { + if !discordEnabled && !telegramEnabled { + return nil + } + if !app.config.Section("ombi").Key("enabled").MustBool(false) { + return nil + } + idList := map[string][2]string{} + for jfID, user := range app.storage.discord { + idList[jfID] = [2]string{user.ID, ""} + } + for jfID, user := range app.storage.telegram { + vals, ok := idList[jfID] + if !ok { + vals = [2]string{"", ""} + } + vals[1] = user.Username + idList[jfID] = vals + } + for jfID, ids := range idList { + ombiUser, status, err := app.getOmbiUser(jfID) + if status != 200 || err != nil { + app.debug.Printf("Failed to get Ombi user with Discord/Telegram \"%s\"/\"%s\" (%d): %v", ids[0], ids[1], status, err) + continue + } + _, status, err = app.ombi.SetNotificationPrefs(ombiUser, ids[0], ids[1]) + if status != 200 || err != nil { + app.debug.Printf("Failed to set prefs for Ombi user \"%s\" (%d): %v", ombiUser["userName"].(string), status, err) + continue + } + } + return nil +} + // Migrate between hyphenated & non-hyphenated user IDs. Doesn't seem to happen anymore, so disabled. // func migrateHyphens(app *appContext) { // checkVersion := func(version string) int {