File tree 2 files changed +12
-10
lines changed 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 {
547
547
return req .Context ().Value (contextKey ).(* Context )
548
548
}
549
549
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
+
550
561
// SignedUserName returns signed user's name via context
551
562
func SignedUserName (req * http.Request ) string {
552
563
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