From caabfbcdd56bdced7c5c1d38e00f488adffe7c60 Mon Sep 17 00:00:00 2001 From: Harrison Healey Date: Thu, 14 Jul 2016 10:08:36 -0400 Subject: PLT-2992 Added the ability to use different themes for each team (#3411) * Cleaned up user_settings_theme.jsx and import_theme_modal.jsx * Made ImportThemeModal use a callback to return the theme to the user settings modal instead of saving it directly * Moved user theme from model to preferences * Added serverside API to delete preferences TODO update package with client stuff * Changed constants.jsx so that Preferences and ActionTypes can be imported on their own * Updated ThemeProps migration code to properly rename solarized code themes * Fixed warnings thrown by AppDispatcher * Added clientside UI to support team-specific themes * Removed debugging code from test * Fixed setting a user's theme when they haven't set their theme before --- api/preference.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'api/preference.go') diff --git a/api/preference.go b/api/preference.go index d9ddb1a21..240ead571 100644 --- a/api/preference.go +++ b/api/preference.go @@ -16,6 +16,7 @@ func InitPreference() { BaseRoutes.Preferences.Handle("/", ApiUserRequired(getAllPreferences)).Methods("GET") BaseRoutes.Preferences.Handle("/save", ApiUserRequired(savePreferences)).Methods("POST") + BaseRoutes.Preferences.Handle("/delete", ApiUserRequired(deletePreferences)).Methods("POST") BaseRoutes.Preferences.Handle("/{category:[A-Za-z0-9_]+}", ApiUserRequired(getPreferenceCategory)).Methods("GET") BaseRoutes.Preferences.Handle("/{category:[A-Za-z0-9_]+}/{name:[A-Za-z0-9_]+}", ApiUserRequired(getPreference)).Methods("GET") } @@ -81,3 +82,30 @@ func getPreference(c *Context, w http.ResponseWriter, r *http.Request) { w.Write([]byte(data.ToJson())) } } + +func deletePreferences(c *Context, w http.ResponseWriter, r *http.Request) { + preferences, err := model.PreferencesFromJson(r.Body) + if err != nil { + c.Err = model.NewLocAppError("savePreferences", "api.preference.delete_preferences.decode.app_error", nil, err.Error()) + c.Err.StatusCode = http.StatusBadRequest + return + } + + for _, preference := range preferences { + if c.Session.UserId != preference.UserId { + c.Err = model.NewLocAppError("deletePreferences", "api.preference.delete_preferences.user_id.app_error", + nil, "session.user_id="+c.Session.UserId+",preference.user_id="+preference.UserId) + c.Err.StatusCode = http.StatusForbidden + return + } + } + + for _, preference := range preferences { + if result := <-Srv.Store.Preference().Delete(c.Session.UserId, preference.Category, preference.Name); result.Err != nil { + c.Err = result.Err + return + } + } + + ReturnStatusOK(w) +} -- cgit v1.2.3-1-g7c22