diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2021-09-28 21:13:04 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-28 21:13:04 +0800 |
commit | 37b29319aaab085001def4bc33b690c9a7a8eb19 (patch) | |
tree | cdefb2a16aa2faf2d2e359eb9ea7048c6727d234 /modules/context | |
parent | a82c799fc81cc9d2611aa9b27d531ee4a23152b3 (diff) | |
download | gitea-37b29319aaab085001def4bc33b690c9a7a8eb19.tar.gz gitea-37b29319aaab085001def4bc33b690c9a7a8eb19.zip |
Fix bug of get context user (#17169)
Co-authored-by: 6543 <6543@obermui.de>
Diffstat (limited to 'modules/context')
-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) { |