profiles: fully deprecate old system

ombi_template, configuration, displayprefs, and policy still stuck
around for the admin new user feature. They are now sourced from the
default profile, and eventually a feature to select the source (or no
source) will be added.

this was still used when creating a new user as admin for some reason.
template is now sourced from the default profile.
db
Harvey Tindall 1 year ago
parent 3bb9272f06
commit 9c84fb5887
No known key found for this signature in database
GPG Key ID: BBC65952848FB1A2

@ -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,9 +64,11 @@ 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)
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, ", "))
@ -74,7 +76,6 @@ func (app *appContext) NewUserAdmin(gc *gin.Context) {
app.info.Println("Created Ombi user")
}
}
}
if emailEnabled && app.config.Section("welcome_email").Key("enabled").MustBool(false) && req.Email != "" {
app.debug.Printf("%s: Sending welcome email to %s", req.Username, req.Email)
msg, err := app.email.constructWelcome(req.Username, time.Time{}, app, false)

@ -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")

@ -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()
}

Loading…
Cancel
Save