Add optional config parameter to test elasticsearch endpoint. (#6877)

Этот коммит содержится в:
George Goldberg
2017-07-07 17:12:14 +01:00
коммит произвёл Joram Wilander
родитель db2f6cf076
Коммит 39b071bc0e
4 изменённых файлов: 22 добавлений и 4 удалений

Просмотреть файл

@@ -19,12 +19,17 @@ func InitElasticsearch() {
}
func testElasticsearch(c *Context, w http.ResponseWriter, r *http.Request) {
cfg := model.ConfigFromJson(r.Body)
if cfg == nil {
cfg = utils.Cfg
}
if !app.SessionHasPermissionTo(c.Session, model.PERMISSION_MANAGE_SYSTEM) {
c.SetPermissionError(model.PERMISSION_MANAGE_SYSTEM)
return
}
if err := app.TestElasticsearch(); err != nil {
if err := app.TestElasticsearch(cfg); err != nil {
c.Err = err
return
}

Просмотреть файл

@@ -8,11 +8,20 @@ import (
"github.com/mattermost/platform/model"
"github.com/mattermost/platform/einterfaces"
"github.com/mattermost/platform/utils"
)
func TestElasticsearch() *model.AppError {
func TestElasticsearch(cfg *model.Config) *model.AppError {
if *cfg.ElasticSearchSettings.Password == model.FAKE_SETTING {
if *cfg.ElasticSearchSettings.ConnectionUrl == *utils.Cfg.ElasticSearchSettings.ConnectionUrl && *cfg.ElasticSearchSettings.Username == *utils.Cfg.ElasticSearchSettings.Username {
*cfg.ElasticSearchSettings.Password = *utils.Cfg.ElasticSearchSettings.Password
} else {
return model.NewAppError("TestElasticsearch", "ent.elasticsearch.test_config.reenter_password", nil, "", http.StatusBadRequest)
}
}
if esI := einterfaces.GetElasticsearchInterface(); esI != nil {
if err := esI.TestConfig(); err != nil {
if err := esI.TestConfig(cfg); err != nil {
return err
}
} else {

Просмотреть файл

@@ -10,7 +10,7 @@ type ElasticsearchInterface interface {
IndexPost(post *model.Post, teamId string) *model.AppError
SearchPosts(channels *model.ChannelList, searchParams []*model.SearchParams) ([]string, *model.AppError)
DeletePost(postId string) *model.AppError
TestConfig() *model.AppError
TestConfig(cfg *model.Config) *model.AppError
}
var theElasticsearchInterface ElasticsearchInterface

Просмотреть файл

@@ -3547,6 +3547,10 @@
"id": "ent.elasticsearch.test_config.license.error",
"translation": "License does not support Elasticsearch."
},
{
"id": "ent.elasticsearch.test_config.reenter_password",
"translation": "The Elasticsearch Server URL or Username has changed. Please re-enter the Elasticsearch password to test connection."
},
{
"id": "ent.emoji.licence_disable.app_error",
"translation": "Custom emoji restrictions disabled by current license. Please contact your system administrator about upgrading your enterprise license."