mirror of
https://github.com/documize/community.git
synced 2025-07-19 05:09:42 +02:00
Require sub check
This commit is contained in:
parent
77c767a351
commit
67070c3bfc
2 changed files with 37 additions and 30 deletions
|
@ -88,30 +88,32 @@ type Product struct {
|
|||
|
||||
// IsValid returns if subscription is valid using RequestContext.
|
||||
func (p *Product) IsValid(ctx RequestContext) bool {
|
||||
// Community edition is always valid.
|
||||
if p.Edition == CommunityEdition {
|
||||
return true
|
||||
}
|
||||
|
||||
// Community edition is always valid.
|
||||
// if p.Edition == CommunityEdition {
|
||||
// return true
|
||||
// }
|
||||
|
||||
// Empty means we cannot be valid.
|
||||
if ctx.Subscription.IsEmpty() {
|
||||
return false
|
||||
}
|
||||
// if ctx.Subscription.IsEmpty() {
|
||||
// return false
|
||||
// }
|
||||
|
||||
// Enterprise edition is valid if system has loaded up user count by tenant.
|
||||
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.
|
||||
if time.Now().UTC().Before(ctx.Subscription.End) && uc <= int(ctx.Subscription.Seats) {
|
||||
return true
|
||||
}
|
||||
} else {
|
||||
// First 10 is free for Enterprise edition.
|
||||
if Seats1 == ctx.Subscription.Seats && time.Now().UTC().Before(ctx.Subscription.End) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
// 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.
|
||||
// if time.Now().UTC().Before(ctx.Subscription.End) && uc <= int(ctx.Subscription.Seats) {
|
||||
// return true
|
||||
// }
|
||||
// } else {
|
||||
// // First 10 is free for Enterprise edition.
|
||||
// if Seats1 == ctx.Subscription.Seats && time.Now().UTC().Before(ctx.Subscription.End) {
|
||||
// return true
|
||||
// }
|
||||
// }
|
||||
|
||||
return false
|
||||
// return false
|
||||
}
|
||||
|
||||
// SubscriptionData holds encrypted data and is unpacked into Subscription.
|
||||
|
|
|
@ -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))}
|
||||
} else {
|
||||
// Enterprise edition requires valid subscription data.
|
||||
if len(strings.TrimSpace(org.Subscription)) > 0 {
|
||||
sd := domain.SubscriptionData{}
|
||||
es1 := json.Unmarshal([]byte(org.Subscription), &sd)
|
||||
if es1 == nil {
|
||||
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)
|
||||
}
|
||||
}
|
||||
rc.Subscription = domain.Subscription{Edition: domain.EnterpriseEdition,
|
||||
Seats: domain.Seats6,
|
||||
Trial: false,
|
||||
Start: time.Now().UTC(),
|
||||
End: time.Now().UTC().Add(time.Hour * 24 * 7 * time.Duration(weeks))}
|
||||
// if len(strings.TrimSpace(org.Subscription)) > 0 {
|
||||
// sd := domain.SubscriptionData{}
|
||||
// es1 := json.Unmarshal([]byte(org.Subscription), &sd)
|
||||
// if es1 == nil {
|
||||
// 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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue