Skip to content

Commit

Permalink
Merge pull request #185 from documize/app-subscription
Browse files Browse the repository at this point in the history
App subscription
  • Loading branch information
HarveyKandola authored Nov 11, 2018
2 parents 745e610 + 4df1574 commit cb9fd09
Show file tree
Hide file tree
Showing 61 changed files with 1,714 additions and 1,194 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ Space view.

## Latest version

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

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

## OS support

Expand Down Expand Up @@ -100,7 +100,7 @@ Documize supports the following (evergreen) browsers:
Documize is built with the following technologies:

- EmberJS (v3.1.2)
- Go (v1.11.1)
- Go (v1.11.2)

## Authentication options

Expand Down
64 changes: 9 additions & 55 deletions core/database/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,6 @@ func InstallUpgrade(runtime *env.Runtime, existingDB bool) (err error) {
return
}

// Filter out database specific scripts.
dbTypeScripts := SpecificScripts(runtime, scripts)
if len(dbTypeScripts) == 0 {
runtime.Log.Info(fmt.Sprintf("Database: unable to load scripts for database type %s", runtime.StoreProvider.Type()))
return
}

runtime.Log.Info(fmt.Sprintf("Database: loaded %d SQL scripts for provider %s", len(dbTypeScripts), runtime.StoreProvider.Type()))

// Get current database version.
currentVersion := 0
if existingDB {
Expand All @@ -53,6 +44,15 @@ func InstallUpgrade(runtime *env.Runtime, existingDB bool) (err error) {
runtime.Log.Info(fmt.Sprintf("Database: current version number is %d", currentVersion))
}

// Filter out database specific scripts.
dbTypeScripts := SpecificScripts(runtime, scripts)
if len(dbTypeScripts) == 0 {
runtime.Log.Info(fmt.Sprintf("Database: unable to load scripts for database type %s", runtime.StoreProvider.Type()))
return
}

runtime.Log.Info(fmt.Sprintf("Database: loaded %d SQL scripts for provider %s", len(dbTypeScripts), runtime.StoreProvider.Type()))

// Make a list of scripts to execute based upon current database state.
toProcess := []Script{}
for _, s := range dbTypeScripts {
Expand Down Expand Up @@ -90,52 +90,6 @@ func InstallUpgrade(runtime *env.Runtime, existingDB bool) (err error) {
tx.Commit()

return nil

// New style schema
// if existingDB {
// amLeader, err = Lock(runtime, len(toProcess))
// if err != nil {
// runtime.Log.Error("Database: failed to lock existing database for processing", err)
// }
// } else {
// // New installation hopes that you are only spinning up one instance of Documize.
// // Assumption: nobody will perform the intial setup in a clustered environment.
// amLeader = true
// }

// tx, err := runtime.Db.Beginx()
// if err != nil {
// return Unlock(runtime, tx, err, amLeader)
// }

// // If currently running process is database leader then we perform upgrade.
// if amLeader {
// runtime.Log.Info(fmt.Sprintf("Database: %d SQL scripts to process", len(toProcess)))

// err = runScripts(runtime, tx, toProcess)
// if err != nil {
// runtime.Log.Error("Database: error processing SQL script", err)
// }

// return Unlock(runtime, tx, err, amLeader)
// }

// // If currently running process is a slave instance then we wait for migration to complete.
// targetVersion := toProcess[len(toProcess)-1].Version

// for targetVersion != currentVersion {
// time.Sleep(time.Second)
// runtime.Log.Info("Database: slave instance polling for upgrade process completion")
// tx.Rollback()

// // Get database version and check again.
// currentVersion, err = CurrentVersion(runtime)
// if err != nil {
// return Unlock(runtime, tx, err, amLeader)
// }
// }

// return Unlock(runtime, tx, nil, amLeader)
}

// Run SQL scripts to instal or upgrade this database.
Expand Down
6 changes: 6 additions & 0 deletions core/database/scripts/mysql/db_00026.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* community edition */

-- add subscription
ALTER TABLE dmz_org ADD COLUMN `c_sub` JSON NULL AFTER `c_authconfig`;

-- deprecations
6 changes: 6 additions & 0 deletions core/database/scripts/postgresql/db_00002.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* community edition */

-- add subscription
ALTER TABLE dmz_org ADD COLUMN c_sub JSON NULL;

-- deprecations
27 changes: 20 additions & 7 deletions core/env/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ import (
type Flags struct {
DBConn string // database connection string
Salt string // the salt string used to encode JWT tokens
DBType string // (optional) database type
DBType string // database type
SSLCertFile string // (optional) name of SSL certificate PEM file
SSLKeyFile string // (optional) name of SSL key PEM file
HTTPPort string // (optional) HTTP or HTTPS port
ForceHTTPPort2SSL string // (optional) HTTP that should be redirected to HTTPS
SiteMode string // (optional) if 1 then serve offline web page
Location string // reserved
}

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

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

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

parse("db")
if !parse("db") {
ok = false
}

f.DBConn = dbConn
f.ForceHTTPPort2SSL = forcePort2SSL
Expand All @@ -94,7 +99,13 @@ func ParseFlags() (f Flags) {
f.SSLKeyFile = keyFile
f.DBType = strings.ToLower(dbType)

return f
// reserved
if len(location) == 0 {
location = "selfhost"
}
f.Location = strings.ToLower(location)

return f, ok
}

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

// parse loads flags from OS environment and command line switches
func parse(doFirst string) {
func parse(doFirst string) (ok bool) {
loadMutex.Lock()
defer loadMutex.Unlock()

Expand All @@ -141,10 +152,12 @@ func parse(doFirst string) {
}
fmt.Fprintln(os.Stderr)
flag.Usage()
return
return false
}
}
}
}
}

return true
}
73 changes: 0 additions & 73 deletions core/env/product.go

This file was deleted.

11 changes: 2 additions & 9 deletions core/env/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package env

import (
"github.com/documize/community/domain"
"github.com/jmoiron/sqlx"
)

Expand All @@ -23,7 +24,7 @@ type Runtime struct {
Db *sqlx.DB
StoreProvider StoreProvider
Log Logger
Product ProdInfo
Product domain.Product
}

const (
Expand All @@ -39,11 +40,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"
)
14 changes: 0 additions & 14 deletions core/uniqueid/uniqueid.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,10 @@ package uniqueid

import (
"github.com/documize/community/core/uniqueid/xid"
"github.com/documize/community/core/uniqueid/xid16"
)

// Generate creates a randomly generated string suitable for use as part of an URI.
// It returns a string that is always 16 characters long.
func Generate() string {
return xid.New().String()
}

// Generate16 creates a randomly generated 16 character length string suitable for use as part of an URI.
// It returns a string that is always 16 characters long.
func Generate16() string {
return xid16.New().String()
}

// beqassjmvbajrivsc0eg
// beqat1bmvbajrivsc0f0

// beqat1bmvbajrivsc1ag
// beqat1bmvbajrivsc1g0
// beqat1bmvbajrivsc1ug
2 changes: 2 additions & 0 deletions domain/auth/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion domain/backup/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ package backup
// the file is deleted at the end of the process.
//
// The backup file contains a manifest file that describes the backup.
//
// TODO: explore writing straight to HTTP response via https://github.com/mholt/archiver

import (
"archive/zip"
Expand Down Expand Up @@ -266,7 +268,10 @@ func (b backerHandler) dmzConfig(files *[]backupItem) (err error) {
if err != nil {
return
}
*files = append(*files, backupItem{Filename: "dmz_config.json", Content: content})

if b.Spec.SystemBackup() {
*files = append(*files, backupItem{Filename: "dmz_config.json", Content: content})
}

w := ""
if !b.Spec.SystemBackup() {
Expand Down
16 changes: 11 additions & 5 deletions domain/backup/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,11 @@ func (r *restoreHandler) PerformRestore(b []byte, l int64) (err error) {
}

// Config.
err = r.dmzConfig()
if err != nil {
return
if r.Context.GlobalAdmin {
err = r.dmzConfig()
if err != nil {
return
}
}

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

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

0 comments on commit cb9fd09

Please sign in to comment.