From b17d8424e9bc837b5b7c996d54589b744499360d Mon Sep 17 00:00:00 2001 From: Harvey Tindall Date: Mon, 26 Jun 2023 12:57:16 +0100 Subject: [PATCH] profiles: fix application moving to a DB meant empty slices in the Configuration & Policy structs were being stored as null, and striking a nerve with Jellyfin. Mediabrowser library change fixed that by de-nulling them itself, and a new bool field called "Homescreen" is now used to decide if a profile has a homescreen layout stored or not. This field is hopefully correctly filled in during migration. --- api-profiles.go | 5 +++-- api-users.go | 40 ++++++++++++++++++++-------------------- discord.go | 1 - go.mod | 2 +- go.sum | 4 ++++ html/admin.html | 5 +++++ migrations.go | 3 +++ models.go | 1 + storage.go | 4 ++++ ts/modules/accounts.ts | 18 ++++++++++++++++-- 10 files changed, 57 insertions(+), 26 deletions(-) diff --git a/api-profiles.go b/api-profiles.go index 579cdff..b118838 100644 --- a/api-profiles.go +++ b/api-profiles.go @@ -79,8 +79,9 @@ func (app *appContext) CreateProfile(gc *gin.Context) { return } profile := Profile{ - FromUser: user.Name, - Policy: user.Policy, + FromUser: user.Name, + Policy: user.Policy, + Homescreen: req.Homescreen, } app.debug.Printf("Creating profile from user \"%s\"", user.Name) if req.Homescreen { diff --git a/api-users.go b/api-users.go index 5a01915..28a040e 100644 --- a/api-users.go +++ b/api-users.go @@ -45,8 +45,13 @@ func (app *appContext) NewUserAdmin(gc *gin.Context) { } id := user.ID profile := app.storage.GetDefaultProfile() - // Check profile isn't empty - if profile.Policy.BlockedTags != nil { + if req.Profile != "" && req.Profile != "none" { + if p, ok := app.storage.GetProfileKey(req.Profile); ok { + profile = p + } else { + app.debug.Printf("Couldn't find profile \"%s\", using default", req.Profile) + } + 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) @@ -64,7 +69,6 @@ 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) { - profile := app.storage.GetDefaultProfile() if profile.Ombi == nil { profile.Ombi = map[string]interface{}{} } @@ -305,22 +309,18 @@ func (app *appContext) newUser(req newUserDTO, confirmed bool) (f errorFunc, suc if !ok { profile = app.storage.GetDefaultProfile() } - if profile.Policy.BlockedTags != nil { - app.debug.Printf("Applying policy from profile \"%s\"", invite.Profile) - 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.Code, status, err) - } + app.debug.Printf("Applying policy from profile \"%s\"", invite.Profile) + 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.Code, status, err) } - if profile.Configuration.GroupedFolders != nil && len(profile.Displayprefs) != 0 { - app.debug.Printf("Applying homescreen from profile \"%s\"", invite.Profile) - status, err = app.jf.SetConfiguration(id, profile.Configuration) - if (status == 200 || status == 204) && err == nil { - 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.Code, status, err) - } + app.debug.Printf("Applying homescreen from profile \"%s\"", invite.Profile) + status, err = app.jf.SetConfiguration(id, profile.Configuration) + if (status == 200 || status == 204) && err == nil { + 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.Code, status, err) } } // if app.config.Section("password_resets").Key("enabled").MustBool(false) { @@ -1010,13 +1010,13 @@ func (app *appContext) ApplySettings(gc *gin.Context) { if req.From == "profile" { // Check profile exists & isn't empty profile, ok := app.storage.GetProfileKey(req.Profile) - if !ok || profile.Policy.BlockedTags == nil { + if !ok { app.err.Printf("Couldn't find profile \"%s\" or profile was empty", req.Profile) respond(500, "Couldn't find profile", gc) return } if req.Homescreen { - if profile.Configuration.GroupedFolders == nil || len(profile.Displayprefs) == 0 { + if !profile.Homescreen { app.err.Printf("No homescreen saved in profile \"%s\"", req.Profile) respond(500, "No homescreen template available", gc) return diff --git a/discord.go b/discord.go index 7164114..8efd8fe 100644 --- a/discord.go +++ b/discord.go @@ -222,7 +222,6 @@ func (d *DiscordDaemon) NewTempInvite(ageSeconds, maxUses int) (inviteURL, iconU } // FIXME: Fix CSS, and handle no icon iconURL = guild.IconURL("256") - fmt.Println("GOT ICON", iconURL) return } diff --git a/go.mod b/go.mod index 8dccf00..08fa60d 100644 --- a/go.mod +++ b/go.mod @@ -31,7 +31,6 @@ require ( github.com/hrfee/jfa-go/linecache v0.0.0-20230421170108-d800b97f69b6 github.com/hrfee/jfa-go/logger v0.0.0-20230421170108-d800b97f69b6 github.com/hrfee/jfa-go/ombi v0.0.0-20230421170108-d800b97f69b6 - github.com/hrfee/mediabrowser v0.3.8 github.com/itchyny/timefmt-go v0.1.5 github.com/lithammer/shortuuid/v3 v3.0.7 github.com/mailgun/mailgun-go/v4 v4.9.0 @@ -84,6 +83,7 @@ require ( github.com/google/uuid v1.3.0 // indirect github.com/gorilla/mux v1.8.0 // indirect github.com/gorilla/websocket v1.5.0 // indirect + github.com/hrfee/mediabrowser v0.3.10 // indirect github.com/josharian/intern v1.0.0 // indirect github.com/json-iterator/go v1.1.12 // indirect github.com/klauspost/compress v1.13.1 // indirect diff --git a/go.sum b/go.sum index 8a032c7..c0c701a 100644 --- a/go.sum +++ b/go.sum @@ -216,6 +216,10 @@ github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/ad github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/hrfee/mediabrowser v0.3.8 h1:y0iBCb6jE3QKcsiCJSYva2fFPHRn4UA+sGRzoPuJ/Dk= github.com/hrfee/mediabrowser v0.3.8/go.mod h1:PnHZbdxmbv1wCVdAQyM7nwPwpVj9fdKx2EcET7sAk+U= +github.com/hrfee/mediabrowser v0.3.9 h1:ecBUd7LMjQrh+9SFRen2T2DzQqI7W8J7vV2lGExD0YU= +github.com/hrfee/mediabrowser v0.3.9/go.mod h1:PnHZbdxmbv1wCVdAQyM7nwPwpVj9fdKx2EcET7sAk+U= +github.com/hrfee/mediabrowser v0.3.10 h1:MUrgZQVY3mk76Bhn7PsZ4LFRhtGitkZA4FP+1qg1HFo= +github.com/hrfee/mediabrowser v0.3.10/go.mod h1:PnHZbdxmbv1wCVdAQyM7nwPwpVj9fdKx2EcET7sAk+U= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= github.com/itchyny/timefmt-go v0.1.5 h1:G0INE2la8S6ru/ZI5JecgyzbbJNs5lG1RcBqa7Jm6GE= github.com/itchyny/timefmt-go v0.1.5/go.mod h1:nEP7L+2YmAbT2kZ2HfSs1d8Xtw9LY8D2stDBckWakZ8= diff --git a/html/admin.html b/html/admin.html index 0d0f7a5..3f58840 100644 --- a/html/admin.html +++ b/html/admin.html @@ -29,6 +29,11 @@ + +
+ +