mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
PLT-6554 Add config setting to control enabling API version 3 (#6835)
* Add config setting to control enabling API version 3 * Update help text for APIv3 config setting (#6843) * Update configuration_settings.jsx * Update en.json
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -652,3 +653,24 @@ func TestGetRecentlyActiveUsers(t *testing.T) {
|
||||
t.Fatal("should have been at least 2")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDisableAPIv3(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
Client := th.BasicClient
|
||||
|
||||
enableAPIv3 := *utils.Cfg.ServiceSettings.EnableAPIv3
|
||||
defer func() {
|
||||
*utils.Cfg.ServiceSettings.EnableAPIv3 = enableAPIv3
|
||||
}()
|
||||
*utils.Cfg.ServiceSettings.EnableAPIv3 = false
|
||||
|
||||
_, err := Client.GetUser(th.BasicUser.Id, "")
|
||||
|
||||
if err.StatusCode != http.StatusNotImplemented {
|
||||
t.Fatal("wrong error code")
|
||||
}
|
||||
|
||||
if err.Id != "api.context.v3_disabled.app_error" {
|
||||
t.Fatal("wrong error message")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ package api
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
l4g "github.com/alecthomas/log4go"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/mattermost/platform/app"
|
||||
"github.com/mattermost/platform/einterfaces"
|
||||
@@ -115,6 +116,10 @@ func InitApi() {
|
||||
utils.InitHTML()
|
||||
|
||||
app.InitEmailBatching()
|
||||
|
||||
if *utils.Cfg.ServiceSettings.EnableAPIv3 {
|
||||
l4g.Info("API version 3 is scheduled for deprecation. Please see https://api.mattermost.com for details.")
|
||||
}
|
||||
}
|
||||
|
||||
func HandleEtag(etag string, routeName string, w http.ResponseWriter, r *http.Request) bool {
|
||||
|
||||
@@ -205,6 +205,10 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
c.Path = "/" + strings.Join(splitURL[2:], "/")
|
||||
}
|
||||
|
||||
if h.isApi && !*utils.Cfg.ServiceSettings.EnableAPIv3 {
|
||||
c.Err = model.NewAppError("ServeHTTP", "api.context.v3_disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
if c.Err == nil && h.requireUser {
|
||||
c.UserRequired()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user