mirror of
https://github.com/hanzoai/team.git
synced 2026-09-30 01:57:35 +00:00
The server module named github.com/hanzoai/team/server/v8 — a path that resolves to the retired workspace's repository, not this one — while server/public still published github.com/mattermost/mattermost/server/public. Both are github.com/hanzoteam/server/... now, which is where this code actually lives. That second half is what made the binary unbootable. Upstream's public path stayed claimed by upstream, mattermost-plugin-ai imported it, and the build linked public/model twice; public/plugin's gob.Register then ran twice under one name and panicked at init, before main. Reverting the rename traded the brand for a working binary. Rebranding the plugin alongside it needs no such trade: the agents fork is github.com/hanzoteam/agents/v2 against our public module, so no module named mattermost/mattermost is in the graph at all. Measured: `go list -deps ./cmd/mattermost` names exactly one public/model, and it is ours.
73 lines
2.4 KiB
Go
73 lines
2.4 KiB
Go
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
package api4
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
|
|
"github.com/hanzoteam/server/server/public/model"
|
|
"github.com/hanzoteam/server/server/public/shared/mlog"
|
|
)
|
|
|
|
func (api *API) InitElasticsearch() {
|
|
api.BaseRoutes.Elasticsearch.Handle("/test", api.APISessionRequired(testElasticsearch)).Methods(http.MethodPost)
|
|
api.BaseRoutes.Elasticsearch.Handle("/purge_indexes", api.APISessionRequired(purgeElasticsearchIndexes)).Methods(http.MethodPost)
|
|
}
|
|
|
|
func testElasticsearch(c *Context, w http.ResponseWriter, r *http.Request) {
|
|
var cfg *model.Config
|
|
err := json.NewDecoder(r.Body).Decode(&cfg)
|
|
if err != nil {
|
|
c.Logger.Warn("Error decoding config.", mlog.Err(err))
|
|
}
|
|
if cfg == nil {
|
|
cfg = c.App.Config()
|
|
}
|
|
|
|
// we set BulkIndexingTimeWindowSeconds to a random value to avoid failing on the nil check
|
|
// TODO: remove this hack once we remove BulkIndexingTimeWindowSeconds from the config.
|
|
if cfg.ElasticsearchSettings.BulkIndexingTimeWindowSeconds == nil {
|
|
cfg.ElasticsearchSettings.BulkIndexingTimeWindowSeconds = new(0)
|
|
}
|
|
if checkHasNilFields(&cfg.ElasticsearchSettings) {
|
|
c.Err = model.NewAppError("testElasticsearch", "api.elasticsearch.test_elasticsearch_settings_nil.app_error", nil, "", http.StatusBadRequest)
|
|
return
|
|
}
|
|
|
|
// PERMISSION_TEST_ELASTICSEARCH is an ancillary permission of PERMISSION_SYSCONSOLE_WRITE_ENVIRONMENT_ELASTICSEARCH,
|
|
// which should prevent read-only managers from password sniffing
|
|
if !c.App.SessionHasPermissionToAndNotRestrictedAdmin(*c.AppContext.Session(), model.PermissionTestElasticsearch) {
|
|
c.SetPermissionError(model.PermissionTestElasticsearch)
|
|
return
|
|
}
|
|
|
|
if err := c.App.TestElasticsearch(c.AppContext, cfg); err != nil {
|
|
c.Err = err
|
|
return
|
|
}
|
|
|
|
ReturnStatusOK(w)
|
|
}
|
|
|
|
func purgeElasticsearchIndexes(c *Context, w http.ResponseWriter, r *http.Request) {
|
|
auditRec := c.MakeAuditRecord(model.AuditEventPurgeElasticsearchIndexes, model.AuditStatusFail)
|
|
defer c.LogAuditRec(auditRec)
|
|
|
|
if !c.App.SessionHasPermissionToAndNotRestrictedAdmin(*c.AppContext.Session(), model.PermissionPurgeElasticsearchIndexes) {
|
|
c.SetPermissionError(model.PermissionPurgeElasticsearchIndexes)
|
|
return
|
|
}
|
|
|
|
specifiedIndexesQuery := r.URL.Query()["index"]
|
|
if err := c.App.PurgeElasticsearchIndexes(c.AppContext, specifiedIndexesQuery); err != nil {
|
|
c.Err = err
|
|
return
|
|
}
|
|
|
|
auditRec.Success()
|
|
|
|
ReturnStatusOK(w)
|
|
}
|