summaryrefslogtreecommitdiffstats
path: root/api4/brand.go
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2017-03-14 09:35:48 -0400
committerGitHub <noreply@github.com>2017-03-14 09:35:48 -0400
commitad0ed008fe54534fcc089f479df606ab921901a9 (patch)
treea5fda084fb7ea61941449b393a6084f0c049195c /api4/brand.go
parentd03367c56005470396d883d273323ecbd8d4f243 (diff)
downloadchat-ad0ed008fe54534fcc089f479df606ab921901a9.tar.gz
chat-ad0ed008fe54534fcc089f479df606ab921901a9.tar.bz2
chat-ad0ed008fe54534fcc089f479df606ab921901a9.zip
Implement brand image endpoints for APIv4 (#5733)
* Implement brand image endpoints for APIv4 * Fix unit test
Diffstat (limited to 'api4/brand.go')
-rw-r--r--api4/brand.go70
1 files changed, 70 insertions, 0 deletions
diff --git a/api4/brand.go b/api4/brand.go
new file mode 100644
index 000000000..00e6bbbff
--- /dev/null
+++ b/api4/brand.go
@@ -0,0 +1,70 @@
+// Copyright (c) 2017 Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+package api4
+
+import (
+ "net/http"
+
+ l4g "github.com/alecthomas/log4go"
+ "github.com/mattermost/platform/app"
+ "github.com/mattermost/platform/model"
+ "github.com/mattermost/platform/utils"
+)
+
+func InitBrand() {
+ l4g.Debug(utils.T("api.brand.init.debug"))
+
+ BaseRoutes.Brand.Handle("/image", ApiHandlerTrustRequester(getBrandImage)).Methods("GET")
+ BaseRoutes.Brand.Handle("/image", ApiSessionRequired(uploadBrandImage)).Methods("POST")
+}
+
+func getBrandImage(c *Context, w http.ResponseWriter, r *http.Request) {
+ // No permission check required
+
+ if img, err := app.GetBrandImage(); err != nil {
+ w.Write(nil)
+ } else {
+ w.Header().Set("Content-Type", "image/png")
+ w.Write(img)
+ }
+}
+
+func uploadBrandImage(c *Context, w http.ResponseWriter, r *http.Request) {
+ if r.ContentLength > *utils.Cfg.FileSettings.MaxFileSize {
+ c.Err = model.NewAppError("uploadBrandImage", "api.admin.upload_brand_image.too_large.app_error", nil, "", http.StatusRequestEntityTooLarge)
+ return
+ }
+
+ if err := r.ParseMultipartForm(*utils.Cfg.FileSettings.MaxFileSize); err != nil {
+ c.Err = model.NewAppError("uploadBrandImage", "api.admin.upload_brand_image.parse.app_error", nil, "", http.StatusBadRequest)
+ return
+ }
+
+ m := r.MultipartForm
+
+ imageArray, ok := m.File["image"]
+ if !ok {
+ c.Err = model.NewAppError("uploadBrandImage", "api.admin.upload_brand_image.no_file.app_error", nil, "", http.StatusBadRequest)
+ return
+ }
+
+ if len(imageArray) <= 0 {
+ c.Err = model.NewAppError("uploadBrandImage", "api.admin.upload_brand_image.array.app_error", nil, "", http.StatusBadRequest)
+ return
+ }
+
+ if !app.SessionHasPermissionTo(c.Session, model.PERMISSION_MANAGE_SYSTEM) {
+ c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
+ return
+ }
+
+ if err := app.SaveBrandImage(imageArray[0]); err != nil {
+ c.Err = err
+ return
+ }
+
+ c.LogAudit("")
+
+ ReturnStatusOK(w)
+}