diff options
author | Joram Wilander <jwawilander@gmail.com> | 2018-05-16 13:43:22 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-16 13:43:22 -0400 |
commit | 1f6c271b3bedd6656ae7155714423b1b39a669c1 (patch) | |
tree | 9ce6390c237cc5f7c16d63addb4372033807cff8 /api/license.go | |
parent | 02f8c18f40cd0e973e4c75b751e8fcbbbd019728 (diff) | |
download | chat-1f6c271b3bedd6656ae7155714423b1b39a669c1.tar.gz chat-1f6c271b3bedd6656ae7155714423b1b39a669c1.tar.bz2 chat-1f6c271b3bedd6656ae7155714423b1b39a669c1.zip |
MM-8708 Remove api package (#8784)
* Remove api package
* Remove api dependency from cmd package
* Remove EnableAPIv3 setting
* Update web tests
* Add more websocket tests
* Move some ws and oauth tests to api4 package
* Move command tests into api4 package
* Test fixes
* Fix msg command test
* Add some app file tests
Diffstat (limited to 'api/license.go')
-rw-r--r-- | api/license.go | 100 |
1 files changed, 0 insertions, 100 deletions
diff --git a/api/license.go b/api/license.go deleted file mode 100644 index 432442ad6..000000000 --- a/api/license.go +++ /dev/null @@ -1,100 +0,0 @@ -// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -package api - -import ( - "bytes" - "io" - "net/http" - - "github.com/mattermost/mattermost-server/model" -) - -func (api *API) InitLicense() { - api.BaseRoutes.License.Handle("/add", api.ApiAdminSystemRequired(addLicense)).Methods("POST") - api.BaseRoutes.License.Handle("/remove", api.ApiAdminSystemRequired(removeLicense)).Methods("POST") - api.BaseRoutes.License.Handle("/client_config", api.ApiAppHandler(getClientLicenceConfig)).Methods("GET") -} - -func addLicense(c *Context, w http.ResponseWriter, r *http.Request) { - c.LogAudit("attempt") - err := r.ParseMultipartForm(*c.App.Config().FileSettings.MaxFileSize) - if err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - return - } - - m := r.MultipartForm - - fileArray, ok := m.File["license"] - if !ok { - c.Err = model.NewAppError("addLicense", "api.license.add_license.no_file.app_error", nil, "", http.StatusBadRequest) - return - } - - if len(fileArray) <= 0 { - c.Err = model.NewAppError("addLicense", "api.license.add_license.array.app_error", nil, "", http.StatusBadRequest) - return - } - - fileData := fileArray[0] - - file, err := fileData.Open() - if err != nil { - c.Err = model.NewAppError("addLicense", "api.license.add_license.open.app_error", nil, err.Error(), http.StatusInternalServerError) - return - } - defer file.Close() - - buf := bytes.NewBuffer(nil) - io.Copy(buf, file) - - if license, err := c.App.SaveLicense(buf.Bytes()); err != nil { - if err.Id == model.EXPIRED_LICENSE_ERROR { - c.LogAudit("failed - expired or non-started license") - } else if err.Id == model.INVALID_LICENSE_ERROR { - c.LogAudit("failed - invalid license") - } else { - c.LogAudit("failed - unable to save license") - } - c.Err = err - return - } else { - c.LogAudit("success") - w.Write([]byte(license.ToJson())) - } -} - -func removeLicense(c *Context, w http.ResponseWriter, r *http.Request) { - c.LogAudit("") - - if err := c.App.RemoveLicense(); err != nil { - c.Err = err - return - } - - rdata := map[string]string{} - rdata["status"] = "ok" - w.Write([]byte(model.MapToJson(rdata))) -} - -func getClientLicenceConfig(c *Context, w http.ResponseWriter, r *http.Request) { - useSanitizedLicense := !c.App.SessionHasPermissionTo(c.Session, model.PERMISSION_MANAGE_SYSTEM) - - etag := c.App.GetClientLicenseEtag(useSanitizedLicense) - if c.HandleEtag(etag, "Get Client License Config", w, r) { - return - } - - var clientLicense map[string]string - - if useSanitizedLicense { - clientLicense = c.App.ClientLicense() - } else { - clientLicense = c.App.GetSanitizedClientLicense() - } - - w.Header().Set(model.HEADER_ETAG_SERVER, etag) - w.Write([]byte(model.MapToJson(clientLicense))) -} |