2016-07-24 14:49:40 -07:00
|
|
|
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
|
|
|
//
|
|
|
|
// This software (Documize Community Edition) is licensed under
|
|
|
|
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
|
|
|
//
|
|
|
|
// You can operate outside the AGPL restrictions by purchasing
|
|
|
|
// Documize Enterprise Edition and obtaining a commercial license
|
|
|
|
// by contacting <sales@documize.com>.
|
|
|
|
//
|
|
|
|
// https://documize.com
|
|
|
|
|
2017-07-19 18:47:01 +01:00
|
|
|
package env
|
2016-07-24 14:49:40 -07:00
|
|
|
|
2017-02-23 10:29:51 -08:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
)
|
2016-07-24 14:49:40 -07:00
|
|
|
|
2018-10-29 16:53:54 +00:00
|
|
|
// Edition is either Community or Enterprise.
|
|
|
|
type Edition string
|
|
|
|
|
|
|
|
// Package controls feature-set within edition.
|
|
|
|
type Package string
|
|
|
|
|
|
|
|
// Plan tells us if instance if self-hosted or Documize SaaS/Cloud.
|
|
|
|
type Plan string
|
|
|
|
|
|
|
|
// Seats represents number of users.
|
|
|
|
type Seats int
|
|
|
|
|
|
|
|
const (
|
|
|
|
// CommunityEdition is AGPL licensed open core of product.
|
|
|
|
CommunityEdition Edition = "Community"
|
|
|
|
|
|
|
|
// EnterpriseEdition is proprietary closed-source product.
|
|
|
|
EnterpriseEdition Edition = "Enterprise"
|
|
|
|
|
|
|
|
// PackageEssentials provides core capabilities.
|
|
|
|
PackageEssentials Package = "Essentials"
|
|
|
|
|
|
|
|
// PackageAdvanced provides analytics, reporting,
|
|
|
|
// content lifecycle, content verisoning, and audit logs.
|
|
|
|
PackageAdvanced Package = "Advanced"
|
|
|
|
|
|
|
|
// PackagePremium provides actions, feedback capture,
|
|
|
|
// approvals workflow, secure external sharing.
|
|
|
|
PackagePremium Package = "Premium"
|
|
|
|
|
|
|
|
// PackageDataCenter provides multi-tenanting
|
|
|
|
// and a bunch of professional services.
|
|
|
|
PackageDataCenter Package = "Data Center"
|
|
|
|
|
|
|
|
// PlanCloud represents *.documize.com hosting.
|
|
|
|
PlanCloud Plan = "Cloud"
|
|
|
|
|
|
|
|
// PlanSelfHost represents privately hosted Documize instance.
|
|
|
|
PlanSelfHost Plan = "Self-host"
|
|
|
|
|
|
|
|
// Seats0 is 0 users.
|
|
|
|
Seats0 Seats = 0
|
|
|
|
|
|
|
|
// Seats1 is 10 users.
|
|
|
|
Seats1 Seats = 10
|
|
|
|
|
|
|
|
// Seats2 is 25 users.
|
|
|
|
Seats2 Seats = 25
|
|
|
|
|
|
|
|
//Seats3 is 50 users.
|
|
|
|
Seats3 Seats = 50
|
|
|
|
|
|
|
|
// Seats4 is 100 users.
|
|
|
|
Seats4 Seats = 100
|
|
|
|
|
|
|
|
//Seats5 is 250 users.
|
|
|
|
Seats5 Seats = 250
|
|
|
|
|
|
|
|
// Seats6 is unlimited.
|
|
|
|
Seats6 Seats = 9999
|
|
|
|
)
|
|
|
|
|
|
|
|
// Product provides meta information about product and licensing.
|
|
|
|
type Product struct {
|
|
|
|
Edition Edition
|
2018-10-04 21:03:47 +01:00
|
|
|
Title string
|
|
|
|
Version string
|
|
|
|
Major string
|
|
|
|
Minor string
|
|
|
|
Patch string
|
|
|
|
Revision int
|
|
|
|
License License
|
2016-07-24 14:49:40 -07:00
|
|
|
}
|
|
|
|
|
2018-10-29 16:53:54 +00:00
|
|
|
// License provides details of product license.
|
2017-02-22 20:03:40 -08:00
|
|
|
type License struct {
|
|
|
|
Name string `json:"name"`
|
|
|
|
Email string `json:"email"`
|
2018-10-29 16:53:54 +00:00
|
|
|
Edition Edition `json:"edition"`
|
|
|
|
Package Package `json:"package"`
|
|
|
|
Plan Plan `json:"plan"`
|
2017-02-22 20:03:40 -08:00
|
|
|
Start time.Time `json:"start"`
|
|
|
|
End time.Time `json:"end"`
|
2018-10-29 16:53:54 +00:00
|
|
|
Seats Seats `json:"seats"`
|
2017-02-22 20:03:40 -08:00
|
|
|
Trial bool `json:"trial"`
|
2018-10-29 16:53:54 +00:00
|
|
|
|
|
|
|
// UserCount is number of users within Documize instance by tenant.
|
|
|
|
// Provided at runtime.
|
|
|
|
UserCount map[string]int
|
2017-02-22 20:03:40 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// IsEmpty determines if we have a license.
|
|
|
|
func (l *License) IsEmpty() bool {
|
2018-10-29 16:53:54 +00:00
|
|
|
return l.Seats == Seats0 &&
|
|
|
|
len(l.Name) == 0 && len(l.Email) == 0 && l.Start.Year() == 1 && l.End.Year() == 1
|
2017-02-22 20:03:40 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Status returns formatted message stating if license is empty/populated and invalid/valid.
|
2018-10-29 16:53:54 +00:00
|
|
|
func (l *License) Status(orgID string) string {
|
2017-02-22 20:03:40 -08:00
|
|
|
lp := "populated"
|
|
|
|
if l.IsEmpty() {
|
|
|
|
lp = "empty"
|
|
|
|
}
|
|
|
|
lv := "invalid"
|
2018-10-29 16:53:54 +00:00
|
|
|
if l.IsValid(orgID) {
|
2017-02-22 20:03:40 -08:00
|
|
|
lv = "valid"
|
|
|
|
}
|
|
|
|
|
|
|
|
return fmt.Sprintf("License is %s and %s", lp, lv)
|
|
|
|
}
|
|
|
|
|
2018-10-29 16:53:54 +00:00
|
|
|
// IsValid returns if license is valid for specified tenant.
|
|
|
|
func (l *License) IsValid(orgID string) bool {
|
|
|
|
valid := false
|
|
|
|
|
|
|
|
// Community edition is always valid.
|
|
|
|
if l.Edition == CommunityEdition {
|
|
|
|
valid = true
|
|
|
|
}
|
|
|
|
|
|
|
|
// Enterprise edition is valid if subcription date is
|
|
|
|
// greater than now and we have enough users/seats.
|
|
|
|
if l.Edition == EnterpriseEdition {
|
|
|
|
if time.Now().UTC().Before(l.End) && l.UserCount[orgID] <= int(l.Seats) {
|
|
|
|
valid = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Empty means we cannot be valid
|
|
|
|
if l.IsEmpty() || len(l.UserCount) == 0 {
|
|
|
|
valid = false
|
|
|
|
}
|
|
|
|
|
|
|
|
return valid
|
2017-07-24 16:24:21 +01:00
|
|
|
}
|
|
|
|
|
2017-02-22 20:03:40 -08:00
|
|
|
// LicenseData holds encrypted data and is unpacked into License.
|
|
|
|
type LicenseData struct {
|
|
|
|
Key string `json:"key"`
|
|
|
|
Signature string `json:"signature"`
|
2016-07-24 14:49:40 -07:00
|
|
|
}
|
2018-10-29 16:53:54 +00:00
|
|
|
|
|
|
|
// LicenseUserAcount states number of active users by tenant.
|
|
|
|
type LicenseUserAcount struct {
|
|
|
|
OrgID string `json:"orgId"`
|
|
|
|
Users int `json:"users"`
|
|
|
|
}
|