diff --git a/api-users.go b/api-users.go index 0117457..5a01915 100644 --- a/api-users.go +++ b/api-users.go @@ -44,16 +44,16 @@ func (app *appContext) NewUserAdmin(gc *gin.Context) { return } id := user.ID - if app.storage.policy.BlockedTags != nil { - status, err = app.jf.SetPolicy(id, app.storage.policy) + profile := app.storage.GetDefaultProfile() + // Check profile isn't empty + if profile.Policy.BlockedTags != nil { + status, err = app.jf.SetPolicy(id, profile.Policy) if !(status == 200 || status == 204 || err == nil) { app.err.Printf("%s: Failed to set user policy (%d): %v", req.Username, status, err) } - } - if app.storage.configuration.GroupedFolders != nil && len(app.storage.displayprefs) != 0 { - status, err = app.jf.SetConfiguration(id, app.storage.configuration) + status, err = app.jf.SetConfiguration(id, profile.Configuration) if (status == 200 || status == 204) && err == nil { - status, err = app.jf.SetDisplayPreferences(id, app.storage.displayprefs) + status, err = app.jf.SetDisplayPreferences(id, profile.Displayprefs) } if !((status == 200 || status == 204) && err == nil) { app.err.Printf("%s: Failed to set configuration template (%d): %v", req.Username, status, err) @@ -64,15 +64,16 @@ func (app *appContext) NewUserAdmin(gc *gin.Context) { app.storage.SetEmailsKey(id, EmailAddress{Addr: req.Email, Contact: true}) } if app.config.Section("ombi").Key("enabled").MustBool(false) { - app.storage.loadOmbiTemplate() - if len(app.storage.ombi_template) != 0 { - errors, code, err := app.ombi.NewUser(req.Username, req.Password, req.Email, app.storage.ombi_template) - if err != nil || code != 200 { - app.err.Printf("Failed to create Ombi user (%d): %v", code, err) - app.debug.Printf("Errors reported by Ombi: %s", strings.Join(errors, ", ")) - } else { - app.info.Println("Created Ombi user") - } + profile := app.storage.GetDefaultProfile() + if profile.Ombi == nil { + profile.Ombi = map[string]interface{}{} + } + errors, code, err := app.ombi.NewUser(req.Username, req.Password, req.Email, profile.Ombi) + if err != nil || code != 200 { + app.err.Printf("Failed to create Ombi user (%d): %v", code, err) + app.debug.Printf("Errors reported by Ombi: %s", strings.Join(errors, ", ")) + } else { + app.info.Println("Created Ombi user") } } if emailEnabled && app.config.Section("welcome_email").Key("enabled").MustBool(false) && req.Email != "" { diff --git a/migrations.go b/migrations.go index 6e9806b..2c856a2 100644 --- a/migrations.go +++ b/migrations.go @@ -21,7 +21,7 @@ func runMigrations(app *appContext) { // Migrate pre-0.2.0 user templates to profiles func migrateProfiles(app *appContext) { - if app.storage.policy.BlockedTags == nil && app.storage.configuration.GroupedFolders == nil && len(app.storage.displayprefs) == 0 { + if app.storage.deprecatedPolicy.BlockedTags == nil && app.storage.deprecatedConfiguration.GroupedFolders == nil && len(app.storage.deprecatedDisplayprefs) == 0 { return } app.info.Println("Migrating user template files to new profile format") diff --git a/storage.go b/storage.go index 2fc6cf9..4729743 100644 --- a/storage.go +++ b/storage.go @@ -35,15 +35,15 @@ type Storage struct { deprecatedUserExpiries map[string]time.Time // Map of Jellyfin User IDs to their expiry times. deprecatedInvites Invites deprecatedProfiles map[string]Profile - displayprefs, ombi_template map[string]interface{} + deprecatedDisplayprefs, deprecatedOmbiTemplate map[string]interface{} deprecatedEmails emailStore // Map of Jellyfin User IDs to Email addresses. deprecatedTelegram telegramStore // Map of Jellyfin User IDs to telegram users. deprecatedDiscord discordStore // Map of Jellyfin user IDs to discord users. deprecatedMatrix matrixStore // Map of Jellyfin user IDs to Matrix users. customEmails customEmails userPage userPageContent - policy mediabrowser.Policy - configuration mediabrowser.Configuration + deprecatedPolicy mediabrowser.Policy + deprecatedConfiguration mediabrowser.Configuration lang Lang deprecatedAnnouncements map[string]announcementTemplate } @@ -1213,35 +1213,35 @@ func (st *Storage) storeUserPageContent() error { } func (st *Storage) loadPolicy() error { - return loadJSON(st.policy_path, &st.policy) + return loadJSON(st.policy_path, &st.deprecatedPolicy) } func (st *Storage) storePolicy() error { - return storeJSON(st.policy_path, st.policy) + return storeJSON(st.policy_path, st.deprecatedPolicy) } func (st *Storage) loadConfiguration() error { - return loadJSON(st.configuration_path, &st.configuration) + return loadJSON(st.configuration_path, &st.deprecatedConfiguration) } func (st *Storage) storeConfiguration() error { - return storeJSON(st.configuration_path, st.configuration) + return storeJSON(st.configuration_path, st.deprecatedConfiguration) } func (st *Storage) loadDisplayprefs() error { - return loadJSON(st.displayprefs_path, &st.displayprefs) + return loadJSON(st.displayprefs_path, &st.deprecatedDisplayprefs) } func (st *Storage) storeDisplayprefs() error { - return storeJSON(st.displayprefs_path, st.displayprefs) + return storeJSON(st.displayprefs_path, st.deprecatedDisplayprefs) } func (st *Storage) loadOmbiTemplate() error { - return loadJSON(st.ombi_path, &st.ombi_template) + return loadJSON(st.ombi_path, &st.deprecatedOmbiTemplate) } func (st *Storage) storeOmbiTemplate() error { - return storeJSON(st.ombi_path, st.ombi_template) + return storeJSON(st.ombi_path, st.deprecatedOmbiTemplate) } func (st *Storage) loadAnnouncements() error { @@ -1298,9 +1298,9 @@ func (st *Storage) migrateToProfile() error { st.loadDisplayprefs() st.loadProfiles() st.deprecatedProfiles["Default"] = Profile{ - Policy: st.policy, - Configuration: st.configuration, - Displayprefs: st.displayprefs, + Policy: st.deprecatedPolicy, + Configuration: st.deprecatedConfiguration, + Displayprefs: st.deprecatedDisplayprefs, } return st.storeProfiles() }