diff options
author | Martin Kraft <martinkraft@gmail.com> | 2018-05-17 07:53:16 -0400 |
---|---|---|
committer | Martin Kraft <martinkraft@gmail.com> | 2018-05-17 07:53:16 -0400 |
commit | 6f31d90e2f31ae597b83b2f845d5db938af8e38c (patch) | |
tree | 81c59b83ffb033df92ff7fba5ffaf3ba5fe7a3cf /api/preference.go | |
parent | 319d61123a0418ea9caa9510b8ad1e9a302c7b93 (diff) | |
parent | 1f6c271b3bedd6656ae7155714423b1b39a669c1 (diff) | |
download | chat-6f31d90e2f31ae597b83b2f845d5db938af8e38c.tar.gz chat-6f31d90e2f31ae597b83b2f845d5db938af8e38c.tar.bz2 chat-6f31d90e2f31ae597b83b2f845d5db938af8e38c.zip |
Merge remote-tracking branch 'origin/master' into advanced-permissions-phase-2
Diffstat (limited to 'api/preference.go')
-rw-r--r-- | api/preference.go | 85 |
1 files changed, 0 insertions, 85 deletions
diff --git a/api/preference.go b/api/preference.go deleted file mode 100644 index 8de1ea453..000000000 --- a/api/preference.go +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -package api - -import ( - "net/http" - - "github.com/gorilla/mux" - "github.com/mattermost/mattermost-server/model" -) - -func (api *API) InitPreference() { - api.BaseRoutes.Preferences.Handle("/", api.ApiUserRequired(getAllPreferences)).Methods("GET") - api.BaseRoutes.Preferences.Handle("/save", api.ApiUserRequired(savePreferences)).Methods("POST") - api.BaseRoutes.Preferences.Handle("/delete", api.ApiUserRequired(deletePreferences)).Methods("POST") - api.BaseRoutes.Preferences.Handle("/{category:[A-Za-z0-9_]+}", api.ApiUserRequired(getPreferenceCategory)).Methods("GET") - api.BaseRoutes.Preferences.Handle("/{category:[A-Za-z0-9_]+}/{name:[A-Za-z0-9_]+}", api.ApiUserRequired(getPreference)).Methods("GET") -} - -func getAllPreferences(c *Context, w http.ResponseWriter, r *http.Request) { - if result := <-c.App.Srv.Store.Preference().GetAll(c.Session.UserId); result.Err != nil { - c.Err = result.Err - } else { - data := result.Data.(model.Preferences) - - w.Write([]byte(data.ToJson())) - } -} - -func savePreferences(c *Context, w http.ResponseWriter, r *http.Request) { - preferences, err := model.PreferencesFromJson(r.Body) - if err != nil { - c.Err = model.NewAppError("savePreferences", "api.preference.save_preferences.decode.app_error", nil, err.Error(), http.StatusBadRequest) - return - } - - if err := c.App.UpdatePreferences(c.Session.UserId, preferences); err != nil { - c.Err = err - return - } - - w.Write([]byte("true")) -} - -func getPreferenceCategory(c *Context, w http.ResponseWriter, r *http.Request) { - params := mux.Vars(r) - category := params["category"] - - if result := <-c.App.Srv.Store.Preference().GetCategory(c.Session.UserId, category); result.Err != nil { - c.Err = result.Err - } else { - data := result.Data.(model.Preferences) - - w.Write([]byte(data.ToJson())) - } -} - -func getPreference(c *Context, w http.ResponseWriter, r *http.Request) { - params := mux.Vars(r) - category := params["category"] - name := params["name"] - - if result := <-c.App.Srv.Store.Preference().Get(c.Session.UserId, category, name); result.Err != nil { - c.Err = result.Err - } else { - data := result.Data.(model.Preference) - 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.NewAppError("savePreferences", "api.preference.delete_preferences.decode.app_error", nil, err.Error(), http.StatusBadRequest) - return - } - - if err := c.App.DeletePreferences(c.Session.UserId, preferences); err != nil { - c.Err = err - return - } - - ReturnStatusOK(w) -} |