mirror of
https://github.com/documize/community.git
synced 2025-07-19 05:09:42 +02:00
Write HTTP methods, database connection limits, product entity
This commit is contained in:
parent
360d3d93e9
commit
7d38102eb6
10 changed files with 870 additions and 588 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -18,7 +18,6 @@ _convert
|
|||
bin/*
|
||||
dist/*
|
||||
embed/bindata/*
|
||||
embed/bindata_assetfs.go
|
||||
app/dist/*
|
||||
app/dist-prod/*
|
||||
|
||||
|
|
|
@ -151,4 +151,4 @@ export default Ember.Route.extend(NotifierMixin, {
|
|||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -21,8 +21,8 @@ export default Ember.Route.extend(ApplicationRouteMixin, {
|
|||
appMeta: service(),
|
||||
session: service(),
|
||||
|
||||
beforeModel() {
|
||||
return this.get('appMeta').boot().then(data => {
|
||||
beforeModel(transition) {
|
||||
return this.get('appMeta').boot(transition.targetName).then(data => {
|
||||
if (this.get('session.session.authenticator') !== "authenticator:documize" && data.allowAnonymousAccess) {
|
||||
return this.get('session').authenticate('authenticator:anonymous', data);
|
||||
}
|
||||
|
@ -57,4 +57,4 @@ export default Ember.Route.extend(ApplicationRouteMixin, {
|
|||
return true;
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
||||
//
|
||||
// This software (Documize Community Edition) is licensed under
|
||||
// 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 <sales@documize.com>.
|
||||
// by contacting <sales@documize.com>.
|
||||
//
|
||||
// https://documize.com
|
||||
|
||||
|
@ -34,7 +34,7 @@ export default Ember.Service.extend({
|
|||
return [this.get('host'), endpoint].join('/');
|
||||
},
|
||||
|
||||
boot() {
|
||||
boot(/*requestedUrl*/) {
|
||||
let dbhash;
|
||||
if (is.not.null(document.head.querySelector("[property=dbhash]"))) {
|
||||
dbhash = document.head.querySelector("[property=dbhash]").content;
|
||||
|
@ -57,4 +57,4 @@ export default Ember.Service.extend({
|
|||
return response;
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
||||
//
|
||||
// This software (Documize Community Edition) is licensed under
|
||||
// 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 <sales@documize.com>.
|
||||
// by contacting <sales@documize.com>.
|
||||
//
|
||||
// https://documize.com
|
||||
|
||||
|
@ -18,6 +18,7 @@ import (
|
|||
"net/http"
|
||||
"text/template"
|
||||
|
||||
"github.com/documize/community/core"
|
||||
"github.com/documize/community/core/api/entity"
|
||||
"github.com/documize/community/core/api/request"
|
||||
"github.com/documize/community/core/log"
|
||||
|
@ -40,11 +41,13 @@ func GetMeta(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
product := core.Product()
|
||||
|
||||
data.OrgID = org.RefID
|
||||
data.Title = org.Title
|
||||
data.Message = org.Message
|
||||
data.AllowAnonymousAccess = org.AllowAnonymousAccess
|
||||
data.Version = AppVersion
|
||||
data.Version = product.Version
|
||||
|
||||
json, err := json.Marshal(data)
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/codegangsta/negroni"
|
||||
"github.com/documize/community/core"
|
||||
"github.com/documize/community/core/api/plugins"
|
||||
"github.com/documize/community/core/database"
|
||||
"github.com/documize/community/core/environment"
|
||||
|
@ -26,15 +27,11 @@ import (
|
|||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
const (
|
||||
// AppVersion does what it says
|
||||
// Note: versioning scheme is not http://semver.org
|
||||
AppVersion = "0.15.2"
|
||||
)
|
||||
|
||||
var port, certFile, keyFile, forcePort2SSL string
|
||||
var product core.ProdInfo
|
||||
|
||||
func init() {
|
||||
product = core.Product()
|
||||
environment.GetString(&certFile, "cert", false, "the cert.pem file used for https", nil)
|
||||
environment.GetString(&keyFile, "key", false, "the key.pem file used for https", nil)
|
||||
environment.GetString(&port, "port", false, "http/https port number", nil)
|
||||
|
@ -52,7 +49,7 @@ func Serve(ready chan struct{}) {
|
|||
os.Exit(1)
|
||||
}
|
||||
|
||||
log.Info(fmt.Sprintf("Documize version %s", AppVersion))
|
||||
log.Info(fmt.Sprintf("Starting %s version %s", product.Title, product.Version))
|
||||
|
||||
switch web.SiteMode {
|
||||
case web.SiteModeOffline:
|
||||
|
@ -148,7 +145,8 @@ func cors(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
|
|||
}
|
||||
|
||||
func metrics(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
|
||||
w.Header().Add("X-Documize-Version", AppVersion)
|
||||
|
||||
w.Header().Add("X-Documize-Version", product.Version)
|
||||
w.Header().Add("Cache-Control", "no-cache")
|
||||
|
||||
// Prevent page from being displayed in an iframe
|
||||
|
@ -163,7 +161,7 @@ func metrics(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
|
|||
}
|
||||
|
||||
func version(w http.ResponseWriter, r *http.Request) {
|
||||
if _, err := w.Write([]byte(AppVersion)); err != nil {
|
||||
if _, err := w.Write([]byte(product.Version)); err != nil {
|
||||
log.Error("versionHandler", err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,14 +15,15 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/jmoiron/sqlx"
|
||||
|
||||
"github.com/documize/community/core/database"
|
||||
"github.com/documize/community/core/web"
|
||||
"github.com/documize/community/core/environment"
|
||||
"github.com/documize/community/core/log"
|
||||
"github.com/documize/community/core/utility"
|
||||
"github.com/documize/community/core/web"
|
||||
)
|
||||
|
||||
var connectionString string
|
||||
|
@ -59,6 +60,7 @@ func init() {
|
|||
|
||||
Db.SetMaxIdleConns(30)
|
||||
Db.SetMaxOpenConns(100)
|
||||
Db.SetConnMaxLifetime(time.Second * 14400)
|
||||
|
||||
err = Db.Ping()
|
||||
|
||||
|
|
126
core/api/util/writeHTTP.go
Normal file
126
core/api/util/writeHTTP.go
Normal file
|
@ -0,0 +1,126 @@
|
|||
// Copyright 2016 Documize Inc. <legal@documize.com>. 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 <sales@documize.com>.
|
||||
//
|
||||
// https://documize.com
|
||||
|
||||
package util
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/documize/community/core/log"
|
||||
)
|
||||
|
||||
func WritePayloadError(w http.ResponseWriter, method string, err error) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
_, err2 := w.Write([]byte("{Error: 'Bad payload'}"))
|
||||
log.IfErr(err2)
|
||||
log.Error(fmt.Sprintf("Unable to decode HTML request body for method %s", method), err)
|
||||
}
|
||||
|
||||
func WriteTransactionError(w http.ResponseWriter, method string, err error) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
_, err2 := w.Write([]byte("{Error: 'No transaction'}"))
|
||||
log.IfErr(err2)
|
||||
log.Error(fmt.Sprintf("Unable to get database transaction for method %s", method), err)
|
||||
}
|
||||
|
||||
func WriteMissingDataError(w http.ResponseWriter, method, parameter string) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
_, err := w.Write([]byte("{Error: 'Missing data'}"))
|
||||
log.IfErr(err)
|
||||
log.Info(fmt.Sprintf("Missing data %s for method %s", parameter, method))
|
||||
}
|
||||
|
||||
func WriteNotFoundError(w http.ResponseWriter, method string, id string) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
_, err := w.Write([]byte("{Error: 'Not found'}"))
|
||||
log.IfErr(err)
|
||||
log.Info(fmt.Sprintf("Not found ID %s for method %s", id, method))
|
||||
}
|
||||
|
||||
func WriteGeneralSQLError(w http.ResponseWriter, method string, err error) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
_, err2 := w.Write([]byte("{Error: 'SQL error'}"))
|
||||
log.IfErr(err2)
|
||||
log.Error(fmt.Sprintf("General SQL error for method %s", method), err)
|
||||
}
|
||||
|
||||
func WriteJSONMarshalError(w http.ResponseWriter, method, entity string, err error) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
_, err2 := w.Write([]byte("{Error: 'JSON marshal failed'}"))
|
||||
log.IfErr(err2)
|
||||
log.Error(fmt.Sprintf("Failed to JSON marshal %s for method %s", entity, method), err)
|
||||
}
|
||||
|
||||
func WriteServerError(w http.ResponseWriter, method string, err error) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
_, err2 := w.Write([]byte("{Error: 'Internal server error'}"))
|
||||
log.IfErr(err2)
|
||||
log.Error(fmt.Sprintf("Internal server error for method %s", method), err)
|
||||
}
|
||||
|
||||
func WriteDuplicateError(w http.ResponseWriter, method, entity string) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
w.WriteHeader(http.StatusConflict)
|
||||
_, err := w.Write([]byte("{Error: 'Duplicate record'}"))
|
||||
log.IfErr(err)
|
||||
log.Info(fmt.Sprintf("Duplicate %s record detected for method %s", entity, method))
|
||||
}
|
||||
|
||||
func WriteUnauthorizedError(w http.ResponseWriter) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
_, err := w.Write([]byte("{Error: 'Unauthorized'}"))
|
||||
log.IfErr(err)
|
||||
}
|
||||
|
||||
func WriteForbiddenError(w http.ResponseWriter) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
w.WriteHeader(http.StatusForbidden)
|
||||
_, err := w.Write([]byte("{Error: 'Forbidden'}"))
|
||||
log.IfErr(err)
|
||||
}
|
||||
|
||||
func WriteBadRequestError(w http.ResponseWriter, method, message string) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
_, err := w.Write([]byte("{Error: 'Bad Request'}"))
|
||||
log.IfErr(err)
|
||||
log.Info(fmt.Sprintf("Bad Request %s for method %s", message, method))
|
||||
}
|
||||
|
||||
func WriteSuccessBytes(w http.ResponseWriter, data []byte) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_, err := w.Write(data)
|
||||
log.IfErr(err)
|
||||
}
|
||||
|
||||
func WriteSuccessString(w http.ResponseWriter, data string) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_, err := w.Write([]byte(data))
|
||||
log.IfErr(err)
|
||||
}
|
||||
|
||||
func WriteSuccessEmptyJSON(w http.ResponseWriter) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_, err := w.Write([]byte("{}"))
|
||||
log.IfErr(err)
|
||||
}
|
37
core/product.go
Normal file
37
core/product.go
Normal file
|
@ -0,0 +1,37 @@
|
|||
// Copyright 2016 Documize Inc. <legal@documize.com>. 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 <sales@documize.com>.
|
||||
//
|
||||
// https://documize.com
|
||||
|
||||
// Package extensions represents Enterprise Edition capabilities.
|
||||
package core
|
||||
|
||||
import "fmt"
|
||||
|
||||
// ProdInfo describes a product
|
||||
type ProdInfo struct {
|
||||
Edition string
|
||||
Title string
|
||||
Version string
|
||||
Major string
|
||||
Minor string
|
||||
Patch string
|
||||
}
|
||||
|
||||
// Product returns product edition details
|
||||
func Product() (p ProdInfo) {
|
||||
p.Major = "0"
|
||||
p.Minor = "16"
|
||||
p.Patch = "0"
|
||||
p.Version = fmt.Sprintf("%s.%s.%s", p.Major, p.Minor, p.Patch)
|
||||
p.Edition = "Community"
|
||||
p.Title = fmt.Sprintf("Documize %s Edition", p.Edition)
|
||||
|
||||
return p
|
||||
}
|
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue