1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-19 13:19:43 +02:00

Require sub check

This commit is contained in:
Harvey Kandola 2022-03-17 16:31:11 -04:00
parent 77c767a351
commit 67070c3bfc
2 changed files with 37 additions and 30 deletions

View file

@ -88,30 +88,32 @@ type Product struct {
// IsValid returns if subscription is valid using RequestContext. // IsValid returns if subscription is valid using RequestContext.
func (p *Product) IsValid(ctx RequestContext) bool { func (p *Product) IsValid(ctx RequestContext) bool {
// Community edition is always valid.
if p.Edition == CommunityEdition {
return true return true
}
// Community edition is always valid.
// if p.Edition == CommunityEdition {
// return true
// }
// Empty means we cannot be valid. // Empty means we cannot be valid.
if ctx.Subscription.IsEmpty() { // if ctx.Subscription.IsEmpty() {
return false // return false
} // }
// Enterprise edition is valid if system has loaded up user count by tenant. // Enterprise edition is valid if system has loaded up user count by tenant.
if uc, ok := p.UserCount[ctx.OrgID]; ok { // if uc, ok := p.UserCount[ctx.OrgID]; ok {
// Enterprise edition is valid if subcription date is greater than now and we have enough users/seats. // // Enterprise edition is valid if subcription date is greater than now and we have enough users/seats.
if time.Now().UTC().Before(ctx.Subscription.End) && uc <= int(ctx.Subscription.Seats) { // if time.Now().UTC().Before(ctx.Subscription.End) && uc <= int(ctx.Subscription.Seats) {
return true // return true
} // }
} else { // } else {
// First 10 is free for Enterprise edition. // // First 10 is free for Enterprise edition.
if Seats1 == ctx.Subscription.Seats && time.Now().UTC().Before(ctx.Subscription.End) { // if Seats1 == ctx.Subscription.Seats && time.Now().UTC().Before(ctx.Subscription.End) {
return true // return true
} // }
} // }
return false // return false
} }
// SubscriptionData holds encrypted data and is unpacked into Subscription. // SubscriptionData holds encrypted data and is unpacked into Subscription.

View file

@ -155,18 +155,23 @@ func (m *middleware) Authorize(w http.ResponseWriter, r *http.Request, next http
End: time.Now().UTC().Add(time.Hour * 24 * 7 * time.Duration(weeks))} End: time.Now().UTC().Add(time.Hour * 24 * 7 * time.Duration(weeks))}
} else { } else {
// Enterprise edition requires valid subscription data. // Enterprise edition requires valid subscription data.
if len(strings.TrimSpace(org.Subscription)) > 0 { rc.Subscription = domain.Subscription{Edition: domain.EnterpriseEdition,
sd := domain.SubscriptionData{} Seats: domain.Seats6,
es1 := json.Unmarshal([]byte(org.Subscription), &sd) Trial: false,
if es1 == nil { Start: time.Now().UTC(),
rc.Subscription, err = domain.DecodeSubscription(sd) End: time.Now().UTC().Add(time.Hour * 24 * 7 * time.Duration(weeks))}
if err != nil { // if len(strings.TrimSpace(org.Subscription)) > 0 {
m.Runtime.Log.Error("unable to decode subscription for org "+rc.OrgID, err) // sd := domain.SubscriptionData{}
} // es1 := json.Unmarshal([]byte(org.Subscription), &sd)
} else { // if es1 == nil {
m.Runtime.Log.Error("unable to load subscription for org "+rc.OrgID, es1) // rc.Subscription, err = domain.DecodeSubscription(sd)
} // if err != nil {
} // m.Runtime.Log.Error("unable to decode subscription for org "+rc.OrgID, err)
// }
// } else {
// m.Runtime.Log.Error("unable to load subscription for org "+rc.OrgID, es1)
// }
// }
} }
// Tag all HTTP calls with subscription status // Tag all HTTP calls with subscription status