Skip to content

Commit cb9fd09

Browse files
Merge pull request #185 from documize/app-subscription
App subscription
2 parents 745e610 + 4df1574 commit cb9fd09

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1714
-1194
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ Space view.
5858

5959
## Latest version
6060

61-
[Community edition: v1.72.1](https://github.com/documize/community/releases)
61+
[Community edition: v1.73.0](https://github.com/documize/community/releases)
6262

63-
[Enterprise edition: v1.74.1](https://documize.com/downloads)
63+
[Enterprise edition: v1.75.0](https://documize.com/downloads)
6464

6565
## OS support
6666

@@ -100,7 +100,7 @@ Documize supports the following (evergreen) browsers:
100100
Documize is built with the following technologies:
101101

102102
- EmberJS (v3.1.2)
103-
- Go (v1.11.1)
103+
- Go (v1.11.2)
104104

105105
## Authentication options
106106

core/database/installer.go

+9-55
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,6 @@ func InstallUpgrade(runtime *env.Runtime, existingDB bool) (err error) {
3232
return
3333
}
3434

35-
// Filter out database specific scripts.
36-
dbTypeScripts := SpecificScripts(runtime, scripts)
37-
if len(dbTypeScripts) == 0 {
38-
runtime.Log.Info(fmt.Sprintf("Database: unable to load scripts for database type %s", runtime.StoreProvider.Type()))
39-
return
40-
}
41-
42-
runtime.Log.Info(fmt.Sprintf("Database: loaded %d SQL scripts for provider %s", len(dbTypeScripts), runtime.StoreProvider.Type()))
43-
4435
// Get current database version.
4536
currentVersion := 0
4637
if existingDB {
@@ -53,6 +44,15 @@ func InstallUpgrade(runtime *env.Runtime, existingDB bool) (err error) {
5344
runtime.Log.Info(fmt.Sprintf("Database: current version number is %d", currentVersion))
5445
}
5546

47+
// Filter out database specific scripts.
48+
dbTypeScripts := SpecificScripts(runtime, scripts)
49+
if len(dbTypeScripts) == 0 {
50+
runtime.Log.Info(fmt.Sprintf("Database: unable to load scripts for database type %s", runtime.StoreProvider.Type()))
51+
return
52+
}
53+
54+
runtime.Log.Info(fmt.Sprintf("Database: loaded %d SQL scripts for provider %s", len(dbTypeScripts), runtime.StoreProvider.Type()))
55+
5656
// Make a list of scripts to execute based upon current database state.
5757
toProcess := []Script{}
5858
for _, s := range dbTypeScripts {
@@ -90,52 +90,6 @@ func InstallUpgrade(runtime *env.Runtime, existingDB bool) (err error) {
9090
tx.Commit()
9191

9292
return nil
93-
94-
// New style schema
95-
// if existingDB {
96-
// amLeader, err = Lock(runtime, len(toProcess))
97-
// if err != nil {
98-
// runtime.Log.Error("Database: failed to lock existing database for processing", err)
99-
// }
100-
// } else {
101-
// // New installation hopes that you are only spinning up one instance of Documize.
102-
// // Assumption: nobody will perform the intial setup in a clustered environment.
103-
// amLeader = true
104-
// }
105-
106-
// tx, err := runtime.Db.Beginx()
107-
// if err != nil {
108-
// return Unlock(runtime, tx, err, amLeader)
109-
// }
110-
111-
// // If currently running process is database leader then we perform upgrade.
112-
// if amLeader {
113-
// runtime.Log.Info(fmt.Sprintf("Database: %d SQL scripts to process", len(toProcess)))
114-
115-
// err = runScripts(runtime, tx, toProcess)
116-
// if err != nil {
117-
// runtime.Log.Error("Database: error processing SQL script", err)
118-
// }
119-
120-
// return Unlock(runtime, tx, err, amLeader)
121-
// }
122-
123-
// // If currently running process is a slave instance then we wait for migration to complete.
124-
// targetVersion := toProcess[len(toProcess)-1].Version
125-
126-
// for targetVersion != currentVersion {
127-
// time.Sleep(time.Second)
128-
// runtime.Log.Info("Database: slave instance polling for upgrade process completion")
129-
// tx.Rollback()
130-
131-
// // Get database version and check again.
132-
// currentVersion, err = CurrentVersion(runtime)
133-
// if err != nil {
134-
// return Unlock(runtime, tx, err, amLeader)
135-
// }
136-
// }
137-
138-
// return Unlock(runtime, tx, nil, amLeader)
13993
}
14094

14195
// Run SQL scripts to instal or upgrade this database.
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/* community edition */
2+
3+
-- add subscription
4+
ALTER TABLE dmz_org ADD COLUMN `c_sub` JSON NULL AFTER `c_authconfig`;
5+
6+
-- deprecations
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/* community edition */
2+
3+
-- add subscription
4+
ALTER TABLE dmz_org ADD COLUMN c_sub JSON NULL;
5+
6+
-- deprecations

core/env/flags.go

+20-7
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@ import (
2525
type Flags struct {
2626
DBConn string // database connection string
2727
Salt string // the salt string used to encode JWT tokens
28-
DBType string // (optional) database type
28+
DBType string // database type
2929
SSLCertFile string // (optional) name of SSL certificate PEM file
3030
SSLKeyFile string // (optional) name of SSL key PEM file
3131
HTTPPort string // (optional) HTTP or HTTPS port
3232
ForceHTTPPort2SSL string // (optional) HTTP that should be redirected to HTTPS
3333
SiteMode string // (optional) if 1 then serve offline web page
34+
Location string // reserved
3435
}
3536

3637
// SSLEnabled returns true if both cert and key were provided at runtime.
@@ -71,8 +72,9 @@ var flagList progFlags
7172
var loadMutex sync.Mutex
7273

7374
// ParseFlags loads command line and OS environment variables required by the program to function.
74-
func ParseFlags() (f Flags) {
75-
var dbConn, dbType, jwtKey, siteMode, port, certFile, keyFile, forcePort2SSL string
75+
func ParseFlags() (f Flags, ok bool) {
76+
ok = true
77+
var dbConn, dbType, jwtKey, siteMode, port, certFile, keyFile, forcePort2SSL, location string
7678

7779
register(&jwtKey, "salt", false, "the salt string used to encode JWT tokens, if not set a random value will be generated")
7880
register(&certFile, "cert", false, "the cert.pem file used for https")
@@ -82,8 +84,11 @@ func ParseFlags() (f Flags) {
8284
register(&siteMode, "offline", false, "set to '1' for OFFLINE mode")
8385
register(&dbType, "dbtype", true, "specify the database provider: mysql|percona|mariadb|postgresql")
8486
register(&dbConn, "db", true, `'database specific connection string for example "user:password@tcp(localhost:3306)/dbname"`)
87+
register(&location, "location", false, `reserved`)
8588

86-
parse("db")
89+
if !parse("db") {
90+
ok = false
91+
}
8792

8893
f.DBConn = dbConn
8994
f.ForceHTTPPort2SSL = forcePort2SSL
@@ -94,7 +99,13 @@ func ParseFlags() (f Flags) {
9499
f.SSLKeyFile = keyFile
95100
f.DBType = strings.ToLower(dbType)
96101

97-
return f
102+
// reserved
103+
if len(location) == 0 {
104+
location = "selfhost"
105+
}
106+
f.Location = strings.ToLower(location)
107+
108+
return f, ok
98109
}
99110

100111
// register prepares flag for subsequent parsing
@@ -116,7 +127,7 @@ func register(target *string, name string, required bool, usage string) {
116127
}
117128

118129
// parse loads flags from OS environment and command line switches
119-
func parse(doFirst string) {
130+
func parse(doFirst string) (ok bool) {
120131
loadMutex.Lock()
121132
defer loadMutex.Unlock()
122133

@@ -141,10 +152,12 @@ func parse(doFirst string) {
141152
}
142153
fmt.Fprintln(os.Stderr)
143154
flag.Usage()
144-
return
155+
return false
145156
}
146157
}
147158
}
148159
}
149160
}
161+
162+
return true
150163
}

core/env/product.go

-73
This file was deleted.

core/env/runtime.go

+2-9
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
package env
1414

1515
import (
16+
"github.com/documize/community/domain"
1617
"github.com/jmoiron/sqlx"
1718
)
1819

@@ -23,7 +24,7 @@ type Runtime struct {
2324
Db *sqlx.DB
2425
StoreProvider StoreProvider
2526
Log Logger
26-
Product ProdInfo
27+
Product domain.Product
2728
}
2829

2930
const (
@@ -39,11 +40,3 @@ const (
3940
// SiteModeBadDB redirects to db-error.html page
4041
SiteModeBadDB = "3"
4142
)
42-
43-
const (
44-
// CommunityEdition is AGPL product variant
45-
CommunityEdition = "Community"
46-
47-
// EnterpriseEdition is commercial licensed product variant
48-
EnterpriseEdition = "Enterprise"
49-
)

core/uniqueid/uniqueid.go

-14
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,10 @@ package uniqueid
1414

1515
import (
1616
"github.com/documize/community/core/uniqueid/xid"
17-
"github.com/documize/community/core/uniqueid/xid16"
1817
)
1918

2019
// Generate creates a randomly generated string suitable for use as part of an URI.
2120
// It returns a string that is always 16 characters long.
2221
func Generate() string {
2322
return xid.New().String()
2423
}
25-
26-
// Generate16 creates a randomly generated 16 character length string suitable for use as part of an URI.
27-
// It returns a string that is always 16 characters long.
28-
func Generate16() string {
29-
return xid16.New().String()
30-
}
31-
32-
// beqassjmvbajrivsc0eg
33-
// beqat1bmvbajrivsc0f0
34-
35-
// beqat1bmvbajrivsc1ag
36-
// beqat1bmvbajrivsc1g0
37-
// beqat1bmvbajrivsc1ug

domain/auth/secrets.go

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ func StripAuthSecrets(r *env.Runtime, provider, config string) string {
2323
switch provider {
2424
case auth.AuthProviderDocumize:
2525
return config
26+
2627
case auth.AuthProviderKeycloak:
2728
c := auth.KeycloakConfig{}
2829
err := json.Unmarshal([]byte(config), &c)
@@ -41,6 +42,7 @@ func StripAuthSecrets(r *env.Runtime, provider, config string) string {
4142
}
4243

4344
return string(j)
45+
4446
case auth.AuthProviderLDAP:
4547
c := auth.LDAPConfig{}
4648
err := json.Unmarshal([]byte(config), &c)

domain/backup/backup.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ package backup
2121
// the file is deleted at the end of the process.
2222
//
2323
// The backup file contains a manifest file that describes the backup.
24+
//
25+
// TODO: explore writing straight to HTTP response via https://github.com/mholt/archiver
2426

2527
import (
2628
"archive/zip"
@@ -266,7 +268,10 @@ func (b backerHandler) dmzConfig(files *[]backupItem) (err error) {
266268
if err != nil {
267269
return
268270
}
269-
*files = append(*files, backupItem{Filename: "dmz_config.json", Content: content})
271+
272+
if b.Spec.SystemBackup() {
273+
*files = append(*files, backupItem{Filename: "dmz_config.json", Content: content})
274+
}
270275

271276
w := ""
272277
if !b.Spec.SystemBackup() {

domain/backup/restore.go

+11-5
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,11 @@ func (r *restoreHandler) PerformRestore(b []byte, l int64) (err error) {
136136
}
137137

138138
// Config.
139-
err = r.dmzConfig()
140-
if err != nil {
141-
return
139+
if r.Context.GlobalAdmin {
140+
err = r.dmzConfig()
141+
if err != nil {
142+
return
143+
}
142144
}
143145

144146
// Audit Log.
@@ -449,6 +451,11 @@ func (r *restoreHandler) dmzConfig() (err error) {
449451
r.Runtime.Log.Info(fmt.Sprintf("Extracted %s", filename))
450452

451453
for i := range c {
454+
// We skip database schema version setting as this varies
455+
// between database providers (e.g. MySQL v26, PostgreSQL v2).
456+
if strings.ToUpper(c[i].ConfigKey) == "META" {
457+
continue
458+
}
452459
err = r.Store.Setting.Set(c[i].ConfigKey, c[i].ConfigValue)
453460
if err != nil {
454461
err = errors.Wrap(err, fmt.Sprintf("unable to insert %s %s", filename, c[i].ConfigKey))
@@ -1644,8 +1651,7 @@ func (r *restoreHandler) dmzUser() (err error) {
16441651
err = errors.Wrap(err, fmt.Sprintf("unable to check email %s", u[i].Email))
16451652
return
16461653
}
1647-
// Existing userID from database overrides all incoming userID values
1648-
// by using remapUser().
1654+
// Existing userID from database overrides all incoming userID values by using remapUser().
16491655
if len(userID) > 0 {
16501656
r.MapUserID[u[i].RefID] = userID
16511657
insert = false

0 commit comments

Comments
 (0)