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 @@ -587,6 +587,17 @@ func GetContext(req *http.Request) *Context {
587
587
return req .Context ().Value (contextKey ).(* Context )
588
588
}
589
589
590
+ // GetContextUser returns context user
591
+ func GetContextUser (req * http.Request ) * models.User {
592
+ if apiContext , ok := req .Context ().Value (apiContextKey ).(* APIContext ); ok {
593
+ return apiContext .User
594
+ }
595
+ if ctx , ok := req .Context ().Value (contextKey ).(* Context ); ok {
596
+ return ctx .User
597
+ }
598
+ return nil
599
+ }
600
+
590
601
// SignedUserName returns signed user's name via context
591
602
func SignedUserName (req * http.Request ) string {
592
603
if middleware .IsInternalPath (req ) {
Original file line number Diff line number Diff line change @@ -14,7 +14,6 @@ import (
14
14
"path/filepath"
15
15
"strings"
16
16
17
- "code.gitea.io/gitea/models"
18
17
"code.gitea.io/gitea/modules/context"
19
18
"code.gitea.io/gitea/modules/httpcache"
20
19
"code.gitea.io/gitea/modules/log"
@@ -147,15 +146,7 @@ func Recovery() func(next http.Handler) http.Handler {
147
146
"i18n" : lc ,
148
147
}
149
148
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 )
159
150
if user == nil {
160
151
// Get user from session if logged in - do not attempt to sign-in
161
152
user = auth .SessionUser (sessionStore )
You can’t perform that action at this time.
0 commit comments