Refactor context out of API packages (#8755)
* Refactor context out of API packages * Update function names per feedback * Move webhook handlers to web and fix web tests * Move more webhook tests out of api package * Fix static handler
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
7e7c551987
Коммит
47250c6629
67
api4/handlers.go
Обычный файл
67
api4/handlers.go
Обычный файл
@@ -0,0 +1,67 @@
|
||||
// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved.
|
||||
// See License.txt for license information.
|
||||
|
||||
package api4
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/mattermost/mattermost-server/web"
|
||||
)
|
||||
|
||||
type Context = web.Context
|
||||
|
||||
func (api *API) ApiHandler(h func(*Context, http.ResponseWriter, *http.Request)) http.Handler {
|
||||
return &web.Handler{
|
||||
App: api.App,
|
||||
HandleFunc: h,
|
||||
RequireSession: false,
|
||||
TrustRequester: false,
|
||||
RequireMfa: false,
|
||||
IsStatic: false,
|
||||
}
|
||||
}
|
||||
|
||||
func (api *API) ApiSessionRequired(h func(*Context, http.ResponseWriter, *http.Request)) http.Handler {
|
||||
return &web.Handler{
|
||||
App: api.App,
|
||||
HandleFunc: h,
|
||||
RequireSession: true,
|
||||
TrustRequester: false,
|
||||
RequireMfa: true,
|
||||
IsStatic: false,
|
||||
}
|
||||
}
|
||||
|
||||
func (api *API) ApiSessionRequiredMfa(h func(*Context, http.ResponseWriter, *http.Request)) http.Handler {
|
||||
return &web.Handler{
|
||||
App: api.App,
|
||||
HandleFunc: h,
|
||||
RequireSession: true,
|
||||
TrustRequester: false,
|
||||
RequireMfa: false,
|
||||
IsStatic: false,
|
||||
}
|
||||
}
|
||||
|
||||
func (api *API) ApiHandlerTrustRequester(h func(*Context, http.ResponseWriter, *http.Request)) http.Handler {
|
||||
return &web.Handler{
|
||||
App: api.App,
|
||||
HandleFunc: h,
|
||||
RequireSession: false,
|
||||
TrustRequester: true,
|
||||
RequireMfa: false,
|
||||
IsStatic: false,
|
||||
}
|
||||
}
|
||||
|
||||
func (api *API) ApiSessionRequiredTrustRequester(h func(*Context, http.ResponseWriter, *http.Request)) http.Handler {
|
||||
return &web.Handler{
|
||||
App: api.App,
|
||||
HandleFunc: h,
|
||||
RequireSession: true,
|
||||
TrustRequester: true,
|
||||
RequireMfa: true,
|
||||
IsStatic: false,
|
||||
}
|
||||
}
|
||||
Ссылка в новой задаче
Block a user