From 517faccc332ce48de43e597d1b2d29a3961241e7 Mon Sep 17 00:00:00 2001 From: FurmanovD <39990503+FurmanovD@users.noreply.github.com> Date: Mon, 17 Sep 2018 13:46:06 +0300 Subject: MM-11424 Extend bulk import to support themes across teams(#9305) (#9419) * MM-11424 Extend bulk import to support themes across teams(#9305) Also added: Advanced Settings: +'feature_enabled_markdown_preview' +'formatting' Sidebar Settings: +'show_unread_section' * MM-11424 (PR review) user teams' theme validator test updated * MM-11424 (PR review) added test with valid JSON of invalid theme(by structure) JSON string contains numeric and JSON object fields, not just a correct "string":"string" map --- app/import_functions.go | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'app/import_functions.go') diff --git a/app/import_functions.go b/app/import_functions.go index ff22f23bb..98306d3a7 100644 --- a/app/import_functions.go +++ b/app/import_functions.go @@ -555,6 +555,33 @@ func (a *App) ImportUser(data *UserImportData, dryRun bool) *model.AppError { }) } + if data.UseMarkdownPreview != nil { + preferences = append(preferences, model.Preference{ + UserId: savedUser.Id, + Category: model.PREFERENCE_CATEGORY_ADVANCED_SETTINGS, + Name: "feature_enabled_markdown_preview", + Value: *data.UseMarkdownPreview, + }) + } + + if data.UseFormatting != nil { + preferences = append(preferences, model.Preference{ + UserId: savedUser.Id, + Category: model.PREFERENCE_CATEGORY_ADVANCED_SETTINGS, + Name: "formatting", + Value: *data.UseFormatting, + }) + } + + if data.ShowUnreadSection != nil { + preferences = append(preferences, model.Preference{ + UserId: savedUser.Id, + Category: model.PREFERENCE_CATEGORY_SIDEBAR_SETTINGS, + Name: "show_unread_section", + Value: *data.ShowUnreadSection, + }) + } + if len(preferences) > 0 { if result := <-a.Srv.Store.Preference().Save(&preferences); result.Err != nil { return model.NewAppError("BulkImport", "app.import.import_user.save_preferences.error", nil, result.Err.Error(), http.StatusInternalServerError) @@ -569,12 +596,23 @@ func (a *App) ImportUserTeams(user *model.User, data *[]UserTeamImportData) *mod return nil } + var teamThemePreferences model.Preferences for _, tdata := range *data { team, err := a.GetTeamByName(*tdata.Name) if err != nil { return err } + // Team-specific theme Preferences. + if tdata.Theme != nil { + teamThemePreferences = append(teamThemePreferences, model.Preference{ + UserId: user.Id, + Category: model.PREFERENCE_CATEGORY_THEME, + Name: team.Id, + Value: *tdata.Theme, + }) + } + var roles string isSchemeUser := true isSchemeAdmin := false @@ -622,6 +660,12 @@ func (a *App) ImportUserTeams(user *model.User, data *[]UserTeamImportData) *mod } } + if len(teamThemePreferences) > 0 { + if result := <-a.Srv.Store.Preference().Save(&teamThemePreferences); result.Err != nil { + return model.NewAppError("BulkImport", "app.import.import_user_teams.save_preferences.error", nil, result.Err.Error(), http.StatusInternalServerError) + } + } + return nil } -- cgit v1.2.3-1-g7c22