From bbcf00f02e469bcf04a45c1cdf8a7932e30ccfc0 Mon Sep 17 00:00:00 2001 From: JoramWilander Date: Fri, 22 Jan 2016 09:53:17 -0500 Subject: [PATCH] Add create_at back to profile fields to fix analytics --- api/license.go | 13 +++++++++++++ model/user.go | 1 - utils/license.go | 3 ++- .../components/admin_console/system_analytics.jsx | 2 +- .../components/admin_console/team_analytics.jsx | 4 ++++ 5 files changed, 20 insertions(+), 3 deletions(-) diff --git a/api/license.go b/api/license.go index 5b3809651b..fc2fd43842 100644 --- a/api/license.go +++ b/api/license.go @@ -5,6 +5,7 @@ package api import ( "bytes" + "fmt" l4g "github.com/alecthomas/log4go" "github.com/gorilla/mux" "github.com/mattermost/platform/model" @@ -63,6 +64,18 @@ func addLicense(c *Context, w http.ResponseWriter, r *http.Request) { if success, licenseStr := utils.ValidateLicense(data); success { license = model.LicenseFromJson(strings.NewReader(licenseStr)) + if result := <-Srv.Store.User().AnalyticsUniqueUserCount(""); result.Err != nil { + c.Err = model.NewAppError("addLicense", "Unable to count total unique users.", fmt.Sprintf("err=%v", result.Err.Error())) + return + } else { + uniqueUserCount := result.Data.(int64) + + if uniqueUserCount > int64(*license.Features.Users) { + c.Err = model.NewAppError("addLicense", fmt.Sprintf("This license only supports %d users, when your system has %d unique users. Unique users are counted distinctly by email address. You can see total user count under Site Reports -> View Statistics.", *license.Features.Users, uniqueUserCount), "") + return + } + } + if ok := utils.SetLicense(license); !ok { c.LogAudit("failed - expired or non-started license") c.Err = model.NewAppError("addLicense", "License is either expired or has not yet started.", "") diff --git a/model/user.go b/model/user.go index 7744b00730..44228d93fc 100644 --- a/model/user.go +++ b/model/user.go @@ -236,7 +236,6 @@ func (u *User) Sanitize(options map[string]bool) { } func (u *User) ClearNonProfileFields() { - u.CreateAt = 0 u.UpdateAt = 0 u.Password = "" u.AuthData = "" diff --git a/utils/license.go b/utils/license.go index 7594e33af2..4fba94d4d9 100644 --- a/utils/license.go +++ b/utils/license.go @@ -55,6 +55,7 @@ func LoadLicense() { if success, licenseStr := ValidateLicense(buf.Bytes()); success { license := model.LicenseFromJson(strings.NewReader(licenseStr)) SetLicense(license) + return } l4g.Warn("No valid enterprise license found") @@ -105,7 +106,7 @@ func ValidateLicense(signed []byte) (bool, string) { } // remove null terminator - if decoded[len(decoded)-1] == byte(0) { + for decoded[len(decoded)-1] == byte(0) { decoded = decoded[:len(decoded)-1] } diff --git a/web/react/components/admin_console/system_analytics.jsx b/web/react/components/admin_console/system_analytics.jsx index 640f17ff00..fffe7cc53b 100644 --- a/web/react/components/admin_console/system_analytics.jsx +++ b/web/react/components/admin_console/system_analytics.jsx @@ -142,7 +142,7 @@ export default class SystemAnalytics extends React.Component { return (
19) { break;