mirror of
https://github.com/documize/community.git
synced 2025-08-02 20:15:26 +02:00
Subscription checks
This commit is contained in:
parent
6e4c5194e2
commit
e116d3b000
20 changed files with 211 additions and 76 deletions
122
core/env/product.go
vendored
122
core/env/product.go
vendored
|
@ -16,9 +16,71 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
// ProdInfo describes a product
|
||||
type ProdInfo struct {
|
||||
Edition string
|
||||
// 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
|
||||
Title string
|
||||
Version string
|
||||
Major string
|
||||
|
@ -28,42 +90,66 @@ type ProdInfo struct {
|
|||
License License
|
||||
}
|
||||
|
||||
// License holds details of product license.
|
||||
// License provides details of product license.
|
||||
type License struct {
|
||||
Name string `json:"name"`
|
||||
Email string `json:"email"`
|
||||
Edition string `json:"edition"`
|
||||
Package string `json:"package"`
|
||||
Plan string `json:"plan"`
|
||||
Edition Edition `json:"edition"`
|
||||
Package Package `json:"package"`
|
||||
Plan Plan `json:"plan"`
|
||||
Start time.Time `json:"start"`
|
||||
End time.Time `json:"end"`
|
||||
Seats int `json:"seats"`
|
||||
Seats Seats `json:"seats"`
|
||||
Trial bool `json:"trial"`
|
||||
Valid bool `json:"valid"`
|
||||
|
||||
// UserCount is number of users within Documize instance by tenant.
|
||||
// Provided at runtime.
|
||||
UserCount map[string]int
|
||||
}
|
||||
|
||||
// IsEmpty determines if we have a license.
|
||||
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 == Seats0 &&
|
||||
len(l.Name) == 0 && len(l.Email) == 0 && l.Start.Year() == 1 && l.End.Year() == 1
|
||||
}
|
||||
|
||||
// Status returns formatted message stating if license is empty/populated and invalid/valid.
|
||||
func (l *License) Status() string {
|
||||
func (l *License) Status(orgID string) string {
|
||||
lp := "populated"
|
||||
if l.IsEmpty() {
|
||||
lp = "empty"
|
||||
}
|
||||
lv := "invalid"
|
||||
if l.Valid {
|
||||
if l.IsValid(orgID) {
|
||||
lv = "valid"
|
||||
}
|
||||
|
||||
return fmt.Sprintf("License is %s and %s", lp, lv)
|
||||
}
|
||||
|
||||
// IsValid returns if license is valid
|
||||
func (l *License) IsValid() bool {
|
||||
return l.Valid == true
|
||||
// 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
|
||||
}
|
||||
|
||||
// LicenseData holds encrypted data and is unpacked into License.
|
||||
|
@ -71,3 +157,9 @@ type LicenseData struct {
|
|||
Key string `json:"key"`
|
||||
Signature string `json:"signature"`
|
||||
}
|
||||
|
||||
// LicenseUserAcount states number of active users by tenant.
|
||||
type LicenseUserAcount struct {
|
||||
OrgID string `json:"orgId"`
|
||||
Users int `json:"users"`
|
||||
}
|
||||
|
|
10
core/env/runtime.go
vendored
10
core/env/runtime.go
vendored
|
@ -23,7 +23,7 @@ type Runtime struct {
|
|||
Db *sqlx.DB
|
||||
StoreProvider StoreProvider
|
||||
Log Logger
|
||||
Product ProdInfo
|
||||
Product Product
|
||||
}
|
||||
|
||||
const (
|
||||
|
@ -39,11 +39,3 @@ const (
|
|||
// SiteModeBadDB redirects to db-error.html page
|
||||
SiteModeBadDB = "3"
|
||||
)
|
||||
|
||||
const (
|
||||
// CommunityEdition is AGPL product variant
|
||||
CommunityEdition = "Community"
|
||||
|
||||
// EnterpriseEdition is commercial licensed product variant
|
||||
EnterpriseEdition = "Enterprise"
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue