mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
remove einterface gets (#7455)
This commit is contained in:
27
api/admin.go
27
api/admin.go
@@ -10,7 +10,6 @@ import (
|
||||
l4g "github.com/alecthomas/log4go"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/mattermost/mattermost-server/app"
|
||||
"github.com/mattermost/mattermost-server/einterfaces"
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
"github.com/mattermost/mattermost-server/utils"
|
||||
"github.com/mssola/user_agent"
|
||||
@@ -47,7 +46,7 @@ func InitAdmin() {
|
||||
}
|
||||
|
||||
func getLogs(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
lines, err := app.GetLogs(0, 10000)
|
||||
lines, err := c.App.GetLogs(0, 10000)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -57,10 +56,10 @@ func getLogs(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func getClusterStatus(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
infos := app.GetClusterStatus()
|
||||
infos := c.App.GetClusterStatus()
|
||||
|
||||
if einterfaces.GetClusterInterface() != nil {
|
||||
w.Header().Set(model.HEADER_CLUSTER_ID, einterfaces.GetClusterInterface().GetClusterId())
|
||||
if c.App.Cluster != nil {
|
||||
w.Header().Set(model.HEADER_CLUSTER_ID, c.App.Cluster.GetClusterId())
|
||||
}
|
||||
|
||||
w.Write([]byte(model.ClusterInfosToJson(infos)))
|
||||
@@ -84,13 +83,13 @@ func getAllAudits(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func getConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
cfg := app.GetConfig()
|
||||
cfg := c.App.GetConfig()
|
||||
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
|
||||
w.Write([]byte(cfg.ToJson()))
|
||||
}
|
||||
|
||||
func reloadConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
app.ReloadConfig()
|
||||
c.App.ReloadConfig()
|
||||
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
|
||||
ReturnStatusOK(w)
|
||||
}
|
||||
@@ -113,7 +112,7 @@ func saveConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
err := app.SaveConfig(cfg, true)
|
||||
err := c.App.SaveConfig(cfg, true)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -261,7 +260,7 @@ func uploadBrandImage(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := app.SaveBrandImage(imageArray[0]); err != nil {
|
||||
if err := c.App.SaveBrandImage(imageArray[0]); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
@@ -272,7 +271,7 @@ func uploadBrandImage(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func getBrandImage(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if img, err := app.GetBrandImage(); err != nil {
|
||||
if img, err := c.App.GetBrandImage(); err != nil {
|
||||
w.Write(nil)
|
||||
} else {
|
||||
w.Header().Set("Content-Type", "image/png")
|
||||
@@ -289,7 +288,7 @@ func adminResetMfa(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := app.DeactivateMfa(userId); err != nil {
|
||||
if err := c.App.DeactivateMfa(userId); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
@@ -329,7 +328,7 @@ func adminResetPassword(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func ldapSyncNow(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
app.SyncLdap()
|
||||
c.App.SyncLdap()
|
||||
|
||||
rdata := map[string]string{}
|
||||
rdata["status"] = "ok"
|
||||
@@ -337,7 +336,7 @@ func ldapSyncNow(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func ldapTest(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if err := app.TestLdap(); err != nil {
|
||||
if err := c.App.TestLdap(); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
@@ -348,7 +347,7 @@ func ldapTest(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func samlMetadata(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
if result, err := app.GetSamlMetadata(); err != nil {
|
||||
if result, err := c.App.GetSamlMetadata(); err != nil {
|
||||
c.Err = model.NewAppError("loginWithSaml", "api.admin.saml.metadata.app_error", nil, "err="+err.Message, http.StatusInternalServerError)
|
||||
return
|
||||
} else {
|
||||
|
||||
@@ -15,7 +15,6 @@ import (
|
||||
goi18n "github.com/nicksnyder/go-i18n/i18n"
|
||||
|
||||
"github.com/mattermost/mattermost-server/app"
|
||||
"github.com/mattermost/mattermost-server/einterfaces"
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
"github.com/mattermost/mattermost-server/utils"
|
||||
)
|
||||
@@ -103,10 +102,6 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
now := time.Now()
|
||||
l4g.Debug("%v", r.URL.Path)
|
||||
|
||||
if metrics := einterfaces.GetMetricsInterface(); metrics != nil && h.isApi {
|
||||
metrics.IncrementHttpRequest()
|
||||
}
|
||||
|
||||
c := &Context{}
|
||||
c.App = app.Global()
|
||||
c.T, c.Locale = utils.GetTranslationsAndLocale(w, r)
|
||||
@@ -114,6 +109,10 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
c.IpAddress = utils.GetIpAddress(r)
|
||||
c.TeamId = mux.Vars(r)["team_id"]
|
||||
|
||||
if metrics := c.App.Metrics; metrics != nil && h.isApi {
|
||||
metrics.IncrementHttpRequest()
|
||||
}
|
||||
|
||||
token := ""
|
||||
isTokenFromQueryString := false
|
||||
|
||||
@@ -237,8 +236,8 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(c.Err.StatusCode)
|
||||
w.Write([]byte(c.Err.ToJson()))
|
||||
|
||||
if einterfaces.GetMetricsInterface() != nil {
|
||||
einterfaces.GetMetricsInterface().IncrementHttpError()
|
||||
if c.App.Metrics != nil {
|
||||
c.App.Metrics.IncrementHttpError()
|
||||
}
|
||||
} else {
|
||||
if c.Err.StatusCode == http.StatusUnauthorized {
|
||||
@@ -250,10 +249,10 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
}
|
||||
|
||||
if h.isApi && einterfaces.GetMetricsInterface() != nil {
|
||||
if h.isApi && c.App.Metrics != nil {
|
||||
if r.URL.Path != model.API_URL_SUFFIX_V3+"/users/websocket" {
|
||||
elapsed := float64(time.Since(now)) / float64(time.Second)
|
||||
einterfaces.GetMetricsInterface().ObserveHttpRequestDuration(elapsed)
|
||||
c.App.Metrics.ObserveHttpRequestDuration(elapsed)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
11
api/user.go
11
api/user.go
@@ -14,7 +14,6 @@ import (
|
||||
l4g "github.com/alecthomas/log4go"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/mattermost/mattermost-server/app"
|
||||
"github.com/mattermost/mattermost-server/einterfaces"
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
"github.com/mattermost/mattermost-server/store"
|
||||
"github.com/mattermost/mattermost-server/utils"
|
||||
@@ -169,7 +168,7 @@ func attachDeviceId(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
app.ClearSessionCacheForUser(c.Session.UserId)
|
||||
c.App.ClearSessionCacheForUser(c.Session.UserId)
|
||||
c.Session.SetExpireInDays(*utils.Cfg.ServiceSettings.SessionLengthMobileInDays)
|
||||
|
||||
maxAge := *utils.Cfg.ServiceSettings.SessionLengthMobileInDays * 60 * 60 * 24
|
||||
@@ -1075,7 +1074,7 @@ func updateMfa(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
c.LogAudit("success - activated")
|
||||
} else {
|
||||
if err := app.DeactivateMfa(c.Session.UserId); err != nil {
|
||||
if err := c.App.DeactivateMfa(c.Session.UserId); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
@@ -1126,7 +1125,7 @@ func checkMfa(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func loginWithSaml(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
samlInterface := einterfaces.GetSamlInterface()
|
||||
samlInterface := c.App.Saml
|
||||
|
||||
if samlInterface == nil {
|
||||
c.Err = model.NewAppError("loginWithSaml", "api.user.saml.not_available.app_error", nil, "", http.StatusFound)
|
||||
@@ -1169,7 +1168,7 @@ func loginWithSaml(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func completeSaml(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
samlInterface := einterfaces.GetSamlInterface()
|
||||
samlInterface := c.App.Saml
|
||||
|
||||
if samlInterface == nil {
|
||||
c.Err = model.NewAppError("completeSaml", "api.user.saml.not_available.app_error", nil, "", http.StatusFound)
|
||||
@@ -1203,7 +1202,7 @@ func completeSaml(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
return
|
||||
} else {
|
||||
if err := app.CheckUserAdditionalAuthenticationCriteria(user, ""); err != nil {
|
||||
if err := c.App.CheckUserAdditionalAuthenticationCriteria(user, ""); err != nil {
|
||||
c.Err = err
|
||||
c.Err.StatusCode = http.StatusFound
|
||||
return
|
||||
|
||||
@@ -22,7 +22,7 @@ func InitBrand() {
|
||||
func getBrandImage(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
// No permission check required
|
||||
|
||||
if img, err := app.GetBrandImage(); err != nil {
|
||||
if img, err := c.App.GetBrandImage(); err != nil {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
w.Write(nil)
|
||||
} else {
|
||||
@@ -60,7 +60,7 @@ func uploadBrandImage(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := app.SaveBrandImage(imageArray[0]); err != nil {
|
||||
if err := c.App.SaveBrandImage(imageArray[0]); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
@@ -24,6 +24,6 @@ func getClusterStatus(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
infos := app.GetClusterStatus()
|
||||
infos := c.App.GetClusterStatus()
|
||||
w.Write([]byte(model.ClusterInfosToJson(infos)))
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ import (
|
||||
goi18n "github.com/nicksnyder/go-i18n/i18n"
|
||||
|
||||
"github.com/mattermost/mattermost-server/app"
|
||||
"github.com/mattermost/mattermost-server/einterfaces"
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
"github.com/mattermost/mattermost-server/utils"
|
||||
)
|
||||
@@ -184,17 +183,17 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(c.Err.StatusCode)
|
||||
w.Write([]byte(c.Err.ToJson()))
|
||||
|
||||
if einterfaces.GetMetricsInterface() != nil {
|
||||
einterfaces.GetMetricsInterface().IncrementHttpError()
|
||||
if c.App.Metrics != nil {
|
||||
c.App.Metrics.IncrementHttpError()
|
||||
}
|
||||
}
|
||||
|
||||
if einterfaces.GetMetricsInterface() != nil {
|
||||
einterfaces.GetMetricsInterface().IncrementHttpRequest()
|
||||
if c.App.Metrics != nil {
|
||||
c.App.Metrics.IncrementHttpRequest()
|
||||
|
||||
if r.URL.Path != model.API_URL_SUFFIX+"/websocket" {
|
||||
elapsed := float64(time.Since(now)) / float64(time.Second)
|
||||
einterfaces.GetMetricsInterface().ObserveHttpRequestDuration(elapsed)
|
||||
c.App.Metrics.ObserveHttpRequestDuration(elapsed)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ func testElasticsearch(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := app.TestElasticsearch(cfg); err != nil {
|
||||
if err := c.App.TestElasticsearch(cfg); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
@@ -44,7 +44,7 @@ func purgeElasticsearchIndexes(c *Context, w http.ResponseWriter, r *http.Reques
|
||||
return
|
||||
}
|
||||
|
||||
if err := app.PurgeElasticsearchIndexes(); err != nil {
|
||||
if err := c.App.PurgeElasticsearchIndexes(); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ func syncLdap(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
app.SyncLdap()
|
||||
c.App.SyncLdap()
|
||||
|
||||
ReturnStatusOK(w)
|
||||
}
|
||||
@@ -36,7 +36,7 @@ func testLdap(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if err := app.TestLdap(); err != nil {
|
||||
if err := c.App.TestLdap(); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ func InitSaml() {
|
||||
}
|
||||
|
||||
func getSamlMetadata(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
metadata, err := app.GetSamlMetadata()
|
||||
metadata, err := c.App.GetSamlMetadata()
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
||||
@@ -94,7 +94,7 @@ func getConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
cfg := app.GetConfig()
|
||||
cfg := c.App.GetConfig()
|
||||
|
||||
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
|
||||
w.Write([]byte(cfg.ToJson()))
|
||||
@@ -106,7 +106,7 @@ func configReload(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
app.ReloadConfig()
|
||||
c.App.ReloadConfig()
|
||||
|
||||
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
|
||||
ReturnStatusOK(w)
|
||||
@@ -124,7 +124,7 @@ func updateConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
err := app.SaveConfig(cfg, true)
|
||||
err := c.App.SaveConfig(cfg, true)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
@@ -132,7 +132,7 @@ func updateConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
c.LogAudit("updateConfig")
|
||||
|
||||
cfg = app.GetConfig()
|
||||
cfg = c.App.GetConfig()
|
||||
|
||||
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
|
||||
w.Write([]byte(cfg.ToJson()))
|
||||
@@ -188,7 +188,7 @@ func getLogs(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
lines, err := app.GetLogs(c.Params.Page, c.Params.PerPage)
|
||||
lines, err := c.App.GetLogs(c.Params.Page, c.Params.PerPage)
|
||||
if err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"testing"
|
||||
|
||||
l4g "github.com/alecthomas/log4go"
|
||||
"github.com/mattermost/mattermost-server/app"
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
"github.com/mattermost/mattermost-server/utils"
|
||||
)
|
||||
@@ -108,7 +107,7 @@ func TestUpdateConfig(t *testing.T) {
|
||||
defer TearDown()
|
||||
Client := th.Client
|
||||
|
||||
cfg := app.GetConfig()
|
||||
cfg := th.App.GetConfig()
|
||||
|
||||
_, resp := Client.UpdateConfig(cfg)
|
||||
CheckForbiddenStatus(t, resp)
|
||||
|
||||
@@ -947,7 +947,7 @@ func attachDeviceId(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
app.ClearSessionCacheForUser(c.Session.UserId)
|
||||
c.App.ClearSessionCacheForUser(c.Session.UserId)
|
||||
c.Session.SetExpireInDays(*utils.Cfg.ServiceSettings.SessionLengthMobileInDays)
|
||||
|
||||
maxAge := *utils.Cfg.ServiceSettings.SessionLengthMobileInDays * 60 * 60 * 24
|
||||
|
||||
41
app/admin.go
41
app/admin.go
@@ -14,35 +14,34 @@ import (
|
||||
"net/http"
|
||||
|
||||
l4g "github.com/alecthomas/log4go"
|
||||
"github.com/mattermost/mattermost-server/einterfaces"
|
||||
"github.com/mattermost/mattermost-server/jobs"
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
"github.com/mattermost/mattermost-server/store"
|
||||
"github.com/mattermost/mattermost-server/utils"
|
||||
)
|
||||
|
||||
func GetLogs(page, perPage int) ([]string, *model.AppError) {
|
||||
func (a *App) GetLogs(page, perPage int) ([]string, *model.AppError) {
|
||||
|
||||
perPage = 10000
|
||||
|
||||
var lines []string
|
||||
if einterfaces.GetClusterInterface() != nil && *utils.Cfg.ClusterSettings.Enable {
|
||||
if a.Cluster != nil && *utils.Cfg.ClusterSettings.Enable {
|
||||
lines = append(lines, "-----------------------------------------------------------------------------------------------------------")
|
||||
lines = append(lines, "-----------------------------------------------------------------------------------------------------------")
|
||||
lines = append(lines, einterfaces.GetClusterInterface().GetMyClusterInfo().Hostname)
|
||||
lines = append(lines, a.Cluster.GetMyClusterInfo().Hostname)
|
||||
lines = append(lines, "-----------------------------------------------------------------------------------------------------------")
|
||||
lines = append(lines, "-----------------------------------------------------------------------------------------------------------")
|
||||
}
|
||||
|
||||
melines, err := GetLogsSkipSend(page, perPage)
|
||||
melines, err := a.GetLogsSkipSend(page, perPage)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
lines = append(lines, melines...)
|
||||
|
||||
if einterfaces.GetClusterInterface() != nil && *utils.Cfg.ClusterSettings.Enable {
|
||||
clines, err := einterfaces.GetClusterInterface().GetLogs(page, perPage)
|
||||
if a.Cluster != nil && *utils.Cfg.ClusterSettings.Enable {
|
||||
clines, err := a.Cluster.GetLogs(page, perPage)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -53,7 +52,7 @@ func GetLogs(page, perPage int) ([]string, *model.AppError) {
|
||||
return lines, nil
|
||||
}
|
||||
|
||||
func GetLogsSkipSend(page, perPage int) ([]string, *model.AppError) {
|
||||
func (a *App) GetLogsSkipSend(page, perPage int) ([]string, *model.AppError) {
|
||||
var lines []string
|
||||
|
||||
if utils.Cfg.LogSettings.EnableFile {
|
||||
@@ -86,11 +85,11 @@ func GetLogsSkipSend(page, perPage int) ([]string, *model.AppError) {
|
||||
return lines, nil
|
||||
}
|
||||
|
||||
func GetClusterStatus() []*model.ClusterInfo {
|
||||
func (a *App) GetClusterStatus() []*model.ClusterInfo {
|
||||
infos := make([]*model.ClusterInfo, 0)
|
||||
|
||||
if einterfaces.GetClusterInterface() != nil {
|
||||
infos = einterfaces.GetClusterInterface().GetClusterInfos()
|
||||
if a.Cluster != nil {
|
||||
infos = a.Cluster.GetClusterInfos()
|
||||
}
|
||||
|
||||
return infos
|
||||
@@ -100,7 +99,7 @@ func (a *App) InvalidateAllCaches() *model.AppError {
|
||||
debug.FreeOSMemory()
|
||||
a.InvalidateAllCachesSkipSend()
|
||||
|
||||
if einterfaces.GetClusterInterface() != nil {
|
||||
if a.Cluster != nil {
|
||||
|
||||
msg := &model.ClusterMessage{
|
||||
Event: model.CLUSTER_EVENT_INVALIDATE_ALL_CACHES,
|
||||
@@ -108,7 +107,7 @@ func (a *App) InvalidateAllCaches() *model.AppError {
|
||||
WaitForAllToSend: true,
|
||||
}
|
||||
|
||||
einterfaces.GetClusterInterface().SendClusterMessage(msg)
|
||||
a.Cluster.SendClusterMessage(msg)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -125,7 +124,7 @@ func (a *App) InvalidateAllCachesSkipSend() {
|
||||
a.LoadLicense()
|
||||
}
|
||||
|
||||
func GetConfig() *model.Config {
|
||||
func (a *App) GetConfig() *model.Config {
|
||||
json := utils.Cfg.ToJson()
|
||||
cfg := model.ConfigFromJson(strings.NewReader(json))
|
||||
cfg.Sanitize()
|
||||
@@ -133,7 +132,7 @@ func GetConfig() *model.Config {
|
||||
return cfg
|
||||
}
|
||||
|
||||
func ReloadConfig() {
|
||||
func (a *App) ReloadConfig() {
|
||||
debug.FreeOSMemory()
|
||||
utils.LoadConfig(utils.CfgFileName)
|
||||
|
||||
@@ -141,7 +140,7 @@ func ReloadConfig() {
|
||||
InitEmailBatching()
|
||||
}
|
||||
|
||||
func SaveConfig(cfg *model.Config, sendConfigChangeClusterMessage bool) *model.AppError {
|
||||
func (a *App) SaveConfig(cfg *model.Config, sendConfigChangeClusterMessage bool) *model.AppError {
|
||||
oldCfg := utils.Cfg
|
||||
cfg.SetDefaults()
|
||||
utils.Desanitize(cfg)
|
||||
@@ -163,16 +162,16 @@ func SaveConfig(cfg *model.Config, sendConfigChangeClusterMessage bool) *model.A
|
||||
utils.LoadConfig(utils.CfgFileName)
|
||||
utils.EnableConfigWatch()
|
||||
|
||||
if einterfaces.GetMetricsInterface() != nil {
|
||||
if a.Metrics != nil {
|
||||
if *utils.Cfg.MetricsSettings.Enable {
|
||||
einterfaces.GetMetricsInterface().StartServer()
|
||||
a.Metrics.StartServer()
|
||||
} else {
|
||||
einterfaces.GetMetricsInterface().StopServer()
|
||||
a.Metrics.StopServer()
|
||||
}
|
||||
}
|
||||
|
||||
if einterfaces.GetClusterInterface() != nil {
|
||||
err := einterfaces.GetClusterInterface().ConfigChanged(cfg, oldCfg, sendConfigChangeClusterMessage)
|
||||
if a.Cluster != nil {
|
||||
err := a.Cluster.ConfigChanged(cfg, oldCfg, sendConfigChangeClusterMessage)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ package app
|
||||
|
||||
import (
|
||||
l4g "github.com/alecthomas/log4go"
|
||||
"github.com/mattermost/mattermost-server/einterfaces"
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
"github.com/mattermost/mattermost-server/store"
|
||||
"github.com/mattermost/mattermost-server/utils"
|
||||
@@ -98,8 +97,8 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
|
||||
}
|
||||
|
||||
// If in HA mode then aggregrate all the stats
|
||||
if einterfaces.GetClusterInterface() != nil && *utils.Cfg.ClusterSettings.Enable {
|
||||
stats, err := einterfaces.GetClusterInterface().GetClusterStats()
|
||||
if a.Cluster != nil && *utils.Cfg.ClusterSettings.Enable {
|
||||
stats, err := a.Cluster.GetClusterStats()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
28
app/app.go
28
app/app.go
@@ -6,19 +6,45 @@ package app
|
||||
import (
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"sync"
|
||||
|
||||
"github.com/mattermost/mattermost-server/einterfaces"
|
||||
"github.com/mattermost/mattermost-server/plugin/pluginenv"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
Srv *Server
|
||||
Srv *Server
|
||||
|
||||
PluginEnv *pluginenv.Environment
|
||||
PluginConfigListenerId string
|
||||
|
||||
AccountMigration einterfaces.AccountMigrationInterface
|
||||
Brand einterfaces.BrandInterface
|
||||
Cluster einterfaces.ClusterInterface
|
||||
Compliance einterfaces.ComplianceInterface
|
||||
Elasticsearch einterfaces.ElasticsearchInterface
|
||||
Ldap einterfaces.LdapInterface
|
||||
Metrics einterfaces.MetricsInterface
|
||||
Mfa einterfaces.MfaInterface
|
||||
Saml einterfaces.SamlInterface
|
||||
}
|
||||
|
||||
var globalApp App
|
||||
|
||||
var initEnterprise sync.Once
|
||||
|
||||
func Global() *App {
|
||||
initEnterprise.Do(func() {
|
||||
globalApp.AccountMigration = einterfaces.GetAccountMigrationInterface()
|
||||
globalApp.Brand = einterfaces.GetBrandInterface()
|
||||
globalApp.Cluster = einterfaces.GetClusterInterface()
|
||||
globalApp.Compliance = einterfaces.GetComplianceInterface()
|
||||
globalApp.Elasticsearch = einterfaces.GetElasticsearchInterface()
|
||||
globalApp.Ldap = einterfaces.GetLdapInterface()
|
||||
globalApp.Metrics = einterfaces.GetMetricsInterface()
|
||||
globalApp.Mfa = einterfaces.GetMfaInterface()
|
||||
globalApp.Saml = einterfaces.GetSamlInterface()
|
||||
})
|
||||
return &globalApp
|
||||
}
|
||||
|
||||
|
||||
@@ -7,13 +7,12 @@ import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/mattermost/mattermost-server/einterfaces"
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
"github.com/mattermost/mattermost-server/utils"
|
||||
)
|
||||
|
||||
func (a *App) CheckPasswordAndAllCriteria(user *model.User, password string, mfaToken string) *model.AppError {
|
||||
if err := CheckUserAdditionalAuthenticationCriteria(user, mfaToken); err != nil {
|
||||
if err := a.CheckUserAdditionalAuthenticationCriteria(user, mfaToken); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -53,23 +52,21 @@ func (a *App) checkUserPassword(user *model.User, password string) *model.AppErr
|
||||
}
|
||||
}
|
||||
|
||||
func checkLdapUserPasswordAndAllCriteria(ldapId *string, password string, mfaToken string) (*model.User, *model.AppError) {
|
||||
ldapInterface := einterfaces.GetLdapInterface()
|
||||
|
||||
if ldapInterface == nil || ldapId == nil {
|
||||
func (a *App) checkLdapUserPasswordAndAllCriteria(ldapId *string, password string, mfaToken string) (*model.User, *model.AppError) {
|
||||
if a.Ldap == nil || ldapId == nil {
|
||||
err := model.NewAppError("doLdapAuthentication", "api.user.login_ldap.not_available.app_error", nil, "", http.StatusNotImplemented)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var user *model.User
|
||||
if ldapUser, err := ldapInterface.DoLogin(*ldapId, password); err != nil {
|
||||
if ldapUser, err := a.Ldap.DoLogin(*ldapId, password); err != nil {
|
||||
err.StatusCode = http.StatusUnauthorized
|
||||
return nil, err
|
||||
} else {
|
||||
user = ldapUser
|
||||
}
|
||||
|
||||
if err := CheckUserMfa(user, mfaToken); err != nil {
|
||||
if err := a.CheckUserMfa(user, mfaToken); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -81,8 +78,8 @@ func checkLdapUserPasswordAndAllCriteria(ldapId *string, password string, mfaTok
|
||||
return user, nil
|
||||
}
|
||||
|
||||
func CheckUserAdditionalAuthenticationCriteria(user *model.User, mfaToken string) *model.AppError {
|
||||
if err := CheckUserMfa(user, mfaToken); err != nil {
|
||||
func (a *App) CheckUserAdditionalAuthenticationCriteria(user *model.User, mfaToken string) *model.AppError {
|
||||
if err := a.CheckUserMfa(user, mfaToken); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -101,17 +98,16 @@ func CheckUserAdditionalAuthenticationCriteria(user *model.User, mfaToken string
|
||||
return nil
|
||||
}
|
||||
|
||||
func CheckUserMfa(user *model.User, token string) *model.AppError {
|
||||
func (a *App) CheckUserMfa(user *model.User, token string) *model.AppError {
|
||||
if !user.MfaActive || !utils.IsLicensed() || !*utils.License().Features.MFA || !*utils.Cfg.ServiceSettings.EnableMultifactorAuthentication {
|
||||
return nil
|
||||
}
|
||||
|
||||
mfaInterface := einterfaces.GetMfaInterface()
|
||||
if mfaInterface == nil {
|
||||
if a.Mfa == nil {
|
||||
return model.NewAppError("checkUserMfa", "api.user.check_user_mfa.not_available.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
if ok, err := mfaInterface.ValidateToken(user.MfaSecret, token); err != nil {
|
||||
if ok, err := a.Mfa.ValidateToken(user.MfaSecret, token); err != nil {
|
||||
return err
|
||||
} else if !ok {
|
||||
return model.NewAppError("checkUserMfa", "api.user.check_user_mfa.bad_code.app_error", nil, "", http.StatusUnauthorized)
|
||||
@@ -143,13 +139,13 @@ func checkUserNotDisabled(user *model.User) *model.AppError {
|
||||
}
|
||||
|
||||
func (a *App) authenticateUser(user *model.User, password, mfaToken string) (*model.User, *model.AppError) {
|
||||
ldapAvailable := *utils.Cfg.LdapSettings.Enable && einterfaces.GetLdapInterface() != nil && utils.IsLicensed() && *utils.License().Features.LDAP
|
||||
ldapAvailable := *utils.Cfg.LdapSettings.Enable && a.Ldap != nil && utils.IsLicensed() && *utils.License().Features.LDAP
|
||||
|
||||
if user.AuthService == model.USER_AUTH_SERVICE_LDAP {
|
||||
if !ldapAvailable {
|
||||
err := model.NewAppError("login", "api.user.login_ldap.not_available.app_error", nil, "", http.StatusNotImplemented)
|
||||
return user, err
|
||||
} else if ldapUser, err := checkLdapUserPasswordAndAllCriteria(user.AuthData, password, mfaToken); err != nil {
|
||||
} else if ldapUser, err := a.checkLdapUserPasswordAndAllCriteria(user.AuthData, password, mfaToken); err != nil {
|
||||
err.StatusCode = http.StatusUnauthorized
|
||||
return user, err
|
||||
} else {
|
||||
|
||||
15
app/brand.go
15
app/brand.go
@@ -7,39 +7,36 @@ import (
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
|
||||
"github.com/mattermost/mattermost-server/einterfaces"
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
"github.com/mattermost/mattermost-server/utils"
|
||||
)
|
||||
|
||||
func SaveBrandImage(imageData *multipart.FileHeader) *model.AppError {
|
||||
func (a *App) SaveBrandImage(imageData *multipart.FileHeader) *model.AppError {
|
||||
if len(*utils.Cfg.FileSettings.DriverName) == 0 {
|
||||
return model.NewAppError("SaveBrandImage", "api.admin.upload_brand_image.storage.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
brandInterface := einterfaces.GetBrandInterface()
|
||||
if brandInterface == nil {
|
||||
if a.Brand == nil {
|
||||
return model.NewAppError("SaveBrandImage", "api.admin.upload_brand_image.not_available.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
if err := brandInterface.SaveBrandImage(imageData); err != nil {
|
||||
if err := a.Brand.SaveBrandImage(imageData); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetBrandImage() ([]byte, *model.AppError) {
|
||||
func (a *App) GetBrandImage() ([]byte, *model.AppError) {
|
||||
if len(*utils.Cfg.FileSettings.DriverName) == 0 {
|
||||
return nil, model.NewAppError("GetBrandImage", "api.admin.get_brand_image.storage.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
brandInterface := einterfaces.GetBrandInterface()
|
||||
if brandInterface == nil {
|
||||
if a.Brand == nil {
|
||||
return nil, model.NewAppError("GetBrandImage", "api.admin.get_brand_image.not_available.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
if img, err := brandInterface.GetBrandImage(); err != nil {
|
||||
if img, err := a.Brand.GetBrandImage(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return img, nil
|
||||
|
||||
@@ -1087,7 +1087,7 @@ func (a *App) SetActiveChannel(userId string, channelId string) *model.AppError
|
||||
status.LastActivityAt = model.GetMillis()
|
||||
}
|
||||
|
||||
AddStatusCache(status)
|
||||
a.AddStatusCache(status)
|
||||
|
||||
if status.Status != oldStatus {
|
||||
BroadcastStatus(status)
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
l4g "github.com/alecthomas/log4go"
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
"github.com/mattermost/mattermost-server/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -75,3 +76,11 @@ func (me *ClusterDiscoveryService) Start() {
|
||||
func (me *ClusterDiscoveryService) Stop() {
|
||||
me.stop <- true
|
||||
}
|
||||
|
||||
func (a *App) IsLeader() bool {
|
||||
if utils.IsLicensed() && *utils.Cfg.ClusterSettings.Enable && a.Cluster != nil {
|
||||
return a.Cluster.IsLeader()
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,33 +6,31 @@ package app
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/mattermost/mattermost-server/einterfaces"
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
)
|
||||
|
||||
func (a *App) RegisterAllClusterMessageHandlers() {
|
||||
einterfaces.GetClusterInterface().RegisterClusterMessageHandler(model.CLUSTER_EVENT_PUBLISH, ClusterPublishHandler)
|
||||
einterfaces.GetClusterInterface().RegisterClusterMessageHandler(model.CLUSTER_EVENT_UPDATE_STATUS, ClusterUpdateStatusHandler)
|
||||
einterfaces.GetClusterInterface().RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_ALL_CACHES, a.ClusterInvalidateAllCachesHandler)
|
||||
einterfaces.GetClusterInterface().RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_WEBHOOK, a.ClusterInvalidateCacheForWebhookHandler)
|
||||
einterfaces.GetClusterInterface().RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_POSTS, a.ClusterInvalidateCacheForChannelPostsHandler)
|
||||
einterfaces.GetClusterInterface().RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_MEMBERS_NOTIFY_PROPS, a.ClusterInvalidateCacheForChannelMembersNotifyPropHandler)
|
||||
einterfaces.GetClusterInterface().RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_MEMBERS, a.ClusterInvalidateCacheForChannelMembersHandler)
|
||||
einterfaces.GetClusterInterface().RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_BY_NAME, a.ClusterInvalidateCacheForChannelByNameHandler)
|
||||
einterfaces.GetClusterInterface().RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL, a.ClusterInvalidateCacheForChannelHandler)
|
||||
einterfaces.GetClusterInterface().RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_USER, a.ClusterInvalidateCacheForUserHandler)
|
||||
einterfaces.GetClusterInterface().RegisterClusterMessageHandler(model.CLUSTER_EVENT_CLEAR_SESSION_CACHE_FOR_USER, ClusterClearSessionCacheForUserHandler)
|
||||
|
||||
a.Cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_PUBLISH, a.ClusterPublishHandler)
|
||||
a.Cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_UPDATE_STATUS, a.ClusterUpdateStatusHandler)
|
||||
a.Cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_ALL_CACHES, a.ClusterInvalidateAllCachesHandler)
|
||||
a.Cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_WEBHOOK, a.ClusterInvalidateCacheForWebhookHandler)
|
||||
a.Cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_POSTS, a.ClusterInvalidateCacheForChannelPostsHandler)
|
||||
a.Cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_MEMBERS_NOTIFY_PROPS, a.ClusterInvalidateCacheForChannelMembersNotifyPropHandler)
|
||||
a.Cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_MEMBERS, a.ClusterInvalidateCacheForChannelMembersHandler)
|
||||
a.Cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_BY_NAME, a.ClusterInvalidateCacheForChannelByNameHandler)
|
||||
a.Cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL, a.ClusterInvalidateCacheForChannelHandler)
|
||||
a.Cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_USER, a.ClusterInvalidateCacheForUserHandler)
|
||||
a.Cluster.RegisterClusterMessageHandler(model.CLUSTER_EVENT_CLEAR_SESSION_CACHE_FOR_USER, ClusterClearSessionCacheForUserHandler)
|
||||
}
|
||||
|
||||
func ClusterPublishHandler(msg *model.ClusterMessage) {
|
||||
func (a *App) ClusterPublishHandler(msg *model.ClusterMessage) {
|
||||
event := model.WebSocketEventFromJson(strings.NewReader(msg.Data))
|
||||
PublishSkipClusterSend(event)
|
||||
}
|
||||
|
||||
func ClusterUpdateStatusHandler(msg *model.ClusterMessage) {
|
||||
func (a *App) ClusterUpdateStatusHandler(msg *model.ClusterMessage) {
|
||||
status := model.StatusFromJson(strings.NewReader(msg.Data))
|
||||
AddStatusCacheSkipClusterSend(status)
|
||||
a.AddStatusCacheSkipClusterSend(status)
|
||||
}
|
||||
|
||||
func (a *App) ClusterInvalidateAllCachesHandler(msg *model.ClusterMessage) {
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
|
||||
"net/http"
|
||||
|
||||
"github.com/mattermost/mattermost-server/einterfaces"
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
"github.com/mattermost/mattermost-server/utils"
|
||||
)
|
||||
@@ -26,7 +25,7 @@ func (a *App) GetComplianceReports(page, perPage int) (model.Compliances, *model
|
||||
}
|
||||
|
||||
func (a *App) SaveComplianceReport(job *model.Compliance) (*model.Compliance, *model.AppError) {
|
||||
if !*utils.Cfg.ComplianceSettings.Enable || !utils.IsLicensed() || !*utils.License().Features.Compliance || einterfaces.GetComplianceInterface() == nil {
|
||||
if !*utils.Cfg.ComplianceSettings.Enable || !utils.IsLicensed() || !*utils.License().Features.Compliance || a.Compliance == nil {
|
||||
return nil, model.NewAppError("saveComplianceReport", "ent.compliance.licence_disable.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
@@ -36,14 +35,14 @@ func (a *App) SaveComplianceReport(job *model.Compliance) (*model.Compliance, *m
|
||||
return nil, result.Err
|
||||
} else {
|
||||
job = result.Data.(*model.Compliance)
|
||||
go einterfaces.GetComplianceInterface().RunComplianceJob(job)
|
||||
go a.Compliance.RunComplianceJob(job)
|
||||
}
|
||||
|
||||
return job, nil
|
||||
}
|
||||
|
||||
func (a *App) GetComplianceReport(reportId string) (*model.Compliance, *model.AppError) {
|
||||
if !*utils.Cfg.ComplianceSettings.Enable || !utils.IsLicensed() || !*utils.License().Features.Compliance || einterfaces.GetComplianceInterface() == nil {
|
||||
if !*utils.Cfg.ComplianceSettings.Enable || !utils.IsLicensed() || !*utils.License().Features.Compliance || a.Compliance == nil {
|
||||
return nil, model.NewAppError("downloadComplianceReport", "ent.compliance.licence_disable.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ const (
|
||||
var client *analytics.Client
|
||||
|
||||
func (a *App) SendDailyDiagnostics() {
|
||||
if *utils.Cfg.LogSettings.EnableDiagnostics && utils.IsLeader() {
|
||||
if *utils.Cfg.LogSettings.EnableDiagnostics && a.IsLeader() {
|
||||
initDiagnostics("")
|
||||
a.trackActivity()
|
||||
trackConfig()
|
||||
|
||||
@@ -6,12 +6,11 @@ package app
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/mattermost/mattermost-server/einterfaces"
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
"github.com/mattermost/mattermost-server/utils"
|
||||
)
|
||||
|
||||
func TestElasticsearch(cfg *model.Config) *model.AppError {
|
||||
func (a *App) 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
|
||||
@@ -20,7 +19,7 @@ func TestElasticsearch(cfg *model.Config) *model.AppError {
|
||||
}
|
||||
}
|
||||
|
||||
if esI := einterfaces.GetElasticsearchInterface(); esI != nil {
|
||||
if esI := a.Elasticsearch; esI != nil {
|
||||
if err := esI.TestConfig(cfg); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -32,8 +31,8 @@ func TestElasticsearch(cfg *model.Config) *model.AppError {
|
||||
return nil
|
||||
}
|
||||
|
||||
func PurgeElasticsearchIndexes() *model.AppError {
|
||||
if esI := einterfaces.GetElasticsearchInterface(); esI != nil {
|
||||
func (a *App) PurgeElasticsearchIndexes() *model.AppError {
|
||||
if esI := a.Elasticsearch; esI != nil {
|
||||
if err := esI.PurgeIndexes(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
15
app/ldap.go
15
app/ldap.go
@@ -7,15 +7,14 @@ import (
|
||||
"net/http"
|
||||
|
||||
l4g "github.com/alecthomas/log4go"
|
||||
"github.com/mattermost/mattermost-server/einterfaces"
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
"github.com/mattermost/mattermost-server/utils"
|
||||
)
|
||||
|
||||
func SyncLdap() {
|
||||
func (a *App) SyncLdap() {
|
||||
go func() {
|
||||
if utils.IsLicensed() && *utils.License().Features.LDAP && *utils.Cfg.LdapSettings.Enable {
|
||||
if ldapI := einterfaces.GetLdapInterface(); ldapI != nil {
|
||||
if ldapI := a.Ldap; ldapI != nil {
|
||||
ldapI.SyncNow()
|
||||
} else {
|
||||
l4g.Error("%v", model.NewAppError("SyncLdap", "ent.ldap.disabled.app_error", nil, "", http.StatusNotImplemented).Error())
|
||||
@@ -24,8 +23,8 @@ func SyncLdap() {
|
||||
}()
|
||||
}
|
||||
|
||||
func TestLdap() *model.AppError {
|
||||
if ldapI := einterfaces.GetLdapInterface(); ldapI != nil && utils.IsLicensed() && *utils.License().Features.LDAP && *utils.Cfg.LdapSettings.Enable {
|
||||
func (a *App) TestLdap() *model.AppError {
|
||||
if ldapI := a.Ldap; ldapI != nil && utils.IsLicensed() && *utils.License().Features.LDAP && *utils.Cfg.LdapSettings.Enable {
|
||||
if err := ldapI.RunTest(); err != nil {
|
||||
err.StatusCode = 500
|
||||
return err
|
||||
@@ -52,7 +51,7 @@ func (a *App) SwitchEmailToLdap(email, password, code, ldapId, ldapPassword stri
|
||||
return "", err
|
||||
}
|
||||
|
||||
ldapInterface := einterfaces.GetLdapInterface()
|
||||
ldapInterface := a.Ldap
|
||||
if ldapInterface == nil {
|
||||
return "", model.NewAppError("SwitchEmailToLdap", "api.user.email_to_ldap.not_available.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
@@ -80,7 +79,7 @@ func (a *App) SwitchLdapToEmail(ldapPassword, code, email, newPassword string) (
|
||||
return "", model.NewAppError("SwitchLdapToEmail", "api.user.ldap_to_email.not_ldap_account.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
ldapInterface := einterfaces.GetLdapInterface()
|
||||
ldapInterface := a.Ldap
|
||||
if ldapInterface == nil || user.AuthData == nil {
|
||||
return "", model.NewAppError("SwitchLdapToEmail", "api.user.ldap_to_email.not_available.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
@@ -89,7 +88,7 @@ func (a *App) SwitchLdapToEmail(ldapPassword, code, email, newPassword string) (
|
||||
return "", err
|
||||
}
|
||||
|
||||
if err := CheckUserMfa(user, code); err != nil {
|
||||
if err := a.CheckUserMfa(user, code); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ func (a *App) SaveLicense(licenseBytes []byte) (*model.License, *model.AppError)
|
||||
return nil, model.NewAppError("addLicense", model.INVALID_LICENSE_ERROR, nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
ReloadConfig()
|
||||
a.ReloadConfig()
|
||||
a.InvalidateAllCaches()
|
||||
|
||||
return license, nil
|
||||
@@ -104,7 +104,7 @@ func (a *App) RemoveLicense() *model.AppError {
|
||||
return result.Err
|
||||
}
|
||||
|
||||
ReloadConfig()
|
||||
a.ReloadConfig()
|
||||
|
||||
a.InvalidateAllCaches()
|
||||
|
||||
|
||||
17
app/login.go
17
app/login.go
@@ -9,7 +9,6 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/mattermost/mattermost-server/einterfaces"
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
"github.com/mattermost/mattermost-server/utils"
|
||||
"github.com/mssola/user_agent"
|
||||
@@ -27,15 +26,15 @@ func (a *App) AuthenticateUserForLogin(id, loginId, password, mfaToken, deviceId
|
||||
if len(id) != 0 {
|
||||
if user, err = a.GetUser(id); err != nil {
|
||||
err.StatusCode = http.StatusBadRequest
|
||||
if einterfaces.GetMetricsInterface() != nil {
|
||||
einterfaces.GetMetricsInterface().IncrementLoginFail()
|
||||
if a.Metrics != nil {
|
||||
a.Metrics.IncrementLoginFail()
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
if user, err = a.GetUserForLogin(loginId, ldapOnly); err != nil {
|
||||
if einterfaces.GetMetricsInterface() != nil {
|
||||
einterfaces.GetMetricsInterface().IncrementLoginFail()
|
||||
if a.Metrics != nil {
|
||||
a.Metrics.IncrementLoginFail()
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
@@ -43,14 +42,14 @@ func (a *App) AuthenticateUserForLogin(id, loginId, password, mfaToken, deviceId
|
||||
|
||||
// and then authenticate them
|
||||
if user, err = a.authenticateUser(user, password, mfaToken); err != nil {
|
||||
if einterfaces.GetMetricsInterface() != nil {
|
||||
einterfaces.GetMetricsInterface().IncrementLoginFail()
|
||||
if a.Metrics != nil {
|
||||
a.Metrics.IncrementLoginFail()
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if einterfaces.GetMetricsInterface() != nil {
|
||||
einterfaces.GetMetricsInterface().IncrementLogin()
|
||||
if a.Metrics != nil {
|
||||
a.Metrics.IncrementLogin()
|
||||
}
|
||||
|
||||
return user, nil
|
||||
|
||||
@@ -18,7 +18,6 @@ import (
|
||||
"unicode"
|
||||
|
||||
l4g "github.com/alecthomas/log4go"
|
||||
"github.com/mattermost/mattermost-server/einterfaces"
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
"github.com/mattermost/mattermost-server/store"
|
||||
"github.com/mattermost/mattermost-server/utils"
|
||||
@@ -369,8 +368,8 @@ func (a *App) sendNotificationEmail(post *model.Post, user *model.User, channel
|
||||
}
|
||||
}()
|
||||
|
||||
if einterfaces.GetMetricsInterface() != nil {
|
||||
einterfaces.GetMetricsInterface().IncrementPostSentEmail()
|
||||
if a.Metrics != nil {
|
||||
a.Metrics.IncrementPostSentEmail()
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -641,8 +640,8 @@ func (a *App) sendPushNotification(post *model.Post, user *model.User, channel *
|
||||
|
||||
go a.sendToPushProxy(tmpMessage, session)
|
||||
|
||||
if einterfaces.GetMetricsInterface() != nil {
|
||||
einterfaces.GetMetricsInterface().IncrementPostSentPush()
|
||||
if a.Metrics != nil {
|
||||
a.Metrics.IncrementPostSentPush()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -701,7 +700,7 @@ func (a *App) sendToPushProxy(msg model.PushNotification, session *model.Session
|
||||
if pushResponse[model.PUSH_STATUS] == model.PUSH_STATUS_REMOVE {
|
||||
l4g.Info("Device was reported as removed for UserId=%v SessionId=%v removing push for this session", session.UserId, session.Id)
|
||||
a.AttachDeviceId(session.Id, "", session.ExpiresAt)
|
||||
ClearSessionCacheForUser(session.UserId)
|
||||
a.ClearSessionCacheForUser(session.UserId)
|
||||
}
|
||||
|
||||
if pushResponse[model.PUSH_STATUS] == model.PUSH_STATUS_FAIL {
|
||||
|
||||
@@ -426,7 +426,7 @@ func (a *App) RevokeAccessToken(token string) *model.AppError {
|
||||
}
|
||||
|
||||
if session != nil {
|
||||
ClearSessionCacheForUser(session.UserId)
|
||||
a.ClearSessionCacheForUser(session.UserId)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -16,7 +16,6 @@ import (
|
||||
l4g "github.com/alecthomas/log4go"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/mattermost/mattermost-server/einterfaces"
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
"github.com/mattermost/mattermost-server/utils"
|
||||
|
||||
@@ -96,8 +95,7 @@ func (api *BuiltInPluginAPI) CreatePost(post *model.Post) (*model.Post, *model.A
|
||||
}
|
||||
|
||||
func (api *BuiltInPluginAPI) GetLdapUserAttributes(userId string, attributes []string) (map[string]string, *model.AppError) {
|
||||
ldapInterface := einterfaces.GetLdapInterface()
|
||||
if ldapInterface == nil {
|
||||
if api.app.Ldap == nil {
|
||||
return nil, model.NewAppError("GetLdapUserAttributes", "ent.ldap.disabled.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
@@ -106,7 +104,7 @@ func (api *BuiltInPluginAPI) GetLdapUserAttributes(userId string, attributes []s
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ldapInterface.GetUserAttributes(*user.AuthData, attributes)
|
||||
return api.app.Ldap.GetUserAttributes(*user.AuthData, attributes)
|
||||
}
|
||||
|
||||
func (api *BuiltInPluginAPI) GetSessionFromRequest(r *http.Request) (*model.Session, *model.AppError) {
|
||||
|
||||
19
app/post.go
19
app/post.go
@@ -12,7 +12,6 @@ import (
|
||||
|
||||
l4g "github.com/alecthomas/log4go"
|
||||
"github.com/dyatlov/go-opengraph/opengraph"
|
||||
"github.com/mattermost/mattermost-server/einterfaces"
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
"github.com/mattermost/mattermost-server/store"
|
||||
"github.com/mattermost/mattermost-server/utils"
|
||||
@@ -151,13 +150,13 @@ func (a *App) CreatePost(post *model.Post, channel *model.Channel, triggerWebhoo
|
||||
rpost = result.Data.(*model.Post)
|
||||
}
|
||||
|
||||
esInterface := einterfaces.GetElasticsearchInterface()
|
||||
esInterface := a.Elasticsearch
|
||||
if esInterface != nil && *utils.Cfg.ElasticsearchSettings.EnableIndexing {
|
||||
go esInterface.IndexPost(rpost, channel.TeamId)
|
||||
}
|
||||
|
||||
if einterfaces.GetMetricsInterface() != nil {
|
||||
einterfaces.GetMetricsInterface().IncrementPostCreate()
|
||||
if a.Metrics != nil {
|
||||
a.Metrics.IncrementPostCreate()
|
||||
}
|
||||
|
||||
if len(post.FileIds) > 0 {
|
||||
@@ -170,8 +169,8 @@ func (a *App) CreatePost(post *model.Post, channel *model.Channel, triggerWebhoo
|
||||
}
|
||||
}
|
||||
|
||||
if einterfaces.GetMetricsInterface() != nil {
|
||||
einterfaces.GetMetricsInterface().IncrementPostFileAttachment(len(post.FileIds))
|
||||
if a.Metrics != nil {
|
||||
a.Metrics.IncrementPostFileAttachment(len(post.FileIds))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -320,7 +319,7 @@ func (a *App) UpdatePost(post *model.Post, safeUpdate bool) (*model.Post, *model
|
||||
} else {
|
||||
rpost := result.Data.(*model.Post)
|
||||
|
||||
esInterface := einterfaces.GetElasticsearchInterface()
|
||||
esInterface := a.Elasticsearch
|
||||
if esInterface != nil && *utils.Cfg.ElasticsearchSettings.EnableIndexing {
|
||||
go func() {
|
||||
if rchannel := <-a.Srv.Store.Channel().GetForPost(rpost.Id); rchannel.Err != nil {
|
||||
@@ -507,7 +506,7 @@ func (a *App) DeletePost(postId string) (*model.Post, *model.AppError) {
|
||||
go a.DeletePostFiles(post)
|
||||
go a.DeleteFlaggedPosts(post.Id)
|
||||
|
||||
esInterface := einterfaces.GetElasticsearchInterface()
|
||||
esInterface := a.Elasticsearch
|
||||
if esInterface != nil && *utils.Cfg.ElasticsearchSettings.EnableIndexing {
|
||||
go esInterface.DeletePost(post)
|
||||
}
|
||||
@@ -538,7 +537,7 @@ func (a *App) DeletePostFiles(post *model.Post) {
|
||||
func (a *App) SearchPostsInTeam(terms string, userId string, teamId string, isOrSearch bool) (*model.PostList, *model.AppError) {
|
||||
paramsList := model.ParseSearchParams(terms)
|
||||
|
||||
esInterface := einterfaces.GetElasticsearchInterface()
|
||||
esInterface := a.Elasticsearch
|
||||
if esInterface != nil && *utils.Cfg.ElasticsearchSettings.EnableSearching && utils.IsLicensed() && *utils.License().Features.Elasticsearch {
|
||||
finalParamsList := []*model.SearchParams{}
|
||||
|
||||
@@ -580,7 +579,7 @@ func (a *App) SearchPostsInTeam(terms string, userId string, teamId string, isOr
|
||||
return nil, err
|
||||
}
|
||||
|
||||
postIds, err := einterfaces.GetElasticsearchInterface().SearchPosts(userChannels, finalParamsList)
|
||||
postIds, err := a.Elasticsearch.SearchPosts(userChannels, finalParamsList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -11,19 +11,17 @@ import (
|
||||
|
||||
"path/filepath"
|
||||
|
||||
"github.com/mattermost/mattermost-server/einterfaces"
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
"github.com/mattermost/mattermost-server/utils"
|
||||
)
|
||||
|
||||
func GetSamlMetadata() (string, *model.AppError) {
|
||||
samlInterface := einterfaces.GetSamlInterface()
|
||||
if samlInterface == nil {
|
||||
func (a *App) GetSamlMetadata() (string, *model.AppError) {
|
||||
if a.Saml == nil {
|
||||
err := model.NewAppError("GetSamlMetadata", "api.admin.saml.not_available.app_error", nil, "", http.StatusNotImplemented)
|
||||
return "", err
|
||||
}
|
||||
|
||||
if result, err := samlInterface.GetMetadata(); err != nil {
|
||||
if result, err := a.Saml.GetMetadata(); err != nil {
|
||||
return "", model.NewAppError("GetSamlMetadata", "api.admin.saml.metadata.app_error", nil, "err="+err.Message, err.StatusCode)
|
||||
} else {
|
||||
return result, nil
|
||||
|
||||
@@ -6,7 +6,6 @@ package app
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/mattermost/mattermost-server/einterfaces"
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
"github.com/mattermost/mattermost-server/utils"
|
||||
|
||||
@@ -30,7 +29,7 @@ func (a *App) CreateSession(session *model.Session) (*model.Session, *model.AppE
|
||||
}
|
||||
|
||||
func (a *App) GetSession(token string) (*model.Session, *model.AppError) {
|
||||
metrics := einterfaces.GetMetricsInterface()
|
||||
metrics := a.Metrics
|
||||
|
||||
var session *model.Session
|
||||
if ts, ok := sessionCache.Get(token); ok {
|
||||
@@ -102,22 +101,22 @@ func (a *App) RevokeAllSessions(userId string) *model.AppError {
|
||||
}
|
||||
}
|
||||
|
||||
ClearSessionCacheForUser(userId)
|
||||
a.ClearSessionCacheForUser(userId)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func ClearSessionCacheForUser(userId string) {
|
||||
func (a *App) ClearSessionCacheForUser(userId string) {
|
||||
|
||||
ClearSessionCacheForUserSkipClusterSend(userId)
|
||||
|
||||
if einterfaces.GetClusterInterface() != nil {
|
||||
if a.Cluster != nil {
|
||||
msg := &model.ClusterMessage{
|
||||
Event: model.CLUSTER_EVENT_CLEAR_SESSION_CACHE_FOR_USER,
|
||||
SendType: model.CLUSTER_SEND_BEST_EFFORT,
|
||||
Data: userId,
|
||||
}
|
||||
einterfaces.GetClusterInterface().SendClusterMessage(msg)
|
||||
a.Cluster.SendClusterMessage(msg)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,7 +184,7 @@ func (a *App) RevokeSession(session *model.Session) *model.AppError {
|
||||
}
|
||||
|
||||
RevokeWebrtcToken(session.Id)
|
||||
ClearSessionCacheForUser(session.UserId)
|
||||
a.ClearSessionCacheForUser(session.UserId)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ import (
|
||||
)
|
||||
|
||||
func TestCache(t *testing.T) {
|
||||
th := Setup().InitBasic()
|
||||
|
||||
session := &model.Session{
|
||||
Id: model.NewId(),
|
||||
Token: model.NewId(),
|
||||
@@ -23,7 +25,7 @@ func TestCache(t *testing.T) {
|
||||
t.Fatal("should have items")
|
||||
}
|
||||
|
||||
ClearSessionCacheForUser(session.UserId)
|
||||
th.App.ClearSessionCacheForUser(session.UserId)
|
||||
|
||||
rkeys := sessionCache.Keys()
|
||||
if len(rkeys) != len(keys)-1 {
|
||||
|
||||
@@ -6,7 +6,6 @@ package app
|
||||
import (
|
||||
l4g "github.com/alecthomas/log4go"
|
||||
|
||||
"github.com/mattermost/mattermost-server/einterfaces"
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
"github.com/mattermost/mattermost-server/store"
|
||||
"github.com/mattermost/mattermost-server/utils"
|
||||
@@ -18,20 +17,20 @@ func ClearStatusCache() {
|
||||
statusCache.Purge()
|
||||
}
|
||||
|
||||
func AddStatusCacheSkipClusterSend(status *model.Status) {
|
||||
func (a *App) AddStatusCacheSkipClusterSend(status *model.Status) {
|
||||
statusCache.Add(status.UserId, status)
|
||||
}
|
||||
|
||||
func AddStatusCache(status *model.Status) {
|
||||
AddStatusCacheSkipClusterSend(status)
|
||||
func (a *App) AddStatusCache(status *model.Status) {
|
||||
a.AddStatusCacheSkipClusterSend(status)
|
||||
|
||||
if einterfaces.GetClusterInterface() != nil {
|
||||
if a.Cluster != nil {
|
||||
msg := &model.ClusterMessage{
|
||||
Event: model.CLUSTER_EVENT_UPDATE_STATUS,
|
||||
SendType: model.CLUSTER_SEND_BEST_EFFORT,
|
||||
Data: status.ToJson(),
|
||||
}
|
||||
einterfaces.GetClusterInterface().SendClusterMessage(msg)
|
||||
a.Cluster.SendClusterMessage(msg)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +62,7 @@ func (a *App) GetStatusesByIds(userIds []string) (map[string]interface{}, *model
|
||||
}
|
||||
|
||||
statusMap := map[string]interface{}{}
|
||||
metrics := einterfaces.GetMetricsInterface()
|
||||
metrics := a.Metrics
|
||||
|
||||
missingUserIds := []string{}
|
||||
for _, userId := range userIds {
|
||||
@@ -87,7 +86,7 @@ func (a *App) GetStatusesByIds(userIds []string) (map[string]interface{}, *model
|
||||
statuses := result.Data.([]*model.Status)
|
||||
|
||||
for _, s := range statuses {
|
||||
AddStatusCache(s)
|
||||
a.AddStatusCache(s)
|
||||
statusMap[s.UserId] = s.Status
|
||||
}
|
||||
}
|
||||
@@ -110,7 +109,7 @@ func (a *App) GetUserStatusesByIds(userIds []string) ([]*model.Status, *model.Ap
|
||||
}
|
||||
|
||||
var statusMap []*model.Status
|
||||
metrics := einterfaces.GetMetricsInterface()
|
||||
metrics := a.Metrics
|
||||
|
||||
missingUserIds := []string{}
|
||||
for _, userId := range userIds {
|
||||
@@ -134,7 +133,7 @@ func (a *App) GetUserStatusesByIds(userIds []string) ([]*model.Status, *model.Ap
|
||||
statuses := result.Data.([]*model.Status)
|
||||
|
||||
for _, s := range statuses {
|
||||
AddStatusCache(s)
|
||||
a.AddStatusCache(s)
|
||||
}
|
||||
|
||||
statusMap = append(statusMap, statuses...)
|
||||
@@ -195,7 +194,7 @@ func (a *App) SetStatusOnline(userId string, sessionId string, manual bool) {
|
||||
status.LastActivityAt = model.GetMillis()
|
||||
}
|
||||
|
||||
AddStatusCache(status)
|
||||
a.AddStatusCache(status)
|
||||
|
||||
// Only update the database if the status has changed, the status has been manually set,
|
||||
// or enough time has passed since the previous action
|
||||
@@ -237,7 +236,7 @@ func (a *App) SetStatusOffline(userId string, manual bool) {
|
||||
|
||||
status = &model.Status{UserId: userId, Status: model.STATUS_OFFLINE, Manual: manual, LastActivityAt: model.GetMillis(), ActiveChannel: ""}
|
||||
|
||||
AddStatusCache(status)
|
||||
a.AddStatusCache(status)
|
||||
|
||||
if result := <-a.Srv.Store.Status().SaveOrUpdate(status); result.Err != nil {
|
||||
l4g.Error(utils.T("api.status.save_status.error"), userId, result.Err)
|
||||
@@ -278,7 +277,7 @@ func (a *App) SetStatusAwayIfNeeded(userId string, manual bool) {
|
||||
status.Manual = manual
|
||||
status.ActiveChannel = ""
|
||||
|
||||
AddStatusCache(status)
|
||||
a.AddStatusCache(status)
|
||||
|
||||
if result := <-a.Srv.Store.Status().SaveOrUpdate(status); result.Err != nil {
|
||||
l4g.Error(utils.T("api.status.save_status.error"), userId, result.Err)
|
||||
|
||||
@@ -161,7 +161,7 @@ func (a *App) UpdateTeamMemberRoles(teamId string, userId string, newRoles strin
|
||||
return nil, result.Err
|
||||
}
|
||||
|
||||
ClearSessionCacheForUser(userId)
|
||||
a.ClearSessionCacheForUser(userId)
|
||||
|
||||
sendUpdatedMemberRoleEvent(userId, member)
|
||||
|
||||
@@ -324,7 +324,7 @@ func (a *App) JoinUserToTeam(team *model.Team, user *model.User, userRequestorId
|
||||
l4g.Error(utils.T("api.user.create_user.joining.error"), user.Id, team.Id, err)
|
||||
}
|
||||
|
||||
ClearSessionCacheForUser(user.Id)
|
||||
a.ClearSessionCacheForUser(user.Id)
|
||||
a.InvalidateCacheForUser(user.Id)
|
||||
|
||||
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_ADDED_TO_TEAM, "", "", user.Id, nil)
|
||||
@@ -621,7 +621,7 @@ func (a *App) LeaveTeam(team *model.Team, user *model.User) *model.AppError {
|
||||
return result.Err
|
||||
}
|
||||
|
||||
ClearSessionCacheForUser(user.Id)
|
||||
a.ClearSessionCacheForUser(user.Id)
|
||||
a.InvalidateCacheForUser(user.Id)
|
||||
|
||||
return nil
|
||||
|
||||
25
app/user.go
25
app/user.go
@@ -372,7 +372,7 @@ func (a *App) GetUserByAuth(authData *string, authService string) (*model.User,
|
||||
}
|
||||
|
||||
func (a *App) GetUserForLogin(loginId string, onlyLdap bool) (*model.User, *model.AppError) {
|
||||
ldapAvailable := *utils.Cfg.LdapSettings.Enable && einterfaces.GetLdapInterface() != nil && utils.IsLicensed() && *utils.License().Features.LDAP
|
||||
ldapAvailable := *utils.Cfg.LdapSettings.Enable && a.Ldap != nil && utils.IsLicensed() && *utils.License().Features.LDAP
|
||||
|
||||
if result := <-a.Srv.Store.User().GetForLogin(
|
||||
loginId,
|
||||
@@ -391,7 +391,7 @@ func (a *App) GetUserForLogin(loginId string, onlyLdap bool) (*model.User, *mode
|
||||
}
|
||||
|
||||
// fall back to LDAP server to see if we can find a user
|
||||
if ldapUser, ldapErr := einterfaces.GetLdapInterface().GetUser(loginId); ldapErr != nil {
|
||||
if ldapUser, ldapErr := a.Ldap.GetUser(loginId); ldapErr != nil {
|
||||
ldapErr.StatusCode = http.StatusBadRequest
|
||||
return nil, ldapErr
|
||||
} else {
|
||||
@@ -607,8 +607,7 @@ func sanitizeProfiles(users []*model.User, asAdmin bool) []*model.User {
|
||||
}
|
||||
|
||||
func (a *App) GenerateMfaSecret(userId string) (*model.MfaSecret, *model.AppError) {
|
||||
mfaInterface := einterfaces.GetMfaInterface()
|
||||
if mfaInterface == nil {
|
||||
if a.Mfa == nil {
|
||||
return nil, model.NewAppError("generateMfaSecret", "api.user.generate_mfa_qr.not_available.app_error", nil, "", http.StatusNotImplemented)
|
||||
}
|
||||
|
||||
@@ -618,7 +617,7 @@ func (a *App) GenerateMfaSecret(userId string) (*model.MfaSecret, *model.AppErro
|
||||
return nil, err
|
||||
}
|
||||
|
||||
secret, img, err := mfaInterface.GenerateSecret(user)
|
||||
secret, img, err := a.Mfa.GenerateSecret(user)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -628,8 +627,7 @@ func (a *App) GenerateMfaSecret(userId string) (*model.MfaSecret, *model.AppErro
|
||||
}
|
||||
|
||||
func (a *App) ActivateMfa(userId, token string) *model.AppError {
|
||||
mfaInterface := einterfaces.GetMfaInterface()
|
||||
if mfaInterface == nil {
|
||||
if a.Mfa == nil {
|
||||
err := model.NewAppError("ActivateMfa", "api.user.update_mfa.not_available.app_error", nil, "", http.StatusNotImplemented)
|
||||
return err
|
||||
}
|
||||
@@ -645,21 +643,20 @@ func (a *App) ActivateMfa(userId, token string) *model.AppError {
|
||||
return model.NewAppError("ActivateMfa", "api.user.activate_mfa.email_and_ldap_only.app_error", nil, "", http.StatusBadRequest)
|
||||
}
|
||||
|
||||
if err := mfaInterface.Activate(user, token); err != nil {
|
||||
if err := a.Mfa.Activate(user, token); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func DeactivateMfa(userId string) *model.AppError {
|
||||
mfaInterface := einterfaces.GetMfaInterface()
|
||||
if mfaInterface == nil {
|
||||
func (a *App) DeactivateMfa(userId string) *model.AppError {
|
||||
if a.Mfa == nil {
|
||||
err := model.NewAppError("DeactivateMfa", "api.user.update_mfa.not_available.app_error", nil, "", http.StatusNotImplemented)
|
||||
return err
|
||||
}
|
||||
|
||||
if err := mfaInterface.Deactivate(userId); err != nil {
|
||||
if err := a.Mfa.Deactivate(userId); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1045,7 +1042,7 @@ func (a *App) UpdateMfa(activate bool, userId, token string) *model.AppError {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if err := DeactivateMfa(userId); err != nil {
|
||||
if err := a.DeactivateMfa(userId); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -1215,7 +1212,7 @@ func (a *App) UpdateUserRoles(userId string, newRoles string) (*model.User, *mod
|
||||
l4g.Error(result.Err)
|
||||
}
|
||||
|
||||
ClearSessionCacheForUser(user.Id)
|
||||
a.ClearSessionCacheForUser(user.Id)
|
||||
|
||||
return ruser, nil
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/mattermost/mattermost-server/einterfaces"
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
"github.com/mattermost/mattermost-server/utils"
|
||||
|
||||
@@ -191,8 +190,8 @@ func (c *WebConn) WritePump() {
|
||||
return
|
||||
}
|
||||
|
||||
if einterfaces.GetMetricsInterface() != nil {
|
||||
go einterfaces.GetMetricsInterface().IncrementWebSocketBroadcast(msg.EventType())
|
||||
if c.App.Metrics != nil {
|
||||
go c.App.Metrics.IncrementWebSocketBroadcast(msg.EventType())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@ import (
|
||||
|
||||
l4g "github.com/alecthomas/log4go"
|
||||
|
||||
"github.com/mattermost/mattermost-server/einterfaces"
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
"github.com/mattermost/mattermost-server/utils"
|
||||
)
|
||||
@@ -145,13 +144,17 @@ func HubUnregister(webConn *WebConn) {
|
||||
}
|
||||
|
||||
func Publish(message *model.WebSocketEvent) {
|
||||
if metrics := einterfaces.GetMetricsInterface(); metrics != nil {
|
||||
Global().Publish(message)
|
||||
}
|
||||
|
||||
func (a *App) Publish(message *model.WebSocketEvent) {
|
||||
if metrics := a.Metrics; metrics != nil {
|
||||
metrics.IncrementWebsocketEvent(message.Event)
|
||||
}
|
||||
|
||||
PublishSkipClusterSend(message)
|
||||
|
||||
if einterfaces.GetClusterInterface() != nil {
|
||||
if a.Cluster != nil {
|
||||
cm := &model.ClusterMessage{
|
||||
Event: model.CLUSTER_EVENT_PUBLISH,
|
||||
SendType: model.CLUSTER_SEND_BEST_EFFORT,
|
||||
@@ -166,7 +169,7 @@ func Publish(message *model.WebSocketEvent) {
|
||||
cm.SendType = model.CLUSTER_SEND_RELIABLE
|
||||
}
|
||||
|
||||
einterfaces.GetClusterInterface().SendClusterMessage(cm)
|
||||
a.Cluster.SendClusterMessage(cm)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,14 +183,14 @@ func (a *App) InvalidateCacheForChannel(channel *model.Channel) {
|
||||
a.InvalidateCacheForChannelSkipClusterSend(channel.Id)
|
||||
a.InvalidateCacheForChannelByNameSkipClusterSend(channel.TeamId, channel.Name)
|
||||
|
||||
if cluster := einterfaces.GetClusterInterface(); cluster != nil {
|
||||
if a.Cluster != nil {
|
||||
msg := &model.ClusterMessage{
|
||||
Event: model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL,
|
||||
SendType: model.CLUSTER_SEND_BEST_EFFORT,
|
||||
Data: channel.Id,
|
||||
}
|
||||
|
||||
einterfaces.GetClusterInterface().SendClusterMessage(msg)
|
||||
a.Cluster.SendClusterMessage(msg)
|
||||
|
||||
nameMsg := &model.ClusterMessage{
|
||||
Event: model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_BY_NAME,
|
||||
@@ -202,7 +205,7 @@ func (a *App) InvalidateCacheForChannel(channel *model.Channel) {
|
||||
nameMsg.Props["id"] = channel.TeamId
|
||||
}
|
||||
|
||||
einterfaces.GetClusterInterface().SendClusterMessage(nameMsg)
|
||||
a.Cluster.SendClusterMessage(nameMsg)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -213,13 +216,13 @@ func (a *App) InvalidateCacheForChannelSkipClusterSend(channelId string) {
|
||||
func (a *App) InvalidateCacheForChannelMembers(channelId string) {
|
||||
a.InvalidateCacheForChannelMembersSkipClusterSend(channelId)
|
||||
|
||||
if einterfaces.GetClusterInterface() != nil {
|
||||
if a.Cluster != nil {
|
||||
msg := &model.ClusterMessage{
|
||||
Event: model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_MEMBERS,
|
||||
SendType: model.CLUSTER_SEND_BEST_EFFORT,
|
||||
Data: channelId,
|
||||
}
|
||||
einterfaces.GetClusterInterface().SendClusterMessage(msg)
|
||||
a.Cluster.SendClusterMessage(msg)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -231,13 +234,13 @@ func (a *App) InvalidateCacheForChannelMembersSkipClusterSend(channelId string)
|
||||
func (a *App) InvalidateCacheForChannelMembersNotifyProps(channelId string) {
|
||||
a.InvalidateCacheForChannelMembersNotifyPropsSkipClusterSend(channelId)
|
||||
|
||||
if einterfaces.GetClusterInterface() != nil {
|
||||
if a.Cluster != nil {
|
||||
msg := &model.ClusterMessage{
|
||||
Event: model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_MEMBERS_NOTIFY_PROPS,
|
||||
SendType: model.CLUSTER_SEND_BEST_EFFORT,
|
||||
Data: channelId,
|
||||
}
|
||||
einterfaces.GetClusterInterface().SendClusterMessage(msg)
|
||||
a.Cluster.SendClusterMessage(msg)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -256,13 +259,13 @@ func (a *App) InvalidateCacheForChannelByNameSkipClusterSend(teamId, name string
|
||||
func (a *App) InvalidateCacheForChannelPosts(channelId string) {
|
||||
a.InvalidateCacheForChannelPostsSkipClusterSend(channelId)
|
||||
|
||||
if einterfaces.GetClusterInterface() != nil {
|
||||
if a.Cluster != nil {
|
||||
msg := &model.ClusterMessage{
|
||||
Event: model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_CHANNEL_POSTS,
|
||||
SendType: model.CLUSTER_SEND_BEST_EFFORT,
|
||||
Data: channelId,
|
||||
}
|
||||
einterfaces.GetClusterInterface().SendClusterMessage(msg)
|
||||
a.Cluster.SendClusterMessage(msg)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -273,13 +276,13 @@ func (a *App) InvalidateCacheForChannelPostsSkipClusterSend(channelId string) {
|
||||
func (a *App) InvalidateCacheForUser(userId string) {
|
||||
a.InvalidateCacheForUserSkipClusterSend(userId)
|
||||
|
||||
if einterfaces.GetClusterInterface() != nil {
|
||||
if a.Cluster != nil {
|
||||
msg := &model.ClusterMessage{
|
||||
Event: model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_USER,
|
||||
SendType: model.CLUSTER_SEND_BEST_EFFORT,
|
||||
Data: userId,
|
||||
}
|
||||
einterfaces.GetClusterInterface().SendClusterMessage(msg)
|
||||
a.Cluster.SendClusterMessage(msg)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -296,13 +299,13 @@ func (a *App) InvalidateCacheForUserSkipClusterSend(userId string) {
|
||||
func (a *App) InvalidateCacheForWebhook(webhookId string) {
|
||||
a.InvalidateCacheForWebhookSkipClusterSend(webhookId)
|
||||
|
||||
if einterfaces.GetClusterInterface() != nil {
|
||||
if a.Cluster != nil {
|
||||
msg := &model.ClusterMessage{
|
||||
Event: model.CLUSTER_EVENT_INVALIDATE_CACHE_FOR_WEBHOOK,
|
||||
SendType: model.CLUSTER_SEND_BEST_EFFORT,
|
||||
Data: webhookId,
|
||||
}
|
||||
einterfaces.GetClusterInterface().SendClusterMessage(msg)
|
||||
a.Cluster.SendClusterMessage(msg)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
"unicode/utf8"
|
||||
|
||||
l4g "github.com/alecthomas/log4go"
|
||||
"github.com/mattermost/mattermost-server/einterfaces"
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
"github.com/mattermost/mattermost-server/store"
|
||||
"github.com/mattermost/mattermost-server/utils"
|
||||
@@ -126,7 +125,7 @@ func (a *App) CreateWebhookPost(userId string, channel *model.Channel, text, ove
|
||||
post := &model.Post{UserId: userId, ChannelId: channel.Id, Message: text, Type: postType}
|
||||
post.AddProp("from_webhook", "true")
|
||||
|
||||
if metrics := einterfaces.GetMetricsInterface(); metrics != nil {
|
||||
if metrics := a.Metrics; metrics != nil {
|
||||
metrics.IncrementWebhookPost()
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/mattermost/mattermost-server/einterfaces"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@@ -27,11 +26,12 @@ func init() {
|
||||
}
|
||||
|
||||
func ldapSyncCmdF(cmd *cobra.Command, args []string) error {
|
||||
if _, err := initDBCommandContextCobra(cmd); err != nil {
|
||||
a, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if ldapI := einterfaces.GetLdapInterface(); ldapI != nil {
|
||||
if ldapI := a.Ldap; ldapI != nil {
|
||||
if err := ldapI.Syncronize(); err != nil {
|
||||
CommandPrintErrorln("ERROR: AD/LDAP Synchronization Failed")
|
||||
} else {
|
||||
|
||||
@@ -13,7 +13,6 @@ import (
|
||||
"github.com/mattermost/mattermost-server/api"
|
||||
"github.com/mattermost/mattermost-server/api4"
|
||||
"github.com/mattermost/mattermost-server/app"
|
||||
"github.com/mattermost/mattermost-server/einterfaces"
|
||||
"github.com/mattermost/mattermost-server/jobs"
|
||||
"github.com/mattermost/mattermost-server/manualtesting"
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
@@ -96,7 +95,7 @@ func runServer(configFileLocation string) {
|
||||
utils.Cfg.TeamSettings.MaxNotificationsPerChannel = &MaxNotificationsPerChannelDefault
|
||||
}
|
||||
|
||||
app.ReloadConfig()
|
||||
a.ReloadConfig()
|
||||
|
||||
// Enable developer settings if this is a "dev" build
|
||||
if model.BuildNumber == "dev" {
|
||||
@@ -120,21 +119,21 @@ func runServer(configFileLocation string) {
|
||||
go runTokenCleanupJob(a)
|
||||
go runCommandWebhookCleanupJob(a)
|
||||
|
||||
if complianceI := einterfaces.GetComplianceInterface(); complianceI != nil {
|
||||
if complianceI := a.Compliance; complianceI != nil {
|
||||
complianceI.StartComplianceDailyJob()
|
||||
}
|
||||
|
||||
if einterfaces.GetClusterInterface() != nil {
|
||||
if a.Cluster != nil {
|
||||
a.RegisterAllClusterMessageHandlers()
|
||||
einterfaces.GetClusterInterface().StartInterNodeCommunication()
|
||||
a.Cluster.StartInterNodeCommunication()
|
||||
}
|
||||
|
||||
if einterfaces.GetMetricsInterface() != nil {
|
||||
einterfaces.GetMetricsInterface().StartServer()
|
||||
if a.Metrics != nil {
|
||||
a.Metrics.StartServer()
|
||||
}
|
||||
|
||||
if einterfaces.GetElasticsearchInterface() != nil {
|
||||
if err := einterfaces.GetElasticsearchInterface().Start(); err != nil {
|
||||
if a.Elasticsearch != nil {
|
||||
if err := a.Elasticsearch.Start(); err != nil {
|
||||
l4g.Error(err.Error())
|
||||
}
|
||||
}
|
||||
@@ -153,12 +152,12 @@ func runServer(configFileLocation string) {
|
||||
signal.Notify(c, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
|
||||
<-c
|
||||
|
||||
if einterfaces.GetClusterInterface() != nil {
|
||||
einterfaces.GetClusterInterface().StopInterNodeCommunication()
|
||||
if a.Cluster != nil {
|
||||
a.Cluster.StopInterNodeCommunication()
|
||||
}
|
||||
|
||||
if einterfaces.GetMetricsInterface() != nil {
|
||||
einterfaces.GetMetricsInterface().StopServer()
|
||||
if a.Metrics != nil {
|
||||
a.Metrics.StopServer()
|
||||
}
|
||||
|
||||
jobs.Srv.StopSchedulers()
|
||||
|
||||
@@ -7,7 +7,6 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/mattermost/mattermost-server/app"
|
||||
"github.com/mattermost/mattermost-server/einterfaces"
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
"github.com/mattermost/mattermost-server/utils"
|
||||
"github.com/spf13/cobra"
|
||||
@@ -320,7 +319,7 @@ func resetUserPasswordCmdF(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func resetUserMfaCmdF(cmd *cobra.Command, args []string) error {
|
||||
_, err := initDBCommandContextCobra(cmd)
|
||||
a, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -336,7 +335,7 @@ func resetUserMfaCmdF(cmd *cobra.Command, args []string) error {
|
||||
return errors.New("Unable to find user '" + args[i] + "'")
|
||||
}
|
||||
|
||||
if err := app.DeactivateMfa(user.Id); err != nil {
|
||||
if err := a.DeactivateMfa(user.Id); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -420,7 +419,7 @@ func deleteAllUsersCommandF(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func migrateAuthCmdF(cmd *cobra.Command, args []string) error {
|
||||
_, err := initDBCommandContextCobra(cmd)
|
||||
a, err := initDBCommandContextCobra(cmd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -452,7 +451,7 @@ func migrateAuthCmdF(cmd *cobra.Command, args []string) error {
|
||||
|
||||
forceFlag, _ := cmd.Flags().GetBool("force")
|
||||
|
||||
if migrate := einterfaces.GetAccountMigrationInterface(); migrate != nil {
|
||||
if migrate := a.AccountMigration; migrate != nil {
|
||||
if err := migrate.MigrateToLdap(fromAuth, matchField, forceFlag); err != nil {
|
||||
return errors.New("Error while migrating users: " + err.Error())
|
||||
}
|
||||
|
||||
@@ -689,11 +689,3 @@ func Desanitize(cfg *model.Config) {
|
||||
cfg.SqlSettings.DataSourceSearchReplicas[i] = Cfg.SqlSettings.DataSourceSearchReplicas[i]
|
||||
}
|
||||
}
|
||||
|
||||
func IsLeader() bool {
|
||||
if IsLicensed() && *Cfg.ClusterSettings.Enable && einterfaces.GetClusterInterface() != nil {
|
||||
return einterfaces.GetClusterInterface().IsLeader()
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user