From 3f5993eedfd52a0497f7a537601b2d7c9e4d744d Mon Sep 17 00:00:00 2001 From: hmhealey Date: Tue, 11 Aug 2015 14:36:45 -0400 Subject: Added initial api to allow clientside code to query serverside configuration --- api/api.go | 1 + api/config.go | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 api/config.go (limited to 'api') diff --git a/api/api.go b/api/api.go index 2ea27ed9f..9770930f7 100644 --- a/api/api.go +++ b/api/api.go @@ -40,6 +40,7 @@ func InitApi() { InitWebSocket(r) InitFile(r) InitCommand(r) + InitConfig(r) templatesDir := utils.FindDir("api/templates") l4g.Debug("Parsing server templates at %v", templatesDir) diff --git a/api/config.go b/api/config.go new file mode 100644 index 000000000..91097b4a1 --- /dev/null +++ b/api/config.go @@ -0,0 +1,23 @@ +// Copyright (c) 2015 Spinpunch, Inc. All Rights Reserved. +// See License.txt for license information. + +package api + +import ( + l4g "code.google.com/p/log4go" + "github.com/gorilla/mux" + "github.com/mattermost/platform/utils" + "net/http" + "strconv" +) + +func InitConfig(r *mux.Router) { + l4g.Debug("Initializing config api routes") + + sr := r.PathPrefix("/config").Subrouter() + sr.Handle("/get/bypass_email", ApiAppHandler(getBypassEmail)).Methods("GET") +} + +func getBypassEmail(c *Context, w http.ResponseWriter, r *http.Request) { + w.Write([]byte(strconv.FormatBool(utils.Cfg.EmailSettings.ByPassEmail))) +} -- cgit v1.2.3-1-g7c22 From ca919538cc402ed90ce42ffc3ef98994bb1081f4 Mon Sep 17 00:00:00 2001 From: hmhealey Date: Thu, 13 Aug 2015 13:01:21 -0400 Subject: Added ConfigStore that is populated from the server --- api/config.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'api') diff --git a/api/config.go b/api/config.go index 91097b4a1..d8d52ca67 100644 --- a/api/config.go +++ b/api/config.go @@ -5,7 +5,9 @@ package api import ( l4g "code.google.com/p/log4go" + "encoding/json" "github.com/gorilla/mux" + "github.com/mattermost/platform/model" "github.com/mattermost/platform/utils" "net/http" "strconv" @@ -15,9 +17,23 @@ func InitConfig(r *mux.Router) { l4g.Debug("Initializing config api routes") sr := r.PathPrefix("/config").Subrouter() + sr.Handle("/get_all", ApiAppHandler(getConfig)).Methods("GET") sr.Handle("/get/bypass_email", ApiAppHandler(getBypassEmail)).Methods("GET") } +func getConfig(c *Context, w http.ResponseWriter, r *http.Request) { + settings := make(map[string]string) + + settings["ByPassEmail"] = strconv.FormatBool(utils.Cfg.EmailSettings.ByPassEmail) + + if bytes, err := json.Marshal(settings); err != nil { + c.Err = model.NewAppError("getConfig", "Unable to marshall configuration data", err.Error()) + return + } else { + w.Write(bytes) + } +} + func getBypassEmail(c *Context, w http.ResponseWriter, r *http.Request) { w.Write([]byte(strconv.FormatBool(utils.Cfg.EmailSettings.ByPassEmail))) } -- cgit v1.2.3-1-g7c22 From 8fc4456213c5ee16863b7f1bcb20e35a19469a1d Mon Sep 17 00:00:00 2001 From: hmhealey Date: Thu, 13 Aug 2015 13:23:56 -0400 Subject: Removed isEmailEnabledSynchronous and switched the email disabled warnings to use ConfigStore --- api/config.go | 5 ----- 1 file changed, 5 deletions(-) (limited to 'api') diff --git a/api/config.go b/api/config.go index d8d52ca67..142d1ca66 100644 --- a/api/config.go +++ b/api/config.go @@ -18,7 +18,6 @@ func InitConfig(r *mux.Router) { sr := r.PathPrefix("/config").Subrouter() sr.Handle("/get_all", ApiAppHandler(getConfig)).Methods("GET") - sr.Handle("/get/bypass_email", ApiAppHandler(getBypassEmail)).Methods("GET") } func getConfig(c *Context, w http.ResponseWriter, r *http.Request) { @@ -33,7 +32,3 @@ func getConfig(c *Context, w http.ResponseWriter, r *http.Request) { w.Write(bytes) } } - -func getBypassEmail(c *Context, w http.ResponseWriter, r *http.Request) { - w.Write([]byte(strconv.FormatBool(utils.Cfg.EmailSettings.ByPassEmail))) -} -- cgit v1.2.3-1-g7c22