diff options
Diffstat (limited to 'modules/context/context.go')
-rw-r--r-- | modules/context/context.go | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/modules/context/context.go b/modules/context/context.go index 3dbc2bb9dc..bed4760322 100644 --- a/modules/context/context.go +++ b/modules/context/context.go @@ -547,6 +547,17 @@ func GetContext(req *http.Request) *Context { return req.Context().Value(contextKey).(*Context) } +// GetContextUser returns context user +func GetContextUser(req *http.Request) *models.User { + if apiContext, ok := req.Context().Value(apiContextKey).(*APIContext); ok { + return apiContext.User + } + if ctx, ok := req.Context().Value(contextKey).(*Context); ok { + return ctx.User + } + return nil +} + // SignedUserName returns signed user's name via context func SignedUserName(req *http.Request) string { if middleware.IsInternalPath(req) { |