From edccb39019d1b323bd236b1af0b6288de8f9e16f Mon Sep 17 00:00:00 2001 From: Harvey Kandola Date: Thu, 23 Feb 2017 10:29:51 -0800 Subject: [PATCH] license code refactoring --- .../templates/components/global-settings.hbs | 8 ++--- cmd/documize-community/documize.go | 3 +- core/api/endpoint/meta_endpoint.go | 5 +-- core/api/endpoint/server.go | 13 ++++++-- core/product.go | 33 ++++--------------- 5 files changed, 22 insertions(+), 40 deletions(-) diff --git a/app/app/templates/components/global-settings.hbs b/app/app/templates/components/global-settings.hbs index 28146c08..5f80caea 100644 --- a/app/app/templates/components/global-settings.hbs +++ b/app/app/templates/components/global-settings.hbs @@ -36,12 +36,12 @@
-
Edition License
-
Product license
+
Optional Edition License
+
Only applies to Enterprise Edition
- -
Please provide valid XML
+ +
XML format accepted
{{textarea value=model.license rows="5"}}
save
diff --git a/cmd/documize-community/documize.go b/cmd/documize-community/documize.go index 79390d9b..0379f1bc 100644 --- a/cmd/documize-community/documize.go +++ b/cmd/documize-community/documize.go @@ -18,8 +18,7 @@ import ( "github.com/documize/community/core/section" _ "github.com/documize/community/embed" // the compressed front-end code and static data - - _ "github.com/go-sql-driver/mysql" // the mysql driver is required behind the scenes + _ "github.com/go-sql-driver/mysql" // the mysql driver is required behind the scenes ) func main() { diff --git a/core/api/endpoint/meta_endpoint.go b/core/api/endpoint/meta_endpoint.go index 6cec5a05..b22d421d 100644 --- a/core/api/endpoint/meta_endpoint.go +++ b/core/api/endpoint/meta_endpoint.go @@ -18,7 +18,6 @@ import ( "net/http" "text/template" - "github.com/documize/community/core" "github.com/documize/community/core/api/entity" "github.com/documize/community/core/api/request" "github.com/documize/community/core/log" @@ -41,13 +40,11 @@ func GetMeta(w http.ResponseWriter, r *http.Request) { return } - product := core.Product() - data.OrgID = org.RefID data.Title = org.Title data.Message = org.Message data.AllowAnonymousAccess = org.AllowAnonymousAccess - data.Version = product.Version + data.Version = Product.Version json, err := json.Marshal(data) diff --git a/core/api/endpoint/server.go b/core/api/endpoint/server.go index ec5ceedb..04b528fb 100644 --- a/core/api/endpoint/server.go +++ b/core/api/endpoint/server.go @@ -33,14 +33,21 @@ var port, certFile, keyFile, forcePort2SSL string var Product core.ProdInfo func init() { - Product = core.Product() + Product.Major = "0" + Product.Minor = "42" + Product.Patch = "0" + Product.Version = fmt.Sprintf("%s.%s.%s", Product.Major, Product.Minor, Product.Patch) + Product.Edition = "Community" + Product.Title = fmt.Sprintf("%s Edition", Product.Edition) + Product.License = core.License{} + Product.License.Valid = true + environment.GetString(&certFile, "cert", false, "the cert.pem file used for https", nil) environment.GetString(&keyFile, "key", false, "the key.pem file used for https", nil) environment.GetString(&port, "port", false, "http/https port number", nil) environment.GetString(&forcePort2SSL, "forcesslport", false, "redirect given http port number to TLS", nil) - // license state - log.Info(Product.License.Status()) + log.Info("Server.Init complete") } var testHost string // used during automated testing diff --git a/core/product.go b/core/product.go index cee134aa..dcc653e9 100644 --- a/core/product.go +++ b/core/product.go @@ -11,8 +11,10 @@ package core -import "fmt" -import "time" +import ( + "fmt" + "time" +) // ProdInfo describes a product type ProdInfo struct { @@ -25,19 +27,6 @@ type ProdInfo struct { License License } -// Product returns product edition details -func Product() (p ProdInfo) { - p.Major = "0" - p.Minor = "42" - p.Patch = "0" - p.Version = fmt.Sprintf("%s.%s.%s", p.Major, p.Minor, p.Patch) - p.Edition = "Community" - p.Title = fmt.Sprintf("%s Edition", p.Edition) - p.License = License{} - - return -} - // License holds details of product license. type License struct { Name string `json:"name"` @@ -47,6 +36,7 @@ type License struct { End time.Time `json:"end"` Seats int `json:"seats"` Trial bool `json:"trial"` + Valid bool } // IsEmpty determines if we have a license. @@ -54,17 +44,6 @@ func (l *License) IsEmpty() bool { return l.Seats == 0 && len(l.Name) == 0 && len(l.Email) == 0 && l.Start.Year() == 1 && l.End.Year() == 1 } -// IsValid determines if we have populated and valid license. -// An empty license is valid. -func (l *License) IsValid() bool { - if l.IsEmpty() { - return true - } - - now := time.Now().UTC() - return l.End.Day() <= now.Day() && l.End.Month() <= now.Month() && l.End.Year() <= now.Year() -} - // Status returns formatted message stating if license is empty/populated and invalid/valid. func (l *License) Status() string { lp := "populated" @@ -72,7 +51,7 @@ func (l *License) Status() string { lp = "empty" } lv := "invalid" - if l.IsValid() { + if l.Valid { lv = "valid" }