File tree Expand file tree Collapse file tree 2 files changed +12
-10
lines changed Expand file tree Collapse file tree 2 files changed +12
-10
lines changed Original file line number Diff line number Diff line change @@ -547,6 +547,17 @@ func GetContext(req *http.Request) *Context {
547547 return req .Context ().Value (contextKey ).(* Context )
548548}
549549
550+ // GetContextUser returns context user
551+ func GetContextUser (req * http.Request ) * models.User {
552+ if apiContext , ok := req .Context ().Value (apiContextKey ).(* APIContext ); ok {
553+ return apiContext .User
554+ }
555+ if ctx , ok := req .Context ().Value (contextKey ).(* Context ); ok {
556+ return ctx .User
557+ }
558+ return nil
559+ }
560+
550561// SignedUserName returns signed user's name via context
551562func SignedUserName (req * http.Request ) string {
552563 if middleware .IsInternalPath (req ) {
Original file line number Diff line number Diff line change @@ -14,7 +14,6 @@ import (
1414 "path/filepath"
1515 "strings"
1616
17- "code.gitea.io/gitea/models"
1817 "code.gitea.io/gitea/modules/context"
1918 "code.gitea.io/gitea/modules/httpcache"
2019 "code.gitea.io/gitea/modules/log"
@@ -147,15 +146,7 @@ func Recovery() func(next http.Handler) http.Handler {
147146 "i18n" : lc ,
148147 }
149148
150- var user * models.User
151- if apiContext := context .GetAPIContext (req ); apiContext != nil {
152- user = apiContext .User
153- }
154- if user == nil {
155- if ctx := context .GetContext (req ); ctx != nil {
156- user = ctx .User
157- }
158- }
149+ var user = context .GetContextUser (req )
159150 if user == nil {
160151 // Get user from session if logged in - do not attempt to sign-in
161152 user = auth .SessionUser (sessionStore )
You can’t perform that action at this time.
0 commit comments