mirror of
https://github.com/documize/community.git
synced 2025-07-19 21:29:42 +02:00
license code refactoring
This commit is contained in:
parent
3f87401d49
commit
edccb39019
5 changed files with 22 additions and 40 deletions
|
@ -36,12 +36,12 @@
|
||||||
|
|
||||||
<form class="form-bordered">
|
<form class="form-bordered">
|
||||||
<div class="form-header">
|
<div class="form-header">
|
||||||
<div class="title">Edition License</div>
|
<div class="title">Optional Edition License</div>
|
||||||
<div class="tip">Product license</div>
|
<div class="tip">Only applies to Enterprise Edition</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="input-control">
|
<div class="input-control">
|
||||||
<label>License XML</label>
|
<label>License</label>
|
||||||
<div class="tip">Please provide valid XML</div>
|
<div class="tip">XML format accepted</div>
|
||||||
{{textarea value=model.license rows="5"}}
|
{{textarea value=model.license rows="5"}}
|
||||||
</div>
|
</div>
|
||||||
<div class="regular-button button-blue" {{ action 'saveLicense' }}>save</div>
|
<div class="regular-button button-blue" {{ action 'saveLicense' }}>save</div>
|
||||||
|
|
|
@ -18,7 +18,6 @@ import (
|
||||||
"github.com/documize/community/core/section"
|
"github.com/documize/community/core/section"
|
||||||
|
|
||||||
_ "github.com/documize/community/embed" // the compressed front-end code and static data
|
_ "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
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,6 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
"github.com/documize/community/core"
|
|
||||||
"github.com/documize/community/core/api/entity"
|
"github.com/documize/community/core/api/entity"
|
||||||
"github.com/documize/community/core/api/request"
|
"github.com/documize/community/core/api/request"
|
||||||
"github.com/documize/community/core/log"
|
"github.com/documize/community/core/log"
|
||||||
|
@ -41,13 +40,11 @@ func GetMeta(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
product := core.Product()
|
|
||||||
|
|
||||||
data.OrgID = org.RefID
|
data.OrgID = org.RefID
|
||||||
data.Title = org.Title
|
data.Title = org.Title
|
||||||
data.Message = org.Message
|
data.Message = org.Message
|
||||||
data.AllowAnonymousAccess = org.AllowAnonymousAccess
|
data.AllowAnonymousAccess = org.AllowAnonymousAccess
|
||||||
data.Version = product.Version
|
data.Version = Product.Version
|
||||||
|
|
||||||
json, err := json.Marshal(data)
|
json, err := json.Marshal(data)
|
||||||
|
|
||||||
|
|
|
@ -33,14 +33,21 @@ var port, certFile, keyFile, forcePort2SSL string
|
||||||
var Product core.ProdInfo
|
var Product core.ProdInfo
|
||||||
|
|
||||||
func init() {
|
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(&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(&keyFile, "key", false, "the key.pem file used for https", nil)
|
||||||
environment.GetString(&port, "port", false, "http/https port number", nil)
|
environment.GetString(&port, "port", false, "http/https port number", nil)
|
||||||
environment.GetString(&forcePort2SSL, "forcesslport", false, "redirect given http port number to TLS", nil)
|
environment.GetString(&forcePort2SSL, "forcesslport", false, "redirect given http port number to TLS", nil)
|
||||||
|
|
||||||
// license state
|
log.Info("Server.Init complete")
|
||||||
log.Info(Product.License.Status())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var testHost string // used during automated testing
|
var testHost string // used during automated testing
|
||||||
|
|
|
@ -11,8 +11,10 @@
|
||||||
|
|
||||||
package core
|
package core
|
||||||
|
|
||||||
import "fmt"
|
import (
|
||||||
import "time"
|
"fmt"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
// ProdInfo describes a product
|
// ProdInfo describes a product
|
||||||
type ProdInfo struct {
|
type ProdInfo struct {
|
||||||
|
@ -25,19 +27,6 @@ type ProdInfo struct {
|
||||||
License License
|
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.
|
// License holds details of product license.
|
||||||
type License struct {
|
type License struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
@ -47,6 +36,7 @@ type License struct {
|
||||||
End time.Time `json:"end"`
|
End time.Time `json:"end"`
|
||||||
Seats int `json:"seats"`
|
Seats int `json:"seats"`
|
||||||
Trial bool `json:"trial"`
|
Trial bool `json:"trial"`
|
||||||
|
Valid bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsEmpty determines if we have a license.
|
// 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
|
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.
|
// Status returns formatted message stating if license is empty/populated and invalid/valid.
|
||||||
func (l *License) Status() string {
|
func (l *License) Status() string {
|
||||||
lp := "populated"
|
lp := "populated"
|
||||||
|
@ -72,7 +51,7 @@ func (l *License) Status() string {
|
||||||
lp = "empty"
|
lp = "empty"
|
||||||
}
|
}
|
||||||
lv := "invalid"
|
lv := "invalid"
|
||||||
if l.IsValid() {
|
if l.Valid {
|
||||||
lv = "valid"
|
lv = "valid"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue