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
|
@ -23,6 +23,7 @@ func StripAuthSecrets(r *env.Runtime, provider, config string) string {
|
|||
switch provider {
|
||||
case auth.AuthProviderDocumize:
|
||||
return config
|
||||
|
||||
case auth.AuthProviderKeycloak:
|
||||
c := auth.KeycloakConfig{}
|
||||
err := json.Unmarshal([]byte(config), &c)
|
||||
|
@ -41,6 +42,7 @@ func StripAuthSecrets(r *env.Runtime, provider, config string) string {
|
|||
}
|
||||
|
||||
return string(j)
|
||||
|
||||
case auth.AuthProviderLDAP:
|
||||
c := auth.LDAPConfig{}
|
||||
err := json.Unmarshal([]byte(config), &c)
|
||||
|
|
|
@ -206,7 +206,7 @@ func (b backerHandler) produce(id string) (files []backupItem, err error) {
|
|||
func (b backerHandler) manifest(id string) (string, error) {
|
||||
m := m.Manifest{
|
||||
ID: id,
|
||||
Edition: b.Runtime.Product.Edition,
|
||||
Edition: b.Runtime.Product.License.Edition,
|
||||
Version: b.Runtime.Product.Version,
|
||||
Major: b.Runtime.Product.Major,
|
||||
Minor: b.Runtime.Product.Minor,
|
||||
|
|
|
@ -39,7 +39,7 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) {
|
|||
method := "block.add"
|
||||
ctx := domain.GetRequestContext(r)
|
||||
|
||||
if !h.Runtime.Product.License.IsValid() {
|
||||
if !h.Runtime.Product.License.IsValid(ctx.OrgID) {
|
||||
response.WriteBadLicense(w)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ func (h *Handler) Meta(w http.ResponseWriter, r *http.Request) {
|
|||
data.Version = h.Runtime.Product.Version
|
||||
data.Revision = h.Runtime.Product.Revision
|
||||
data.Edition = h.Runtime.Product.Edition
|
||||
data.Valid = h.Runtime.Product.License.Valid
|
||||
data.Valid = h.Runtime.Product.License.IsValid(org.RefID)
|
||||
data.ConversionEndpoint = org.ConversionEndpoint
|
||||
data.License = h.Runtime.Product.License
|
||||
data.Storage = h.Runtime.StoreProvider.Type()
|
||||
|
|
|
@ -52,7 +52,7 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) {
|
|||
method := "page.add"
|
||||
ctx := domain.GetRequestContext(r)
|
||||
|
||||
if !h.Runtime.Product.License.IsValid() {
|
||||
if !h.Runtime.Product.License.IsValid(ctx.OrgID) {
|
||||
response.WriteBadLicense(w)
|
||||
return
|
||||
}
|
||||
|
@ -322,7 +322,7 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request) {
|
|||
method := "page.update"
|
||||
ctx := domain.GetRequestContext(r)
|
||||
|
||||
if !h.Runtime.Product.License.IsValid() {
|
||||
if !h.Runtime.Product.License.IsValid(ctx.OrgID) {
|
||||
response.WriteBadLicense(w)
|
||||
return
|
||||
}
|
||||
|
@ -510,7 +510,7 @@ func (h *Handler) Delete(w http.ResponseWriter, r *http.Request) {
|
|||
method := "page.delete"
|
||||
ctx := domain.GetRequestContext(r)
|
||||
|
||||
if !h.Runtime.Product.License.IsValid() {
|
||||
if !h.Runtime.Product.License.IsValid(ctx.OrgID) {
|
||||
response.WriteBadLicense(w)
|
||||
return
|
||||
}
|
||||
|
@ -608,7 +608,7 @@ func (h *Handler) DeletePages(w http.ResponseWriter, r *http.Request) {
|
|||
method := "page.delete.pages"
|
||||
ctx := domain.GetRequestContext(r)
|
||||
|
||||
if !h.Runtime.Product.License.IsValid() {
|
||||
if !h.Runtime.Product.License.IsValid(ctx.OrgID) {
|
||||
response.WriteBadLicense(w)
|
||||
return
|
||||
}
|
||||
|
@ -721,7 +721,7 @@ func (h *Handler) ChangePageSequence(w http.ResponseWriter, r *http.Request) {
|
|||
method := "page.sequence"
|
||||
ctx := domain.GetRequestContext(r)
|
||||
|
||||
if !h.Runtime.Product.License.IsValid() {
|
||||
if !h.Runtime.Product.License.IsValid(ctx.OrgID) {
|
||||
response.WriteBadLicense(w)
|
||||
return
|
||||
}
|
||||
|
@ -791,7 +791,7 @@ func (h *Handler) ChangePageLevel(w http.ResponseWriter, r *http.Request) {
|
|||
method := "page.level"
|
||||
ctx := domain.GetRequestContext(r)
|
||||
|
||||
if !h.Runtime.Product.License.IsValid() {
|
||||
if !h.Runtime.Product.License.IsValid(ctx.OrgID) {
|
||||
response.WriteBadLicense(w)
|
||||
return
|
||||
}
|
||||
|
@ -987,7 +987,7 @@ func (h *Handler) GetDocumentRevisions(w http.ResponseWriter, r *http.Request) {
|
|||
method := "page.document.revisions"
|
||||
ctx := domain.GetRequestContext(r)
|
||||
|
||||
if !h.Runtime.Product.License.IsValid() {
|
||||
if !h.Runtime.Product.License.IsValid(ctx.OrgID) {
|
||||
response.WriteBadLicense(w)
|
||||
return
|
||||
}
|
||||
|
@ -1018,7 +1018,7 @@ func (h *Handler) GetRevisions(w http.ResponseWriter, r *http.Request) {
|
|||
method := "page.revisions"
|
||||
ctx := domain.GetRequestContext(r)
|
||||
|
||||
if !h.Runtime.Product.License.IsValid() {
|
||||
if !h.Runtime.Product.License.IsValid(ctx.OrgID) {
|
||||
response.WriteBadLicense(w)
|
||||
return
|
||||
}
|
||||
|
@ -1053,7 +1053,7 @@ func (h *Handler) GetDiff(w http.ResponseWriter, r *http.Request) {
|
|||
method := "page.diff"
|
||||
ctx := domain.GetRequestContext(r)
|
||||
|
||||
if !h.Runtime.Product.License.IsValid() {
|
||||
if !h.Runtime.Product.License.IsValid(ctx.OrgID) {
|
||||
response.WriteBadLicense(w)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !h.Runtime.Product.License.IsValid() {
|
||||
if !h.Runtime.Product.License.IsValid(ctx.OrgID) {
|
||||
response.WriteBadLicense(w)
|
||||
return
|
||||
}
|
||||
|
@ -154,7 +154,7 @@ func (h *Handler) DeleteUserPin(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !h.Runtime.Product.License.IsValid() {
|
||||
if !h.Runtime.Product.License.IsValid(ctx.OrgID) {
|
||||
response.WriteBadLicense(w)
|
||||
return
|
||||
}
|
||||
|
@ -198,7 +198,7 @@ func (h *Handler) UpdatePinSequence(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if !h.Runtime.Product.License.IsValid() {
|
||||
if !h.Runtime.Product.License.IsValid(ctx.OrgID) {
|
||||
response.WriteBadLicense(w)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) {
|
|||
method := "space.add"
|
||||
ctx := domain.GetRequestContext(r)
|
||||
|
||||
if !h.Runtime.Product.License.IsValid() {
|
||||
if !h.Runtime.Product.License.IsValid(ctx.OrgID) {
|
||||
response.WriteBadLicense(w)
|
||||
return
|
||||
}
|
||||
|
@ -582,7 +582,7 @@ func (h *Handler) Remove(w http.ResponseWriter, r *http.Request) {
|
|||
method := "space.remove"
|
||||
ctx := domain.GetRequestContext(r)
|
||||
|
||||
if !h.Runtime.Product.License.IsValid() {
|
||||
if !h.Runtime.Product.License.IsValid(ctx.OrgID) {
|
||||
response.WriteBadLicense(w)
|
||||
return
|
||||
}
|
||||
|
@ -675,7 +675,7 @@ func (h *Handler) Delete(w http.ResponseWriter, r *http.Request) {
|
|||
method := "space.delete"
|
||||
ctx := domain.GetRequestContext(r)
|
||||
|
||||
if !h.Runtime.Product.License.IsValid() {
|
||||
if !h.Runtime.Product.License.IsValid(ctx.OrgID) {
|
||||
response.WriteBadLicense(w)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
package store
|
||||
|
||||
import (
|
||||
"github.com/documize/community/core/env"
|
||||
"github.com/documize/community/domain"
|
||||
"github.com/documize/community/model/account"
|
||||
"github.com/documize/community/model/activity"
|
||||
|
@ -122,7 +123,7 @@ type UserStorer interface {
|
|||
UpdateUserPassword(ctx domain.RequestContext, userID, salt, password string) (err error)
|
||||
DeactiveUser(ctx domain.RequestContext, userID string) (err error)
|
||||
ForgotUserPassword(ctx domain.RequestContext, email, token string) (err error)
|
||||
CountActiveUsers() (c int)
|
||||
CountActiveUsers() (c []env.LicenseUserAcount)
|
||||
MatchUsers(ctx domain.RequestContext, text string, maxMatches int) (u []user.User, err error)
|
||||
}
|
||||
|
||||
|
|
|
@ -90,7 +90,7 @@ func (h *Handler) SaveAs(w http.ResponseWriter, r *http.Request) {
|
|||
method := "template.saved"
|
||||
ctx := domain.GetRequestContext(r)
|
||||
|
||||
if !h.Runtime.Product.License.IsValid() {
|
||||
if !h.Runtime.Product.License.IsValid(ctx.OrgID) {
|
||||
response.WriteBadLicense(w)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package test
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/documize/community/domain/store"
|
||||
|
||||
"github.com/documize/community/core/env"
|
||||
"github.com/documize/community/domain"
|
||||
|
@ -13,20 +14,21 @@ import (
|
|||
)
|
||||
|
||||
// SetupTest prepares test environment
|
||||
func SetupTest() (rt *env.Runtime, s *domain.Store, ctx domain.RequestContext) {
|
||||
func SetupTest() (rt *env.Runtime, s *store
|
||||
.Store, ctx domain.RequestContext) {
|
||||
rt, s = startRuntime()
|
||||
ctx = setupContext()
|
||||
return rt, s, ctx
|
||||
}
|
||||
|
||||
func startRuntime() (rt *env.Runtime, s *domain.Store) {
|
||||
func startRuntime() (rt *env.Runtime, s *store.Store) {
|
||||
rt = new(env.Runtime)
|
||||
s = new(domain.Store)
|
||||
s = new(store.Store)
|
||||
|
||||
rt.Log = logging.NewLogger(false)
|
||||
web.Embed = embed.NewEmbedder()
|
||||
|
||||
rt.Product = env.ProdInfo{}
|
||||
rt.Product = env.Product{}
|
||||
rt.Product.Major = "0"
|
||||
rt.Product.Minor = "0"
|
||||
rt.Product.Patch = "0"
|
||||
|
@ -35,9 +37,8 @@ func startRuntime() (rt *env.Runtime, s *domain.Store) {
|
|||
rt.Product.Title = fmt.Sprintf("%s Edition", rt.Product.Edition)
|
||||
rt.Product.License = env.License{}
|
||||
rt.Product.License.Seats = 1
|
||||
rt.Product.License.Valid = true
|
||||
rt.Product.License.Trial = false
|
||||
rt.Product.License.Edition = "Community"
|
||||
rt.Product.License.Edition = env.CommunityEdition
|
||||
|
||||
// parse settings from command line and environment
|
||||
rt.Flags = env.ParseFlags()
|
||||
|
@ -56,7 +57,7 @@ func setupContext() domain.RequestContext {
|
|||
ctx.Administrator = true
|
||||
ctx.Guest = false
|
||||
ctx.Editor = true
|
||||
ctx.Global = true
|
||||
ctx.GlobalAdmin = true
|
||||
ctx.UserID = "test"
|
||||
ctx.OrgID = "test"
|
||||
return ctx
|
||||
|
|
|
@ -51,7 +51,7 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) {
|
|||
method := "user.Add"
|
||||
ctx := domain.GetRequestContext(r)
|
||||
|
||||
if !h.Runtime.Product.License.IsValid() {
|
||||
if !h.Runtime.Product.License.IsValid(ctx.OrgID) {
|
||||
response.WriteBadLicense(w)
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ package user
|
|||
import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"github.com/documize/community/core/env"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
@ -312,17 +313,11 @@ func (s Store) ForgotUserPassword(ctx domain.RequestContext, email, token string
|
|||
}
|
||||
|
||||
// CountActiveUsers returns the number of active users in the system.
|
||||
func (s Store) CountActiveUsers() (c int) {
|
||||
row := s.Runtime.Db.QueryRow("SELECT count(*) FROM dmz_user WHERE c_refid IN (SELECT c_userid FROM dmz_user_account WHERE c_active=true)")
|
||||
|
||||
err := row.Scan(&c)
|
||||
if err == sql.ErrNoRows {
|
||||
return 0
|
||||
}
|
||||
func (s Store) CountActiveUsers() (c []env.LicenseUserAcount) {
|
||||
err := s.Runtime.Db.Select(&c, "SELECT c_orgid AS orgid, COUNT(*) AS users FROM dmz_user_account WHERE c_active=true GROUP BY c_orgid ORDER BY c_orgid")
|
||||
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
s.Runtime.Log.Error("CountActiveUsers", err)
|
||||
return 0
|
||||
}
|
||||
|
||||
return
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue