mirror of
https://github.com/hrfee/jfa-go.git
synced 2024-12-22 09:00:10 +00:00
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.
This commit is contained in:
parent
3bb9272f06
commit
9c84fb5887
31
api-users.go
31
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 != "" {
|
||||
|
@ -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")
|
||||
|
28
storage.go
28
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()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user