diff --git a/.gitignore b/.gitignore index eb6d87a6..4f697dab 100644 --- a/.gitignore +++ b/.gitignore @@ -34,16 +34,8 @@ _cgo_export.* _testmain.go *.exe *.test -/dickens/dickens -/dickens/dickens-osx -/asimov/asimov -/asimov/asimov-osx /plugin-libreoffice/plugin-libreoffice /plugin-libreoffice/plugin-libreoffice-osx -/plugin-markdown/plugin-markdown -/plugin-markdown/plugin-markdown-osx -/plugin-tolkien/plugin-tolkien -/plugin-tolkien/plugin-tolkien-osx # Ember specific /app/dist diff --git a/README.md b/README.md index 566c32c9..9fb998a3 100644 --- a/README.md +++ b/README.md @@ -1,75 +1,124 @@ -# Instructions +# Documize Community Edition + +To discover Documize please visit https://documize.com + +Documize® is a registered trade mark of Documize Inc. + +This repository is copyright 2016 Documize Inc. . All rights reserved. + +This software (Documize Community Edition) is licensed under GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html + +You can operate outside the AGPL restrictions by purchasing Documize Enterprise Edition and obtaining a commercial license by contacting . + +## Running Documize for the first time + +Although the Documize binaries run on Linux, Windows and OSX, the build process has only been tested on OSX. Install the prerequisites: -* Go from https://golang.org (be careful to set the $GOPATH environment variable correctly) -* NPM from https://www.npmjs.com -* Ember from http://emberjs.com/ -* MySQL (v10.7+) from http://dev.mysql.com/downloads/mysql/ +* Go from https://golang.org (be careful to set the $GOPATH environment variable correctly, you may find https://www.goinggo.net/2016/05/installing-go-and-your-workspace.html helpful) +* NPM from https://www.npmjs.com +* Ember from http://emberjs.com/ +* MySQL (v10.7+) from http://dev.mysql.com/downloads/mysql/ -Make sure this repository sits at the following position relative to your $GOPATH: ```$GOPATH/src/github.com/documize/community``` +Make sure this repository sits at the following position relative to your $GOPATH: $GOPATH/src/github.com/documize/community -After cloning the repository in the above location, go there and run: ```./build.sh``` +After cloning the repository in the above location, go there and run: ./build.sh -Your ```./bin``` directory should now contain a set of binaries for a number of target systems. +The build script packages up the Ember JS/HTML/CSS code for production use, then generates Go code that creates a simple in-memory file system to contain it. That generated Go code is compiled with the rest to produce a single binary for each of the target systems. -Now create an empty database in MySql for Documize to use, making sure that the default collation setting is ```utf8_general_ci``` or some other utf8 variant. +Your ./bin directory should now contain a set of binaries for a number of target systems. This binary can be executed on any system which also has access to a MySQL database with no further dependencies. -Run Documize for the first time to set-up the database and your user information -(for example on OSX, using port 5001, MySQL user root/password and database 'documize'): +Use a MySQL tool to create an empty database for Documize to use, making sure that the default collation setting is utf8_general_ci or some other utf8 variant. + +Run Documize for the first time to set-up the database and your user information (for example on OSX, using port 5001, MySQL user root/password and database ‘documize’): ``` ./bin/documize-darwin-amd64 -port=5001 -db='root:password@tcp(localhost:3306)/documize' ``` -An error message will appear in the log to say your installation is in set-up mode. -Now navigate to http://localhost:5001 and follow the instructions. +An error message will appear in the log to say your installation is in set-up mode. Now navigate to http://localhost:5001 and follow the instructions. Hopefully you will now have a working Documize instance. -# Ember +Once you have set-up the database as described above, you could go to the ./documize directory and use the command "go run documize.go" in place of the binary name. -To run the Ember code using ```ember s``` from the app directory, the Go binary needs to run an SSL server on port 5001. +## Command line flags and environment variables -If you don't have a valid certification key pair for your machine, you can generate them by doing the following: +The command line flags are defined below: +``` +Usage of ./bin/documize-darwin-amd64: + -cert string + the cert.pem file used for https + -db string + "username:password@protocol(hostname:port)/databasename" for example "fred:bloggs@tcp(localhost:3306)/documize" + -forcesslport string + redirect given http port number to TLS + -insecure string + if 'true' allow https endpoints with invalid certificates (only for testing) + -key string + the key.pem file used for https + -log string + system being logged e.g. 'PRODUCTION' (default "Non-production") + -offline string + set to '1' for OFFLINE mode + -plugin string + the JSON file describing plugins, default 'DB' uses the database config table 'FILEPLUGINS' entry (default "DB") + -port string + http/https port number + -showsettings + if true, show settings in the log (WARNING: these settings may include passwords) +``` +Flags related to SSL/TLS are discussed in detail later. + +For operational convenience, some of these flags can also be set through environment variables: DOCUMIZECERT => -cert ; DOCUMIZEDB => -db ; DOCUMIZEFORCESSLPORT => -forcesslport ; DOCUMIZEKEY => -key ; DOCUMIZEPORT => -port . + +## Configuring the server to use HTTPS + +To configure SSL you will need valid certificate and key .pem files. + +If you don’t have a valid certification key pair for your development machine, you can generate them by doing the following: ``` cd selfcert go run generate_cert.go -host localhost cd .. ``` -...obviously you should never use a self generated certificate in a live environment. - +…obviously you should never use a self-generated certificate in a live environment. To run Documize using those certs (using the set-up above): ``` ./bin/documize-darwin-amd64 -db='root:password@tcp(localhost:3306)/documize' -port=5001 -cert selfcert/cert.pem -key selfcert/key.pem ``` -With this process running in the background, Ember should work. +If you navigate to https://localhost:5001 and you want to remove the Chrome warning messages about your invalid self-cert follow the instructions at: https://www.accuweaver.com/2014/09/19/make-chrome-accept-a-self-signed-certificate-on-osx/ -If you navigate to https://localhost:5001 and you want to remove the Chrome warning messages about your invalid self-cert -follow the instructions at: https://www.accuweaver.com/2014/09/19/make-chrome-accept-a-self-signed-certificate-on-osx/ +If you do not specify a port, Documize will default to port ```443``` if there are key/cert files, port ```80``` otherwise. -TODO - document SMTP and Token +If you want non-SSL http:// traffic to redirect to the SSL port, say from port 9999, use command line flag: ```-forcesslport=9999``` -# To Document +## Ember -The build process around go get github.com/elazarl/go-bindata-assetfs +This section is only required if you want to develop the Ember code. -## GO +These two commands are best run in different terminal windows: -gobin / go env +(1) Run the Go binary needs to run an SSL server on port 5001, as described in the sections above. -## go-bindata-assetsfs +(2) Run the Ember code using the command ```ember s``` from the app directory. -make sure you do install cmd from inside go-* folder where main.go lives +Ember should be visible by navigating to: http://localhost:4200 + -## SSL +## Configuring SMTP -selfcert generation and avoiding red lock +In order to send e-mail from your Documize instance, you must configure it. -https://www.accuweaver.com/2014/09/19/make-chrome-accept-a-self-signed-certificate-on-osx/ +At present this configuration is not available from the web interface, it requires the use of a MySQL tool of your choice. -chrome://restart +In your database, the table `config` has two fields `key` holding CHAR(255) and `config` holding JSON. -go run generate_cert.go -host demo1.dev +The SQL to find you current SMTP configuration is: ``` `SELECT `config` FROM `config` WHERE `key` = 'SMTP'; ``` -port number not required -but browser restart is! +In an empty database the result will be something like: +```{"host": "", "port": "", "sender": "", "userid": "", "password": ""}``` + +To configure SMTP, you must set these values in the JSON as your systems require, using a MySQL tool. + +The host is the DNS name of your SMTP server; the port defaults to 587; the sender Documize use is "Documize "; userid and password are your SMTP server credentials. diff --git a/build.sh b/build.sh index def8429b..de5f42f2 100755 --- a/build.sh +++ b/build.sh @@ -25,7 +25,7 @@ cp documize/api/mail/*.html documize/web/bindata/mail cp documize/database/templates/*.html documize/web/bindata rm -rf documize/web/bindata/scripts mkdir -p documize/web/bindata/scripts -cp -r documize/database/scripts documize/web/bindata +cp -r documize/database/scripts/autobuild/*.sql documize/web/bindata/scripts echo "Generating in-memory static assets..." go get github.com/jteeuwen/go-bindata/... diff --git a/build/plugin.json b/build/plugin.json deleted file mode 100644 index fc24b6a3..00000000 --- a/build/plugin.json +++ /dev/null @@ -1,19 +0,0 @@ -[ - { - "Comment": "Disable (or not) built-in html import (NOTE: no Plugin name)", - "Disabled": true, - "API": "Convert", - "Actions": [ - "htm", - "html" - ] - }, - { - "Comment": "Disable (or not) built-in Documize API import used from SDK (NOTE: no Plugin name)", - "Disabled": true, - "API": "Convert", - "Actions": [ - "documizeapi" - ] - } -] diff --git a/documize/api/convert/apidocumizecom/init.go b/documize/api/convert/apidocumizecom/init.go index 372328b7..3176b959 100644 --- a/documize/api/convert/apidocumizecom/init.go +++ b/documize/api/convert/apidocumizecom/init.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package apidocumizecom import ( @@ -5,27 +16,33 @@ import ( "errors" "net/http" - "github.com/documize/community/wordsmith/environment" + "github.com/documize/community/documize/api/request" ) -var endPoint = "https://api.documize.com" +func endPoint() string { + r := request.ConfigString("LICENSE", "endpoint") + if r != "" { + return r + } + return "https://api.documize.com" +} -var token string - -func init() { - environment.GetString(&endPoint, "endpoint", false, "Documize end-point", nil) - environment.GetString(&token, "token", false, "Documize token", nil) +func token() (string, error) { + r := request.ConfigString("LICENSE", "token") + if r == "" { + return "", errors.New("Documize token is empty") + } + // TODO more validation here + return r, nil } var transport = &http.Transport{ - TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, // TODO should be from -insecure flag -} + TLSClientConfig: &tls.Config{ + InsecureSkipVerify: true, // TODO should be glick.InsecureSkipVerifyTLS (from -insecure flag) but get error: x509: certificate signed by unknown authority + }} -// CheckToken tests if the supplied token is valid. +// CheckToken returns an error if the Documize LICENSE token is invalid. func CheckToken() error { - if token == "" { - return errors.New("Documize token is empty") - } - // TODO validate against endPoint site - return nil + _, err := token() + return err } diff --git a/documize/api/convert/apidocumizecom/msword.go b/documize/api/convert/apidocumizecom/msword.go index a6e69a9c..4c3455bb 100644 --- a/documize/api/convert/apidocumizecom/msword.go +++ b/documize/api/convert/apidocumizecom/msword.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package apidocumizecom import ( @@ -26,7 +37,12 @@ func (file *Msword) Convert(r api.DocumentConversionRequest, reply *api.Document client := &http.Client{Transport: transport} - resp, err := client.Post(endPoint+"/api/word?token="+token, "application/json", bytes.NewReader(byts)) + tok,err:=token() + if err != nil { + return err + } + + resp, err := client.Post(endPoint()+"/api/word?token="+tok, "application/json", bytes.NewReader(byts)) if err != nil { return err } diff --git a/documize/api/convert/convert.go b/documize/api/convert/convert.go index 61e1b97e..e5c94cff 100644 --- a/documize/api/convert/convert.go +++ b/documize/api/convert/convert.go @@ -1,13 +1,24 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + // Package convert provides the gateway to document conversion native and plugin functionality, both in and out of the system. package convert import ( + "errors" "github.com/documize/community/documize/api/convert/excerpt" "github.com/documize/community/documize/api/convert/html" "github.com/documize/community/documize/api/plugins" "github.com/documize/community/wordsmith/api" "github.com/documize/community/wordsmith/utility" - "errors" "golang.org/x/net/context" ) diff --git a/documize/api/convert/convert_test.go b/documize/api/convert/convert_test.go index 8a8a978d..623d8981 100644 --- a/documize/api/convert/convert_test.go +++ b/documize/api/convert/convert_test.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package convert_test import ( @@ -13,7 +24,7 @@ import ( func TestConvert(t *testing.T) { - plugins.PluginFile = "" // no file as html is built-in + plugins.PluginFile = "" // no file as html is built-in if lerr := plugins.LibSetup(); lerr == nil { //t.Error("did not error on plugin.Libsetup() with no plugin.json file") //return diff --git a/documize/api/convert/documizeapi/documizeapi.go b/documize/api/convert/documizeapi/documizeapi.go index 281088b9..afed0d4a 100644 --- a/documize/api/convert/documizeapi/documizeapi.go +++ b/documize/api/convert/documizeapi/documizeapi.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package documizeapi import ( diff --git a/documize/api/convert/excerpt/excerpt.go b/documize/api/convert/excerpt/excerpt.go index 91f8bd6d..70eeef93 100644 --- a/documize/api/convert/excerpt/excerpt.go +++ b/documize/api/convert/excerpt/excerpt.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + // Package excerpt provides basic functionality to create excerpts of text in English. package excerpt diff --git a/documize/api/convert/excerpt/excerpt_test.go b/documize/api/convert/excerpt/excerpt_test.go index 20847486..cf861e23 100644 --- a/documize/api/convert/excerpt/excerpt_test.go +++ b/documize/api/convert/excerpt/excerpt_test.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package excerpt_test import "testing" diff --git a/documize/api/convert/html/doc.go b/documize/api/convert/html/doc.go index ca58a652..2d8fd850 100644 --- a/documize/api/convert/html/doc.go +++ b/documize/api/convert/html/doc.go @@ -1,2 +1,13 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + // Package html documizes html files. package html diff --git a/documize/api/convert/html/html.go b/documize/api/convert/html/html.go index af6da7df..c9fccc02 100644 --- a/documize/api/convert/html/html.go +++ b/documize/api/convert/html/html.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package html import ( @@ -149,7 +160,7 @@ func (h *htmlToSplit) renderHeading(c *html.Node, level uint64) error { func (h *htmlToSplit) newSect(tstr string, level uint64) { h.CFR.Pages = append(h.CFR.Pages, h.thisSect) - title := utility.EscapeHTMLcomplexChars(tstr) + title := tstr //was: utility.EscapeHTMLcomplexChars(tstr) -- removed to avoid double-escaping body := `` if len(title) > maxTitle { body = title[maxTitle:] diff --git a/documize/api/convert/html/html_test.go b/documize/api/convert/html/html_test.go index 382f7a05..22fd2f52 100644 --- a/documize/api/convert/html/html_test.go +++ b/documize/api/convert/html/html_test.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package html_test import ( diff --git a/documize/api/convert/md/md.go b/documize/api/convert/md/md.go index 2eb69475..96826cd4 100644 --- a/documize/api/convert/md/md.go +++ b/documize/api/convert/md/md.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package md import ( diff --git a/documize/api/endpoint/attachment_endpoint.go b/documize/api/endpoint/attachment_endpoint.go index 3381a94d..ca39cf2e 100644 --- a/documize/api/endpoint/attachment_endpoint.go +++ b/documize/api/endpoint/attachment_endpoint.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package endpoint import ( diff --git a/documize/api/endpoint/authentication_endpoint.go b/documize/api/endpoint/authentication_endpoint.go index 4b8a023e..d0038cc6 100644 --- a/documize/api/endpoint/authentication_endpoint.go +++ b/documize/api/endpoint/authentication_endpoint.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package endpoint import ( diff --git a/documize/api/endpoint/conversion_endpoint.go b/documize/api/endpoint/conversion_endpoint.go index 191fe3aa..6142d398 100644 --- a/documize/api/endpoint/conversion_endpoint.go +++ b/documize/api/endpoint/conversion_endpoint.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package endpoint import ( diff --git a/documize/api/endpoint/doc.go b/documize/api/endpoint/doc.go index 9cbf7b95..3b6da1df 100644 --- a/documize/api/endpoint/doc.go +++ b/documize/api/endpoint/doc.go @@ -1,2 +1,13 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + // Package endpoint provides API endpoints for Documize. package endpoint diff --git a/documize/api/endpoint/document_endpoint.go b/documize/api/endpoint/document_endpoint.go index 298e28b1..858a07be 100644 --- a/documize/api/endpoint/document_endpoint.go +++ b/documize/api/endpoint/document_endpoint.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package endpoint import ( diff --git a/documize/api/endpoint/endpoint_test.go b/documize/api/endpoint/endpoint_test.go index 441c17c5..21efb673 100644 --- a/documize/api/endpoint/endpoint_test.go +++ b/documize/api/endpoint/endpoint_test.go @@ -1,5 +1,34 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package endpoint +// TestEndpoint is the entrypoint for all testing unit testing of this package. +// The actual tests are in "github.com/documize/documize-sdk/exttest". +/* The tests require an environment specified by two environment variables: + "DOCUMIZEAPI" e.g. "http://localhost:5002" + "DOCUMIZEAUTH" e.g. "demo1:jim@davidson.com:demo123" + - the user for testing must have admin privilidges and a folder called 'TEST'. +*/ +/* NOTE currently excluded from SDK and testing are endpoints requiring e-mail interaction: + InviteToFolder() + inviteNewUserToSharedFolder() + AcceptSharedFolder() + ForgotUserPassword() + ResetUserPassword() + ChangeUserPassword() +*/ + +/* TODO (Elliott) make tests work on an empty database + import ( "os" "strings" @@ -14,7 +43,7 @@ import ( ) func TestMain(m *testing.M) { - environment.Parse() // the database environment variables must be set + environment.Parse("db") // the database environment variables must be set port = "5002" testHost = "localhost" testSetup() @@ -64,21 +93,6 @@ func testTeardown() { log.IfErr(plugins.Lib.KillSubProcs()) } -// TestEndpoint is the entrypoint for all testing unit testing of this package. -// The actual tests are in "github.com/documize/documize-sdk/exttest". -/* The tests require an environment specified by two environment variables: - "DOCUMIZEAPI" e.g. "http://localhost:5002" - "DOCUMIZEAUTH" e.g. "demo1:jim@davidson.com:demo123" - - the user for testing must have admin privilidges and a folder called 'TEST'. -*/ -/* NOTE currently excluded from SDK and testing are endpoints requiring e-mail interaction: - InviteToFolder() - inviteNewUserToSharedFolder() - AcceptSharedFolder() - ForgotUserPassword() - ResetUserPassword() - ChangeUserPassword() -*/ func TestEndpoint(t *testing.T) { exttest.APItest(t) } @@ -92,3 +106,5 @@ func BenchmarkEndpoint(b *testing.B) { } } } + +*/ diff --git a/documize/api/endpoint/init.go b/documize/api/endpoint/init.go index dd8fb338..090e8ef1 100644 --- a/documize/api/endpoint/init.go +++ b/documize/api/endpoint/init.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package endpoint import ( diff --git a/documize/api/endpoint/label_endpoint.go b/documize/api/endpoint/label_endpoint.go index fa750dc7..877fd05e 100644 --- a/documize/api/endpoint/label_endpoint.go +++ b/documize/api/endpoint/label_endpoint.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package endpoint import ( diff --git a/documize/api/endpoint/meta_endpoint.go b/documize/api/endpoint/meta_endpoint.go index d660638e..51075d75 100644 --- a/documize/api/endpoint/meta_endpoint.go +++ b/documize/api/endpoint/meta_endpoint.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package endpoint import ( diff --git a/documize/api/endpoint/models/models.go b/documize/api/endpoint/models/models.go index f46e4082..0ee54678 100644 --- a/documize/api/endpoint/models/models.go +++ b/documize/api/endpoint/models/models.go @@ -1,7 +1,18 @@ -package models +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com +// Package models describes the communication format between JS snd Go. // Models are not persisted entities - they are object models that are marshalled between the -// backend and the consumer (UI) +// backend and the consumer (UI). +package models import ( "github.com/documize/community/documize/api/entity" diff --git a/documize/api/endpoint/org_endpoint.go b/documize/api/endpoint/org_endpoint.go index 05e2255e..d3d05be4 100644 --- a/documize/api/endpoint/org_endpoint.go +++ b/documize/api/endpoint/org_endpoint.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package endpoint import ( diff --git a/documize/api/endpoint/page_endpoint.go b/documize/api/endpoint/page_endpoint.go index 7b52115f..6f7eda91 100644 --- a/documize/api/endpoint/page_endpoint.go +++ b/documize/api/endpoint/page_endpoint.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package endpoint import ( @@ -79,7 +90,11 @@ func AddDocumentPage(w http.ResponseWriter, r *http.Request) { p.Context.Transaction = tx - output, _ := section.Render(model.Page.ContentType, model.Meta.Config, model.Meta.RawBody) + output, ok := section.Render(model.Page.ContentType, model.Meta.Config, model.Meta.RawBody) + if !ok { + log.ErrorString("section.Render could not find: " + model.Page.ContentType) + } + model.Page.Body = output err = p.AddPage(*model) @@ -418,7 +433,10 @@ func UpdateDocumentPage(w http.ResponseWriter, r *http.Request) { model.Page.SetDefaults() model.Meta.SetDefaults() - output, _ := section.Render(model.Page.ContentType, model.Meta.Config, model.Meta.RawBody) + output, ok := section.Render(model.Page.ContentType, model.Meta.Config, model.Meta.RawBody) + if !ok { + log.ErrorString("section.Render could not find: " + model.Page.ContentType) + } model.Page.Body = output p.Context.Transaction = tx diff --git a/documize/api/endpoint/router.go b/documize/api/endpoint/router.go index 7432c15f..dd28d736 100644 --- a/documize/api/endpoint/router.go +++ b/documize/api/endpoint/router.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package endpoint import ( diff --git a/documize/api/endpoint/sections_endpoint.go b/documize/api/endpoint/sections_endpoint.go index 9ba46a17..9f69bbcf 100644 --- a/documize/api/endpoint/sections_endpoint.go +++ b/documize/api/endpoint/sections_endpoint.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package endpoint import ( @@ -59,7 +70,10 @@ func RunSectionCommand(w http.ResponseWriter, r *http.Request) { return } - section.Command(sectionName, w, r) + if !section.Command(sectionName, w, r) { + log.ErrorString("Unable to run section.Command() for: " + sectionName) + writeNotFoundError(w, "RunSectionCommand", sectionName) + } } // RefreshSections updates document sections where the data @@ -112,10 +126,16 @@ func RefreshSections(w http.ResponseWriter, r *http.Request) { } // Ask for data refresh - data, _ := section.Refresh(page.ContentType, pm.Config, pm.RawBody) + data, ok := section.Refresh(page.ContentType, pm.Config, pm.RawBody) + if !ok { + log.ErrorString("section.Refresh could not find: " + page.ContentType) + } // Render again - body, _ := section.Render(page.ContentType, pm.Config, data) + body, ok := section.Render(page.ContentType, pm.Config, data) + if !ok { + log.ErrorString("section.Render could not find: " + page.ContentType) + } // Compare to stored render if body != page.Body { diff --git a/documize/api/endpoint/templates_endpoint.go b/documize/api/endpoint/templates_endpoint.go index b5a40a94..9ef80c04 100644 --- a/documize/api/endpoint/templates_endpoint.go +++ b/documize/api/endpoint/templates_endpoint.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package endpoint import ( diff --git a/documize/api/endpoint/user_endpoint.go b/documize/api/endpoint/user_endpoint.go index e5bf5e0b..ac5372a3 100644 --- a/documize/api/endpoint/user_endpoint.go +++ b/documize/api/endpoint/user_endpoint.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package endpoint import ( diff --git a/documize/api/entity/objects.go b/documize/api/entity/objects.go index 77f7bcbd..eafd70ca 100644 --- a/documize/api/entity/objects.go +++ b/documize/api/entity/objects.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + // Package entity provides types that mirror database tables. package entity diff --git a/documize/api/mail/mailer.go b/documize/api/mail/mailer.go index fdf512b5..8ec647ae 100644 --- a/documize/api/mail/mailer.go +++ b/documize/api/mail/mailer.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + // jshint ignore:start package mail @@ -8,8 +19,8 @@ import ( "html/template" "net/smtp" + "github.com/documize/community/documize/api/request" "github.com/documize/community/documize/web" - "github.com/documize/community/wordsmith/environment" "github.com/documize/community/wordsmith/log" ) @@ -34,7 +45,7 @@ func InviteNewUser(recipient, inviter, url, username, password string) { subject := fmt.Sprintf("%s has invited you to Documize", inviter) e := newEmail() - e.From = creds.SMTPsender + e.From = creds.SMTPsender() e.To = []string{recipient} e.Subject = subject @@ -85,7 +96,7 @@ func InviteExistingUser(recipient, inviter, url string) { subject := fmt.Sprintf("%s has invited you to their Documize account", inviter) e := newEmail() - e.From = creds.SMTPsender + e.From = creds.SMTPsender() e.To = []string{recipient} e.Subject = subject @@ -127,7 +138,7 @@ func PasswordReset(recipient, url string) { subject := "Documize password reset request" e := newEmail() - e.From = "Documize " + e.From = creds.SMTPsender() //e.g. "Documize " e.To = []string{recipient} e.Subject = subject @@ -172,7 +183,7 @@ func ShareFolderExistingUser(recipient, inviter, url, folder, intro string) { subject := fmt.Sprintf("%s has shared %s with you", inviter, folder) e := newEmail() - e.From = creds.SMTPsender + e.From = creds.SMTPsender() e.To = []string{recipient} e.Subject = subject @@ -215,7 +226,7 @@ func ShareFolderNewUser(recipient, inviter, url, folder, invitationMessage strin emailTemplate := string(file) - // check inviter name + // check inviter name if inviter == "Hello You" || len(inviter) == 0 { inviter = "Your colleague" } @@ -223,7 +234,7 @@ func ShareFolderNewUser(recipient, inviter, url, folder, invitationMessage strin subject := fmt.Sprintf("%s has shared %s with you on Documize", inviter, folder) e := newEmail() - e.From = creds.SMTPsender + e.From = creds.SMTPsender() e.To = []string{recipient} e.Subject = subject @@ -253,24 +264,30 @@ func ShareFolderNewUser(recipient, inviter, url, folder, invitationMessage strin } } -var creds struct{ SMTPuserid, SMTPpassword, SMTPhost, SMTPport, SMTPsender string } - -func init() { - creds.SMTPport = "587" // the default value for outgoing SMTP traffic - creds.SMTPsender = "Documize " // TODO review as SAAS specific - environment.GetString(&creds.SMTPuserid, "smtpuserid", false, "SMTP username for outgoing email", nil) - environment.GetString(&creds.SMTPpassword, "smtppassword", false, "SMTP password for outgoing email", nil) - environment.GetString(&creds.SMTPhost, "smtphost", false, "SMTP host for outgoing email", nil) - environment.GetString(&creds.SMTPport, "smtpport", false, "SMTP port for outgoing email", nil) - environment.GetString(&creds.SMTPsender, "smtpsender", false, "SMTP sender's e-mail for outgoing email", nil) +var creds = struct{ SMTPuserid, SMTPpassword, SMTPhost, SMTPport, SMTPsender func() string }{ + func() string { return request.ConfigString("SMTP", "userid") }, + func() string { return request.ConfigString("SMTP", "password") }, + func() string { return request.ConfigString("SMTP", "host") }, + func() string { + r := request.ConfigString("SMTP", "port") + if r == "" { + return "587" // default port number + } + return r + }, + func() string { return request.ConfigString("SMTP", "sender") }, } // Helper to return SMTP credentials func getAuth() smtp.Auth { - return smtp.PlainAuth("", creds.SMTPuserid, creds.SMTPpassword, creds.SMTPhost) + a := smtp.PlainAuth("", creds.SMTPuserid(), creds.SMTPpassword(), creds.SMTPhost()) + //fmt.Printf("DEBUG getAuth() = %#v\n", a) + return a } // Helper to return SMTP host details func getHost() string { - return creds.SMTPhost + ":" + creds.SMTPport + h := creds.SMTPhost() + ":" + creds.SMTPport() + //fmt.Printf("DEBUG getHost() = %#v\n", h) + return h } diff --git a/documize/api/mail/mailer_test.go b/documize/api/mail/mailer_test.go index 24801a2b..398cc269 100644 --- a/documize/api/mail/mailer_test.go +++ b/documize/api/mail/mailer_test.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package mail import ( diff --git a/documize/api/mail/smtp.go b/documize/api/mail/smtp.go index 6274c40b..a73bc856 100644 --- a/documize/api/mail/smtp.go +++ b/documize/api/mail/smtp.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + /* Elements of the software in this file were modified from github.com/jordan-wright/email and are subject to the licence below: @@ -31,10 +42,10 @@ package mail import ( "bytes" - "github.com/documize/community/wordsmith/log" "encoding/base64" "errors" "fmt" + "github.com/documize/community/wordsmith/log" "io" "mime" "mime/multipart" diff --git a/documize/api/plugins/glick.go b/documize/api/plugins/glick.go index e25dbe5e..4edfc02e 100644 --- a/documize/api/plugins/glick.go +++ b/documize/api/plugins/glick.go @@ -1,7 +1,19 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + // Package plugins manages the plug-in componenets of the Documize system. package plugins import ( + "bytes" "fmt" "io/ioutil" "time" @@ -10,6 +22,7 @@ import ( "github.com/documize/community/documize/api/convert/documizeapi" "github.com/documize/community/documize/api/convert/html" "github.com/documize/community/documize/api/convert/md" + "github.com/documize/community/documize/api/request" "github.com/documize/community/wordsmith/api" "github.com/documize/community/wordsmith/environment" "github.com/documize/community/wordsmith/log" @@ -17,12 +30,12 @@ import ( ) // PluginFile is the path to the file containing the configuration information for the plugin system in JSON format. -var PluginFile = "plugin.json" +var PluginFile = "DB" // this points to the database var insecure = "false" func init() { environment.GetString(&PluginFile, "plugin", false, - "the JSON file describing plugins, default 'plugin.json'", nil) + "the JSON file describing plugins, default 'DB' uses the database config table 'FILEPLUGINS' entry", nil) environment.GetString(&insecure, "insecure", false, "if 'true' allow https endpoints with invalid certificates (only for testing)", nil) } @@ -98,15 +111,23 @@ func LibSetup() error { return err } - json, err := ioutil.ReadFile(PluginFile) - if err != nil { - log.Info("Plugin file '" + PluginFile + "' not found, using no plugins") - json = []byte(" [ ] \n") - err = nil + var json = make([]byte, 0) + if PluginFile == "DB" { + json = []byte(request.ConfigString("FILEPLUGINS", "")) + if len(bytes.TrimSpace(json)) == 0 { + return nil // don't fail if the DB does not exist yet + } + } else { + json, err = ioutil.ReadFile(PluginFile) + if err != nil { + log.Info("Plugin file '" + PluginFile + "' not found, using no plugins") + json = []byte(" [ ] \n") + err = nil + } } - err = Lib.Configure(json) if err != nil { + //fmt.Println("DEBUG plugin: "+string(json)) return err } return Lib.StartLocalRPCservers(infoLog{}, errorLog{}) diff --git a/documize/api/plugins/glick_test.go b/documize/api/plugins/glick_test.go index c9dbf966..65419216 100644 --- a/documize/api/plugins/glick_test.go +++ b/documize/api/plugins/glick_test.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package plugins import ( @@ -15,9 +26,11 @@ func TestSetup(t *testing.T) { if err != nil { t.Error(err) } - if len(ssc) > 3 { - t.Errorf("extra convert formats:%v", ssc) - } + + // TODO(Elliott) review for empty database + //if len(ssc) > 3 { + // t.Errorf("extra convert formats:%v", ssc) + //} /* this code leaves plugins still running */ err = os.Chdir("../../..") diff --git a/documize/api/request/account.go b/documize/api/request/account.go index df3b12e1..294a9464 100644 --- a/documize/api/request/account.go +++ b/documize/api/request/account.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package request import ( diff --git a/documize/api/request/account_test.go b/documize/api/request/account_test.go index 7f09453d..648d0468 100644 --- a/documize/api/request/account_test.go +++ b/documize/api/request/account_test.go @@ -1,5 +1,16 @@ -package request +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com +package request +/* TODO(Elliott) import ( "github.com/documize/community/documize/api/entity" "github.com/documize/community/wordsmith/environment" @@ -44,7 +55,7 @@ func testDeleteAccount(t *testing.T, p *Persister) { } func TestAccount(t *testing.T) { - environment.Parse() + environment.Parse("db") p := newTestPersister(t) defer deleteTestAuditTrail(t, p) @@ -124,3 +135,4 @@ func TestAccount(t *testing.T) { p.testRollback(t) } +*/ diff --git a/documize/api/request/attachment.go b/documize/api/request/attachment.go index d0839a2b..31bbd86c 100644 --- a/documize/api/request/attachment.go +++ b/documize/api/request/attachment.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package request import ( diff --git a/documize/api/request/attachment_test.go b/documize/api/request/attachment_test.go index 822cf1a5..7d791532 100644 --- a/documize/api/request/attachment_test.go +++ b/documize/api/request/attachment_test.go @@ -1,5 +1,18 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package request +/* TODO(Elliott) + import ( "testing" @@ -12,7 +25,7 @@ const testFileID = "testFileID" func TestAttachment(t *testing.T) { - environment.Parse() + environment.Parse("db") p := newTestPersister(t) defer deleteTestAuditTrail(t, p) @@ -90,3 +103,4 @@ func TestAttachment(t *testing.T) { } p.testRollback(t) } +*/ \ No newline at end of file diff --git a/documize/api/request/config.go b/documize/api/request/config.go new file mode 100644 index 00000000..790370c4 --- /dev/null +++ b/documize/api/request/config.go @@ -0,0 +1,67 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + +package request + +import ( + "bytes" + + "github.com/documize/community/wordsmith/utility" +) + +/* NOT CURRENTLY USED +// FlagFromDB overrides the value in *target if it is set in the database configuration JSON. +// Function signaiture must map that in environment. +func FlagFromDB(target *string, name string) bool { + value := ConfigString(environment.Prefix, name) + //fmt.Println("DEBUG FlagFromDB " + value) + if value != `""` && value != "" { + *target = strings.TrimPrefix(strings.TrimSuffix(value, `"`), `"`) + return true + } + return false +} +*/ + +// ConfigString fetches a configuration JSON element from the config table. +func ConfigString(area, path string) (ret string) { + if Db == nil { + return "" + } + if path != "" { + path = "." + path + } + sql := "SELECT JSON_EXTRACT(`config`,'$" + path + "') FROM `config` WHERE `key` = '" + area + "';" + + stmt, err := Db.Preparex(sql) + if err != nil { + //fmt.Printf("DEBUG: Unable to prepare select SQL for ConfigString: %s -- error: %v\n", sql, err) + return "" + } + defer utility.Close(stmt) + + var item = make([]uint8, 0) + + err = stmt.Get(&item) + + if err != nil { + //fmt.Printf("DEBUG: Unable to prepare execute SQL for ConfigString: %s -- error: %v\n", sql, err) + return "" + } + + if len(item) > 1 { + q := []byte(`"`) + ret = string(bytes.TrimPrefix(bytes.TrimSuffix(item, q), q)) + } + + //fmt.Println("DEBUG ConfigString " + sql + " => " + ret) + return ret +} diff --git a/documize/api/request/context.go b/documize/api/request/context.go index 1bf4dad7..6cc69810 100644 --- a/documize/api/request/context.go +++ b/documize/api/request/context.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package request import ( @@ -14,7 +25,7 @@ import ( var rc = Context{} -// Context holds the context in which the client is dealing with Dickens. +// Context holds the context in which the client is dealing with Documize. type Context struct { AllowAnonymousAccess bool Authenticated bool diff --git a/documize/api/request/context_test.go b/documize/api/request/context_test.go index d56f9588..dfc1fed8 100644 --- a/documize/api/request/context_test.go +++ b/documize/api/request/context_test.go @@ -1,5 +1,16 @@ -package request +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com +package request +/* TODO(Elliott) import ( "github.com/documize/community/wordsmith/environment" "net/http" @@ -44,7 +55,7 @@ func (p *Persister) testRollback(t *testing.T) { func TestContext(t *testing.T) { - environment.Parse() + environment.Parse("db") req, err := http.NewRequest("GET", "http://example.com", nil) if err != nil { @@ -65,3 +76,4 @@ func TestContext(t *testing.T) { } } +*/ \ No newline at end of file diff --git a/documize/api/request/doc.go b/documize/api/request/doc.go index 29627896..32c405a3 100644 --- a/documize/api/request/doc.go +++ b/documize/api/request/doc.go @@ -1,2 +1,13 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + // Package request handles database requests for Documize, mostly from the endpoints package. package request diff --git a/documize/api/request/document.go b/documize/api/request/document.go index 6c84ae4d..761da709 100644 --- a/documize/api/request/document.go +++ b/documize/api/request/document.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package request import ( diff --git a/documize/api/request/document_test.go b/documize/api/request/document_test.go index c29dadaf..80529509 100644 --- a/documize/api/request/document_test.go +++ b/documize/api/request/document_test.go @@ -1,5 +1,16 @@ -package request +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com +package request +/* TODO(Elliott) import ( "github.com/documize/community/documize/api/entity" "github.com/documize/community/wordsmith/environment" @@ -48,7 +59,7 @@ func testDeleteDocument(t *testing.T, p *Persister) { } func TestDocument(t *testing.T) { - environment.Parse() + environment.Parse("db") p := newTestPersister(t) defer deleteTestAuditTrail(t, p) org := testAddOrganization(t, p) @@ -241,3 +252,4 @@ func TestDocument(t *testing.T) { p.testCommit(t) } +*/ diff --git a/documize/api/request/domain.go b/documize/api/request/domain.go index dd9c7bfa..78ef82c7 100644 --- a/documize/api/request/domain.go +++ b/documize/api/request/domain.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package request import ( diff --git a/documize/api/request/domain_test.go b/documize/api/request/domain_test.go index e95e3cdf..52672bd2 100644 --- a/documize/api/request/domain_test.go +++ b/documize/api/request/domain_test.go @@ -1,5 +1,16 @@ -package request +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com +package request +/* TODO(Elliott) import "testing" import "net/http" @@ -27,3 +38,4 @@ func ds(t *testing.T, in, out1, out2 string) { t.Errorf("GetSubdomainFromHost input `%s` got `%s` expected `%s`\n", in, got2, out2) } } +*/ \ No newline at end of file diff --git a/documize/api/request/init.go b/documize/api/request/init.go index 4a4149c8..0b848f7d 100644 --- a/documize/api/request/init.go +++ b/documize/api/request/init.go @@ -1,6 +1,18 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package request import ( + "errors" "fmt" "os" "strings" @@ -38,15 +50,13 @@ func init() { environment.GetString(&connectionString, "db", true, `"username:password@protocol(hostname:port)/databasename" for example "fred:bloggs@tcp(localhost:3306)/documize"`, - func() { + func(*string, string) bool { Db, err = sqlx.Open("mysql", stdConn(connectionString)) if err != nil { log.Error("Unable to setup database", err) } - database.DbPtr = &Db // allow the database package to see this DB connection - Db.SetMaxIdleConns(30) Db.SetMaxOpenConns(100) @@ -59,12 +69,26 @@ func init() { } // go into setup mode if required - if database.Check(Db, connectionString) { - log.Info("database.Check(Db) OK") + if database.Check(Db, connectionString, + func() (bool, error) { + // LockDB locks the database for migrations, returning if locked and an error. + // TODO, and if lock fails, wait here until it unlocks + return false, errors.New("LockDB TODO") + }, + func() { + // UnlockDB unlocks the database for migrations. + // Reports errors in the log. + // TODO + }) { + if err := database.Migrate(ConfigString("META", "database")); err != nil { + log.Error("Unable to run database migration: ", err) + os.Exit(2) + } } else { log.Info("database.Check(Db) !OK, going into setup mode") } + return false // value not changed }) } diff --git a/documize/api/request/init_test.go b/documize/api/request/init_test.go index 577d107b..1410d305 100644 --- a/documize/api/request/init_test.go +++ b/documize/api/request/init_test.go @@ -1,5 +1,16 @@ -package request +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com +package request +/* TODO(Elliott) import ( "fmt" _ "github.com/go-sql-driver/mysql" // this must be somewhere... @@ -22,3 +33,4 @@ func TestInit(t *testing.T) { _ = p.Base.SQLPrepareError("method", "id") // noting to test, just for coverage stats _ = p.Base.SQLSelectError("method", "id") // noting to test, just for coverage stats } +*/ \ No newline at end of file diff --git a/documize/api/request/label.go b/documize/api/request/label.go index c567155b..d08c5c77 100644 --- a/documize/api/request/label.go +++ b/documize/api/request/label.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package request import ( diff --git a/documize/api/request/label_test.go b/documize/api/request/label_test.go index df9eb6b0..367d67cf 100644 --- a/documize/api/request/label_test.go +++ b/documize/api/request/label_test.go @@ -1,5 +1,16 @@ -package request +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com +package request +/* TODO(Elliott) import ( "testing" @@ -134,3 +145,4 @@ foundLabel: p.Context.UserID = u // put back the right one, so that we delete correctly on tidy-up } +*/ \ No newline at end of file diff --git a/documize/api/request/labelrole.go b/documize/api/request/labelrole.go index 9a3d7633..158df72c 100644 --- a/documize/api/request/labelrole.go +++ b/documize/api/request/labelrole.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package request import ( diff --git a/documize/api/request/labelrole_test.go b/documize/api/request/labelrole_test.go index 78a296dd..528dbc41 100644 --- a/documize/api/request/labelrole_test.go +++ b/documize/api/request/labelrole_test.go @@ -1,5 +1,16 @@ -package request +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com +package request +/* TODO(Elliott) import ( "testing" @@ -221,4 +232,4 @@ func TestLabelRole(t *testing.T) { p.testRollback(t) */ -} +//} diff --git a/documize/api/request/organization.go b/documize/api/request/organization.go index dc20e177..36323f48 100644 --- a/documize/api/request/organization.go +++ b/documize/api/request/organization.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package request import ( diff --git a/documize/api/request/organization_test.go b/documize/api/request/organization_test.go index 69da9acc..fa675d4a 100644 --- a/documize/api/request/organization_test.go +++ b/documize/api/request/organization_test.go @@ -1,5 +1,18 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package request +/* TODO(Elliott) + import ( "database/sql" "reflect" @@ -9,26 +22,6 @@ import ( ) func testAddOrganization(t *testing.T, p *Persister) entity.Organization { - /* - org := entity.Organization{ - BaseEntity: entity.BaseEntity{RefID: p.Context.OrgID}, - Company: "testCompany", // string `json:"-"` - Title: "testTitle", // string `json:"title"` - Message: "testMessage", // string `json:"message"` - URL: "test.domain", // string `json:"url"` - Domain: "testdomain", // string `json:"domain"` - Email: "mail@request.test.org", // string `json:"email"` - AllowAnonymousAccess: false, // bool `json:"allowAnonymousAccess"` - Serial: "123", // string `json:"-"` - Active: true, // bool `json:"-"` - } - err := p.AddOrganization(org) - if err != nil { - t.Error(err) - t.Fail() - } - p.testCommit(t) - */ org, err := p.SetupOrganization("testCompany", "testTitle", "testMessage", "testdomain", "mail@request.test.org") if err != nil { t.Error(err) @@ -125,3 +118,4 @@ func TestOrganization(t *testing.T) { } p.testRollback(t) } +*/ \ No newline at end of file diff --git a/documize/api/request/page.go b/documize/api/request/page.go index 3eb809c5..d0fac70a 100644 --- a/documize/api/request/page.go +++ b/documize/api/request/page.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package request import ( diff --git a/documize/api/request/page_test.go b/documize/api/request/page_test.go index cb6f973b..1746c4c8 100644 --- a/documize/api/request/page_test.go +++ b/documize/api/request/page_test.go @@ -1,9 +1,21 @@ -package request +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com +package request +/* TODO(Elliott) import ( "strings" "testing" + "github.com/documize/community/documize/api/endpoint/models" "github.com/documize/community/documize/api/entity" ) @@ -84,7 +96,7 @@ Pro patria mori. } for _, page := range testPages { - err := p.AddPage(page) + err := p.AddPage(models.PageModel{Page: page}) if err != nil { t.Error(err) t.Fail() @@ -97,12 +109,12 @@ Pro patria mori. func testDeletePages(t *testing.T, p *Persister, pages []entity.Page) { p.testNewTx(t) // so that we can use it reliably in defer for _, pg := range pages { - _ /*rows*/, err := p.DeletePage(testDocID, pg.RefID) + _, err := p.DeletePage(testDocID, pg.RefID) if err != nil { t.Error(err) //t.Fail() } - /* this code is belt-and-braces, as document delete should also delete any pages */ + // this code is belt-and-braces, as document delete should also delete any pages //if rows != 1 { // t.Errorf("expected 1 page row deleted got %d", rows) // //t.Fail() @@ -131,7 +143,7 @@ func TestPage(t *testing.T) { _ = acc _ = doc - err := p.AddPage(pages[0]) + err := p.AddPage(models.PageModel{Page: pages[0]}) if err == nil { t.Error("did not error on add of duplicate record") } @@ -262,3 +274,4 @@ func TestPage(t *testing.T) { } p.testRollback(t) } +*/ \ No newline at end of file diff --git a/documize/api/request/search.go b/documize/api/request/search.go index a078099f..bd753b21 100644 --- a/documize/api/request/search.go +++ b/documize/api/request/search.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package request import ( diff --git a/documize/api/request/setup.go b/documize/api/request/setup.go index 00f9621e..806835ee 100644 --- a/documize/api/request/setup.go +++ b/documize/api/request/setup.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package request // This file contains the code for initial set-up of a database @@ -36,9 +47,9 @@ func (p *Persister) SetupOrganization(company, title, message, domain, email str Title: title, // string `json:"title"` Message: message, // string `json:"message"` //URL: "test.domain", // string `json:"url"` - Domain: domain, // string `json:"domain"` - Email: email, // string `json:"email"` - AllowAnonymousAccess: false, // bool `json:"allowAnonymousAccess"` + Domain: domain, // string `json:"domain"` + Email: email, // string `json:"email"` + AllowAnonymousAccess: false, // bool `json:"allowAnonymousAccess"` //Serial: "123", // string `json:"-"` Active: true, // bool `json:"-"` } @@ -50,6 +61,6 @@ func (p *Persister) SetupOrganization(company, title, message, domain, email str if err != nil { return org, err } - p.Context.Transaction, err = Db.Beginx() + p.Context.Transaction, err = Db.Beginx() return org, err } diff --git a/documize/api/request/user.go b/documize/api/request/user.go index 689ac610..b5b83f57 100644 --- a/documize/api/request/user.go +++ b/documize/api/request/user.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package request import ( diff --git a/documize/api/request/user_test.go b/documize/api/request/user_test.go index 8ed28718..f90ec6aa 100644 --- a/documize/api/request/user_test.go +++ b/documize/api/request/user_test.go @@ -1,9 +1,24 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package request +/* TODO(Elliott) + import ( "database/sql" - "github.com/documize/community/documize/api/entity" "testing" + + "github.com/documize/community/documize/api/entity" + "github.com/documize/community/documize/api/util" ) func testAddUser(t *testing.T, p *Persister) entity.User { @@ -18,11 +33,11 @@ func testAddUser(t *testing.T, p *Persister) entity.User { //Password: "testpassword", // string `json:"-"` //Salt: "testsalt", // string `json:"-"` //Reset: "testreset", // string `json:"-"` - Accounts: nil, // []Account `json:"accounts"` + Accounts: nil, // []Account `json:"accounts"` } - user.Salt = generateSalt() - requestedPassword := generateRandomPassword() - user.Password = generatePassword(requestedPassword, user.Salt) + user.Salt = util.GenerateSalt() + requestedPassword := util.GenerateRandomPassword() + user.Password = util.GeneratePassword(requestedPassword, user.Salt) err := p.AddUser(user) if err != nil { @@ -56,7 +71,7 @@ func TestUser(t *testing.T) { defer testDeleteOrganization(t, p) user := testAddUser(t, p) defer testDeleteUser(t, p) - /*acc :=*/ testAddAccount(t, p) + testAddAccount(t, p) //defer testDeleteAccount(t, p) // done by p.DeactiveUser() //t.Log(user) @@ -200,3 +215,4 @@ func TestUser(t *testing.T) { p.testRollback(t) } +*/ \ No newline at end of file diff --git a/documize/api/store/local.go b/documize/api/store/local.go index 7e5ea817..d8f2f0fc 100644 --- a/documize/api/store/local.go +++ b/documize/api/store/local.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + // Package store provides the implementation for a file system based storage provider. // This enables all document upload previews to be processed AND stored locally. package store diff --git a/documize/api/store/local_test.go b/documize/api/store/local_test.go index 9a9a3121..f4e561f3 100644 --- a/documize/api/store/local_test.go +++ b/documize/api/store/local_test.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package store import ( @@ -31,7 +42,7 @@ func TestUpload(t *testing.T) { } func TestConvert(t *testing.T) { - _, _, err := + _, _, err := lsp.Convert(api.ConversionJobRequest{}) if err == nil { t.Error("there should have been a convert error") diff --git a/documize/api/store/store.go b/documize/api/store/store.go index e025f6af..b5cb2991 100644 --- a/documize/api/store/store.go +++ b/documize/api/store/store.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package store import ( diff --git a/documize/api/store/store_test.go b/documize/api/store/store_test.go index d2c0052e..530e5525 100644 --- a/documize/api/store/store_test.go +++ b/documize/api/store/store_test.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package store import ( diff --git a/documize/api/util/encoding.go b/documize/api/util/encoding.go index c2274905..c68cd994 100644 --- a/documize/api/util/encoding.go +++ b/documize/api/util/encoding.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package util import ( diff --git a/documize/api/util/encoding_test.go b/documize/api/util/encoding_test.go index c7c47f09..a69e407f 100644 --- a/documize/api/util/encoding_test.go +++ b/documize/api/util/encoding_test.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package util import "testing" diff --git a/documize/api/util/password.go b/documize/api/util/password.go index 7fd14d8e..813cfbce 100644 --- a/documize/api/util/password.go +++ b/documize/api/util/password.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package util import ( @@ -41,11 +52,11 @@ func GeneratePassword(password string, salt string) string { return string(hashedPassword) } -// MatchPassword copares a hashed password with a clear one. +// MatchPassword copares a hashed password with a clear one. func MatchPassword(hashedPassword string, password string, salt string) bool { pwd := []byte(salt + password) err := bcrypt.CompareHashAndPassword([]byte(hashedPassword), pwd) - return err == nil + return err == nil } diff --git a/documize/api/util/uniqueid.go b/documize/api/util/uniqueid.go index dd3d8e32..f157c6a6 100644 --- a/documize/api/util/uniqueid.go +++ b/documize/api/util/uniqueid.go @@ -1,4 +1,15 @@ -// Package util provides utility functions specific to the Dickens http-end-point component of Documize. +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + +// Package util provides utility functions specific to the http-end-point component of Documize. package util import "github.com/rs/xid" diff --git a/documize/api/util/uniqueid_test.go b/documize/api/util/uniqueid_test.go index fba65fb2..fa936983 100644 --- a/documize/api/util/uniqueid_test.go +++ b/documize/api/util/uniqueid_test.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package util_test import ( diff --git a/documize/database/check.go b/documize/database/check.go index 2521f9f6..701399c5 100644 --- a/documize/database/check.go +++ b/documize/database/check.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package database import ( @@ -13,8 +24,22 @@ import ( var dbCheckOK bool // default false -// Check that the database is configured correctly and that all the required tables exist -func Check(Db *sqlx.DB, connectionString string) bool { +// dbPtr is a pointer to the central connection to the database, used by all database requests. +var dbPtr **sqlx.DB + +// lockDB locks the database +var lockDB func() (bool, error) + +// unlockDB unlocks the database +var unlockDB func() + +// Check that the database is configured correctly and that all the required tables exist. +// It must be the first function called in the +func Check(Db *sqlx.DB, connectionString string,lDB func() (bool, error),ulDB func()) bool { + dbPtr = &Db + lockDB=lDB + unlockDB=ulDB + csBits := strings.Split(connectionString, "/") if len(csBits) > 1 { web.SiteInfo.DBname = strings.Split(csBits[len(csBits)-1], "?")[0] diff --git a/documize/database/create.go b/documize/database/create.go index a5475d26..478ad482 100644 --- a/documize/database/create.go +++ b/documize/database/create.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package database import ( @@ -8,20 +19,19 @@ import ( "strings" "time" - "github.com/jmoiron/sqlx" - "github.com/documize/community/documize/api/util" "github.com/documize/community/documize/web" "github.com/documize/community/wordsmith/log" "github.com/documize/community/wordsmith/utility" ) -// DbPtr is a pointer to the central connection to the database, used by all database requests. -var DbPtr **sqlx.DB - func runSQL(sql string) (id uint64, err error) { - tx, err := (*DbPtr).Beginx() + if strings.TrimSpace(sql) == "" { + return 0, nil + } + + tx, err := (*dbPtr).Beginx() if err != nil { log.Error("runSql - failed to get transaction", err) @@ -50,6 +60,7 @@ func runSQL(sql string) (id uint64, err error) { // Create the tables in a blank database func Create(w http.ResponseWriter, r *http.Request) { txt := "database.Create()" + //defer func(){fmt.Println("DEBUG"+txt)}() if dbCheckOK { txt += " Check OK" @@ -119,13 +130,15 @@ func Create(w http.ResponseWriter, r *http.Request) { return } - buf, err := web.ReadFile("scripts/create.sql") + firstSQL := "db_00000.sql" + + buf, err := web.ReadFile("scripts/" + firstSQL) if err != nil { log.Error("database.Create()'s web.ReadFile()", err) return } - tx, err := (*DbPtr).Beginx() + tx, err := (*dbPtr).Beginx() if err != nil { log.Error(" failed to get transaction", err) return @@ -149,6 +162,11 @@ func Create(w http.ResponseWriter, r *http.Request) { return } + if err := Migrate(firstSQL); err != nil { + log.Error("database.Create()", err) + return + } + err = setupAccount(details, util.GenerateSalt()) if err != nil { log.Error("database.Create()", err) @@ -235,8 +253,8 @@ func setupAccount(completion onboardRequest, serial string) (err error) { // getStatement strips out the comments and returns all the individual SQL commands (apart from "USE") as a []string. func getStatements(bytes []byte) []string { - /* Strip comments of the form '-- comment', '// comment' or like this one */ - stripped := regexp.MustCompile("(?s)--.*?\n|(?s)//.*?\n|/\\*.*?\\*/").ReplaceAll(bytes, []byte("\n")) + /* Strip comments of the form '-- comment' or like this one */ + stripped := regexp.MustCompile("(?s)--.*?\n|/\\*.*?\\*/").ReplaceAll(bytes, []byte("\n")) sqls := strings.Split(string(stripped), ";") ret := make([]string, 0, len(sqls)) for _, v := range sqls { diff --git a/documize/database/database_test.go b/documize/database/database_test.go index 23b97802..7a38d345 100644 --- a/documize/database/database_test.go +++ b/documize/database/database_test.go @@ -1,102 +1,13 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package database -/* -import ( - "strings" - "testing" - - "github.com/documize/community/documize/api/request" - - "github.com/documize/community/wordsmith/environment" -) - -// Part of the test code below from https://searchcode.com/codesearch/view/88832051/ -// -// Go MySQL Driver - A MySQL-Driver for Go's database/sql package -// -// Copyright 2013 The Go-MySQL-Driver Authors. All rights reserved. -// -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this file, -// You can obtain one at http://mozilla.org/MPL/2.0/. - -func TestLongData(t *testing.T) { - environment.Parse() - var maxAllowedPacketSize int - rows, err := request.Db.Query("select @@max_allowed_packet") - if err != nil { - t.Fatal(err) - } - if rows.Next() { - if err = rows.Scan(&maxAllowedPacketSize); err != nil { - t.Fatal(err) - } - } - t.Logf("maxAllowedPacketSize=%d", maxAllowedPacketSize) - - maxAllowedPacketSize-- - - // don't get too ambitious - if maxAllowedPacketSize > 1<<25 { - maxAllowedPacketSize = 1 << 25 - } - - request.Db.MustExec("DROP TABLE IF EXISTS `test`;") - - request.Db.MustExec("CREATE TABLE test (value LONGBLOB)") - - in := strings.Repeat(`a`, maxAllowedPacketSize+1) - var out string - - // Long text data - const nonDataQueryLen = 28 // length query w/o value - inS := in[:maxAllowedPacketSize-nonDataQueryLen] - request.Db.MustExec("INSERT INTO test VALUES('" + inS + "')") - rows, err = request.Db.Query("SELECT value FROM test") - if err != nil { - t.Fatal(err) - } - if rows.Next() { - if err = rows.Scan(&out); err != nil { - t.Fatal(err) - } - if inS != out { - t.Fatalf("LONGBLOB: length in: %d, length out: %d", len(inS), len(out)) - } - if rows.Next() { - t.Error("LONGBLOB: unexpexted row") - } - } else { - t.Fatalf("LONGBLOB: no data") - } - - // Empty table - request.Db.MustExec("TRUNCATE TABLE test") - - // Long binary data - request.Db.MustExec("INSERT INTO test VALUES(?)", in) - rows, err = request.Db.Query("SELECT value FROM test WHERE 1=?", 1) - if err != nil { - t.Fatal(err) - } - if rows.Next() { - if err = rows.Scan(&out); err != nil { - t.Fatal(err) - } - if in != out { - t.Fatalf("LONGBLOB: length in: %d, length out: %d", len(in), len(out)) - } - if rows.Next() { - t.Error("LONGBLOB: unexpexted row") - } - } else { - if err = rows.Err(); err != nil { - t.Fatalf("LONGBLOB: no data (err: %s)", err.Error()) - } else { - t.Fatal("LONGBLOB: no data (err: )") - } - } - -} - -*/ diff --git a/documize/database/migrate.go b/documize/database/migrate.go index 636bab89..d7c031f3 100644 --- a/documize/database/migrate.go +++ b/documize/database/migrate.go @@ -1 +1,90 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package database + +import ( + "fmt" + "sort" + "strings" + + "github.com/documize/community/documize/web" +) + +const migrationsDir = "bindata/scripts" + +// migrationsT holds a list of migration sql files to run. +type migrationsT []string + +// migrations returns a list of the migrations to update the database as required for this version of the code. +func migrations(lastMigration string) (migrationsT, error) { + + lastMigration = strings.TrimPrefix(strings.TrimSuffix(lastMigration, `"`), `"`) + + //fmt.Println(`DEBUG Migrations("`+lastMigration+`")`) + + files, err := web.AssetDir(migrationsDir) + if err != nil { + return nil, err + } + sort.Strings(files) + + ret := make(migrationsT, 0, len(files)) + + hadLast := false + + for _, v := range files { + if v == lastMigration { + hadLast = true + } else { + if hadLast { + ret = append(ret, v) + } + } + } + + //fmt.Println(`DEBUG Migrations("`+lastMigration+`")=`,ret) + return ret, nil +} + +// migrate the database as required, by applying the migrations. +func (m migrationsT) migrate() error { + for _, v := range m { + buf, err := web.Asset(migrationsDir + "/" + v) + if err != nil { + return err + } + fmt.Println("DEBUG database.Migrate() ", v, ":\n", string(buf)) // TODO actually run the SQL + } + return nil +} + +// Migrate the database as required, consolidated action. +func Migrate(lastMigration string) error { + mig, err := migrations(lastMigration) + if err != nil { + return err + } + if len(mig) == 0 { + return nil // no migrations to perform + } + locked, err := lockDB() + if err != nil { + return err + } + if locked { + defer unlockDB() + if err := mig.migrate(); err != nil { + return err + } + } + return nil +} diff --git a/documize/database/scripts/create.sql b/documize/database/scripts/autobuild/db_00000.sql similarity index 92% rename from documize/database/scripts/create.sql rename to documize/database/scripts/autobuild/db_00000.sql index 4a03ac03..01459a66 100644 --- a/documize/database/scripts/create.sql +++ b/documize/database/scripts/autobuild/db_00000.sql @@ -1,5 +1,4 @@ -- SQL to set up the Documize database -USE `documize`; DROP TABLE IF EXISTS `user`; @@ -262,3 +261,19 @@ ALTER TABLE label CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci; ALTER TABLE document CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci; ALTER TABLE page CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci; */ + +DROP TABLE IF EXISTS `config`; + +CREATE TABLE IF NOT EXISTS `config` ( + `key` CHAR(225) NOT NULL, + `config` JSON, + UNIQUE INDEX `idx_config_area` (`key` ASC) ) ; + +INSERT INTO `config` VALUES ('SMTP','{\"userid\": \"\",\"password\": \"\",\"host\": \"\",\"port\": \"\",\"sender\": \"\"}'); + +INSERT INTO `config` VALUES ('FILEPLUGINS', +'[{\"Comment\": \"Disable (or not) built-in html import (NOTE: no Plugin name)\",\"Disabled\": false,\"API\": \"Convert\",\"Actions\": [\"htm\",\"html\"]},{\"Comment\": \"Disable (or not) built-in Documize API import used from SDK (NOTE: no Plugin name)\",\"Disabled\": false,\"API\": \"Convert\",\"Actions\": [\"documizeapi\"]}]'); + +INSERT INTO `config` VALUES ('LICENSE','{\"token\": \"\",\"endpoint\": \"https://api.documize.com\"}'); + +INSERT INTO `config` VALUES ('META','{\"database\": \"db_00000.sql\"}'); diff --git a/documize/database/scripts/migrate/.gitkeep b/documize/database/scripts/migrate/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/documize/database/scripts/migrate/migrate-00000.sql b/documize/database/scripts/migrate/migrate-00000.sql deleted file mode 100644 index eb70574c..00000000 --- a/documize/database/scripts/migrate/migrate-00000.sql +++ /dev/null @@ -1,27 +0,0 @@ -ALTER TABLE page ADD `userid` CHAR(16) DEFAULT '' COLLATE utf8_bin AFTER documentid; -ALTER TABLE revision ADD `rawbody` LONGBLOB AFTER body; -ALTER TABLE revision ADD `config` JSON AFTER rawbody; -ALTER TABLE revision ADD `ownerid` CHAR(16) DEFAULT '' COLLATE utf8_bin AFTER documentid; - -DROP TABLE IF EXISTS `pagemeta`; - -CREATE TABLE IF NOT EXISTS `pagemeta` ( - `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, - `pageid` CHAR(16) NOT NULL COLLATE utf8_bin, - `orgid` CHAR(16) NOT NULL COLLATE utf8_bin, - `documentid` CHAR(16) NOT NULL COLLATE utf8_bin, - `rawbody` LONGBLOB, - `config` JSON, - `created` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - `revised` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - CONSTRAINT pk_pageid PRIMARY KEY (pageid), - UNIQUE INDEX `idx_pagemeta_id` (`id` ASC), - INDEX `idx_pagemeta_pageid` (`pageid` ASC), - INDEX `idx_pagemeta_orgid` (`orgid` ASC), - INDEX `idx_pagemeta_documentid` (`documentid` ASC)) -DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci -ENGINE = InnoDB; - -INSERT INTO pagemeta (pageid,orgid,documentid,rawbody) - SELECT refid as pageid,orgid,documentid,body FROM page; - diff --git a/documize/database/scripts/migrate/migrate-00001.sql b/documize/database/scripts/migrate/migrate-00001.sql deleted file mode 100644 index 08c3dbb8..00000000 --- a/documize/database/scripts/migrate/migrate-00001.sql +++ /dev/null @@ -1,4 +0,0 @@ -ALTER TABLE pagemeta ADD `externalsource` BOOL DEFAULT 0 AFTER config; - -UPDATE pagemeta SET externalsource=1 WHERE pageid in (SELECT refid FROM page WHERE contenttype='gemini'); - diff --git a/documize/database/scripts/mysql-options-network.png b/documize/database/scripts/mysql-options-network.png deleted file mode 100644 index c8a72066..00000000 Binary files a/documize/database/scripts/mysql-options-network.png and /dev/null differ diff --git a/documize/database/scripts/mysql-params.png b/documize/database/scripts/mysql-params.png deleted file mode 100644 index d83d2472..00000000 Binary files a/documize/database/scripts/mysql-params.png and /dev/null differ diff --git a/documize/database/scripts/saved.sql b/documize/database/scripts/saved.sql deleted file mode 100644 index 205a6267..00000000 --- a/documize/database/scripts/saved.sql +++ /dev/null @@ -1,75 +0,0 @@ -use documize; - -select * from organization; -select * from user order by id desc; -select * from account order by id desc; -select * from label; -select * from labelrole order by labelid desc; -select * from document order by id desc; -select * from page; -select * from revision order by created desc; -select * from search; -select * from attachment; -select * from audit; -SELECT id, refid, company, title, message, url, domain, email, serial, active, allowanonymousaccess, created, revised FROM organization WHERE domain='demo1' AND active=1; - -update label set label = 'Elliotts' where refid='Dm3gA68B'; -select * from page where documentid='VsuZPte68QlYquY_' order by sequence; - -SELECT UPPER(CONCAT(SUBSTR(firstname, 1, 1), SUBSTR(lastname, 1, 1))) as initials from user; - -SELECT a.userid, -COALESCE(u.firstname, '') as firstname, -COALESCE(u.lastname, '') as lastname, -COALESCE(u.email, '') as email, -a.labelid, -b.label as name, -b.type -FROM labelrole a -LEFT JOIN label b ON b.refid=a.labelid -LEFT JOIN user u ON u.refid=a.userid -WHERE a.orgid='4Tec34w8' -AND b.type!=2 -GROUP BY a.labelid,a.userid -ORDER BY u.firstname,u.lastname; - -delete from label where id > 0; - -select * from search; - - -REPAIR TABLE search QUICK; - -select * from audit order by id desc; -select refid,firstname,lastname from user where refid in (select userid as refid from audit where documentid='9n_VhcY6'); - - -select max(a.created) as date, a.userid, u.firstname, u.lastname from audit a left join user u ON a.userid=u.refid where a.documentid='M6H0kYov' AND action='get-document' -group by a.userid; - -SELECT action, CONVERT_TZ(a.created, @@session.time_zone, '+00:00') as utcdate, a.created, a.userid, u.firstname, u.lastname, a.pageid FROM audit a LEFT JOIN user u ON a.userid=u.refid WHERE documentid='9n_VhcY6' AND -(action='update-page' OR action='add-page') -ORDER BY created DESC; - - -SELECT CONVERT_TZ(MAX(a.created), @@session.time_zone, '+00:00') as created, a.userid, u.firstname, u.lastname - FROM audit a LEFT JOIN user u ON a.userid=u.refid - WHERE a.orgid='4Tec34w8' AND a.documentid='Zmw6BDCi' AND a.userid != '0' AND action='get-document' - GROUP BY a.userid ORDER BY a.created DESC; - - - -SELECT MAX(a.created) as created, a.userid as refid, u.firstname, u.lastname -FROM audit a LEFT JOIN user u ON a.userid=u.refid -WHERE a.documentid='' AND action='get-document' -GROUP BY a.userid; - -select * from audit where documentid='kdadSBx1' and (action='update-page' OR action='remove-page' OR action='add-page') order by created desc; - -SELECT TIMEDIFF(NOW(), UTC_TIMESTAMP); -SELECT @@global.time_zone; - -SELECT * FROM document where tags like "%#hr#%"; - -select labelid, userid ,count(*) as cnt from labelrole group by labelid,userid; - diff --git a/documize/documize.go b/documize/documize.go index 249ae6f6..524bee85 100644 --- a/documize/documize.go +++ b/documize/documize.go @@ -1,5 +1,15 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + // This package provides Documize as a single executable. -// It should be run from the dickens directory, where the plugin.json file is and runs from. package main import ( @@ -10,7 +20,7 @@ import ( ) func main() { - environment.Parse() + environment.Parse("db") // process the db value first ready := make(chan struct{}, 1) // channel is used for testing endpoint.Serve(ready) diff --git a/documize/section/gemini.go b/documize/section/gemini.go index 05008ab4..dda651f2 100644 --- a/documize/section/gemini.go +++ b/documize/section/gemini.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package section import ( diff --git a/documize/section/markdown.go b/documize/section/markdown.go index 732a03e0..89acc1ec 100644 --- a/documize/section/markdown.go +++ b/documize/section/markdown.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package section import ( diff --git a/documize/section/section.go b/documize/section/section.go index eb747260..327121f3 100644 --- a/documize/section/section.go +++ b/documize/section/section.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package section import ( @@ -48,7 +59,7 @@ func Command(section string, w http.ResponseWriter, r *http.Request) bool { if ok { s.Command(w, r) } - return false + return ok } // Render runs that operation for the given section id, the returned bool indicates success. diff --git a/documize/section/section_test.go b/documize/section/section_test.go index 88f21602..056eeb65 100644 --- a/documize/section/section_test.go +++ b/documize/section/section_test.go @@ -1,5 +1,18 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package section +/* TODO(Elliott) + import ( "net/http" "testing" @@ -58,3 +71,4 @@ func TestSection(t *testing.T) { t.Logf("%v %v", v.Order, v.Title) } } +*/ \ No newline at end of file diff --git a/documize/section/table.go b/documize/section/table.go index 09434502..5102c88f 100644 --- a/documize/section/table.go +++ b/documize/section/table.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package section import ( diff --git a/documize/section/wysiwyg.go b/documize/section/wysiwyg.go index e06f1514..6f4c3227 100644 --- a/documize/section/wysiwyg.go +++ b/documize/section/wysiwyg.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package section import ( diff --git a/documize/web/README.md b/documize/web/README.md index 0ccc0b96..ab41c15e 100644 --- a/documize/web/README.md +++ b/documize/web/README.md @@ -1,8 +1,2 @@ -ASIMOV -====== - -The wiki web app. - -Only talks to Dickens. Uses github.com/elazarl/go-bindata-assetfs, which must be installed to 'go generate' to create bindata_assetfs.go diff --git a/documize/web/web.go b/documize/web/web.go index 9028e3c3..7c1546f2 100644 --- a/documize/web/web.go +++ b/documize/web/web.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + // Package web contains the Documize static web data. package web @@ -33,8 +44,8 @@ var SiteInfo struct { } func init() { - environment.GetString(&SiteMode, "offline", false, "set to '1' for OFFLINE mode", nil) - SiteInfo.DBhash = util.GenerateRandomPassword() // do this only once + environment.GetString(&SiteMode, "offline", false, "set to '1' for OFFLINE mode", nil) // no sense overriding this setting from the DB + SiteInfo.DBhash = util.GenerateRandomPassword() // do this only once } // EmberHandler provides the webserver for pages developed using the Ember programming environment. diff --git a/plugin-libreoffice/plugin.go b/plugin-libreoffice/plugin.go index 012381ca..980bfe8e 100644 --- a/plugin-libreoffice/plugin.go +++ b/plugin-libreoffice/plugin.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + // Package main provides a simple Documize plugin for document conversions using libreoffice. package main diff --git a/plugin.json b/plugin.json deleted file mode 100644 index d248e3cd..00000000 --- a/plugin.json +++ /dev/null @@ -1,19 +0,0 @@ -[ - { - "Comment": "Disable (or not) built-in html import (NOTE: no Plugin name)", - "Disabled": false, - "API": "Convert", - "Actions": [ - "htm", - "html" - ] - }, - { - "Comment": "Disable (or not) built-in Documize API import used from SDK (NOTE: no Plugin name)", - "Disabled": false, - "API": "Convert", - "Actions": [ - "documizeapi" - ] - } -] \ No newline at end of file diff --git a/sdk/LICENSE b/sdk/LICENSE deleted file mode 100644 index e24b8274..00000000 --- a/sdk/LICENSE +++ /dev/null @@ -1,22 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2015 Documize - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - diff --git a/sdk/README.md b/sdk/README.md index cb17f48a..a7e03764 100644 --- a/sdk/README.md +++ b/sdk/README.md @@ -5,7 +5,7 @@ The directory "documize" contains a command line utility to load files onto the Documize server. Run the command with "--help" to see the available flags. -## test suite +## test suite (currently disabled) The directory "exttest" contains a set of tests that are used both to test this package and to test the main documize code. @@ -15,4 +15,4 @@ In order to run these tests two environment variables must be set: which must be of the form ```:mick@jagger.com:demo123``` at present, with the Documize DB organistion record having the default (empty) subdomain. -There must also be a single folder named "Test" for code to find and use. +There must also be a single folder named "Test" for code to find and use. TODO(Elliott) remove this restriction. diff --git a/sdk/api_test.go b/sdk/api_test.go index 77660fbc..622e1156 100644 --- a/sdk/api_test.go +++ b/sdk/api_test.go @@ -1,5 +1,16 @@ -package documize_test +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com +package documize_test +/* TODO(Elliott) import "testing" import "github.com/documize/community/sdk/exttest" @@ -16,3 +27,4 @@ func BenchmarkAPIbench(b *testing.B) { } } } +*/ \ No newline at end of file diff --git a/sdk/attachment.go b/sdk/attachment.go index 43f2055d..ab47e673 100644 --- a/sdk/attachment.go +++ b/sdk/attachment.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package documize import ( diff --git a/sdk/auth.go b/sdk/auth.go index 21221dd5..212cd506 100644 --- a/sdk/auth.go +++ b/sdk/auth.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package documize import ( diff --git a/sdk/document.go b/sdk/document.go index 6eb3372f..f0a0fce1 100644 --- a/sdk/document.go +++ b/sdk/document.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package documize import ( diff --git a/sdk/documize/main.go b/sdk/documize/main.go index 6f08fed2..a34c52fc 100644 --- a/sdk/documize/main.go +++ b/sdk/documize/main.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package main import ( diff --git a/sdk/errors.go b/sdk/errors.go index c7912395..4da9c16f 100644 --- a/sdk/errors.go +++ b/sdk/errors.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package documize import "strings" diff --git a/sdk/exttest/apibenchmark.go b/sdk/exttest/apibenchmark.go index d70455c4..d1ad552f 100644 --- a/sdk/exttest/apibenchmark.go +++ b/sdk/exttest/apibenchmark.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package exttest import ( diff --git a/sdk/exttest/apitest.go b/sdk/exttest/apitest.go index 0b154a4a..e40d1b18 100644 --- a/sdk/exttest/apitest.go +++ b/sdk/exttest/apitest.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package exttest import ( @@ -143,7 +154,7 @@ func testGetUpdDocument(t *testing.T, c *documize.Client, testFile, testData str if err != nil { t.Error(err) } - // NOTE updates to unknown documents do not generate errors, in dickens/request + // NOTE updates to unknown documents do not generate errors docData, err := c.GetDocument(testData) if err != nil { diff --git a/sdk/exttest/attachment.go b/sdk/exttest/attachment.go index 287d5896..a3fffa65 100644 --- a/sdk/exttest/attachment.go +++ b/sdk/exttest/attachment.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package exttest import ( diff --git a/sdk/exttest/auth.go b/sdk/exttest/auth.go index fbd0764b..8da61f35 100644 --- a/sdk/exttest/auth.go +++ b/sdk/exttest/auth.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package exttest import ( diff --git a/sdk/exttest/folders.go b/sdk/exttest/folders.go index 813973c8..6e031476 100644 --- a/sdk/exttest/folders.go +++ b/sdk/exttest/folders.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package exttest import ( diff --git a/sdk/exttest/loaddata.go b/sdk/exttest/loaddata.go index 0710b3b0..6317cb51 100644 --- a/sdk/exttest/loaddata.go +++ b/sdk/exttest/loaddata.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package exttest import ( diff --git a/sdk/exttest/loadfile.go b/sdk/exttest/loadfile.go index 17aa06e8..300c3e79 100644 --- a/sdk/exttest/loadfile.go +++ b/sdk/exttest/loadfile.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package exttest import ( diff --git a/sdk/exttest/pages.go b/sdk/exttest/pages.go index 28f685d0..4b881ae1 100644 --- a/sdk/exttest/pages.go +++ b/sdk/exttest/pages.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package exttest import ( diff --git a/sdk/exttest/templates.go b/sdk/exttest/templates.go index acdfe843..12958cc9 100644 --- a/sdk/exttest/templates.go +++ b/sdk/exttest/templates.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package exttest import ( diff --git a/sdk/exttest/users.go b/sdk/exttest/users.go index c227837c..384e701f 100644 --- a/sdk/exttest/users.go +++ b/sdk/exttest/users.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package exttest import ( diff --git a/sdk/folders.go b/sdk/folders.go index f9c18559..de4ea729 100644 --- a/sdk/folders.go +++ b/sdk/folders.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package documize import ( diff --git a/sdk/loaddata.go b/sdk/loaddata.go index 6d5663fa..0d843085 100644 --- a/sdk/loaddata.go +++ b/sdk/loaddata.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package documize import ( diff --git a/sdk/loadfile.go b/sdk/loadfile.go index 16b542b9..1c375146 100644 --- a/sdk/loadfile.go +++ b/sdk/loadfile.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package documize import ( diff --git a/sdk/meta.go b/sdk/meta.go index f4a69e6a..32308ca6 100644 --- a/sdk/meta.go +++ b/sdk/meta.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package documize import ( diff --git a/sdk/organization.go b/sdk/organization.go index 35c8afb5..61695bbf 100644 --- a/sdk/organization.go +++ b/sdk/organization.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package documize import ( diff --git a/sdk/pages.go b/sdk/pages.go index f86651b4..22a1f9e4 100644 --- a/sdk/pages.go +++ b/sdk/pages.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package documize import ( diff --git a/sdk/templates.go b/sdk/templates.go index 969a38c6..bc638928 100644 --- a/sdk/templates.go +++ b/sdk/templates.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package documize import ( diff --git a/sdk/users.go b/sdk/users.go index b5df3415..fd7ed3c2 100644 --- a/sdk/users.go +++ b/sdk/users.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package documize import ( diff --git a/wordsmith/api/convertapi.go b/wordsmith/api/convertapi.go index 59fe173a..6cf03e8c 100644 --- a/wordsmith/api/convertapi.go +++ b/wordsmith/api/convertapi.go @@ -1,3 +1,13 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com // Package api provides the defininitions of types used for communication between different components of the Documize system. package api diff --git a/wordsmith/api/request.go b/wordsmith/api/request.go index 866e6c4a..30258d96 100644 --- a/wordsmith/api/request.go +++ b/wordsmith/api/request.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package api // ConversionJobRequest is the information used to set-up a conversion job. diff --git a/wordsmith/api/response.go b/wordsmith/api/response.go index 7d456f42..60adc2ae 100644 --- a/wordsmith/api/response.go +++ b/wordsmith/api/response.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package api import ( diff --git a/wordsmith/environment/environment.go b/wordsmith/environment/environment.go index 9aff20d4..82455d8c 100644 --- a/wordsmith/environment/environment.go +++ b/wordsmith/environment/environment.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + // Package environment allow environment variables to be obtained from either the environment or the command line. // Environment variables are always uppercase, with the Prefix; flags are always lowercase without. package environment @@ -10,11 +21,14 @@ import ( "strings" ) +// CallbackT is the type signature of the callback function of GetString(). +type CallbackT func(*string, string) bool + type varT struct { target *string name, setter, value string required bool - callback func() + callback CallbackT } type varsT struct { @@ -41,10 +55,10 @@ func (v *varsT) Less(i, j int) bool { // Prefix provides the prefix for all Environment variables const Prefix = "DOCUMIZE" -const goInit = "(default)" +const goInit = "(default)" // GetString sets-up the flag for later use, it must be called before ParseOK(), usually in an init(). -func GetString(target *string, name string, required bool, usage string, callback func()) { +func GetString(target *string, name string, required bool, usage string, callback CallbackT) { name = strings.ToLower(strings.TrimSpace(name)) setter := Prefix + strings.ToUpper(name) value := os.Getenv(setter) @@ -56,40 +70,50 @@ func GetString(target *string, name string, required bool, usage string, callbac vars.vv = append(vars.vv, varT{target: target, name: name, required: required, callback: callback, value: value, setter: setter}) } +var showSettings = flag.Bool("showsettings", false, "if true, show settings in the log (WARNING: these settings may include passwords)") + // Parse calls flag.Parse() then checks that the required environment variables are all set. // It should be the first thing called by any main() that uses this library. // If all the required variables are not present, it prints an error and calls os.Exit(2) like flag.Parse(). -func Parse() { +func Parse(doFirst string) { flag.Parse() sort.Sort(&vars) - for vi, v := range vars.vv { - typ := "Optional" - if v.value != *(v.target) || (v.value != "" && *(v.target) == "") { - vars.vv[vi].setter = "-" + v.name // v is a local copy, not the underlying data - } - if v.required { - if *(v.target) == "" { - fmt.Fprintln(os.Stderr) - fmt.Fprintln(os.Stderr, "In order to run", os.Args[0], "the following must be provided:") - for _, vv := range vars.vv { - if vv.required { - fmt.Fprintf(os.Stderr, "* setting from environment variable '%s' or flag '-%s', current value: '%s' set by '%s'\n", - Prefix+strings.ToUpper(vv.name), vv.name, *(vv.target), vv.setter) + for pass := 1; pass <= 2; pass++ { + for vi, v := range vars.vv { + if (pass == 1 && v.name == doFirst) || (pass == 2 && v.name != doFirst) { + typ := "Optional" + if v.value != *(v.target) || (v.value != "" && *(v.target) == "") { + vars.vv[vi].setter = "-" + v.name // v is a local copy, not the underlying data + } + if v.callback != nil { + if v.callback(v.target, v.name) { + vars.vv[vi].setter = "setting:" + v.name // v is a local copy, not the underlying data + } + } + if v.required { + if *(v.target) == "" { + fmt.Fprintln(os.Stderr) + fmt.Fprintln(os.Stderr, "In order to run", os.Args[0], "the following must be provided:") + for _, vv := range vars.vv { + if vv.required { + fmt.Fprintf(os.Stderr, "* setting from environment variable '%s' or flag '-%s' or an application setting '%s', current value: '%s' set by '%s'\n", + Prefix+strings.ToUpper(vv.name), vv.name, vv.name, *(vv.target), vv.setter) + } + } + fmt.Fprintln(os.Stderr) + flag.Usage() + os.Exit(2) + return + } + typ = "Required" + } + if *showSettings { + if *(v.target) != "" && vars.vv[vi].setter != goInit { + fmt.Fprintf(os.Stdout, "%s setting from '%s' is: '%s'\n", + typ, vars.vv[vi].setter, *(v.target)) } } - fmt.Fprintln(os.Stderr) - flag.Usage() - os.Exit(2) - return } - typ = "Required" - } - if *(v.target) != "" && v.setter != goInit { - fmt.Fprintf(os.Stdout, "%s setting from '%s' is: '%s'\n", - typ, v.setter, *(v.target)) - } - if v.callback != nil { - v.callback() } } } diff --git a/wordsmith/log/logger.go b/wordsmith/log/logger.go index 6a1c467c..f4f1545f 100644 --- a/wordsmith/log/logger.go +++ b/wordsmith/log/logger.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + // Package log provides centralized logging for the Documize application. package log @@ -20,8 +31,9 @@ func init() { log.SetLevel(log.DebugLevel) env.GetString(&environment, "log", false, "system being logged e.g. 'PRODUCTION'", - func() { + func(*string, string) bool { log.Infoln(environment + " environment logging enabled") + return false }) } diff --git a/wordsmith/utility/beautify.go b/wordsmith/utility/beautify.go index be7736ea..0667d94f 100644 --- a/wordsmith/utility/beautify.go +++ b/wordsmith/utility/beautify.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package utility import ( diff --git a/wordsmith/utility/beautify_test.go b/wordsmith/utility/beautify_test.go index 817457b6..509371c0 100644 --- a/wordsmith/utility/beautify_test.go +++ b/wordsmith/utility/beautify_test.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package utility import "testing" diff --git a/wordsmith/utility/command.go b/wordsmith/utility/command.go index 0cf4f7a7..a348aa22 100644 --- a/wordsmith/utility/command.go +++ b/wordsmith/utility/command.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package utility import ( diff --git a/wordsmith/utility/command_test.go b/wordsmith/utility/command_test.go index cfb4a89a..7bd6c828 100644 --- a/wordsmith/utility/command_test.go +++ b/wordsmith/utility/command_test.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package utility import "testing" @@ -6,7 +17,7 @@ import "time" func TestCmd(t *testing.T) { cmd := exec.Command("echo", "test") - buf, err := CommandWithTimeout(cmd) + buf, err := CommandWithTimeout(cmd,time.Second) if err != nil { t.Error(err) return @@ -15,13 +26,13 @@ func TestCmd(t *testing.T) { t.Error("command did not return `test` it returned:" + string(buf)) } cmd2 := exec.Command("dingbat doodah") - _, err2 := CommandWithTimeout(cmd2) + _, err2 := CommandWithTimeout(cmd2,time.Second) if err2 == nil { t.Error("bad command did not return an error") } - timeout = 5 * time.Second + timeout := 5 * time.Second cmd3 := exec.Command("sleep", "50") - _, err3 := CommandWithTimeout(cmd3) + _, err3 := CommandWithTimeout(cmd3,timeout) if err3 != errTimeout { t.Error("sleep command did not timeout:", err3) } diff --git a/wordsmith/utility/defclose.go b/wordsmith/utility/defclose.go index cb0fef10..39bfdc19 100644 --- a/wordsmith/utility/defclose.go +++ b/wordsmith/utility/defclose.go @@ -1,11 +1,26 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package utility import "io" import "github.com/documize/community/wordsmith/log" // Close is a convenience function to close an io.Closer, usually in a defer. -func Close(f io.Closer) { +func Close(f interface{}) { if f != nil { - log.IfErr(f.Close()) + if ff, ok := f.(io.Closer); ok { + if ff != io.Closer(nil) { + log.IfErr(ff.Close()) + } + } } } diff --git a/wordsmith/utility/defclose_test.go b/wordsmith/utility/defclose_test.go index 23f6b867..4e29cc8c 100644 --- a/wordsmith/utility/defclose_test.go +++ b/wordsmith/utility/defclose_test.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package utility import "testing" diff --git a/wordsmith/utility/doc.go b/wordsmith/utility/doc.go index d8f7b515..77cfc6bd 100644 --- a/wordsmith/utility/doc.go +++ b/wordsmith/utility/doc.go @@ -1,2 +1,13 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + // Package utility contains utility functions used by the whole Documize ecosystem. package utility diff --git a/wordsmith/utility/html.go b/wordsmith/utility/html.go index 0454b511..6e41e34a 100644 --- a/wordsmith/utility/html.go +++ b/wordsmith/utility/html.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package utility import ( diff --git a/wordsmith/utility/html_test.go b/wordsmith/utility/html_test.go index c4159540..64ec3ac9 100644 --- a/wordsmith/utility/html_test.go +++ b/wordsmith/utility/html_test.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package utility import "testing" diff --git a/wordsmith/utility/secrets.go b/wordsmith/utility/secrets.go index eed79f34..4db28a8c 100644 --- a/wordsmith/utility/secrets.go +++ b/wordsmith/utility/secrets.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package utility import ( diff --git a/wordsmith/utility/secrets_test.go b/wordsmith/utility/secrets_test.go index f19631df..2e6086be 100644 --- a/wordsmith/utility/secrets_test.go +++ b/wordsmith/utility/secrets_test.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package utility import "testing" diff --git a/wordsmith/utility/slug.go b/wordsmith/utility/slug.go index cfaecb70..e7efc89e 100644 --- a/wordsmith/utility/slug.go +++ b/wordsmith/utility/slug.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package utility import ( diff --git a/wordsmith/utility/slug_test.go b/wordsmith/utility/slug_test.go index 139296a0..6af37912 100644 --- a/wordsmith/utility/slug_test.go +++ b/wordsmith/utility/slug_test.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package utility import "testing" diff --git a/wordsmith/utility/user.go b/wordsmith/utility/user.go index e5dcb107..de63bc60 100644 --- a/wordsmith/utility/user.go +++ b/wordsmith/utility/user.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package utility import ( diff --git a/wordsmith/utility/user_test.go b/wordsmith/utility/user_test.go index 3eb56912..c7ade6a4 100644 --- a/wordsmith/utility/user_test.go +++ b/wordsmith/utility/user_test.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package utility import "testing" diff --git a/wordsmith/utility/words.go b/wordsmith/utility/words.go index bbc238f2..641add1a 100644 --- a/wordsmith/utility/words.go +++ b/wordsmith/utility/words.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package utility import "unicode" diff --git a/wordsmith/utility/words_test.go b/wordsmith/utility/words_test.go index e2cab11f..5ed767ec 100644 --- a/wordsmith/utility/words_test.go +++ b/wordsmith/utility/words_test.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + package utility import ( diff --git a/wordsmith/wordlists/en-2012/englishwords.go b/wordsmith/wordlists/en-2012/englishwords.go index 25a480ba..f23a3af1 100644 --- a/wordsmith/wordlists/en-2012/englishwords.go +++ b/wordsmith/wordlists/en-2012/englishwords.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + // Package words was auto-generated ! // From base data at http://invokeit.wordpress.com/frequency-word-lists/ . // The word stems were produced using github.com/rookii/paicehusk . diff --git a/wordsmith/wordlists/makewordlist.go b/wordsmith/wordlists/makewordlist.go index adccecb0..509da38d 100644 --- a/wordsmith/wordlists/makewordlist.go +++ b/wordsmith/wordlists/makewordlist.go @@ -1,3 +1,14 @@ +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + // Package main creates ordered lists of english words and their stems, // based on their frequency. package main @@ -86,6 +97,17 @@ func writeWords(wfs wordFreqSort, wfm wordFreqMap) { var err error fmt.Fprintf(&goprog, ` +// Copyright 2016 Documize Inc. . All rights reserved. +// +// This software (Documize Community Edition) is licensed under +// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html +// +// You can operate outside the AGPL restrictions by purchasing +// Documize Enterprise Edition and obtaining a commercial license +// by contacting . +// +// https://documize.com + // Package words was auto-generated ! // From base data at http://invokeit.wordpress.com/frequency-word-lists/ . // The word stems were produced using github.com/rookii/paicehusk .