mirror of
https://github.com/hrfee/jfa-go.git
synced 2024-12-23 01:20:11 +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
21
api-users.go
21
api-users.go
@ -44,16 +44,16 @@ func (app *appContext) NewUserAdmin(gc *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
id := user.ID
|
id := user.ID
|
||||||
if app.storage.policy.BlockedTags != nil {
|
profile := app.storage.GetDefaultProfile()
|
||||||
status, err = app.jf.SetPolicy(id, app.storage.policy)
|
// 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) {
|
if !(status == 200 || status == 204 || err == nil) {
|
||||||
app.err.Printf("%s: Failed to set user policy (%d): %v", req.Username, status, err)
|
app.err.Printf("%s: Failed to set user policy (%d): %v", req.Username, status, err)
|
||||||
}
|
}
|
||||||
}
|
status, err = app.jf.SetConfiguration(id, profile.Configuration)
|
||||||
if app.storage.configuration.GroupedFolders != nil && len(app.storage.displayprefs) != 0 {
|
|
||||||
status, err = app.jf.SetConfiguration(id, app.storage.configuration)
|
|
||||||
if (status == 200 || status == 204) && err == nil {
|
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) {
|
if !((status == 200 || status == 204) && err == nil) {
|
||||||
app.err.Printf("%s: Failed to set configuration template (%d): %v", req.Username, status, err)
|
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})
|
app.storage.SetEmailsKey(id, EmailAddress{Addr: req.Email, Contact: true})
|
||||||
}
|
}
|
||||||
if app.config.Section("ombi").Key("enabled").MustBool(false) {
|
if app.config.Section("ombi").Key("enabled").MustBool(false) {
|
||||||
app.storage.loadOmbiTemplate()
|
profile := app.storage.GetDefaultProfile()
|
||||||
if len(app.storage.ombi_template) != 0 {
|
if profile.Ombi == nil {
|
||||||
errors, code, err := app.ombi.NewUser(req.Username, req.Password, req.Email, app.storage.ombi_template)
|
profile.Ombi = map[string]interface{}{}
|
||||||
|
}
|
||||||
|
errors, code, err := app.ombi.NewUser(req.Username, req.Password, req.Email, profile.Ombi)
|
||||||
if err != nil || code != 200 {
|
if err != nil || code != 200 {
|
||||||
app.err.Printf("Failed to create Ombi user (%d): %v", code, err)
|
app.err.Printf("Failed to create Ombi user (%d): %v", code, err)
|
||||||
app.debug.Printf("Errors reported by Ombi: %s", strings.Join(errors, ", "))
|
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")
|
app.info.Println("Created Ombi user")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if emailEnabled && app.config.Section("welcome_email").Key("enabled").MustBool(false) && req.Email != "" {
|
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)
|
app.debug.Printf("%s: Sending welcome email to %s", req.Username, req.Email)
|
||||||
msg, err := app.email.constructWelcome(req.Username, time.Time{}, app, false)
|
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
|
// Migrate pre-0.2.0 user templates to profiles
|
||||||
func migrateProfiles(app *appContext) {
|
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
|
return
|
||||||
}
|
}
|
||||||
app.info.Println("Migrating user template files to new profile format")
|
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.
|
deprecatedUserExpiries map[string]time.Time // Map of Jellyfin User IDs to their expiry times.
|
||||||
deprecatedInvites Invites
|
deprecatedInvites Invites
|
||||||
deprecatedProfiles map[string]Profile
|
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.
|
deprecatedEmails emailStore // Map of Jellyfin User IDs to Email addresses.
|
||||||
deprecatedTelegram telegramStore // Map of Jellyfin User IDs to telegram users.
|
deprecatedTelegram telegramStore // Map of Jellyfin User IDs to telegram users.
|
||||||
deprecatedDiscord discordStore // Map of Jellyfin user IDs to discord users.
|
deprecatedDiscord discordStore // Map of Jellyfin user IDs to discord users.
|
||||||
deprecatedMatrix matrixStore // Map of Jellyfin user IDs to Matrix users.
|
deprecatedMatrix matrixStore // Map of Jellyfin user IDs to Matrix users.
|
||||||
customEmails customEmails
|
customEmails customEmails
|
||||||
userPage userPageContent
|
userPage userPageContent
|
||||||
policy mediabrowser.Policy
|
deprecatedPolicy mediabrowser.Policy
|
||||||
configuration mediabrowser.Configuration
|
deprecatedConfiguration mediabrowser.Configuration
|
||||||
lang Lang
|
lang Lang
|
||||||
deprecatedAnnouncements map[string]announcementTemplate
|
deprecatedAnnouncements map[string]announcementTemplate
|
||||||
}
|
}
|
||||||
@ -1213,35 +1213,35 @@ func (st *Storage) storeUserPageContent() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (st *Storage) loadPolicy() 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 {
|
func (st *Storage) storePolicy() error {
|
||||||
return storeJSON(st.policy_path, st.policy)
|
return storeJSON(st.policy_path, st.deprecatedPolicy)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *Storage) loadConfiguration() error {
|
func (st *Storage) loadConfiguration() error {
|
||||||
return loadJSON(st.configuration_path, &st.configuration)
|
return loadJSON(st.configuration_path, &st.deprecatedConfiguration)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *Storage) storeConfiguration() error {
|
func (st *Storage) storeConfiguration() error {
|
||||||
return storeJSON(st.configuration_path, st.configuration)
|
return storeJSON(st.configuration_path, st.deprecatedConfiguration)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *Storage) loadDisplayprefs() error {
|
func (st *Storage) loadDisplayprefs() error {
|
||||||
return loadJSON(st.displayprefs_path, &st.displayprefs)
|
return loadJSON(st.displayprefs_path, &st.deprecatedDisplayprefs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *Storage) storeDisplayprefs() error {
|
func (st *Storage) storeDisplayprefs() error {
|
||||||
return storeJSON(st.displayprefs_path, st.displayprefs)
|
return storeJSON(st.displayprefs_path, st.deprecatedDisplayprefs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (st *Storage) loadOmbiTemplate() error {
|
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 {
|
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 {
|
func (st *Storage) loadAnnouncements() error {
|
||||||
@ -1298,9 +1298,9 @@ func (st *Storage) migrateToProfile() error {
|
|||||||
st.loadDisplayprefs()
|
st.loadDisplayprefs()
|
||||||
st.loadProfiles()
|
st.loadProfiles()
|
||||||
st.deprecatedProfiles["Default"] = Profile{
|
st.deprecatedProfiles["Default"] = Profile{
|
||||||
Policy: st.policy,
|
Policy: st.deprecatedPolicy,
|
||||||
Configuration: st.configuration,
|
Configuration: st.deprecatedConfiguration,
|
||||||
Displayprefs: st.displayprefs,
|
Displayprefs: st.deprecatedDisplayprefs,
|
||||||
}
|
}
|
||||||
return st.storeProfiles()
|
return st.storeProfiles()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user