Skip to content

Commit 4a38adf

Browse files
committed
fix backport
1 parent 46892c0 commit 4a38adf

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

routers/api/v1/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ func reqToken() func(ctx *context.APIContext) {
356356

357357
func reqExploreSignIn() func(ctx *context.APIContext) {
358358
return func(ctx *context.APIContext) {
359-
if (setting.Service.RequireSignInView || setting.Service.Explore.RequireSigninView) && !ctx.IsSigned {
359+
if (setting.Service.RequireSignInViewStrict || setting.Service.Explore.RequireSigninView) && !ctx.IsSigned {
360360
ctx.Error(http.StatusUnauthorized, "reqExploreSignIn", "you must be signed in to search for users")
361361
}
362362
}

routers/common/blockexpensive.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
package common
55

66
import (
7+
"context"
78
"net/http"
89
"strings"
910

1011
user_model "code.gitea.io/gitea/models/user"
11-
"code.gitea.io/gitea/modules/reqctx"
1212
"code.gitea.io/gitea/modules/setting"
1313
"code.gitea.io/gitea/modules/web/middleware"
1414

@@ -21,7 +21,7 @@ func BlockExpensive() func(next http.Handler) http.Handler {
2121
}
2222
return func(next http.Handler) http.Handler {
2323
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
24-
ret := determineRequestPriority(reqctx.FromContext(req.Context()))
24+
ret := determineRequestPriority(req.Context())
2525
if !ret.SignedIn {
2626
if ret.Expensive || ret.LongPolling {
2727
http.Redirect(w, req, setting.AppSubURL+"/user/login", http.StatusSeeOther)
@@ -73,14 +73,15 @@ func isRoutePathForLongPolling(routePattern string) bool {
7373
return routePattern == "/user/events"
7474
}
7575

76-
func determineRequestPriority(reqCtx reqctx.RequestContext) (ret struct {
76+
func determineRequestPriority(ctx context.Context) (ret struct {
7777
SignedIn bool
7878
Expensive bool
7979
LongPolling bool
8080
},
8181
) {
82-
chiRoutePath := chi.RouteContext(reqCtx).RoutePattern()
83-
if _, ok := reqCtx.GetData()[middleware.ContextDataKeySignedUser].(*user_model.User); ok {
82+
dataStore := middleware.GetContextData(ctx)
83+
chiRoutePath := chi.RouteContext(ctx).RoutePattern()
84+
if _, ok := dataStore[middleware.ContextDataKeySignedUser].(*user_model.User); ok {
8485
ret.SignedIn = true
8586
} else {
8687
ret.Expensive = isRoutePathExpensive(chiRoutePath)

tests/integration/api_org_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,9 @@ func TestAPIOrgEditBadVisibility(t *testing.T) {
148148

149149
func TestAPIOrgDeny(t *testing.T) {
150150
onGiteaRun(t, func(*testing.T, *url.URL) {
151-
setting.Service.RequireSignInView = true
151+
setting.Service.RequireSignInViewStrict = true
152152
defer func() {
153-
setting.Service.RequireSignInView = false
153+
setting.Service.RequireSignInViewStrict = false
154154
}()
155155

156156
orgName := "user1_org"

tests/integration/signin_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121

2222
"github.com/markbates/goth"
2323
"github.com/stretchr/testify/assert"
24+
"github.com/stretchr/testify/require"
2425
)
2526

2627
func testLoginFailed(t *testing.T, username, password, message string) {

0 commit comments

Comments
 (0)