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) }
func savePreferences(c *Context, w http.ResponseWriter, r *http.Request) { preferences, err := model.PreferencesFromJson(r.Body) if err != nil { c.Err = model.NewLocAppError("savePreferences", "api.preference.save_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("savePreferences", "api.preference.save_preferences.set.app_error", nil, c.T("api.preference.save_preferences.set_details.app_error", map[string]interface{}{"SessionUserId": c.Session.UserId, "PreferenceUserId": preference.UserId})) c.Err.StatusCode = http.StatusForbidden return } } if result := <-Srv.Store.Preference().Save(&preferences); result.Err != nil { c.Err = result.Err return } w.Write([]byte("true")) }
func savePreferences(c *Context, w http.ResponseWriter, r *http.Request) { preferences, err := model.PreferencesFromJson(r.Body) if err != nil { c.Err = model.NewAppError("savePreferences", "Unable to decode preferences from request", err.Error()) c.Err.StatusCode = http.StatusBadRequest return } for _, preference := range preferences { if c.Session.UserId != preference.UserId { c.Err = model.NewAppError("savePreferences", "Unable to set preferences for other user", "session.user_id="+c.Session.UserId+", preference.user_id="+preference.UserId) c.Err.StatusCode = http.StatusUnauthorized return } } if result := <-Srv.Store.Preference().Save(&preferences); result.Err != nil { c.Err = result.Err return } w.Write([]byte("true")) }