mirror of
https://github.com/documize/community.git
synced 2025-07-18 20:59:43 +02:00
wrap errors up, log at top level only
This commit is contained in:
parent
ecc94f31c9
commit
476403bf46
28 changed files with 899 additions and 804 deletions
|
@ -17,7 +17,6 @@ import (
|
|||
"strings"
|
||||
|
||||
api "github.com/documize/community/core/convapi"
|
||||
"github.com/documize/community/core/log"
|
||||
"github.com/documize/community/core/stringutil"
|
||||
"golang.org/x/net/context"
|
||||
"golang.org/x/net/html"
|
||||
|
@ -192,7 +191,6 @@ func (h *htmlToSplit) renderAppend(c *html.Node) error {
|
|||
ebyt := stringutil.EscapeHTMLcomplexCharsByte(byt)
|
||||
if len(ebyt) > maxBody {
|
||||
msg := fmt.Sprintf("(Documize warning: HTML render element ignored, size of %d exceeded maxBody of %d.)", len(ebyt), maxBody)
|
||||
log.Info(msg)
|
||||
ebyt = []byte("<p><b>" + msg + "</b></p>")
|
||||
}
|
||||
if len(h.thisSect.Body)+len(ebyt) > maxBody {
|
||||
|
|
|
@ -22,7 +22,6 @@ import (
|
|||
"github.com/documize/community/core/api/convert/html"
|
||||
"github.com/documize/community/core/api/convert/md"
|
||||
api "github.com/documize/community/core/convapi"
|
||||
"github.com/documize/community/core/log"
|
||||
"github.com/documize/community/domain"
|
||||
"github.com/documize/glick"
|
||||
)
|
||||
|
@ -34,14 +33,14 @@ var insecure = "false"
|
|||
type infoLog struct{}
|
||||
|
||||
func (i infoLog) Write(b []byte) (int, error) {
|
||||
log.Info(string(b))
|
||||
// log.Info(string(b))
|
||||
return len(b), nil
|
||||
}
|
||||
|
||||
type errorLog struct{}
|
||||
|
||||
func (i errorLog) Write(b []byte) (int, error) {
|
||||
log.ErrorString(string(b))
|
||||
// log.ErrorString(string(b))
|
||||
return len(b), nil
|
||||
}
|
||||
|
||||
|
@ -107,7 +106,6 @@ func Setup(s *domain.Store) error {
|
|||
} else {
|
||||
json, err = ioutil.ReadFile(PluginFile)
|
||||
if err != nil {
|
||||
log.Info("Plugin file '" + PluginFile + "' not found, using no plugins")
|
||||
json = []byte(" [ ] \n")
|
||||
err = nil
|
||||
}
|
||||
|
|
|
@ -13,7 +13,6 @@ package convapi
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/documize/community/core/log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
|
@ -33,7 +32,6 @@ func SetJSONResponse(w http.ResponseWriter) {
|
|||
// WriteError to the http.ResponseWriter, taking care to provide the correct
|
||||
// response error code within the JSON response.
|
||||
func WriteError(w http.ResponseWriter, err error) {
|
||||
|
||||
response := apiJSONResponse{}
|
||||
response.Message = err.Error()
|
||||
response.Success = false
|
||||
|
@ -57,20 +55,13 @@ func WriteError(w http.ResponseWriter, err error) {
|
|||
w.WriteHeader(http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
json, err := json.Marshal(response)
|
||||
if err != nil {
|
||||
log.Error("json.Marshal", err)
|
||||
}
|
||||
|
||||
if _, err := w.Write(json); err != nil {
|
||||
log.Error("write to ResponseWriter", err)
|
||||
}
|
||||
json, _ := json.Marshal(response)
|
||||
w.Write(json)
|
||||
}
|
||||
|
||||
// WriteErrorBadRequest provides feedback to a Documize client on an error,
|
||||
// where that error is described in a string.
|
||||
func WriteErrorBadRequest(w http.ResponseWriter, message string) {
|
||||
|
||||
response := apiJSONResponse{}
|
||||
response.Message = message
|
||||
response.Success = false
|
||||
|
@ -79,12 +70,7 @@ func WriteErrorBadRequest(w http.ResponseWriter, message string) {
|
|||
response.Code = 400
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
|
||||
json, err := json.Marshal(response)
|
||||
if err != nil {
|
||||
log.Error("json.Marshal", err)
|
||||
}
|
||||
json, _ := json.Marshal(response)
|
||||
|
||||
if _, err := w.Write(json); err != nil {
|
||||
log.Error("write to ResponseWriter", err)
|
||||
}
|
||||
w.Write(json)
|
||||
}
|
||||
|
|
|
@ -1,70 +0,0 @@
|
|||
// 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 log provides centralized logging for the Documize application.
|
||||
package log
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"os"
|
||||
"runtime"
|
||||
|
||||
log "github.com/Sirupsen/logrus"
|
||||
)
|
||||
|
||||
var environment = "Non-production"
|
||||
|
||||
func init() {
|
||||
log.SetFormatter(new(log.TextFormatter))
|
||||
log.SetOutput(os.Stdout)
|
||||
log.SetLevel(log.DebugLevel)
|
||||
}
|
||||
|
||||
// Debug logs a message for debug purposes.
|
||||
func Debug(message string) {
|
||||
log.WithFields(log.Fields{"env": environment}).Debug(message)
|
||||
}
|
||||
|
||||
// Info logs a message for information purposes.
|
||||
func Info(message string) {
|
||||
log.WithFields(log.Fields{"env": environment}).Info(message)
|
||||
}
|
||||
|
||||
// TestIfErr is used by the test code to signal that a test being run should error, it is reset if an error occurs.
|
||||
var TestIfErr bool
|
||||
|
||||
// ErrorString logs an error, where there is not an error value.
|
||||
func ErrorString(message string) {
|
||||
TestIfErr = false
|
||||
log.WithFields(log.Fields{"env": environment}).Error(message)
|
||||
}
|
||||
|
||||
// Error logs an error, if non-nil, with a message to give some context.
|
||||
func Error(message string, err error) {
|
||||
if err != nil {
|
||||
TestIfErr = false
|
||||
stack := make([]byte, 4096)
|
||||
runtime.Stack(stack, false)
|
||||
if idx := bytes.IndexByte(stack, 0); idx > 0 && idx < len(stack) {
|
||||
stack = stack[:idx] // remove trailing nulls from stack dump
|
||||
}
|
||||
log.WithFields(log.Fields{"env": environment, "error": err.Error(), "stack": fmt.Sprintf("%s", stack)}).Error(message)
|
||||
|
||||
//log.WithField("error: "+message, err.Error()).Errorf("%q\n%s\n", err, stack[:])
|
||||
}
|
||||
}
|
||||
|
||||
// IfErr logs an error if one exists.
|
||||
// It is a convenience wrapper for Error(), with no context message.
|
||||
func IfErr(err error) {
|
||||
Error("", err)
|
||||
}
|
|
@ -15,7 +15,6 @@ import (
|
|||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
|
||||
"github.com/documize/community/core/log"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
)
|
||||
|
||||
|
@ -32,8 +31,8 @@ func GenerateSalt() string {
|
|||
// GenerateRandom returns a string of the specified length using crypo/rand
|
||||
func GenerateRandom(size int) string {
|
||||
b := make([]byte, size)
|
||||
_, err := rand.Read(b)
|
||||
log.IfErr(err)
|
||||
rand.Read(b)
|
||||
|
||||
return hex.EncodeToString(b)
|
||||
}
|
||||
|
||||
|
@ -42,11 +41,7 @@ func GeneratePassword(password string, salt string) string {
|
|||
pwd := []byte(salt + password)
|
||||
|
||||
// Hashing the password with the cost of 10
|
||||
hashedPassword, err := bcrypt.GenerateFromPassword(pwd, 10)
|
||||
|
||||
if err != nil {
|
||||
log.Error("GeneratePassword failed", err)
|
||||
}
|
||||
hashedPassword, _ := bcrypt.GenerateFromPassword(pwd, 10)
|
||||
|
||||
return string(hashedPassword)
|
||||
}
|
||||
|
|
|
@ -50,6 +50,7 @@ func (h *Handler) Download(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
if err != nil {
|
||||
h.Runtime.Log.Error("get attachment", err)
|
||||
response.WriteServerError(w, method, err)
|
||||
return
|
||||
}
|
||||
|
@ -66,7 +67,7 @@ func (h *Handler) Download(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
_, err = w.Write(a.Data)
|
||||
if err != nil {
|
||||
h.Runtime.Log.Error("writing attachment", err)
|
||||
h.Runtime.Log.Error("write attachment", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -91,6 +92,7 @@ func (h *Handler) Get(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
a, err := h.Store.Attachment.GetAttachments(ctx, documentID)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
h.Runtime.Log.Error("get attachment", err)
|
||||
response.WriteServerError(w, method, err)
|
||||
return
|
||||
}
|
||||
|
@ -127,6 +129,7 @@ func (h *Handler) Delete(w http.ResponseWriter, r *http.Request) {
|
|||
var err error
|
||||
ctx.Transaction, err = h.Runtime.Db.Beginx()
|
||||
if err != nil {
|
||||
h.Runtime.Log.Error("transaction", err)
|
||||
response.WriteServerError(w, method, err)
|
||||
return
|
||||
}
|
||||
|
@ -135,6 +138,7 @@ func (h *Handler) Delete(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error("delete attachment", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -143,6 +147,7 @@ func (h *Handler) Delete(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error("delete attachment links", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -170,7 +175,6 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
filedata, filename, err := r.FormFile("attachment")
|
||||
|
||||
if err != nil {
|
||||
response.WriteMissingDataError(w, method, "attachment")
|
||||
return
|
||||
|
@ -180,17 +184,17 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) {
|
|||
_, err = io.Copy(b, filedata)
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error("add attachment", err)
|
||||
return
|
||||
}
|
||||
|
||||
var job = "some-uuid"
|
||||
|
||||
newUUID, err := uuid.NewV4()
|
||||
if err != nil {
|
||||
h.Runtime.Log.Error("uuid", err)
|
||||
response.WriteServerError(w, method, err)
|
||||
return
|
||||
}
|
||||
|
||||
job = newUUID.String()
|
||||
|
||||
var a attachment.Attachment
|
||||
|
@ -206,6 +210,7 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) {
|
|||
ctx.Transaction, err = h.Runtime.Db.Beginx()
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error("transaction", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -213,6 +218,7 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error("add attachment", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,6 @@ import (
|
|||
"github.com/documize/community/core/env"
|
||||
"github.com/documize/community/domain"
|
||||
"github.com/documize/community/model/audit"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// Scope provides data access to MySQL.
|
||||
|
@ -37,21 +36,21 @@ func (s Scope) Record(ctx domain.RequestContext, t audit.EventType) {
|
|||
|
||||
tx, err := s.Runtime.Db.Beginx()
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, "start transaction")
|
||||
s.Runtime.Log.Error("transaction", err)
|
||||
return
|
||||
}
|
||||
|
||||
stmt, err := tx.Preparex("INSERT INTO userevent (orgid, userid, eventtype, ip, created) VALUES (?, ?, ?, ?, ?)")
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
err = errors.Wrap(err, "prepare insert RecordEvent")
|
||||
s.Runtime.Log.Error("prepare audit insert", err)
|
||||
return
|
||||
}
|
||||
|
||||
_, err = stmt.Exec(e.OrgID, e.UserID, e.Type, e.IP, e.Created)
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, "execute insert RecordEvent")
|
||||
tx.Rollback()
|
||||
s.Runtime.Log.Error("execute audit insert", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -53,6 +53,7 @@ func (h *Handler) Login(w http.ResponseWriter, r *http.Request) {
|
|||
decodedBytes, err := secrets.DecodeBase64([]byte(data))
|
||||
if err != nil {
|
||||
response.WriteBadRequestError(w, method, "Unable to decode authentication token")
|
||||
h.Runtime.Log.Error("decode auth header", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -60,9 +61,9 @@ func (h *Handler) Login(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
// check that we have domain:email:password (but allow for : in password field!)
|
||||
credentials := strings.SplitN(decoded, ":", 3)
|
||||
|
||||
if len(credentials) != 3 {
|
||||
response.WriteBadRequestError(w, method, "Bad authentication token, expecting domain:email:password")
|
||||
h.Runtime.Log.Error("bad auth token", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -95,14 +96,15 @@ func (h *Handler) Login(w http.ResponseWriter, r *http.Request) {
|
|||
org, err := h.Store.Organization.GetOrganizationByDomain(dom)
|
||||
if err != nil {
|
||||
response.WriteUnauthorizedError(w)
|
||||
h.Runtime.Log.Error("bad auth organization", err)
|
||||
return
|
||||
}
|
||||
|
||||
// Attach user accounts and work out permissions
|
||||
user.AttachUserAccounts(ctx, *h.Store, org.RefID, &u)
|
||||
|
||||
if len(u.Accounts) == 0 {
|
||||
response.WriteUnauthorizedError(w)
|
||||
h.Runtime.Log.Error("bad auth accounts", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -118,8 +120,8 @@ func (h *Handler) ValidateToken(w http.ResponseWriter, r *http.Request) {
|
|||
// TODO should this go after token validation?
|
||||
if s := r.URL.Query().Get("section"); s != "" {
|
||||
if err := provider.Callback(s, h.Runtime, h.Store, w, r); err != nil {
|
||||
h.Runtime.Log.Error("section validation failure", err)
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
h.Runtime.Log.Error("section validation failure", err)
|
||||
}
|
||||
|
||||
return
|
||||
|
@ -198,6 +200,7 @@ func (h *Handler) ValidateToken(w http.ResponseWriter, r *http.Request) {
|
|||
u, err := user.GetSecuredUser(rc, *h.Store, org.RefID, rc.UserID)
|
||||
if err != nil {
|
||||
response.WriteUnauthorizedError(w)
|
||||
h.Runtime.Log.Error("ValidateToken", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -58,8 +58,8 @@ func (h *Handler) Sync(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
result.Message = "Error: unable to get organization record"
|
||||
result.IsError = true
|
||||
h.Runtime.Log.Error(result.Message, err)
|
||||
response.WriteJSON(w, result)
|
||||
h.Runtime.Log.Error(result.Message, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -67,8 +67,8 @@ func (h *Handler) Sync(w http.ResponseWriter, r *http.Request) {
|
|||
if org.AuthProvider != "keycloak" {
|
||||
result.Message = "Error: skipping user sync with Keycloak as it is not the configured option"
|
||||
result.IsError = true
|
||||
h.Runtime.Log.Info(result.Message)
|
||||
response.WriteJSON(w, result)
|
||||
h.Runtime.Log.Info(result.Message)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -78,8 +78,8 @@ func (h *Handler) Sync(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
result.Message = "Error: unable read Keycloak configuration data"
|
||||
result.IsError = true
|
||||
h.Runtime.Log.Error(result.Message, err)
|
||||
response.WriteJSON(w, result)
|
||||
h.Runtime.Log.Error(result.Message, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -88,8 +88,8 @@ func (h *Handler) Sync(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
result.Message = "Error: unable to fetch Keycloak users: " + err.Error()
|
||||
result.IsError = true
|
||||
h.Runtime.Log.Error(result.Message, err)
|
||||
response.WriteJSON(w, result)
|
||||
h.Runtime.Log.Error(result.Message, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -98,8 +98,8 @@ func (h *Handler) Sync(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
result.Message = "Error: unable to fetch Documize users"
|
||||
result.IsError = true
|
||||
h.Runtime.Log.Error(result.Message, err)
|
||||
response.WriteJSON(w, result)
|
||||
h.Runtime.Log.Error(result.Message, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -128,8 +128,8 @@ func (h *Handler) Sync(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
result.Message = fmt.Sprintf("Keycloak sync'ed %d users, %d new additions", len(kcUsers), len(insert))
|
||||
h.Runtime.Log.Info(result.Message)
|
||||
response.WriteJSON(w, result)
|
||||
h.Runtime.Log.Info(result.Message)
|
||||
}
|
||||
|
||||
// Authenticate checks Keycloak authentication credentials.
|
||||
|
@ -141,6 +141,7 @@ func (h *Handler) Authenticate(w http.ResponseWriter, r *http.Request) {
|
|||
body, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
response.WriteBadRequestError(w, method, "Bad payload")
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -148,6 +149,7 @@ func (h *Handler) Authenticate(w http.ResponseWriter, r *http.Request) {
|
|||
err = json.Unmarshal(body, &a)
|
||||
if err != nil {
|
||||
response.WriteBadRequestError(w, method, err.Error())
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -164,6 +166,7 @@ func (h *Handler) Authenticate(w http.ResponseWriter, r *http.Request) {
|
|||
org, err := h.Store.Organization.GetOrganizationByDomain(a.Domain)
|
||||
if err != nil {
|
||||
response.WriteUnauthorizedError(w)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -174,6 +177,7 @@ func (h *Handler) Authenticate(w http.ResponseWriter, r *http.Request) {
|
|||
err = json.Unmarshal([]byte(org.AuthConfig), &ac)
|
||||
if err != nil {
|
||||
response.WriteBadRequestError(w, method, "Unable to unmarshall Keycloak Public Key")
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -181,6 +185,7 @@ func (h *Handler) Authenticate(w http.ResponseWriter, r *http.Request) {
|
|||
pkb, err := secrets.DecodeBase64([]byte(ac.PublicKey))
|
||||
if err != nil {
|
||||
response.WriteBadRequestError(w, method, "Unable to base64 decode Keycloak Public Key")
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
pk := string(pkb)
|
||||
|
@ -189,8 +194,8 @@ func (h *Handler) Authenticate(w http.ResponseWriter, r *http.Request) {
|
|||
// Decode and verify Keycloak JWT
|
||||
claims, err := auth.DecodeKeycloakJWT(a.Token, pk)
|
||||
if err != nil {
|
||||
h.Runtime.Log.Info("decodeKeycloakJWT failed")
|
||||
response.WriteBadRequestError(w, method, err.Error())
|
||||
h.Runtime.Log.Info("decodeKeycloakJWT failed")
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -198,6 +203,7 @@ func (h *Handler) Authenticate(w http.ResponseWriter, r *http.Request) {
|
|||
// Guards against MITM token tampering.
|
||||
if a.Email != claims["email"].(string) || claims["sub"].(string) != a.RemoteID {
|
||||
response.WriteUnauthorizedError(w)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -206,6 +212,7 @@ func (h *Handler) Authenticate(w http.ResponseWriter, r *http.Request) {
|
|||
u, err := h.Store.User.GetByDomain(ctx, a.Domain, a.Email)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -224,6 +231,7 @@ func (h *Handler) Authenticate(w http.ResponseWriter, r *http.Request) {
|
|||
err = addUser(ctx, h.Runtime, h.Store, u, ac.DefaultPermissionAddSpace)
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -241,6 +249,7 @@ func (h *Handler) Authenticate(w http.ResponseWriter, r *http.Request) {
|
|||
// so we reject login request.
|
||||
if len(u.Accounts) == 0 {
|
||||
response.WriteUnauthorizedError(w)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -249,6 +258,7 @@ func (h *Handler) Authenticate(w http.ResponseWriter, r *http.Request) {
|
|||
if ac.OrgID == org.RefID {
|
||||
if ac.Active == false {
|
||||
response.WriteUnauthorizedError(w)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
break
|
||||
|
|
|
@ -64,6 +64,7 @@ func (h *Handler) upload(w http.ResponseWriter, r *http.Request) (string, string
|
|||
_, err = io.Copy(b, filedata)
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return "", "", ""
|
||||
}
|
||||
|
||||
|
@ -71,6 +72,7 @@ func (h *Handler) upload(w http.ResponseWriter, r *http.Request) (string, string
|
|||
newUUID, err := uuid.NewV4()
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return "", "", ""
|
||||
}
|
||||
|
||||
|
@ -79,6 +81,7 @@ func (h *Handler) upload(w http.ResponseWriter, r *http.Request) (string, string
|
|||
err = storageProvider.Upload(job, filename.Filename, b.Bytes())
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return "", "", ""
|
||||
}
|
||||
|
||||
|
@ -102,6 +105,7 @@ func (h *Handler) convert(w http.ResponseWriter, r *http.Request, job, folderID
|
|||
org, err := h.Store.Organization.GetOrganization(ctx, ctx.OrgID)
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -112,11 +116,13 @@ func (h *Handler) convert(w http.ResponseWriter, r *http.Request, job, folderID
|
|||
filename, fileResult, err = storageProvider.Convert(conversion)
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
if fileResult.Err != "" {
|
||||
response.WriteServerError(w, method, errors.New(fileResult.Err))
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -129,12 +135,14 @@ func (h *Handler) convert(w http.ResponseWriter, r *http.Request, job, folderID
|
|||
ctx.Transaction, err = h.Runtime.Db.Beginx()
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
nd, err := processDocument(ctx, h.Store, filename, job, folderID, fileResult)
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -58,6 +58,7 @@ func (h *Handler) Get(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -69,6 +70,7 @@ func (h *Handler) Get(w http.ResponseWriter, r *http.Request) {
|
|||
ctx.Transaction, err = h.Runtime.Db.Beginx()
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -79,7 +81,7 @@ func (h *Handler) Get(w http.ResponseWriter, r *http.Request) {
|
|||
ActivityType: activity.TypeRead})
|
||||
|
||||
if err != nil {
|
||||
h.Runtime.Log.Error("record user activity", err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
}
|
||||
|
||||
h.Store.Audit.Record(ctx, audit.EventTypeDocumentView)
|
||||
|
@ -103,6 +105,7 @@ func (h *Handler) Activity(w http.ResponseWriter, r *http.Request) {
|
|||
a, err := h.Store.Activity.GetDocumentActivity(ctx, id)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -121,13 +124,12 @@ func (h *Handler) DocumentLinks(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
l, err := h.Store.Link.GetDocumentOutboundLinks(ctx, id)
|
||||
|
||||
if len(l) == 0 {
|
||||
l = []link.Link{}
|
||||
}
|
||||
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -147,21 +149,22 @@ func (h *Handler) BySpace(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
if !space.CanViewSpace(ctx, *h.Store, folderID) {
|
||||
h.Runtime.Log.Info("no permission to view space documents")
|
||||
response.WriteForbiddenError(w)
|
||||
return
|
||||
}
|
||||
|
||||
documents, err := h.Store.Document.GetBySpace(ctx, folderID)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
response.WriteServerError(w, method, err)
|
||||
return
|
||||
}
|
||||
|
||||
if len(documents) == 0 {
|
||||
documents = []doc.Document{}
|
||||
}
|
||||
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
response.WriteJSON(w, documents)
|
||||
}
|
||||
|
||||
|
@ -177,15 +180,17 @@ func (h *Handler) ByTag(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
documents, err := h.Store.Document.GetByTag(ctx, tag)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
response.WriteServerError(w, method, err)
|
||||
return
|
||||
}
|
||||
|
||||
if len(documents) == 0 {
|
||||
documents = []doc.Document{}
|
||||
}
|
||||
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
response.WriteJSON(w, documents)
|
||||
}
|
||||
|
||||
|
@ -215,6 +220,7 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request) {
|
|||
body, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
response.WriteBadRequestError(w, method, err.Error())
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -222,6 +228,7 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request) {
|
|||
err = json.Unmarshal(body, &d)
|
||||
if err != nil {
|
||||
response.WriteBadRequestError(w, method, err.Error())
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -230,6 +237,7 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request) {
|
|||
ctx.Transaction, err = h.Runtime.Db.Beginx()
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -237,6 +245,7 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -268,12 +277,14 @@ func (h *Handler) Delete(w http.ResponseWriter, r *http.Request) {
|
|||
doc, err := h.Store.Document.Get(ctx, documentID)
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Transaction, err = h.Runtime.Db.Beginx()
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -281,6 +292,7 @@ func (h *Handler) Delete(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -288,6 +300,7 @@ func (h *Handler) Delete(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil && err != sql.ErrNoRows {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -323,7 +336,7 @@ func (h *Handler) SearchDocuments(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
results, err := h.Store.Search.Documents(ctx, decoded)
|
||||
if err != nil {
|
||||
h.Runtime.Log.Error("search failed", err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
}
|
||||
|
||||
// Put in slugs for easy UI display of search URL
|
||||
|
|
|
@ -65,14 +65,14 @@ func (h *Handler) GetLinkCandidates(w http.ResponseWriter, r *http.Request) {
|
|||
// We can link to a section within the same document so
|
||||
// let's get all pages for the document and remove "us".
|
||||
pages, err := h.Store.Page.GetPagesWithoutContent(ctx, documentID)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
response.WriteServerError(w, method, err)
|
||||
return
|
||||
}
|
||||
|
||||
if len(pages) == 0 {
|
||||
pages = []page.Page{}
|
||||
}
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
pc := []link.Candidate{}
|
||||
|
||||
|
@ -93,15 +93,16 @@ func (h *Handler) GetLinkCandidates(w http.ResponseWriter, r *http.Request) {
|
|||
// We can link to attachment within the same document so
|
||||
// let's get all attachments for the document.
|
||||
files, err := h.Store.Attachment.GetAttachments(ctx, documentID)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
response.WriteServerError(w, method, err)
|
||||
return
|
||||
}
|
||||
|
||||
if len(files) == 0 {
|
||||
files = []attachment.Attachment{}
|
||||
}
|
||||
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
fc := []link.Candidate{}
|
||||
|
||||
for _, f := range files {
|
||||
|
@ -137,12 +138,13 @@ func (h *Handler) SearchLinkCandidates(w http.ResponseWriter, r *http.Request) {
|
|||
keywords := request.Query(r, "keywords")
|
||||
decoded, err := url.QueryUnescape(keywords)
|
||||
if err != nil {
|
||||
h.Runtime.Log.Error("decode query string", err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
}
|
||||
|
||||
docs, pages, attachments, err := h.Store.Link.SearchCandidates(ctx, decoded)
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -55,8 +55,6 @@ import (
|
|||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/documize/community/core/log"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -177,8 +175,7 @@ func (e *Email) Bytes() ([]byte, error) {
|
|||
// TODO: determine the content type based on message/attachment mix.
|
||||
headers.Set("Content-Type", "multipart/mixed;\r\n boundary="+w.Boundary())
|
||||
headerToBytes(buff, headers)
|
||||
_, err := io.WriteString(buff, "\r\n")
|
||||
log.IfErr(err)
|
||||
io.WriteString(buff, "\r\n")
|
||||
// Start the multipart/mixed part
|
||||
fmt.Fprintf(buff, "--%s\r\n", w.Boundary())
|
||||
header := textproto.MIMEHeader{}
|
||||
|
@ -354,8 +351,7 @@ func base64Wrap(w io.Writer, b []byte) {
|
|||
// Process raw chunks until there's no longer enough to fill a line.
|
||||
for len(b) >= maxRaw {
|
||||
base64.StdEncoding.Encode(buffer, b[:maxRaw])
|
||||
_, err := w.Write(buffer)
|
||||
log.IfErr(err)
|
||||
w.Write(buffer)
|
||||
b = b[maxRaw:]
|
||||
}
|
||||
// Handle the last chunk of bytes.
|
||||
|
@ -363,8 +359,7 @@ func base64Wrap(w io.Writer, b []byte) {
|
|||
out := buffer[:base64.StdEncoding.EncodedLen(len(b))]
|
||||
base64.StdEncoding.Encode(out, b)
|
||||
out = append(out, "\r\n"...)
|
||||
_, err := w.Write(out)
|
||||
log.IfErr(err)
|
||||
w.Write(out)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -373,8 +368,7 @@ func base64Wrap(w io.Writer, b []byte) {
|
|||
func headerToBytes(buff *bytes.Buffer, header textproto.MIMEHeader) {
|
||||
for field, vals := range header {
|
||||
for _, subval := range vals {
|
||||
_, err := io.WriteString(buff, field+": "+subval+"\r\n")
|
||||
log.IfErr(err)
|
||||
io.WriteString(buff, field+": "+subval+"\r\n")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@ import (
|
|||
"text/template"
|
||||
|
||||
"github.com/documize/community/core/env"
|
||||
"github.com/documize/community/core/log"
|
||||
"github.com/documize/community/core/response"
|
||||
"github.com/documize/community/core/stringutil"
|
||||
"github.com/documize/community/domain"
|
||||
|
@ -75,8 +74,8 @@ func (h *Handler) RobotsTxt(w http.ResponseWriter, r *http.Request) {
|
|||
// default is to deny
|
||||
robots :=
|
||||
`User-agent: *
|
||||
Disallow: /
|
||||
`
|
||||
Disallow: /
|
||||
`
|
||||
|
||||
if err != nil {
|
||||
h.Runtime.Log.Error(fmt.Sprintf("%s failed to get Organization for domain %s", method, dom), err)
|
||||
|
@ -122,12 +121,12 @@ func (h *Handler) Sitemap(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
sitemap :=
|
||||
`<?xml version="1.0" encoding="UTF-8"?>
|
||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
|
||||
{{range .}}<url>
|
||||
<loc>{{ .URL }}</loc>
|
||||
<lastmod>{{ .Date }}</lastmod>
|
||||
</url>{{end}}
|
||||
</urlset>`
|
||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
|
||||
{{range .}}<url>
|
||||
<loc>{{ .URL }}</loc>
|
||||
<lastmod>{{ .Date }}</lastmod>
|
||||
</url>{{end}}
|
||||
</urlset>`
|
||||
|
||||
var items []sitemapItem
|
||||
|
||||
|
@ -167,7 +166,7 @@ func (h *Handler) Sitemap(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
buffer := new(bytes.Buffer)
|
||||
t := template.Must(template.New("tmp").Parse(sitemap))
|
||||
log.IfErr(t.Execute(buffer, &items))
|
||||
t.Execute(buffer, &items)
|
||||
|
||||
response.WriteBytes(w, buffer.Bytes())
|
||||
}
|
||||
|
|
|
@ -46,6 +46,7 @@ func (h *Handler) Get(w http.ResponseWriter, r *http.Request) {
|
|||
org, err := h.Store.Organization.GetOrganization(ctx, ctx.OrgID)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -67,6 +68,7 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -78,6 +80,7 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request) {
|
|||
ctx.Transaction, err = h.Runtime.Db.Beginx()
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -85,6 +88,7 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -68,6 +68,7 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) {
|
|||
body, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
response.WriteBadRequestError(w, method, err.Error())
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -75,6 +76,7 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) {
|
|||
err = json.Unmarshal(body, &model)
|
||||
if err != nil {
|
||||
response.WriteBadRequestError(w, method, err.Error())
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -99,15 +101,15 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
doc, err := h.Store.Document.Get(ctx, documentID)
|
||||
if err != nil {
|
||||
h.Runtime.Log.Error(method, err)
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Transaction, err = h.Runtime.Db.Beginx()
|
||||
if err != nil {
|
||||
h.Runtime.Log.Error(method, err)
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -121,8 +123,8 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) {
|
|||
err = h.Store.Page.Add(ctx, *model)
|
||||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
h.Runtime.Log.Error(method, err)
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -176,6 +178,7 @@ func (h *Handler) GetPage(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -219,7 +222,7 @@ func (h *Handler) GetPages(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
return
|
||||
h.Runtime.Log.Error(method, err)
|
||||
}
|
||||
|
||||
response.WriteJSON(w, pages)
|
||||
|
@ -245,6 +248,7 @@ func (h *Handler) GetPagesBatch(w http.ResponseWriter, r *http.Request) {
|
|||
body, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
response.WriteBadRequestError(w, method, err.Error())
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -253,10 +257,12 @@ func (h *Handler) GetPagesBatch(w http.ResponseWriter, r *http.Request) {
|
|||
pages, err := h.Store.Page.GetPagesWhereIn(ctx, documentID, requestedPages)
|
||||
if err == sql.ErrNoRows {
|
||||
response.WriteNotFoundError(w, method, documentID)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -293,12 +299,14 @@ func (h *Handler) Delete(w http.ResponseWriter, r *http.Request) {
|
|||
doc, err := h.Store.Document.Get(ctx, documentID)
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Transaction, err = h.Runtime.Db.Beginx()
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -306,6 +314,7 @@ func (h *Handler) Delete(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -317,6 +326,7 @@ func (h *Handler) Delete(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -379,12 +389,14 @@ func (h *Handler) DeletePages(w http.ResponseWriter, r *http.Request) {
|
|||
doc, err := h.Store.Document.Get(ctx, documentID)
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Transaction, err = h.Runtime.Db.Beginx()
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -393,6 +405,7 @@ func (h *Handler) DeletePages(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -404,6 +417,7 @@ func (h *Handler) DeletePages(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -462,6 +476,7 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request) {
|
|||
body, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
response.WriteBadRequestError(w, method, "Bad request body")
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -469,6 +484,7 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request) {
|
|||
err = json.Unmarshal(body, &model)
|
||||
if err != nil {
|
||||
response.WriteBadRequestError(w, method, err.Error())
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -480,12 +496,14 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request) {
|
|||
doc, err := h.Store.Document.Get(ctx, documentID)
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Transaction, err = h.Runtime.Db.Beginx()
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -495,6 +513,7 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request) {
|
|||
oldPageMeta, err := h.Store.Page.GetPageMeta(ctx, pageID)
|
||||
if err != nil {
|
||||
response.WriteBadRequestError(w, method, err.Error())
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -512,6 +531,7 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
ctx.Transaction.Rollback()
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -519,6 +539,7 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
ctx.Transaction.Rollback()
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -601,6 +622,7 @@ func (h *Handler) ChangePageSequence(w http.ResponseWriter, r *http.Request) {
|
|||
body, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
response.WriteBadRequestError(w, method, err.Error())
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -608,12 +630,14 @@ func (h *Handler) ChangePageSequence(w http.ResponseWriter, r *http.Request) {
|
|||
err = json.Unmarshal(body, &model)
|
||||
if err != nil {
|
||||
response.WriteBadRequestError(w, method, err.Error())
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Transaction, err = h.Runtime.Db.Beginx()
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -622,6 +646,7 @@ func (h *Handler) ChangePageSequence(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -660,6 +685,7 @@ func (h *Handler) ChangePageLevel(w http.ResponseWriter, r *http.Request) {
|
|||
body, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
response.WriteBadRequestError(w, method, err.Error())
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -667,12 +693,14 @@ func (h *Handler) ChangePageLevel(w http.ResponseWriter, r *http.Request) {
|
|||
err = json.Unmarshal(body, &model)
|
||||
if err != nil {
|
||||
response.WriteBadRequestError(w, method, err.Error())
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Transaction, err = h.Runtime.Db.Beginx()
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -681,6 +709,7 @@ func (h *Handler) ChangePageLevel(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -719,14 +748,17 @@ func (h *Handler) GetMeta(w http.ResponseWriter, r *http.Request) {
|
|||
meta, err := h.Store.Page.GetPageMeta(ctx, pageID)
|
||||
if err == sql.ErrNoRows {
|
||||
response.WriteNotFoundError(w, method, pageID)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
if meta.DocumentID != documentID {
|
||||
response.WriteBadRequestError(w, method, "documentID mismatch")
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -751,6 +783,7 @@ func (h *Handler) GetMoveCopyTargets(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -790,26 +823,31 @@ func (h *Handler) Copy(w http.ResponseWriter, r *http.Request) {
|
|||
doc, err := h.Store.Document.Get(ctx, documentID)
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
p, err := h.Store.Page.Get(ctx, pageID)
|
||||
if err == sql.ErrNoRows {
|
||||
response.WriteNotFoundError(w, method, documentID)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
pageMeta, err := h.Store.Page.GetPageMeta(ctx, pageID)
|
||||
if err == sql.ErrNoRows {
|
||||
response.WriteNotFoundError(w, method, documentID)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -830,6 +868,7 @@ func (h *Handler) Copy(w http.ResponseWriter, r *http.Request) {
|
|||
ctx.Transaction, err = h.Runtime.Db.Beginx()
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -837,6 +876,7 @@ func (h *Handler) Copy(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -966,10 +1006,12 @@ func (h *Handler) GetDiff(w http.ResponseWriter, r *http.Request) {
|
|||
p, err := h.Store.Page.Get(ctx, pageID)
|
||||
if err == sql.ErrNoRows {
|
||||
response.WriteNotFoundError(w, method, pageID)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -1029,6 +1071,7 @@ func (h *Handler) Rollback(w http.ResponseWriter, r *http.Request) {
|
|||
ctx.Transaction, err = h.Runtime.Db.Beginx()
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -1041,18 +1084,21 @@ func (h *Handler) Rollback(w http.ResponseWriter, r *http.Request) {
|
|||
meta, err := h.Store.Page.GetPageMeta(ctx, pageID)
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
revision, err := h.Store.Page.GetPageRevision(ctx, revisionID)
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
doc, err := h.Store.Document.Get(ctx, documentID)
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -1064,6 +1110,7 @@ func (h *Handler) Rollback(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -1075,6 +1122,7 @@ func (h *Handler) Rollback(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -58,6 +58,7 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) {
|
|||
body, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
response.WriteBadRequestError(w, method, "body")
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -65,6 +66,7 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) {
|
|||
err = json.Unmarshal(body, &pin)
|
||||
if err != nil {
|
||||
response.WriteBadRequestError(w, method, "pin")
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -79,6 +81,7 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) {
|
|||
ctx.Transaction, err = h.Runtime.Db.Beginx()
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -86,6 +89,7 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -121,6 +125,7 @@ func (h *Handler) GetUserPins(w http.ResponseWriter, r *http.Request) {
|
|||
pins, err := h.Store.Pin.GetUserPins(ctx, userID)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -162,6 +167,7 @@ func (h *Handler) DeleteUserPin(w http.ResponseWriter, r *http.Request) {
|
|||
ctx.Transaction, err = h.Runtime.Db.Beginx()
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -169,6 +175,7 @@ func (h *Handler) DeleteUserPin(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil && err != sql.ErrNoRows {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -204,6 +211,7 @@ func (h *Handler) UpdatePinSequence(w http.ResponseWriter, r *http.Request) {
|
|||
body, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
response.WriteBadRequestError(w, method, err.Error())
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -212,12 +220,14 @@ func (h *Handler) UpdatePinSequence(w http.ResponseWriter, r *http.Request) {
|
|||
err = json.Unmarshal(body, &pins)
|
||||
if err != nil {
|
||||
response.WriteBadRequestError(w, method, err.Error())
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Transaction, err = h.Runtime.Db.Beginx()
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -226,6 +236,7 @@ func (h *Handler) UpdatePinSequence(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -237,6 +248,7 @@ func (h *Handler) UpdatePinSequence(w http.ResponseWriter, r *http.Request) {
|
|||
newPins, err := h.Store.Pin.GetUserPins(ctx, userID)
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -17,8 +17,6 @@ import (
|
|||
"sort"
|
||||
"time"
|
||||
|
||||
"github.com/documize/community/core/log"
|
||||
|
||||
gogithub "github.com/google/go-github/github"
|
||||
)
|
||||
|
||||
|
@ -257,21 +255,19 @@ func getCommits(client *gogithub.Client, config *githubConfig) ([]githubCommit,
|
|||
}
|
||||
|
||||
func refreshCommits(gr *githubRender, config *githubConfig, client *gogithub.Client) (err error) {
|
||||
|
||||
if !config.ShowCommits {
|
||||
return nil
|
||||
}
|
||||
|
||||
gr.BranchCommits, gr.AuthorStats, err = getCommits(client, config)
|
||||
if err != nil {
|
||||
log.Error("github refreshCommits:", err)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func renderCommits(payload *githubRender, c *githubConfig) error {
|
||||
|
||||
if !c.ShowCommits {
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -16,8 +16,6 @@ import (
|
|||
"sort"
|
||||
"time"
|
||||
|
||||
"github.com/documize/community/core/log"
|
||||
|
||||
gogithub "github.com/google/go-github/github"
|
||||
)
|
||||
|
||||
|
@ -69,10 +67,8 @@ func (s issuesToSort) Less(i, j int) bool {
|
|||
return false
|
||||
}
|
||||
// TODO this seems a very slow approach
|
||||
iDate, iErr := time.Parse(issuesTimeFormat, s[i].Updated)
|
||||
log.IfErr(iErr)
|
||||
jDate, jErr := time.Parse(issuesTimeFormat, s[j].Updated)
|
||||
log.IfErr(jErr)
|
||||
iDate, _ := time.Parse(issuesTimeFormat, s[i].Updated)
|
||||
jDate, _ := time.Parse(issuesTimeFormat, s[j].Updated)
|
||||
return iDate.Before(jDate)
|
||||
}
|
||||
|
||||
|
@ -187,14 +183,12 @@ func getIssues(client *gogithub.Client, config *githubConfig) ([]githubIssue, er
|
|||
}
|
||||
|
||||
func refreshIssues(gr *githubRender, config *githubConfig, client *gogithub.Client) (err error) {
|
||||
|
||||
if !config.ShowIssues {
|
||||
return nil
|
||||
}
|
||||
|
||||
gr.Issues, err = getIssues(client, config)
|
||||
if err != nil {
|
||||
log.Error("unable to get github issues (cmd)", err)
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -16,8 +16,6 @@ import (
|
|||
"html/template"
|
||||
"sort"
|
||||
|
||||
"github.com/documize/community/core/log"
|
||||
|
||||
gogithub "github.com/google/go-github/github"
|
||||
)
|
||||
|
||||
|
@ -166,7 +164,6 @@ func refreshMilestones(gr *githubRender, config *githubConfig, client *gogithub.
|
|||
|
||||
gr.Milestones, err = getMilestones(client, config)
|
||||
if err != nil {
|
||||
log.Error("unable to get github milestones", err)
|
||||
return err
|
||||
}
|
||||
gr.OpenMS = 0
|
||||
|
|
|
@ -16,8 +16,6 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/documize/community/core/log"
|
||||
|
||||
gogithub "github.com/google/go-github/github"
|
||||
)
|
||||
|
||||
|
@ -114,7 +112,6 @@ func (c *githubConfig) Clean() {
|
|||
}
|
||||
err := since.UnmarshalText(tt)
|
||||
if err != nil {
|
||||
log.ErrorString("Date unmarshall '" + c.BranchSince + "'->'" + string(tt) + "' error: " + err.Error())
|
||||
} else {
|
||||
c.SincePtr = &since
|
||||
}
|
||||
|
|
|
@ -49,6 +49,7 @@ func (h *Handler) SMTP(w http.ResponseWriter, r *http.Request) {
|
|||
j, err := json.Marshal(y)
|
||||
if err != nil {
|
||||
response.WriteBadRequestError(w, method, err.Error())
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -70,6 +71,7 @@ func (h *Handler) SetSMTP(w http.ResponseWriter, r *http.Request) {
|
|||
body, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
response.WriteBadRequestError(w, method, err.Error())
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -79,6 +81,7 @@ func (h *Handler) SetSMTP(w http.ResponseWriter, r *http.Request) {
|
|||
ctx.Transaction, err = h.Runtime.Db.Beginx()
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -177,6 +180,7 @@ func (h *Handler) SetLicense(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
// AuthConfig returns installation-wide auth configuration
|
||||
func (h *Handler) AuthConfig(w http.ResponseWriter, r *http.Request) {
|
||||
method := "global.auth"
|
||||
ctx := domain.GetRequestContext(r)
|
||||
|
||||
if !ctx.Global {
|
||||
|
@ -187,6 +191,7 @@ func (h *Handler) AuthConfig(w http.ResponseWriter, r *http.Request) {
|
|||
org, err := h.Store.Organization.GetOrganization(ctx, ctx.OrgID)
|
||||
if err != nil {
|
||||
response.WriteForbiddenError(w)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -195,7 +200,7 @@ func (h *Handler) AuthConfig(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
// SetAuthConfig persists installation-wide authentication configuration
|
||||
func (h *Handler) SetAuthConfig(w http.ResponseWriter, r *http.Request) {
|
||||
method := "SaveAuthConfig"
|
||||
method := "global.auth.save"
|
||||
ctx := domain.GetRequestContext(r)
|
||||
|
||||
if !ctx.Global {
|
||||
|
@ -215,12 +220,14 @@ func (h *Handler) SetAuthConfig(w http.ResponseWriter, r *http.Request) {
|
|||
err = json.Unmarshal(body, &data)
|
||||
if err != nil {
|
||||
response.WriteBadRequestError(w, method, err.Error())
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
org, err := h.Store.Organization.GetOrganization(ctx, ctx.OrgID)
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -230,6 +237,7 @@ func (h *Handler) SetAuthConfig(w http.ResponseWriter, r *http.Request) {
|
|||
ctx.Transaction, err = h.Runtime.Db.Beginx()
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -237,6 +245,7 @@ func (h *Handler) SetAuthConfig(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -61,6 +61,7 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) {
|
|||
body, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
response.WriteBadRequestError(w, method, err.Error())
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -68,6 +69,7 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) {
|
|||
err = json.Unmarshal(body, &space)
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -79,6 +81,7 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) {
|
|||
ctx.Transaction, err = h.Runtime.Db.Beginx()
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -89,6 +92,7 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -115,10 +119,12 @@ func (h *Handler) Get(w http.ResponseWriter, r *http.Request) {
|
|||
sp, err := h.Store.Space.Get(ctx, id)
|
||||
if err == sql.ErrNoRows {
|
||||
response.WriteNotFoundError(w, method, id)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -131,8 +137,10 @@ func (h *Handler) GetAll(w http.ResponseWriter, r *http.Request) {
|
|||
ctx := domain.GetRequestContext(r)
|
||||
|
||||
sp, err := h.Store.Space.GetAll(ctx)
|
||||
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -151,6 +159,7 @@ func (h *Handler) GetSpaceViewers(w http.ResponseWriter, r *http.Request) {
|
|||
v, err := h.Store.Space.Viewers(ctx)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -181,6 +190,7 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request) {
|
|||
body, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
response.WriteBadRequestError(w, method, err.Error())
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -188,11 +198,13 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request) {
|
|||
err = json.Unmarshal(body, &sp)
|
||||
if err != nil {
|
||||
response.WriteBadRequestError(w, method, "marshal")
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
if len(sp.Name) == 0 {
|
||||
response.WriteMissingDataError(w, method, "name")
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -201,6 +213,7 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request) {
|
|||
ctx.Transaction, err = h.Runtime.Db.Beginx()
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -208,6 +221,7 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -249,6 +263,7 @@ func (h *Handler) Remove(w http.ResponseWriter, r *http.Request) {
|
|||
ctx.Transaction, err = h.Runtime.Db.Beginx()
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -256,6 +271,7 @@ func (h *Handler) Remove(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -263,6 +279,7 @@ func (h *Handler) Remove(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -270,6 +287,7 @@ func (h *Handler) Remove(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -277,6 +295,7 @@ func (h *Handler) Remove(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil && err != sql.ErrNoRows {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -312,6 +331,7 @@ func (h *Handler) Delete(w http.ResponseWriter, r *http.Request) {
|
|||
ctx.Transaction, err = h.Runtime.Db.Beginx()
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -319,6 +339,7 @@ func (h *Handler) Delete(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -326,6 +347,7 @@ func (h *Handler) Delete(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -333,6 +355,7 @@ func (h *Handler) Delete(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil && err != sql.ErrNoRows {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -374,6 +397,7 @@ func (h *Handler) SetPermissions(w http.ResponseWriter, r *http.Request) {
|
|||
body, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
response.WriteBadRequestError(w, method, err.Error())
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -381,12 +405,14 @@ func (h *Handler) SetPermissions(w http.ResponseWriter, r *http.Request) {
|
|||
err = json.Unmarshal(body, &model)
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Transaction, err = h.Runtime.Db.Beginx()
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -396,6 +422,7 @@ func (h *Handler) SetPermissions(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -411,6 +438,7 @@ func (h *Handler) SetPermissions(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -419,6 +447,7 @@ func (h *Handler) SetPermissions(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -509,6 +538,7 @@ func (h *Handler) SetPermissions(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -557,6 +587,7 @@ func (h *Handler) AcceptInvitation(w http.ResponseWriter, r *http.Request) {
|
|||
org, err := h.Store.Organization.GetOrganizationByDomain(ctx.Subdomain)
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -567,6 +598,7 @@ func (h *Handler) AcceptInvitation(w http.ResponseWriter, r *http.Request) {
|
|||
body, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
response.WriteBadRequestError(w, method, err.Error())
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -574,6 +606,7 @@ func (h *Handler) AcceptInvitation(w http.ResponseWriter, r *http.Request) {
|
|||
err = json.Unmarshal(body, &model)
|
||||
if err != nil {
|
||||
response.WriteBadRequestError(w, method, err.Error())
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -585,6 +618,7 @@ func (h *Handler) AcceptInvitation(w http.ResponseWriter, r *http.Request) {
|
|||
u, err := h.Store.User.GetBySerial(ctx, model.Serial)
|
||||
if err != nil && err == sql.ErrNoRows {
|
||||
response.WriteDuplicateError(w, method, "user")
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -598,6 +632,7 @@ func (h *Handler) AcceptInvitation(w http.ResponseWriter, r *http.Request) {
|
|||
ctx.Transaction, err = h.Runtime.Db.Beginx()
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -605,6 +640,7 @@ func (h *Handler) AcceptInvitation(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -614,6 +650,7 @@ func (h *Handler) AcceptInvitation(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -638,6 +675,7 @@ func (h *Handler) Invite(w http.ResponseWriter, r *http.Request) {
|
|||
sp, err := h.Store.Space.Get(ctx, id)
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -650,6 +688,7 @@ func (h *Handler) Invite(w http.ResponseWriter, r *http.Request) {
|
|||
body, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
response.WriteBadRequestError(w, method, "body")
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -657,18 +696,21 @@ func (h *Handler) Invite(w http.ResponseWriter, r *http.Request) {
|
|||
err = json.Unmarshal(body, &model)
|
||||
if err != nil {
|
||||
response.WriteBadRequestError(w, method, "json")
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Transaction, err = h.Runtime.Db.Beginx()
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
inviter, err := h.Store.User.Get(ctx, ctx.UserID)
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -677,6 +719,7 @@ func (h *Handler) Invite(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil && err != sql.ErrNoRows {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -686,6 +729,7 @@ func (h *Handler) Invite(w http.ResponseWriter, r *http.Request) {
|
|||
if err2 != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -711,6 +755,7 @@ func (h *Handler) Invite(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -731,6 +776,7 @@ func (h *Handler) Invite(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -748,6 +794,7 @@ func (h *Handler) Invite(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -764,6 +811,7 @@ func (h *Handler) Invite(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,6 +50,7 @@ func (h *Handler) SavedList(w http.ResponseWriter, r *http.Request) {
|
|||
documents, err := h.Store.Document.Templates(ctx)
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -90,12 +91,14 @@ func (h *Handler) SaveAs(w http.ResponseWriter, r *http.Request) {
|
|||
body, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
response.WriteBadRequestError(w, method, "Bad payload")
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
err = json.Unmarshal(body, &model)
|
||||
if err != nil {
|
||||
response.WriteBadRequestError(w, method, "unmarshal")
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -108,6 +111,7 @@ func (h *Handler) SaveAs(w http.ResponseWriter, r *http.Request) {
|
|||
ctx.Transaction, err = h.Runtime.Db.Beginx()
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -115,6 +119,7 @@ func (h *Handler) SaveAs(w http.ResponseWriter, r *http.Request) {
|
|||
doc, err := h.Store.Document.Get(ctx, model.DocumentID)
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -132,6 +137,7 @@ func (h *Handler) SaveAs(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -142,6 +148,7 @@ func (h *Handler) SaveAs(w http.ResponseWriter, r *http.Request) {
|
|||
meta, err2 := h.Store.Page.GetPageMeta(ctx, p.RefID)
|
||||
if err2 != nil {
|
||||
response.WriteServerError(w, method, err2)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -171,6 +178,7 @@ func (h *Handler) SaveAs(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -180,6 +188,7 @@ func (h *Handler) SaveAs(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -190,6 +199,7 @@ func (h *Handler) SaveAs(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -202,6 +212,7 @@ func (h *Handler) SaveAs(w http.ResponseWriter, r *http.Request) {
|
|||
doc, err = h.Store.Document.Get(ctx, docID)
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -230,6 +241,7 @@ func (h *Handler) Use(w http.ResponseWriter, r *http.Request) {
|
|||
body, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
response.WriteBadRequestError(w, method, "Bad payload")
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -259,6 +271,7 @@ func (h *Handler) Use(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -269,6 +282,7 @@ func (h *Handler) Use(w http.ResponseWriter, r *http.Request) {
|
|||
ctx.Transaction, err = h.Runtime.Db.Beginx()
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -284,6 +298,7 @@ func (h *Handler) Use(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -292,6 +307,7 @@ func (h *Handler) Use(w http.ResponseWriter, r *http.Request) {
|
|||
if err2 != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -311,6 +327,7 @@ func (h *Handler) Use(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -329,6 +346,7 @@ func (h *Handler) Use(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,6 +62,7 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) {
|
|||
body, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
response.WriteBadRequestError(w, method, err.Error())
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -69,6 +70,7 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) {
|
|||
err = json.Unmarshal(body, &userModel)
|
||||
if err != nil {
|
||||
response.WriteBadRequestError(w, method, err.Error())
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -106,6 +108,7 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) {
|
|||
userDupe, err := h.Store.User.GetByEmail(ctx, userModel.Email)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -119,6 +122,7 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) {
|
|||
ctx.Transaction, err = h.Runtime.Db.Beginx()
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -130,6 +134,7 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -160,6 +165,7 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -186,6 +192,7 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) {
|
|||
inviter, err := h.Store.User.Get(ctx, ctx.UserID)
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -233,6 +240,7 @@ func (h *Handler) GetOrganizationUsers(w http.ResponseWriter, r *http.Request) {
|
|||
u, err = h.Store.User.GetActiveUsersForOrganization(ctx)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -240,6 +248,7 @@ func (h *Handler) GetOrganizationUsers(w http.ResponseWriter, r *http.Request) {
|
|||
u, err = h.Store.User.GetUsersForOrganization(ctx)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -272,8 +281,8 @@ func (h *Handler) GetSpaceUsers(w http.ResponseWriter, r *http.Request) {
|
|||
// check to see space type as it determines user selection criteria
|
||||
folder, err := h.Store.Space.Get(ctx, folderID)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
h.Runtime.Log.Error("cannot get space", err)
|
||||
response.WriteJSON(w, u)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -297,8 +306,8 @@ func (h *Handler) GetSpaceUsers(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
h.Runtime.Log.Error("cannot get users for space", err)
|
||||
response.WriteJSON(w, u)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -328,6 +337,7 @@ func (h *Handler) Get(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -354,6 +364,7 @@ func (h *Handler) Delete(w http.ResponseWriter, r *http.Request) {
|
|||
ctx.Transaction, err = h.Runtime.Db.Beginx()
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -361,6 +372,7 @@ func (h *Handler) Delete(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -368,6 +380,7 @@ func (h *Handler) Delete(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -397,6 +410,7 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request) {
|
|||
body, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
response.WriteBadRequestError(w, method, err.Error())
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -404,6 +418,7 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request) {
|
|||
err = json.Unmarshal(body, &u)
|
||||
if err != nil {
|
||||
response.WriteBadRequestError(w, method, err.Error())
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -422,6 +437,7 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request) {
|
|||
ctx.Transaction, err = h.Runtime.Db.Beginx()
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -432,6 +448,7 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -442,6 +459,7 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -453,6 +471,7 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -478,6 +497,7 @@ func (h *Handler) ChangePassword(w http.ResponseWriter, r *http.Request) {
|
|||
body, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
response.WriteBadRequestError(w, method, err.Error())
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
newPassword := string(body)
|
||||
|
@ -497,6 +517,7 @@ func (h *Handler) ChangePassword(w http.ResponseWriter, r *http.Request) {
|
|||
u, err := h.Store.User.Get(ctx, userID)
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -505,6 +526,7 @@ func (h *Handler) ChangePassword(w http.ResponseWriter, r *http.Request) {
|
|||
err = h.Store.User.UpdateUserPassword(ctx, userID, u.Salt, secrets.GeneratePassword(newPassword, u.Salt))
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -531,6 +553,7 @@ func (h *Handler) UserSpacePermissions(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -548,6 +571,7 @@ func (h *Handler) ForgotPassword(w http.ResponseWriter, r *http.Request) {
|
|||
body, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
response.WriteBadRequestError(w, method, "cannot ready payload")
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -555,12 +579,14 @@ func (h *Handler) ForgotPassword(w http.ResponseWriter, r *http.Request) {
|
|||
err = json.Unmarshal(body, &u)
|
||||
if err != nil {
|
||||
response.WriteBadRequestError(w, method, "JSON body")
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Transaction, err = h.Runtime.Db.Beginx()
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -570,6 +596,7 @@ func (h *Handler) ForgotPassword(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil && err != sql.ErrNoRows {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -603,6 +630,7 @@ func (h *Handler) ResetPassword(w http.ResponseWriter, r *http.Request) {
|
|||
body, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
response.WriteBadRequestError(w, method, "JSON body")
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
newPassword := string(body)
|
||||
|
@ -610,12 +638,14 @@ func (h *Handler) ResetPassword(w http.ResponseWriter, r *http.Request) {
|
|||
ctx.Transaction, err = h.Runtime.Db.Beginx()
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
u, err := h.Store.User.GetByToken(ctx, token)
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -625,6 +655,7 @@ func (h *Handler) ResetPassword(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -65,7 +65,7 @@ func (m *middleware) metrics(w http.ResponseWriter, r *http.Request, next http.H
|
|||
// request.Context provides caller user information.
|
||||
// Site meta sent back as HTTP custom headers.
|
||||
func (m *middleware) Authorize(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
|
||||
method := "Authorize"
|
||||
method := "middleware.auth"
|
||||
|
||||
// Let certain requests pass straight through
|
||||
authenticated := preAuthorizeStaticAssets(m.Runtime, r)
|
||||
|
@ -88,6 +88,7 @@ func (m *middleware) Authorize(w http.ResponseWriter, r *http.Request, next http
|
|||
// Inability to find org record spells the end of this request.
|
||||
if err != nil {
|
||||
response.WriteForbiddenError(w)
|
||||
m.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -103,7 +104,6 @@ func (m *middleware) Authorize(w http.ResponseWriter, r *http.Request, next http
|
|||
|
||||
if org.Domain != dom && org.Domain != dom2 {
|
||||
m.Runtime.Log.Info(fmt.Sprintf("domain mismatch %s vs. %s vs. %s", dom, dom2, org.Domain))
|
||||
|
||||
response.WriteUnauthorizedError(w)
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue