From 6bf09e2c34c568e3cb0d296142d5abed77332635 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Espino?= Date: Wed, 8 Aug 2018 12:04:36 +0200 Subject: MM-11384: Add system install date information to the client config (#9218) * MM-11384: Add system install date information to the client config * Fixing translation text * Fixes from Peer Review --- app/config.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'app/config.go') diff --git a/app/config.go b/app/config.go index 21571f291..1e96fd4fa 100644 --- a/app/config.go +++ b/app/config.go @@ -16,6 +16,7 @@ import ( "runtime/debug" "strconv" "strings" + "time" "github.com/mattermost/mattermost-server/mlog" "github.com/mattermost/mattermost-server/model" @@ -208,6 +209,30 @@ func (a *App) ensureAsymmetricSigningKey() error { return nil } +func (a *App) ensureInstallationDate() error { + _, err := a.getSystemInstallDate() + if err == nil { + return nil + } + + result := <-a.Srv.Store.User().InferSystemInstallDate() + var installationDate int64 + if result.Err == nil && result.Data.(int64) > 0 { + installationDate = result.Data.(int64) + } else { + installationDate = utils.MillisFromTime(time.Now()) + } + + result = <-a.Srv.Store.System().SaveOrUpdate(&model.System{ + Name: model.SYSTEM_INSTALLATION_DATE_KEY, + Value: strconv.FormatInt(installationDate, 10), + }) + if result.Err != nil { + return result.Err + } + return nil +} + // AsymmetricSigningKey will return a private key that can be used for asymmetric signing. func (a *App) AsymmetricSigningKey() *ecdsa.PrivateKey { return a.asymmetricSigningKey @@ -296,6 +321,10 @@ func (a *App) ClientConfigWithComputed() map[string]string { // by the client. respCfg["NoAccounts"] = strconv.FormatBool(a.IsFirstUserAccount()) respCfg["MaxPostSize"] = strconv.Itoa(a.MaxPostSize()) + respCfg["InstallationDate"] = "" + if installationDate, err := a.getSystemInstallDate(); err == nil { + respCfg["InstallationDate"] = strconv.FormatInt(installationDate, 10) + } return respCfg } -- cgit v1.2.3-1-g7c22