You've already forked focalboard
mirror of
https://github.com/mattermost/focalboard.git
synced 2025-07-15 23:54:29 +02:00
Fix nil stringer error (#788)
* fix nil stringer error * include API path with all API ERROR logs * enable "caller" field * disable colour output and min msg length for plugin * bump Logr version to v2.0.4
This commit is contained in:
@ -603,6 +603,8 @@ github.com/mattermost/logr v1.0.13 h1:6F/fM3csvH6Oy5sUpJuW7YyZSzZZAhJm5VcgKMxA2P
|
||||
github.com/mattermost/logr v1.0.13/go.mod h1:Mt4DPu1NXMe6JxPdwCC0XBoxXmN9eXOIRPoZarU2PXs=
|
||||
github.com/mattermost/logr/v2 v2.0.2 h1:+TDMWOFKfSmr9CDJqUUJouD+ZoYFhDL7URedKVYhjLg=
|
||||
github.com/mattermost/logr/v2 v2.0.2/go.mod h1:mpPp935r5dIkFDo2y9Q87cQWhFR/4xXpNh0k/y8Hmwg=
|
||||
github.com/mattermost/logr/v2 v2.0.4 h1:LiqvzNNfia23hlu1zmmCDmjqmSfwWNsEtFlL4/7jf8o=
|
||||
github.com/mattermost/logr/v2 v2.0.4/go.mod h1:mpPp935r5dIkFDo2y9Q87cQWhFR/4xXpNh0k/y8Hmwg=
|
||||
github.com/mattermost/mattermost-server/v5 v5.3.2-0.20210524045451-a4f7df6f6e3c h1:p0C9yt6UYyTExEeHjBPBUCwCMAyTWvwAEc2/plNuZL4=
|
||||
github.com/mattermost/mattermost-server/v5 v5.3.2-0.20210524045451-a4f7df6f6e3c/go.mod h1:6CqGEG0Vnhrl23h8LB+lcOIT8KIUhzbJ7qhXlV7Ek9U=
|
||||
github.com/mattermost/rsc v0.0.0-20160330161541-bbaefb05eaa0/go.mod h1:nV5bfVpT//+B1RPD2JvRnxbkLmJEYXmRaaVl15fsXjs=
|
||||
|
@ -631,8 +631,8 @@ github.com/mattermost/ldap v0.0.0-20201202150706-ee0e6284187d h1:/RJ/UV7M5c7L2TQ
|
||||
github.com/mattermost/ldap v0.0.0-20201202150706-ee0e6284187d/go.mod h1:HLbgMEI5K131jpxGazJ97AxfPDt31osq36YS1oxFQPQ=
|
||||
github.com/mattermost/logr v1.0.13 h1:6F/fM3csvH6Oy5sUpJuW7YyZSzZZAhJm5VcgKMxA2P8=
|
||||
github.com/mattermost/logr v1.0.13/go.mod h1:Mt4DPu1NXMe6JxPdwCC0XBoxXmN9eXOIRPoZarU2PXs=
|
||||
github.com/mattermost/logr/v2 v2.0.2 h1:+TDMWOFKfSmr9CDJqUUJouD+ZoYFhDL7URedKVYhjLg=
|
||||
github.com/mattermost/logr/v2 v2.0.2/go.mod h1:mpPp935r5dIkFDo2y9Q87cQWhFR/4xXpNh0k/y8Hmwg=
|
||||
github.com/mattermost/logr/v2 v2.0.4 h1:LiqvzNNfia23hlu1zmmCDmjqmSfwWNsEtFlL4/7jf8o=
|
||||
github.com/mattermost/logr/v2 v2.0.4/go.mod h1:mpPp935r5dIkFDo2y9Q87cQWhFR/4xXpNh0k/y8Hmwg=
|
||||
github.com/mattermost/mattermost-plugin-api v0.0.16 h1:z6RIUrlAr60ndVsq/jFGUAiXneC3do8DEaJOSwnlCZc=
|
||||
github.com/mattermost/mattermost-plugin-api v0.0.16/go.mod h1:639htr5pWIP6B1/FsRdb024csfq1M1L1MAzfk2FmajQ=
|
||||
github.com/mattermost/mattermost-server/v5 v5.3.2-0.20210524045451-a4f7df6f6e3c/go.mod h1:6CqGEG0Vnhrl23h8LB+lcOIT8KIUhzbJ7qhXlV7Ek9U=
|
||||
|
@ -181,9 +181,10 @@ func defaultLoggingConfig() string {
|
||||
"format": "plain",
|
||||
"format_options": {
|
||||
"delim": " ",
|
||||
"min_level_len": 5,
|
||||
"min_msg_len": 40,
|
||||
"enable_color": true
|
||||
"min_level_len": 0,
|
||||
"min_msg_len": 0,
|
||||
"enable_color": false,
|
||||
"enable_caller": true
|
||||
},
|
||||
"levels": [
|
||||
{"id": 5, "name": "debug"},
|
||||
|
@ -21,14 +21,14 @@ func (a *API) handleAdminSetPassword(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
requestBody, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
var requestData AdminSetPasswordData
|
||||
err = json.Unmarshal(requestBody, &requestData)
|
||||
if err != nil {
|
||||
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -37,13 +37,13 @@ func (a *API) handleAdminSetPassword(w http.ResponseWriter, r *http.Request) {
|
||||
auditRec.AddMeta("username", username)
|
||||
|
||||
if !strings.Contains(requestData.Password, "") {
|
||||
a.errorResponse(w, http.StatusBadRequest, "password is required", err)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, "password is required", err)
|
||||
return
|
||||
}
|
||||
|
||||
err = a.app.UpdateUserPassword(username, requestData.Password)
|
||||
if err != nil {
|
||||
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -103,7 +103,7 @@ func (a *API) requireCSRFToken(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if !a.checkCSRFToken(r) {
|
||||
a.logger.Error("checkCSRFToken FAILED")
|
||||
a.errorResponse(w, http.StatusBadRequest, "", nil)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, "checkCSRFToken FAILED", nil)
|
||||
return
|
||||
}
|
||||
|
||||
@ -228,7 +228,7 @@ func (a *API) handleGetBlocks(w http.ResponseWriter, r *http.Request) {
|
||||
blockType := query.Get("type")
|
||||
container, err := a.getContainer(r)
|
||||
if err != nil {
|
||||
a.noContainerErrorResponse(w, err)
|
||||
a.noContainerErrorResponse(w, r.URL.Path, err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -239,7 +239,7 @@ func (a *API) handleGetBlocks(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
blocks, err := a.app.GetBlocks(*container, parentID, blockType)
|
||||
if err != nil {
|
||||
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -251,7 +251,7 @@ func (a *API) handleGetBlocks(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
json, err := json.Marshal(blocks)
|
||||
if err != nil {
|
||||
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -314,13 +314,13 @@ func (a *API) handlePostBlocks(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
container, err := a.getContainer(r)
|
||||
if err != nil {
|
||||
a.noContainerErrorResponse(w, err)
|
||||
a.noContainerErrorResponse(w, r.URL.Path, err)
|
||||
return
|
||||
}
|
||||
|
||||
requestBody, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -328,7 +328,7 @@ func (a *API) handlePostBlocks(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
err = json.Unmarshal(requestBody, &blocks)
|
||||
if err != nil {
|
||||
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -336,19 +336,19 @@ func (a *API) handlePostBlocks(w http.ResponseWriter, r *http.Request) {
|
||||
// Error checking
|
||||
if len(block.Type) < 1 {
|
||||
message := fmt.Sprintf("missing type for block id %s", block.ID)
|
||||
a.errorResponse(w, http.StatusBadRequest, message, nil)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, message, nil)
|
||||
return
|
||||
}
|
||||
|
||||
if block.CreateAt < 1 {
|
||||
message := fmt.Sprintf("invalid createAt for block id %s", block.ID)
|
||||
a.errorResponse(w, http.StatusBadRequest, message, nil)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, message, nil)
|
||||
return
|
||||
}
|
||||
|
||||
if block.UpdateAt < 1 {
|
||||
message := fmt.Sprintf("invalid UpdateAt for block id %s", block.ID)
|
||||
a.errorResponse(w, http.StatusBadRequest, message, nil)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, message, nil)
|
||||
return
|
||||
}
|
||||
}
|
||||
@ -363,7 +363,7 @@ func (a *API) handlePostBlocks(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
err = a.app.InsertBlocks(*container, blocks, session.UserID)
|
||||
if err != nil {
|
||||
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -409,13 +409,13 @@ func (a *API) handleGetUser(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
user, err := a.app.GetUser(userID)
|
||||
if err != nil {
|
||||
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
userData, err := json.Marshal(user)
|
||||
if err != nil {
|
||||
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -463,14 +463,14 @@ func (a *API) handleGetMe(w http.ResponseWriter, r *http.Request) {
|
||||
} else {
|
||||
user, err = a.app.GetUser(session.UserID)
|
||||
if err != nil {
|
||||
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
userData, err := json.Marshal(user)
|
||||
if err != nil {
|
||||
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -518,7 +518,7 @@ func (a *API) handleDeleteBlock(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
container, err := a.getContainer(r)
|
||||
if err != nil {
|
||||
a.noContainerErrorResponse(w, err)
|
||||
a.noContainerErrorResponse(w, r.URL.Path, err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -528,7 +528,7 @@ func (a *API) handleDeleteBlock(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
err = a.app.DeleteBlock(*container, blockID, userID)
|
||||
if err != nil {
|
||||
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -583,7 +583,7 @@ func (a *API) handleGetSubTree(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
container, err := a.getContainerAllowingReadTokenForBlock(r, blockID)
|
||||
if err != nil {
|
||||
a.noContainerErrorResponse(w, err)
|
||||
a.noContainerErrorResponse(w, r.URL.Path, err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -595,7 +595,7 @@ func (a *API) handleGetSubTree(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
if levels != 2 && levels != 3 {
|
||||
a.logger.Error("Invalid levels", mlog.Int64("levels", levels))
|
||||
a.errorResponse(w, http.StatusBadRequest, "invalid levels", nil)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, "invalid levels", nil)
|
||||
return
|
||||
}
|
||||
|
||||
@ -605,7 +605,7 @@ func (a *API) handleGetSubTree(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
blocks, err := a.app.GetSubTree(*container, blockID, int(levels))
|
||||
if err != nil {
|
||||
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -616,7 +616,7 @@ func (a *API) handleGetSubTree(w http.ResponseWriter, r *http.Request) {
|
||||
)
|
||||
json, err := json.Marshal(blocks)
|
||||
if err != nil {
|
||||
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -658,7 +658,7 @@ func (a *API) handleExport(w http.ResponseWriter, r *http.Request) {
|
||||
rootID := query.Get("root_id")
|
||||
container, err := a.getContainer(r)
|
||||
if err != nil {
|
||||
a.noContainerErrorResponse(w, err)
|
||||
a.noContainerErrorResponse(w, r.URL.Path, err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -673,7 +673,7 @@ func (a *API) handleExport(w http.ResponseWriter, r *http.Request) {
|
||||
blocks, err = a.app.GetBlocksWithRootID(*container, rootID)
|
||||
}
|
||||
if err != nil {
|
||||
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -687,7 +687,7 @@ func (a *API) handleExport(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
json, err := json.Marshal(blocks)
|
||||
if err != nil {
|
||||
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -765,13 +765,13 @@ func (a *API) handleImport(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
container, err := a.getContainer(r)
|
||||
if err != nil {
|
||||
a.noContainerErrorResponse(w, err)
|
||||
a.noContainerErrorResponse(w, r.URL.Path, err)
|
||||
return
|
||||
}
|
||||
|
||||
requestBody, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -779,7 +779,7 @@ func (a *API) handleImport(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
err = json.Unmarshal(requestBody, &blocks)
|
||||
if err != nil {
|
||||
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -792,7 +792,7 @@ func (a *API) handleImport(w http.ResponseWriter, r *http.Request) {
|
||||
session := ctx.Value(sessionContextKey).(*model.Session)
|
||||
err = a.app.InsertBlocks(*container, blocks, session.UserID)
|
||||
if err != nil {
|
||||
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -841,7 +841,7 @@ func (a *API) handleGetSharing(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
container, err := a.getContainer(r)
|
||||
if err != nil {
|
||||
a.noContainerErrorResponse(w, err)
|
||||
a.noContainerErrorResponse(w, r.URL.Path, err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -851,13 +851,13 @@ func (a *API) handleGetSharing(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
sharing, err := a.app.GetSharing(*container, rootID)
|
||||
if err != nil {
|
||||
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
sharingData, err := json.Marshal(sharing)
|
||||
if err != nil {
|
||||
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -913,13 +913,13 @@ func (a *API) handlePostSharing(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
container, err := a.getContainer(r)
|
||||
if err != nil {
|
||||
a.noContainerErrorResponse(w, err)
|
||||
a.noContainerErrorResponse(w, r.URL.Path, err)
|
||||
return
|
||||
}
|
||||
|
||||
requestBody, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -927,7 +927,7 @@ func (a *API) handlePostSharing(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
err = json.Unmarshal(requestBody, &sharing)
|
||||
if err != nil {
|
||||
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -947,7 +947,7 @@ func (a *API) handlePostSharing(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
err = a.app.UpsertSharing(*container, sharing)
|
||||
if err != nil {
|
||||
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -995,22 +995,22 @@ func (a *API) handleGetWorkspace(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
session := ctx.Value(sessionContextKey).(*model.Session)
|
||||
if !a.app.DoesUserHaveWorkspaceAccess(session.UserID, workspaceID) {
|
||||
a.errorResponse(w, http.StatusUnauthorized, "", nil)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusUnauthorized, "user does not have workspace access", nil)
|
||||
return
|
||||
}
|
||||
|
||||
workspace, err = a.app.GetWorkspace(workspaceID)
|
||||
if err != nil {
|
||||
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
}
|
||||
if workspace == nil {
|
||||
a.errorResponse(w, http.StatusUnauthorized, "", nil)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusUnauthorized, "invalid workspace", nil)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
workspace, err = a.app.GetRootWorkspace()
|
||||
if err != nil {
|
||||
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
@ -1021,7 +1021,7 @@ func (a *API) handleGetWorkspace(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
workspaceData, err := json.Marshal(workspace)
|
||||
if err != nil {
|
||||
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -1055,7 +1055,7 @@ func (a *API) handlePostWorkspaceRegenerateSignupToken(w http.ResponseWriter, r
|
||||
|
||||
workspace, err := a.app.GetRootWorkspace()
|
||||
if err != nil {
|
||||
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -1066,7 +1066,7 @@ func (a *API) handlePostWorkspaceRegenerateSignupToken(w http.ResponseWriter, r
|
||||
|
||||
err = a.app.UpsertWorkspaceSignupToken(*workspace)
|
||||
if err != nil {
|
||||
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -1120,7 +1120,7 @@ func (a *API) handleServeFile(w http.ResponseWriter, r *http.Request) {
|
||||
// Caller must have access to the root block's container
|
||||
_, err := a.getContainerAllowingReadTokenForBlock(r, rootID)
|
||||
if err != nil {
|
||||
a.noContainerErrorResponse(w, err)
|
||||
a.noContainerErrorResponse(w, r.URL.Path, err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -1140,7 +1140,7 @@ func (a *API) handleServeFile(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
fileReader, err := a.app.GetFileReader(workspaceID, rootID, filename)
|
||||
if err != nil {
|
||||
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
defer fileReader.Close()
|
||||
@ -1200,7 +1200,7 @@ func (a *API) handleUploadFile(w http.ResponseWriter, r *http.Request) {
|
||||
// Caller must have access to the root block's container
|
||||
_, err := a.getContainerAllowingReadTokenForBlock(r, rootID)
|
||||
if err != nil {
|
||||
a.noContainerErrorResponse(w, err)
|
||||
a.noContainerErrorResponse(w, r.URL.Path, err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -1219,7 +1219,7 @@ func (a *API) handleUploadFile(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
fileID, err := a.app.SaveFile(file, workspaceID, rootID, handle.Filename)
|
||||
if err != nil {
|
||||
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -1229,7 +1229,7 @@ func (a *API) handleUploadFile(w http.ResponseWriter, r *http.Request) {
|
||||
)
|
||||
data, err := json.Marshal(FileUploadResponse{FileID: fileID})
|
||||
if err != nil {
|
||||
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -1273,7 +1273,7 @@ func (a *API) getWorkspaceUsers(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
session := ctx.Value(sessionContextKey).(*model.Session)
|
||||
if !a.app.DoesUserHaveWorkspaceAccess(session.UserID, workspaceID) {
|
||||
a.errorResponse(w, http.StatusForbidden, "Access denied to workspace", PermissionError{"access denied to workspace"})
|
||||
a.errorResponse(w, r.URL.Path, http.StatusForbidden, "Access denied to workspace", PermissionError{"access denied to workspace"})
|
||||
return
|
||||
}
|
||||
|
||||
@ -1282,13 +1282,13 @@ func (a *API) getWorkspaceUsers(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
users, err := a.app.GetWorkspaceUsers(workspaceID)
|
||||
if err != nil {
|
||||
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
data, err := json.Marshal(users)
|
||||
if err != nil {
|
||||
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -1300,10 +1300,12 @@ func (a *API) getWorkspaceUsers(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
// Response helpers
|
||||
|
||||
func (a *API) errorResponse(w http.ResponseWriter, code int, message string, sourceError error) {
|
||||
func (a *API) errorResponse(w http.ResponseWriter, api string, code int, message string, sourceError error) {
|
||||
a.logger.Error("API ERROR",
|
||||
mlog.Int("code", code),
|
||||
mlog.Err(sourceError),
|
||||
mlog.String("msg", message),
|
||||
mlog.String("api", api),
|
||||
)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
data, err := json.Marshal(model.ErrorResponse{Error: message, ErrorCode: code})
|
||||
@ -1314,11 +1316,13 @@ func (a *API) errorResponse(w http.ResponseWriter, code int, message string, sou
|
||||
_, _ = w.Write(data)
|
||||
}
|
||||
|
||||
func (a *API) errorResponseWithCode(w http.ResponseWriter, statusCode int, errorCode int, message string, sourceError error) {
|
||||
func (a *API) errorResponseWithCode(w http.ResponseWriter, api string, statusCode int, errorCode int, message string, sourceError error) {
|
||||
a.logger.Error("API ERROR",
|
||||
mlog.Int("status", statusCode),
|
||||
mlog.Int("code", errorCode),
|
||||
mlog.Err(sourceError),
|
||||
mlog.String("msg", message),
|
||||
mlog.String("api", api),
|
||||
)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
data, err := json.Marshal(model.ErrorResponse{Error: message, ErrorCode: errorCode})
|
||||
@ -1329,8 +1333,8 @@ func (a *API) errorResponseWithCode(w http.ResponseWriter, statusCode int, error
|
||||
_, _ = w.Write(data)
|
||||
}
|
||||
|
||||
func (a *API) noContainerErrorResponse(w http.ResponseWriter, sourceError error) {
|
||||
a.errorResponseWithCode(w, http.StatusBadRequest, ErrorNoWorkspaceCode, ErrorNoWorkspaceMessage, sourceError)
|
||||
func (a *API) noContainerErrorResponse(w http.ResponseWriter, api string, sourceError error) {
|
||||
a.errorResponseWithCode(w, api, http.StatusBadRequest, ErrorNoWorkspaceCode, ErrorNoWorkspaceMessage, sourceError)
|
||||
}
|
||||
|
||||
func jsonStringResponse(w http.ResponseWriter, code int, message string) { //nolint:unparam
|
||||
|
@ -159,20 +159,20 @@ func (a *API) handleLogin(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
if len(a.singleUserToken) > 0 {
|
||||
// Not permitted in single-user mode
|
||||
a.errorResponse(w, http.StatusUnauthorized, "", nil)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusUnauthorized, "not permitted in single-user mode", nil)
|
||||
return
|
||||
}
|
||||
|
||||
requestBody, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
var loginData LoginRequest
|
||||
err = json.Unmarshal(requestBody, &loginData)
|
||||
if err != nil {
|
||||
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -184,12 +184,12 @@ func (a *API) handleLogin(w http.ResponseWriter, r *http.Request) {
|
||||
if loginData.Type == "normal" {
|
||||
token, err := a.app.Login(loginData.Username, loginData.Email, loginData.Password, loginData.MfaToken)
|
||||
if err != nil {
|
||||
a.errorResponse(w, http.StatusUnauthorized, "incorrect login", err)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusUnauthorized, "incorrect login", err)
|
||||
return
|
||||
}
|
||||
json, err := json.Marshal(LoginResponse{Token: token})
|
||||
if err != nil {
|
||||
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -198,7 +198,7 @@ func (a *API) handleLogin(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
a.errorResponse(w, http.StatusBadRequest, "invalid login type", nil)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, "invalid login type", nil)
|
||||
}
|
||||
|
||||
func (a *API) handleRegister(w http.ResponseWriter, r *http.Request) {
|
||||
@ -228,20 +228,20 @@ func (a *API) handleRegister(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
if len(a.singleUserToken) > 0 {
|
||||
// Not permitted in single-user mode
|
||||
a.errorResponse(w, http.StatusUnauthorized, "", nil)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusUnauthorized, "not permitted in single-user mode", nil)
|
||||
return
|
||||
}
|
||||
|
||||
requestBody, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
var registerData RegisterRequest
|
||||
err = json.Unmarshal(requestBody, ®isterData)
|
||||
if err != nil {
|
||||
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -249,29 +249,29 @@ func (a *API) handleRegister(w http.ResponseWriter, r *http.Request) {
|
||||
if len(registerData.Token) > 0 {
|
||||
workspace, err2 := a.app.GetRootWorkspace()
|
||||
if err2 != nil {
|
||||
a.errorResponse(w, http.StatusInternalServerError, "", err2)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err2)
|
||||
return
|
||||
}
|
||||
|
||||
if registerData.Token != workspace.SignupToken {
|
||||
a.errorResponse(w, http.StatusUnauthorized, "", nil)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusUnauthorized, "invalid token", nil)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
// No signup token, check if no active users
|
||||
userCount, err2 := a.app.GetRegisteredUserCount()
|
||||
if err2 != nil {
|
||||
a.errorResponse(w, http.StatusInternalServerError, "", err2)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err2)
|
||||
return
|
||||
}
|
||||
if userCount > 0 {
|
||||
a.errorResponse(w, http.StatusUnauthorized, "", nil)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusUnauthorized, "no sign-up token and user(s) already exist", nil)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if err = registerData.IsValid(); err != nil {
|
||||
a.errorResponse(w, http.StatusBadRequest, err.Error(), err)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, err.Error(), err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -281,7 +281,7 @@ func (a *API) handleRegister(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
err = a.app.RegisterUser(registerData.Username, registerData.Email, registerData.Password)
|
||||
if err != nil {
|
||||
a.errorResponse(w, http.StatusBadRequest, err.Error(), err)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, err.Error(), err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -325,7 +325,7 @@ func (a *API) handleChangePassword(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
if len(a.singleUserToken) > 0 {
|
||||
// Not permitted in single-user mode
|
||||
a.errorResponse(w, http.StatusUnauthorized, "", nil)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusUnauthorized, "not permitted in single-user mode", nil)
|
||||
return
|
||||
}
|
||||
|
||||
@ -334,18 +334,18 @@ func (a *API) handleChangePassword(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
requestBody, err := ioutil.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
var requestData ChangePasswordRequest
|
||||
if err = json.Unmarshal(requestBody, &requestData); err != nil {
|
||||
a.errorResponse(w, http.StatusInternalServerError, "", err)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = requestData.IsValid(); err != nil {
|
||||
a.errorResponse(w, http.StatusBadRequest, err.Error(), err)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, err.Error(), err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -353,7 +353,7 @@ func (a *API) handleChangePassword(w http.ResponseWriter, r *http.Request) {
|
||||
defer a.audit.LogRecord(audit.LevelAuth, auditRec)
|
||||
|
||||
if err = a.app.ChangePassword(userID, requestData.OldPassword, requestData.NewPassword); err != nil {
|
||||
a.errorResponse(w, http.StatusBadRequest, err.Error(), err)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, err.Error(), err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -372,7 +372,7 @@ func (a *API) attachSession(handler func(w http.ResponseWriter, r *http.Request)
|
||||
a.logger.Debug(`attachSession`, mlog.Bool("single_user", len(a.singleUserToken) > 0))
|
||||
if len(a.singleUserToken) > 0 {
|
||||
if required && (token != a.singleUserToken) {
|
||||
a.errorResponse(w, http.StatusUnauthorized, "", nil)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusUnauthorized, "invalid single user token", nil)
|
||||
return
|
||||
}
|
||||
|
||||
@ -411,7 +411,7 @@ func (a *API) attachSession(handler func(w http.ResponseWriter, r *http.Request)
|
||||
session, err := a.app.GetSession(token)
|
||||
if err != nil {
|
||||
if required {
|
||||
a.errorResponse(w, http.StatusUnauthorized, "", err)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusUnauthorized, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -426,7 +426,7 @@ func (a *API) attachSession(handler func(w http.ResponseWriter, r *http.Request)
|
||||
mlog.String("want", a.authService),
|
||||
mlog.String("got", authService),
|
||||
)
|
||||
a.errorResponse(w, http.StatusUnauthorized, "", err)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusUnauthorized, "", err)
|
||||
return
|
||||
}
|
||||
|
||||
@ -440,7 +440,7 @@ func (a *API) adminRequired(handler func(w http.ResponseWriter, r *http.Request)
|
||||
// Currently, admin APIs require local unix connections
|
||||
conn := GetContextConn(r)
|
||||
if _, isUnix := conn.(*net.UnixConn); !isUnix {
|
||||
a.errorResponse(w, http.StatusUnauthorized, "", nil)
|
||||
a.errorResponse(w, r.URL.Path, http.StatusUnauthorized, "not a local unix connection", nil)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@ require (
|
||||
github.com/gorilla/websocket v1.4.2
|
||||
github.com/lib/pq v1.10.0
|
||||
github.com/magiconair/properties v1.8.5 // indirect
|
||||
github.com/mattermost/logr/v2 v2.0.2
|
||||
github.com/mattermost/logr/v2 v2.0.4
|
||||
github.com/mattermost/mattermost-server/v5 v5.3.2-0.20210524045451-a4f7df6f6e3c
|
||||
github.com/mattn/go-sqlite3 v2.0.3+incompatible
|
||||
github.com/mitchellh/mapstructure v1.4.1 // indirect
|
||||
|
@ -606,8 +606,8 @@ github.com/mattermost/ldap v0.0.0-20201202150706-ee0e6284187d h1:/RJ/UV7M5c7L2TQ
|
||||
github.com/mattermost/ldap v0.0.0-20201202150706-ee0e6284187d/go.mod h1:HLbgMEI5K131jpxGazJ97AxfPDt31osq36YS1oxFQPQ=
|
||||
github.com/mattermost/logr v1.0.13 h1:6F/fM3csvH6Oy5sUpJuW7YyZSzZZAhJm5VcgKMxA2P8=
|
||||
github.com/mattermost/logr v1.0.13/go.mod h1:Mt4DPu1NXMe6JxPdwCC0XBoxXmN9eXOIRPoZarU2PXs=
|
||||
github.com/mattermost/logr/v2 v2.0.2 h1:+TDMWOFKfSmr9CDJqUUJouD+ZoYFhDL7URedKVYhjLg=
|
||||
github.com/mattermost/logr/v2 v2.0.2/go.mod h1:mpPp935r5dIkFDo2y9Q87cQWhFR/4xXpNh0k/y8Hmwg=
|
||||
github.com/mattermost/logr/v2 v2.0.4 h1:LiqvzNNfia23hlu1zmmCDmjqmSfwWNsEtFlL4/7jf8o=
|
||||
github.com/mattermost/logr/v2 v2.0.4/go.mod h1:mpPp935r5dIkFDo2y9Q87cQWhFR/4xXpNh0k/y8Hmwg=
|
||||
github.com/mattermost/mattermost-server/v5 v5.3.2-0.20210524045451-a4f7df6f6e3c h1:p0C9yt6UYyTExEeHjBPBUCwCMAyTWvwAEc2/plNuZL4=
|
||||
github.com/mattermost/mattermost-server/v5 v5.3.2-0.20210524045451-a4f7df6f6e3c/go.mod h1:6CqGEG0Vnhrl23h8LB+lcOIT8KIUhzbJ7qhXlV7Ek9U=
|
||||
github.com/mattermost/rsc v0.0.0-20160330161541-bbaefb05eaa0/go.mod h1:nV5bfVpT//+B1RPD2JvRnxbkLmJEYXmRaaVl15fsXjs=
|
||||
|
@ -281,7 +281,8 @@ func defaultLoggingConfig() string {
|
||||
"delim": " ",
|
||||
"min_level_len": 5,
|
||||
"min_msg_len": 40,
|
||||
"enable_color": true
|
||||
"enable_color": true,
|
||||
"enable_caller": true
|
||||
},
|
||||
"levels": [
|
||||
{"id": 5, "name": "debug"},
|
||||
|
Reference in New Issue
Block a user