MM-8604: emit config/license websocket events (#8371)
Этот коммит содержится в:
коммит произвёл
Joram Wilander
родитель
fa98175a46
Коммит
fbff94f3be
@@ -8,7 +8,6 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
|
||||||
|
|
||||||
l4g "github.com/alecthomas/log4go"
|
l4g "github.com/alecthomas/log4go"
|
||||||
"github.com/mattermost/mattermost-server/model"
|
"github.com/mattermost/mattermost-server/model"
|
||||||
@@ -247,14 +246,7 @@ func getClientConfig(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
respCfg := map[string]string{}
|
w.Write([]byte(model.MapToJson(c.App.ClientConfigWithNoAccounts())))
|
||||||
for k, v := range c.App.ClientConfig() {
|
|
||||||
respCfg[k] = v
|
|
||||||
}
|
|
||||||
|
|
||||||
respCfg["NoAccounts"] = strconv.FormatBool(c.App.IsFirstUserAccount())
|
|
||||||
|
|
||||||
w.Write([]byte(model.MapToJson(respCfg)))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func getClientLicense(c *Context, w http.ResponseWriter, r *http.Request) {
|
func getClientLicense(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||||
|
|||||||
18
app/app.go
18
app/app.go
@@ -131,8 +131,24 @@ func New(options ...Option) (outApp *App, outErr error) {
|
|||||||
|
|
||||||
app.configListenerId = app.AddConfigListener(func(_, _ *model.Config) {
|
app.configListenerId = app.AddConfigListener(func(_, _ *model.Config) {
|
||||||
app.configOrLicenseListener()
|
app.configOrLicenseListener()
|
||||||
|
|
||||||
|
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_CONFIG_CHANGED, "", "", "", nil)
|
||||||
|
|
||||||
|
message.Add("config", app.ClientConfigWithNoAccounts())
|
||||||
|
app.Go(func() {
|
||||||
|
app.Publish(message)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
app.licenseListenerId = app.AddLicenseListener(func() {
|
||||||
|
app.configOrLicenseListener()
|
||||||
|
|
||||||
|
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_LICENSE_CHANGED, "", "", "", nil)
|
||||||
|
message.Add("license", app.GetSanitizedClientLicense())
|
||||||
|
app.Go(func() {
|
||||||
|
app.Publish(message)
|
||||||
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
app.licenseListenerId = app.AddLicenseListener(app.configOrLicenseListener)
|
|
||||||
app.regenerateClientConfig()
|
app.regenerateClientConfig()
|
||||||
app.setDefaultRolesBasedOnConfig()
|
app.setDefaultRolesBasedOnConfig()
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
l4g "github.com/alecthomas/log4go"
|
l4g "github.com/alecthomas/log4go"
|
||||||
@@ -34,6 +35,7 @@ func (a *App) UpdateConfig(f func(*model.Config)) {
|
|||||||
updated := old.Clone()
|
updated := old.Clone()
|
||||||
f(updated)
|
f(updated)
|
||||||
a.config.Store(updated)
|
a.config.Store(updated)
|
||||||
|
|
||||||
a.InvokeConfigListeners(old, updated)
|
a.InvokeConfigListeners(old, updated)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -269,3 +271,16 @@ func (a *App) GetCookieDomain() string {
|
|||||||
func (a *App) GetSiteURL() string {
|
func (a *App) GetSiteURL() string {
|
||||||
return a.siteURL
|
return a.siteURL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ClientConfigWithNoAccounts gets the configuration in a format suitable for sending to the client.
|
||||||
|
func (a *App) ClientConfigWithNoAccounts() map[string]string {
|
||||||
|
respCfg := map[string]string{}
|
||||||
|
for k, v := range a.ClientConfig() {
|
||||||
|
respCfg[k] = v
|
||||||
|
}
|
||||||
|
|
||||||
|
// NoAccounts is not actually part of the configuration, but is expected by the client.
|
||||||
|
respCfg["NoAccounts"] = strconv.FormatBool(a.IsFirstUserAccount())
|
||||||
|
|
||||||
|
return respCfg
|
||||||
|
}
|
||||||
|
|||||||
@@ -63,3 +63,13 @@ func TestAsymmetricSigningKey(t *testing.T) {
|
|||||||
assert.NotNil(t, th.App.AsymmetricSigningKey())
|
assert.NotNil(t, th.App.AsymmetricSigningKey())
|
||||||
assert.NotEmpty(t, th.App.ClientConfig()["AsymmetricSigningPublicKey"])
|
assert.NotEmpty(t, th.App.ClientConfig()["AsymmetricSigningPublicKey"])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestClientConfigWithNoAccounts(t *testing.T) {
|
||||||
|
th := Setup().InitBasic()
|
||||||
|
defer th.TearDown()
|
||||||
|
|
||||||
|
config := th.App.ClientConfigWithNoAccounts()
|
||||||
|
if _, ok := config["NoAccounts"]; !ok {
|
||||||
|
t.Fatal("expected NoAccounts in returned config")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -44,6 +44,8 @@ const (
|
|||||||
WEBSOCKET_EVENT_CHANNEL_VIEWED = "channel_viewed"
|
WEBSOCKET_EVENT_CHANNEL_VIEWED = "channel_viewed"
|
||||||
WEBSOCKET_EVENT_PLUGIN_ACTIVATED = "plugin_activated" // EXPERIMENTAL - SUBJECT TO CHANGE
|
WEBSOCKET_EVENT_PLUGIN_ACTIVATED = "plugin_activated" // EXPERIMENTAL - SUBJECT TO CHANGE
|
||||||
WEBSOCKET_EVENT_PLUGIN_DEACTIVATED = "plugin_deactivated" // EXPERIMENTAL - SUBJECT TO CHANGE
|
WEBSOCKET_EVENT_PLUGIN_DEACTIVATED = "plugin_deactivated" // EXPERIMENTAL - SUBJECT TO CHANGE
|
||||||
|
WEBSOCKET_EVENT_LICENSE_CHANGED = "license_changed"
|
||||||
|
WEBSOCKET_EVENT_CONFIG_CHANGED = "config_changed"
|
||||||
)
|
)
|
||||||
|
|
||||||
type WebSocketMessage interface {
|
type WebSocketMessage interface {
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user