summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/app.go18
-rw-r--r--app/config.go15
-rw-r--r--app/config_test.go10
3 files changed, 42 insertions, 1 deletions
diff --git a/app/app.go b/app/app.go
index 26aed4c73..f5e5dd21e 100644
--- a/app/app.go
+++ b/app/app.go
@@ -131,8 +131,24 @@ func New(options ...Option) (outApp *App, outErr error) {
app.configListenerId = app.AddConfigListener(func(_, _ *model.Config) {
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.setDefaultRolesBasedOnConfig()
diff --git a/app/config.go b/app/config.go
index 35a0c9a3f..460d580d8 100644
--- a/app/config.go
+++ b/app/config.go
@@ -14,6 +14,7 @@ import (
"fmt"
"net/url"
"runtime/debug"
+ "strconv"
"strings"
l4g "github.com/alecthomas/log4go"
@@ -34,6 +35,7 @@ func (a *App) UpdateConfig(f func(*model.Config)) {
updated := old.Clone()
f(updated)
a.config.Store(updated)
+
a.InvokeConfigListeners(old, updated)
}
@@ -269,3 +271,16 @@ func (a *App) GetCookieDomain() string {
func (a *App) GetSiteURL() string {
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
+}
diff --git a/app/config_test.go b/app/config_test.go
index 5ee999f0f..051fa8fd8 100644
--- a/app/config_test.go
+++ b/app/config_test.go
@@ -63,3 +63,13 @@ func TestAsymmetricSigningKey(t *testing.T) {
assert.NotNil(t, th.App.AsymmetricSigningKey())
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")
+ }
+}