1
0
mirror of https://github.com/hrfee/jfa-go.git synced 2024-12-22 09:00:10 +00:00

ombi: add migration to link telegram/discord

This commit is contained in:
Harvey Tindall 2022-01-25 18:02:04 +00:00
parent 7b97e1ca26
commit da1b9ccac7
Signed by: hrfee
GPG Key ID: BBC65952848FB1A2

View File

@ -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 {