summaryrefslogtreecommitdiffstats
path: root/api4/handlers.go
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2018-05-14 10:24:58 -0400
committerGitHub <noreply@github.com>2018-05-14 10:24:58 -0400
commit47250c6629416b628a19e5571ac89f7b4646418c (patch)
tree0ccfd50e06af7293e0f9e27c2d1c1200efa78a6a /api4/handlers.go
parent7e7c55198719337e7cb39b07c0d5a48c0a6908de (diff)
downloadchat-47250c6629416b628a19e5571ac89f7b4646418c.tar.gz
chat-47250c6629416b628a19e5571ac89f7b4646418c.tar.bz2
chat-47250c6629416b628a19e5571ac89f7b4646418c.zip
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
Diffstat (limited to 'api4/handlers.go')
-rw-r--r--api4/handlers.go67
1 files changed, 67 insertions, 0 deletions
diff --git a/api4/handlers.go b/api4/handlers.go
new file mode 100644
index 000000000..74e2fc88d
--- /dev/null
+++ b/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,
+ }
+}